forked from D-Net/dnet-hadoop
[bulk tag] fixed Community configuration parsing to void NPE
This commit is contained in:
parent
062abfd669
commit
cd1b58483e
|
@ -90,12 +90,12 @@ public class CommunityConfigurationFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SelectionConstraints parseConstrains(Node node) {
|
private static SelectionConstraints parseConstrains(Node node) {
|
||||||
Node aconstraints = node.selectSingleNode("./advancedConstraints");
|
Node advConstsNode = node.selectSingleNode("./advancedConstraints");
|
||||||
if (aconstraints == null) {
|
if (advConstsNode == null || StringUtils.isBlank(StringUtils.trim(advConstsNode.getText()))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
SelectionConstraints selectionConstraints = new Gson()
|
SelectionConstraints selectionConstraints = new Gson()
|
||||||
.fromJson(aconstraints.getText(), SelectionConstraints.class);
|
.fromJson(advConstsNode.getText(), SelectionConstraints.class);
|
||||||
|
|
||||||
selectionConstraints.setSelection(resolver);
|
selectionConstraints.setSelection(resolver);
|
||||||
return selectionConstraints;
|
return selectionConstraints;
|
||||||
|
|
|
@ -83,4 +83,36 @@ class CommunityConfigurationFactoryTest {
|
||||||
Assertions.assertEquals("dariah", comm.get(0));
|
Assertions.assertEquals("dariah", comm.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void loadSelCriteriaTest2() throws DocumentException, IOException, SAXException {
|
||||||
|
String xml = IOUtils
|
||||||
|
.toString(
|
||||||
|
getClass()
|
||||||
|
.getResourceAsStream(
|
||||||
|
"/eu/dnetlib/dhp/bulktag/communityconfiguration/community_configuration_selcrit2.xml"));
|
||||||
|
final CommunityConfiguration cc = CommunityConfigurationFactory.newInstance(xml);
|
||||||
|
Map<String, List<String>> param = new HashMap<>();
|
||||||
|
param.put("author", new ArrayList<>(Collections.singletonList("Pippo Pippi")));
|
||||||
|
param
|
||||||
|
.put(
|
||||||
|
"description",
|
||||||
|
new ArrayList<>(
|
||||||
|
Collections
|
||||||
|
.singletonList(
|
||||||
|
"This work has been partially supported by DARIAH-EU infrastructure")));
|
||||||
|
param
|
||||||
|
.put(
|
||||||
|
"contributor",
|
||||||
|
new ArrayList<>(
|
||||||
|
Collections
|
||||||
|
.singletonList(
|
||||||
|
"Author X helped to write the paper. X works for DARIAH")));
|
||||||
|
List<String> comm = cc
|
||||||
|
.getCommunityForDatasource(
|
||||||
|
"openaire____::1cfdb2e14977f31a98e0118283401f32", param);
|
||||||
|
|
||||||
|
//TODO add more assertions
|
||||||
|
Assertions.assertEquals(0, comm.size());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue