Change to EditN3Generator that will effect how all null and empty values get substituted into N3 on front end edits. NIHVIVO-3400
This commit is contained in:
parent
c833f5d76c
commit
d4e2ea9ebc
2 changed files with 45 additions and 3 deletions
|
@ -52,10 +52,22 @@ public class EditN3GeneratorVTwo {
|
||||||
continue;
|
continue;
|
||||||
Set<String> keySet = varsToVals.keySet();
|
Set<String> keySet = varsToVals.keySet();
|
||||||
for (String key : keySet) {
|
for (String key : keySet) {
|
||||||
List<String> value = varsToVals.get(key);
|
List<String> values = varsToVals.get(key);
|
||||||
log.debug("The original value String is " + value.toString());
|
if( values == null ){
|
||||||
|
log.debug("skipping var " + key + " because value List is null");
|
||||||
|
continue;
|
||||||
|
}else if( containsNullOrEmpty( values )){
|
||||||
|
|
||||||
|
//bdc34: what should we do if the list contains nulls or empty strings?
|
||||||
|
//for now we just skip the whole key/var.
|
||||||
|
//Maybe it would be useful to strip the nulls+empties out of the list?
|
||||||
|
|
||||||
|
log.debug("skipping var " + key + " because it contains nulls or empty strings");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
log.debug("The original value String is " + values.toString());
|
||||||
|
|
||||||
String valueString = org.apache.commons.lang.StringUtils.join(value,
|
String valueString = org.apache.commons.lang.StringUtils.join(values,
|
||||||
">, <");
|
">, <");
|
||||||
valueString = "<" + valueString + ">";
|
valueString = "<" + valueString + ">";
|
||||||
log.debug("The multiUri value String is " + valueString);
|
log.debug("The multiUri value String is " + valueString);
|
||||||
|
@ -66,6 +78,10 @@ public class EditN3GeneratorVTwo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean containsNullOrEmpty(List<String> values) {
|
||||||
|
return values != null && ( values.contains(null) || values.contains("") );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The List targets will be modified.
|
* The List targets will be modified.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -154,8 +154,34 @@ public class EditN3GeneratorVTwoTest {
|
||||||
|
|
||||||
String not_expected = "<null>";
|
String not_expected = "<null>";
|
||||||
Assert.assertTrue("must not sub in <null>", !not_expected.equals(resultN3));
|
Assert.assertTrue("must not sub in <null>", !not_expected.equals(resultN3));
|
||||||
|
|
||||||
|
not_expected = "<>";
|
||||||
|
Assert.assertTrue("must not sub in <>", !not_expected.equals(resultN3));
|
||||||
|
|
||||||
|
Assert.assertEquals("?varXYZ", resultN3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSubInMultiUrisEmptyString(){
|
||||||
|
String n3 = "?varXYZ" ;
|
||||||
|
List<String> targets = new ArrayList<String>();
|
||||||
|
targets.add(n3);
|
||||||
|
|
||||||
|
Map<String,List<String>> keyToValues = new HashMap<String,List<String>>();
|
||||||
|
List<String> targetValue = new ArrayList<String>();
|
||||||
|
targetValue.add("");
|
||||||
|
keyToValues.put("varXYZ", targetValue);
|
||||||
|
|
||||||
|
gen.subInMultiUris(keyToValues, targets);
|
||||||
|
Assert.assertNotNull(targets);
|
||||||
|
Assert.assertEquals(1,targets.size());
|
||||||
|
|
||||||
|
String resultN3 = targets.get(0);
|
||||||
|
Assert.assertNotNull(resultN3);
|
||||||
|
Assert.assertTrue("String was empty", !resultN3.isEmpty());
|
||||||
|
|
||||||
|
Assert.assertEquals("?varXYZ", resultN3);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSubInUrisNull(){
|
public void testSubInUrisNull(){
|
||||||
|
|
Loading…
Add table
Reference in a new issue