From e431fe4f5bf8762ed217b044d6d0de974f230f49 Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Thu, 23 Apr 2020 11:48:47 +0200 Subject: [PATCH] added the implements Serializable to each class --- .../CommunityConfigurationFactory.java | 47 ++++------ .../eu/dnetlib/dhp/community/Constraint.java | 25 ++--- .../eu/dnetlib/dhp/community/Constraints.java | 40 +++----- .../dhp/community/QueryInformationSystem.java | 92 +++++++++---------- .../dnetlib/dhp/community/ResultTagger.java | 15 ++- .../dhp/community/SelectionConstraints.java | 23 ++--- .../dhp/selectioncriteria/ContainsVerb.java | 9 +- .../dhp/selectioncriteria/EqualVerb.java | 9 +- .../selectioncriteria/InterfaceAdapter.java | 17 ++-- .../selectioncriteria/NotContainsVerb.java | 9 +- .../dhp/selectioncriteria/NotEqualVerb.java | 9 +- .../dhp/selectioncriteria/Selection.java | 2 +- .../dhp/selectioncriteria/VerbResolver.java | 46 ++++++++-- .../VerbResolverFactory.java | 5 +- 14 files changed, 173 insertions(+), 175 deletions(-) diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/CommunityConfigurationFactory.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/CommunityConfigurationFactory.java index 772aea51d..866ec28a1 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/CommunityConfigurationFactory.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/CommunityConfigurationFactory.java @@ -4,11 +4,14 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import eu.dnetlib.dhp.selectioncriteria.InterfaceAdapter; import eu.dnetlib.dhp.selectioncriteria.Selection; import eu.dnetlib.dhp.selectioncriteria.VerbResolver; import eu.dnetlib.dhp.selectioncriteria.VerbResolverFactory; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -17,15 +20,7 @@ import org.dom4j.DocumentException; import org.dom4j.Node; import org.dom4j.io.SAXReader; - -import java.io.StringReader; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * Created by miriam on 03/08/2018. - */ +/** Created by miriam on 03/08/2018. */ public class CommunityConfigurationFactory { private static final Log log = LogFactory.getLog(CommunityConfigurationFactory.class); @@ -38,9 +33,9 @@ public class CommunityConfigurationFactory { final Document doc = new SAXReader().read(new StringReader(xml)); - final Map communities = Maps.newHashMap(); + final Map communities = Maps.newHashMap(); - for(final Object o : doc.selectNodes("//community")) { + for (final Object o : doc.selectNodes("//community")) { final Node node = (Node) o; @@ -54,8 +49,7 @@ public class CommunityConfigurationFactory { log.info(String.format("loaded %s community configuration profiles", communities.size())); log.debug(String.format("loaded community configuration:\n%s", communities.toString())); - - return new CommunityConfiguration(communities); + return new CommunityConfiguration(communities); } public static CommunityConfiguration fromJson(final String json) { @@ -88,9 +82,9 @@ public class CommunityConfigurationFactory { final List subjects = Lists.newArrayList(); - final List list = node.selectNodes("./subjects/subject"); + final List list = node.selectNodes("./subjects/subject"); - for(Node n : list){ + for (Node n : list) { log.debug("text of the node " + n.getText()); subjects.add(StringUtils.trim(n.getText())); } @@ -98,11 +92,10 @@ public class CommunityConfigurationFactory { return subjects; } - private static List parseDatasources(final Node node) { - final List list = node.selectNodes("./datasources/datasource"); + final List list = node.selectNodes("./datasources/datasource"); final List datasourceList = new ArrayList<>(); - for(Node n : list){ + for (Node n : list) { Datasource d = new Datasource(); d.setOpenaireId(n.selectSingleNode("./openaireId").getText()); d.setSelCriteria(n.selectSingleNode("./selcriteria"), resolver); @@ -115,23 +108,21 @@ public class CommunityConfigurationFactory { private static List parseZenodoCommunities(final Node node) { final Node oacommunitynode = node.selectSingleNode("./oacommunity"); String oacommunity = null; - if (oacommunitynode != null){ + if (oacommunitynode != null) { String tmp = oacommunitynode.getText(); - if(StringUtils.isNotBlank(tmp)) - oacommunity = tmp; + if (StringUtils.isNotBlank(tmp)) oacommunity = tmp; } - final List list = node.selectNodes("./zenodocommunities/zenodocommunity"); final List zenodoCommunityList = new ArrayList<>(); - for(Node n : list){ + for (Node n : list) { ZenodoCommunity zc = new ZenodoCommunity(); zc.setZenodoCommunityId(n.selectSingleNode("./zenodoid").getText()); zc.setSelCriteria(n.selectSingleNode("./selcriteria")); zenodoCommunityList.add(zc); } - if(oacommunity != null){ + if (oacommunity != null) { ZenodoCommunity zc = new ZenodoCommunity(); zc.setZenodoCommunityId(oacommunity); zenodoCommunityList.add(zc); @@ -139,8 +130,4 @@ public class CommunityConfigurationFactory { log.info("size of the zenodo community list " + zenodoCommunityList.size()); return zenodoCommunityList; } - - - - -} \ No newline at end of file +} diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/Constraint.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/Constraint.java index 271493ca8..491f3de05 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/Constraint.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/Constraint.java @@ -1,22 +1,17 @@ package eu.dnetlib.dhp.community; - - import eu.dnetlib.dhp.selectioncriteria.Selection; import eu.dnetlib.dhp.selectioncriteria.VerbResolver; - import java.io.Serializable; import java.lang.reflect.InvocationTargetException; - public class Constraint implements Serializable { private String verb; private String field; private String value; private Selection selection; - public Constraint() { - } + public Constraint() {} public String getVerb() { return verb; @@ -42,21 +37,17 @@ public class Constraint implements Serializable { this.value = value; } - - - public void setSelection(Selection sel){ + public void setSelection(Selection sel) { selection = sel; } - public void setSelection(VerbResolver resolver) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { - selection = resolver.getSelectionCriteria(verb,value); + public void setSelection(VerbResolver resolver) + throws InvocationTargetException, NoSuchMethodException, InstantiationException, + IllegalAccessException { + selection = resolver.getSelectionCriteria(verb, value); } - - public boolean verifyCriteria(String metadata){ + public boolean verifyCriteria(String metadata) { return selection.apply(metadata); } - - - -} \ No newline at end of file +} diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/Constraints.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/Constraints.java index a33f993f0..9b2974c27 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/Constraints.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/Constraints.java @@ -1,32 +1,25 @@ package eu.dnetlib.dhp.community; - import com.google.gson.Gson; - import com.google.gson.reflect.TypeToken; import eu.dnetlib.dhp.selectioncriteria.VerbResolver; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - - import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Type; import java.util.Collection; import java.util.List; import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; -/** - * Created by miriam on 02/08/2018. - */ +/** Created by miriam on 02/08/2018. */ public class Constraints implements Serializable { private static final Log log = LogFactory.getLog(Constraints.class); - //private ConstraintEncapsulator ce; + // private ConstraintEncapsulator ce; private List constraint; + public Constraints() {} - public Constraints() { - } public List getConstraint() { return constraint; } @@ -35,14 +28,13 @@ public class Constraints implements Serializable { this.constraint = constraint; } - public void setSc(String json){ - Type collectionType = new TypeToken>(){}.getType(); + public void setSc(String json) { + Type collectionType = new TypeToken>() {}.getType(); constraint = new Gson().fromJson(json, collectionType); - } void setSelection(VerbResolver resolver) { - for(Constraint st: constraint){ + for (Constraint st : constraint) { try { st.setSelection(resolver); @@ -56,24 +48,20 @@ public class Constraints implements Serializable { log.error(e.getMessage()); } } - } - - //Constraint in and + // Constraint in and public boolean verifyCriteria(final Map> param) { - for(Constraint sc : constraint) { + for (Constraint sc : constraint) { boolean verified = false; - for(String value : param.get(sc.getField())){ - if (sc.verifyCriteria(value.trim())){ + for (String value : param.get(sc.getField())) { + if (sc.verifyCriteria(value.trim())) { verified = true; } } - if(!verified) - return verified; + if (!verified) return verified; } return true; } - -} \ No newline at end of file +} diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/QueryInformationSystem.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/QueryInformationSystem.java index 00edf7fdc..7dd9339ef 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/QueryInformationSystem.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/QueryInformationSystem.java @@ -4,63 +4,59 @@ import com.google.common.base.Joiner; import eu.dnetlib.dhp.utils.ISLookupClientFactory; import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; +import java.util.List; import org.dom4j.DocumentException; -import java.util.List; - - public class QueryInformationSystem { - private static final String XQUERY = "for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') " + - " let $subj := $x//CONFIGURATION/context/param[./@name='subject']/text() " + - " let $datasources := $x//CONFIGURATION/context/category[./@id=concat($x//CONFIGURATION/context/@id,'::contentproviders')]/concept " + - " let $organizations := $x//CONFIGURATION/context/category[./@id=concat($x//CONFIGURATION/context/@id,'::resultorganizations')]/concept " + - " let $communities := $x//CONFIGURATION/context/category[./@id=concat($x//CONFIGURATION/context/@id,'::zenodocommunities')]/concept " + - " where $x//CONFIGURATION/context[./@type='community' or ./@type='ri'] " + - " return " + - " " + - " { $x//CONFIGURATION/context/@id} " + - " " + - " {for $y in tokenize($subj,',') " + - " return " + - " {$y}} " + - " " + - " " + - " {for $d in $datasources " + - " where $d/param[./@name='enabled']/text()='true' " + - " return " + - " " + - " " + - " {$d//param[./@name='openaireId']/text()} " + - " " + - " " + - " {$d/param[./@name='selcriteria']/text()} " + - " " + - " } " + - " " + - " " + - " {for $zc in $communities " + - " return " + - " " + - " " + - " {$zc/param[./@name='zenodoid']/text()} " + - " " + - " " + - " {$zc/param[./@name='selcriteria']/text()} " + - " " + - " } " + - " " + - " "; + private static final String XQUERY = + "for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') " + + " let $subj := $x//CONFIGURATION/context/param[./@name='subject']/text() " + + " let $datasources := $x//CONFIGURATION/context/category[./@id=concat($x//CONFIGURATION/context/@id,'::contentproviders')]/concept " + + " let $organizations := $x//CONFIGURATION/context/category[./@id=concat($x//CONFIGURATION/context/@id,'::resultorganizations')]/concept " + + " let $communities := $x//CONFIGURATION/context/category[./@id=concat($x//CONFIGURATION/context/@id,'::zenodocommunities')]/concept " + + " where $x//CONFIGURATION/context[./@type='community' or ./@type='ri'] " + + " return " + + " " + + " { $x//CONFIGURATION/context/@id} " + + " " + + " {for $y in tokenize($subj,',') " + + " return " + + " {$y}} " + + " " + + " " + + " {for $d in $datasources " + + " where $d/param[./@name='enabled']/text()='true' " + + " return " + + " " + + " " + + " {$d//param[./@name='openaireId']/text()} " + + " " + + " " + + " {$d/param[./@name='selcriteria']/text()} " + + " " + + " } " + + " " + + " " + + " {for $zc in $communities " + + " return " + + " " + + " " + + " {$zc/param[./@name='zenodoid']/text()} " + + " " + + " " + + " {$zc/param[./@name='selcriteria']/text()} " + + " " + + " } " + + " " + + " "; - public static CommunityConfiguration getCommunityConfiguration(final String isLookupUrl) throws ISLookUpException, DocumentException { + public static CommunityConfiguration getCommunityConfiguration(final String isLookupUrl) + throws ISLookUpException, DocumentException { ISLookUpService isLookUp = ISLookupClientFactory.getLookUpService(isLookupUrl); final List res = isLookUp.quickSearchProfile(XQUERY); final String xmlConf = "" + Joiner.on(" ").join(res) + ""; - return CommunityConfigurationFactory.newInstance(xmlConf); - } - - } diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/ResultTagger.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/ResultTagger.java index abedab476..4e58bb1a2 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/ResultTagger.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/ResultTagger.java @@ -56,7 +56,8 @@ public class ResultTagger implements Serializable { // Verify if the entity is deletedbyinference. In case verify if to clean the context list // from all the zenodo communities if (result.getDataInfo().getDeletedbyinference()) { - if (clearContext(result)) return result; + clearContext(result); + return result; } // communities contains all the communities to be added as context for the result @@ -118,7 +119,15 @@ public class ResultTagger implements Serializable { .map( c -> { if (communities.contains(c.getId())) { - List dataInfoList = c.getDataInfo(); + Optional> opt_dataInfoList = + Optional.ofNullable(c.getDataInfo()); + List dataInfoList; + if (opt_dataInfoList.isPresent()) + dataInfoList = opt_dataInfoList.get(); + else { + dataInfoList = new ArrayList<>(); + c.setDataInfo(dataInfoList); + } if (subjects.contains(c.getId())) dataInfoList.add( getDataInfo( @@ -153,7 +162,7 @@ public class ResultTagger implements Serializable { c -> { Context context = new Context(); context.setId(c); - List dataInfoList = Arrays.asList(); + List dataInfoList = new ArrayList<>(); if (subjects.contains(c)) dataInfoList.add( getDataInfo( diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/SelectionConstraints.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/SelectionConstraints.java index 2c09ecaf1..530861425 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/SelectionConstraints.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/community/SelectionConstraints.java @@ -3,8 +3,6 @@ package eu.dnetlib.dhp.community; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import eu.dnetlib.dhp.selectioncriteria.VerbResolver; - - import java.io.Serializable; import java.lang.reflect.Type; import java.util.Collection; @@ -14,9 +12,7 @@ import java.util.Map; public class SelectionConstraints implements Serializable { private List criteria; - public SelectionConstraints() { - } - + public SelectionConstraints() {} public List getCriteria() { return criteria; @@ -26,24 +22,25 @@ public class SelectionConstraints implements Serializable { this.criteria = criteria; } - public void setSc(String json){ - Type collectionType = new TypeToken>(){}.getType(); + public void setSc(String json) { + Type collectionType = new TypeToken>() {}.getType(); criteria = new Gson().fromJson(json, collectionType); } - //Constraints in or - public boolean verifyCriteria(final Map> param){ - for(Constraints selc : criteria) { - if(selc.verifyCriteria(param)){ + // Constraints in or + public boolean verifyCriteria(final Map> param) { + for (Constraints selc : criteria) { + if (selc.verifyCriteria(param)) { return true; } } return false; } + public void setSelection(VerbResolver resolver) { - for(Constraints cs : criteria){ + for (Constraints cs : criteria) { cs.setSelection(resolver); } } -} \ No newline at end of file +} diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/ContainsVerb.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/ContainsVerb.java index eb7f059d8..fc6456a8c 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/ContainsVerb.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/ContainsVerb.java @@ -1,12 +1,13 @@ package eu.dnetlib.dhp.selectioncriteria; +import java.io.Serializable; + @VerbClass("contains") -public class ContainsVerb implements Selection { +public class ContainsVerb implements Selection, Serializable { private String param; - public ContainsVerb() { - } + public ContainsVerb() {} public ContainsVerb(final String param) { this.param = param; @@ -24,4 +25,4 @@ public class ContainsVerb implements Selection { public void setParam(String param) { this.param = param; } -} \ No newline at end of file +} diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/EqualVerb.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/EqualVerb.java index 9b35e9583..32171001e 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/EqualVerb.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/EqualVerb.java @@ -1,19 +1,18 @@ package eu.dnetlib.dhp.selectioncriteria; +import java.io.Serializable; @VerbClass("equals") -public class EqualVerb implements Selection { +public class EqualVerb implements Selection, Serializable { private String param; - public EqualVerb() { - } + public EqualVerb() {} public EqualVerb(final String param) { this.param = param; } - @Override public boolean apply(String value) { return value.equalsIgnoreCase(param); @@ -26,4 +25,4 @@ public class EqualVerb implements Selection { public void setParam(String param) { this.param = param; } -} \ No newline at end of file +} diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/InterfaceAdapter.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/InterfaceAdapter.java index 7cd261b85..a4a1494b3 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/InterfaceAdapter.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/InterfaceAdapter.java @@ -1,7 +1,6 @@ package eu.dnetlib.dhp.selectioncriteria; import com.google.gson.*; - import java.lang.reflect.Type; public class InterfaceAdapter implements JsonSerializer, JsonDeserializer { @@ -9,8 +8,11 @@ public class InterfaceAdapter implements JsonSerializer, JsonDeserializer { private static final String CLASSNAME = "CLASSNAME"; private static final String DATA = "DATA"; - public Object deserialize(JsonElement jsonElement, Type type, - JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + public Object deserialize( + JsonElement jsonElement, + Type type, + JsonDeserializationContext jsonDeserializationContext) + throws JsonParseException { JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonPrimitive prim = (JsonPrimitive) jsonObject.get(CLASSNAME); @@ -18,20 +20,21 @@ public class InterfaceAdapter implements JsonSerializer, JsonDeserializer { Class klass = getObjectClass(className); return jsonDeserializationContext.deserialize(jsonObject.get(DATA), klass); } - public JsonElement serialize(Object jsonElement, Type type, JsonSerializationContext jsonSerializationContext) { + + public JsonElement serialize( + Object jsonElement, Type type, JsonSerializationContext jsonSerializationContext) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(CLASSNAME, jsonElement.getClass().getName()); jsonObject.add(DATA, jsonSerializationContext.serialize(jsonElement)); return jsonObject; } - /****** Helper method to get the className of the object to be deserialized *****/ + /** **** Helper method to get the className of the object to be deserialized **** */ public Class getObjectClass(String className) { try { return Class.forName(className); } catch (ClassNotFoundException e) { - //e.printStackTrace(); + // e.printStackTrace(); throw new JsonParseException(e.getMessage()); } } } - diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/NotContainsVerb.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/NotContainsVerb.java index ecfabd7de..f07540d35 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/NotContainsVerb.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/NotContainsVerb.java @@ -1,12 +1,13 @@ package eu.dnetlib.dhp.selectioncriteria; +import java.io.Serializable; + @VerbClass("not_contains") -public class NotContainsVerb implements Selection { +public class NotContainsVerb implements Selection, Serializable { private String param; - public NotContainsVerb() { - } + public NotContainsVerb() {} public NotContainsVerb(final String param) { this.param = param; @@ -24,4 +25,4 @@ public class NotContainsVerb implements Selection { public void setParam(String param) { this.param = param; } -} \ No newline at end of file +} diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/NotEqualVerb.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/NotEqualVerb.java index c2c9e73ad..d1716588e 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/NotEqualVerb.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/NotEqualVerb.java @@ -1,18 +1,17 @@ package eu.dnetlib.dhp.selectioncriteria; +import java.io.Serializable; @VerbClass("not_equals") -public class NotEqualVerb implements Selection { +public class NotEqualVerb implements Selection, Serializable { private String param; - public NotEqualVerb(final String param) { this.param = param; } - public NotEqualVerb() { - } + public NotEqualVerb() {} public String getParam() { return param; @@ -26,4 +25,4 @@ public class NotEqualVerb implements Selection { public boolean apply(String value) { return !value.equalsIgnoreCase(param); } -} \ No newline at end of file +} diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/Selection.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/Selection.java index cd9888a7e..c9b30790f 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/Selection.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/Selection.java @@ -3,4 +3,4 @@ package eu.dnetlib.dhp.selectioncriteria; public interface Selection { boolean apply(String value); -} \ No newline at end of file +} diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/VerbResolver.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/VerbResolver.java index f6d5394e3..c2a9b4544 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/VerbResolver.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/VerbResolver.java @@ -1,29 +1,57 @@ package eu.dnetlib.dhp.selectioncriteria; +import io.github.classgraph.ClassGraph; +import io.github.classgraph.ClassInfo; +import io.github.classgraph.ClassInfoList; +import io.github.classgraph.ScanResult; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.util.Map; import java.util.stream.Collectors; -import org.reflections.Reflections; public class VerbResolver implements Serializable { - private final Map> map; + private Map> map = null; // = new HashMap<>(); + private final ClassGraph classgraph = new ClassGraph(); public VerbResolver() { - this.map = - new Reflections("eu.dnetlib") - .getTypesAnnotatedWith(VerbClass.class).stream() - .collect( - Collectors.toMap( - v -> v.getAnnotation(VerbClass.class).value(), - v -> (Class) v)); + try (ScanResult scanResult = // Assign scanResult in try-with-resources + classgraph // Create a new ClassGraph instance + .verbose() // If you want to enable logging to stderr + .enableAllInfo() // Scan classes, methods, fields, annotations + .whitelistPackages( + "eu.dnetlib.dhp.selectioncriteria") // Scan com.xyz and subpackages + .scan()) { // Perform the scan and return a ScanResult + + ClassInfoList routeClassInfoList = + scanResult.getClassesWithAnnotation( + "eu.dnetlib.dhp.selectioncriteria.VerbClass"); + + this.map = + routeClassInfoList.stream() + .collect( + Collectors.toMap( + value -> + (String) + ((ClassInfo) value) + .getAnnotationInfo() + .get(0) + .getParameterValues() + .get(0) + .getValue(), + value -> + (Class) + ((ClassInfo) value).loadClass())); + } catch (Exception e) { + e.printStackTrace(); + } } public Selection getSelectionCriteria(String name, String param) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { + // return Class.forName(tmp_map.get(name)). return map.get(name).getDeclaredConstructor((String.class)).newInstance(param); } } diff --git a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/VerbResolverFactory.java b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/VerbResolverFactory.java index 8879e2d3b..c878c7f58 100644 --- a/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/VerbResolverFactory.java +++ b/dhp-workflows/dhp-bulktag/src/main/java/eu/dnetlib/dhp/selectioncriteria/VerbResolverFactory.java @@ -2,9 +2,8 @@ package eu.dnetlib.dhp.selectioncriteria; public class VerbResolverFactory { - public static VerbResolver newInstance(){ + public static VerbResolver newInstance() { return new VerbResolver(); } - -} \ No newline at end of file +}