[bulk tag] fixed Community configuration parsing to void NPE

This commit is contained in:
Claudio Atzori 2022-12-07 10:38:42 +01:00
parent 062abfd669
commit cd1b58483e
3 changed files with 4494 additions and 3 deletions

View File

@ -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;

View File

@ -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());
}
} }