forked from D-Net/dnet-hadoop
added the implements Serializable to each class
This commit is contained in:
parent
24fa81d7e8
commit
e431fe4f5b
|
@ -4,11 +4,14 @@ import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
import eu.dnetlib.dhp.selectioncriteria.InterfaceAdapter;
|
import eu.dnetlib.dhp.selectioncriteria.InterfaceAdapter;
|
||||||
import eu.dnetlib.dhp.selectioncriteria.Selection;
|
import eu.dnetlib.dhp.selectioncriteria.Selection;
|
||||||
import eu.dnetlib.dhp.selectioncriteria.VerbResolver;
|
import eu.dnetlib.dhp.selectioncriteria.VerbResolver;
|
||||||
import eu.dnetlib.dhp.selectioncriteria.VerbResolverFactory;
|
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.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -17,15 +20,7 @@ import org.dom4j.DocumentException;
|
||||||
import org.dom4j.Node;
|
import org.dom4j.Node;
|
||||||
import org.dom4j.io.SAXReader;
|
import org.dom4j.io.SAXReader;
|
||||||
|
|
||||||
|
/** Created by miriam on 03/08/2018. */
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by miriam on 03/08/2018.
|
|
||||||
*/
|
|
||||||
public class CommunityConfigurationFactory {
|
public class CommunityConfigurationFactory {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(CommunityConfigurationFactory.class);
|
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 Document doc = new SAXReader().read(new StringReader(xml));
|
||||||
|
|
||||||
final Map<String,Community> communities = Maps.newHashMap();
|
final Map<String, Community> communities = Maps.newHashMap();
|
||||||
|
|
||||||
for(final Object o : doc.selectNodes("//community")) {
|
for (final Object o : doc.selectNodes("//community")) {
|
||||||
|
|
||||||
final Node node = (Node) o;
|
final Node node = (Node) o;
|
||||||
|
|
||||||
|
@ -54,8 +49,7 @@ public class CommunityConfigurationFactory {
|
||||||
log.info(String.format("loaded %s community configuration profiles", communities.size()));
|
log.info(String.format("loaded %s community configuration profiles", communities.size()));
|
||||||
log.debug(String.format("loaded community configuration:\n%s", communities.toString()));
|
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) {
|
public static CommunityConfiguration fromJson(final String json) {
|
||||||
|
@ -88,9 +82,9 @@ public class CommunityConfigurationFactory {
|
||||||
|
|
||||||
final List<String> subjects = Lists.newArrayList();
|
final List<String> subjects = Lists.newArrayList();
|
||||||
|
|
||||||
final List <Node> list = node.selectNodes("./subjects/subject");
|
final List<Node> list = node.selectNodes("./subjects/subject");
|
||||||
|
|
||||||
for(Node n : list){
|
for (Node n : list) {
|
||||||
log.debug("text of the node " + n.getText());
|
log.debug("text of the node " + n.getText());
|
||||||
subjects.add(StringUtils.trim(n.getText()));
|
subjects.add(StringUtils.trim(n.getText()));
|
||||||
}
|
}
|
||||||
|
@ -98,11 +92,10 @@ public class CommunityConfigurationFactory {
|
||||||
return subjects;
|
return subjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static List<Datasource> parseDatasources(final Node node) {
|
private static List<Datasource> parseDatasources(final Node node) {
|
||||||
final List <Node> list = node.selectNodes("./datasources/datasource");
|
final List<Node> list = node.selectNodes("./datasources/datasource");
|
||||||
final List<Datasource> datasourceList = new ArrayList<>();
|
final List<Datasource> datasourceList = new ArrayList<>();
|
||||||
for(Node n : list){
|
for (Node n : list) {
|
||||||
Datasource d = new Datasource();
|
Datasource d = new Datasource();
|
||||||
d.setOpenaireId(n.selectSingleNode("./openaireId").getText());
|
d.setOpenaireId(n.selectSingleNode("./openaireId").getText());
|
||||||
d.setSelCriteria(n.selectSingleNode("./selcriteria"), resolver);
|
d.setSelCriteria(n.selectSingleNode("./selcriteria"), resolver);
|
||||||
|
@ -115,23 +108,21 @@ public class CommunityConfigurationFactory {
|
||||||
private static List<ZenodoCommunity> parseZenodoCommunities(final Node node) {
|
private static List<ZenodoCommunity> parseZenodoCommunities(final Node node) {
|
||||||
final Node oacommunitynode = node.selectSingleNode("./oacommunity");
|
final Node oacommunitynode = node.selectSingleNode("./oacommunity");
|
||||||
String oacommunity = null;
|
String oacommunity = null;
|
||||||
if (oacommunitynode != null){
|
if (oacommunitynode != null) {
|
||||||
String tmp = oacommunitynode.getText();
|
String tmp = oacommunitynode.getText();
|
||||||
if(StringUtils.isNotBlank(tmp))
|
if (StringUtils.isNotBlank(tmp)) oacommunity = tmp;
|
||||||
oacommunity = tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final List<Node> list = node.selectNodes("./zenodocommunities/zenodocommunity");
|
final List<Node> list = node.selectNodes("./zenodocommunities/zenodocommunity");
|
||||||
final List<ZenodoCommunity> zenodoCommunityList = new ArrayList<>();
|
final List<ZenodoCommunity> zenodoCommunityList = new ArrayList<>();
|
||||||
for(Node n : list){
|
for (Node n : list) {
|
||||||
ZenodoCommunity zc = new ZenodoCommunity();
|
ZenodoCommunity zc = new ZenodoCommunity();
|
||||||
zc.setZenodoCommunityId(n.selectSingleNode("./zenodoid").getText());
|
zc.setZenodoCommunityId(n.selectSingleNode("./zenodoid").getText());
|
||||||
zc.setSelCriteria(n.selectSingleNode("./selcriteria"));
|
zc.setSelCriteria(n.selectSingleNode("./selcriteria"));
|
||||||
|
|
||||||
zenodoCommunityList.add(zc);
|
zenodoCommunityList.add(zc);
|
||||||
}
|
}
|
||||||
if(oacommunity != null){
|
if (oacommunity != null) {
|
||||||
ZenodoCommunity zc = new ZenodoCommunity();
|
ZenodoCommunity zc = new ZenodoCommunity();
|
||||||
zc.setZenodoCommunityId(oacommunity);
|
zc.setZenodoCommunityId(oacommunity);
|
||||||
zenodoCommunityList.add(zc);
|
zenodoCommunityList.add(zc);
|
||||||
|
@ -139,8 +130,4 @@ public class CommunityConfigurationFactory {
|
||||||
log.info("size of the zenodo community list " + zenodoCommunityList.size());
|
log.info("size of the zenodo community list " + zenodoCommunityList.size());
|
||||||
return zenodoCommunityList;
|
return zenodoCommunityList;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,22 +1,17 @@
|
||||||
package eu.dnetlib.dhp.community;
|
package eu.dnetlib.dhp.community;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import eu.dnetlib.dhp.selectioncriteria.Selection;
|
import eu.dnetlib.dhp.selectioncriteria.Selection;
|
||||||
import eu.dnetlib.dhp.selectioncriteria.VerbResolver;
|
import eu.dnetlib.dhp.selectioncriteria.VerbResolver;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
|
|
||||||
public class Constraint implements Serializable {
|
public class Constraint implements Serializable {
|
||||||
private String verb;
|
private String verb;
|
||||||
private String field;
|
private String field;
|
||||||
private String value;
|
private String value;
|
||||||
private Selection selection;
|
private Selection selection;
|
||||||
|
|
||||||
public Constraint() {
|
public Constraint() {}
|
||||||
}
|
|
||||||
|
|
||||||
public String getVerb() {
|
public String getVerb() {
|
||||||
return verb;
|
return verb;
|
||||||
|
@ -42,21 +37,17 @@ public class Constraint implements Serializable {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSelection(Selection sel) {
|
||||||
|
|
||||||
public void setSelection(Selection sel){
|
|
||||||
selection = sel;
|
selection = sel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelection(VerbResolver resolver) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
public void setSelection(VerbResolver resolver)
|
||||||
selection = resolver.getSelectionCriteria(verb,value);
|
throws InvocationTargetException, NoSuchMethodException, InstantiationException,
|
||||||
|
IllegalAccessException {
|
||||||
|
selection = resolver.getSelectionCriteria(verb, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean verifyCriteria(String metadata) {
|
||||||
public boolean verifyCriteria(String metadata){
|
|
||||||
return selection.apply(metadata);
|
return selection.apply(metadata);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,32 +1,25 @@
|
||||||
package eu.dnetlib.dhp.community;
|
package eu.dnetlib.dhp.community;
|
||||||
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import eu.dnetlib.dhp.selectioncriteria.VerbResolver;
|
import eu.dnetlib.dhp.selectioncriteria.VerbResolver;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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 {
|
public class Constraints implements Serializable {
|
||||||
private static final Log log = LogFactory.getLog(Constraints.class);
|
private static final Log log = LogFactory.getLog(Constraints.class);
|
||||||
//private ConstraintEncapsulator ce;
|
// private ConstraintEncapsulator ce;
|
||||||
private List<Constraint> constraint;
|
private List<Constraint> constraint;
|
||||||
|
|
||||||
|
public Constraints() {}
|
||||||
|
|
||||||
public Constraints() {
|
|
||||||
}
|
|
||||||
public List<Constraint> getConstraint() {
|
public List<Constraint> getConstraint() {
|
||||||
return constraint;
|
return constraint;
|
||||||
}
|
}
|
||||||
|
@ -35,14 +28,13 @@ public class Constraints implements Serializable {
|
||||||
this.constraint = constraint;
|
this.constraint = constraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSc(String json){
|
public void setSc(String json) {
|
||||||
Type collectionType = new TypeToken<Collection<Constraint>>(){}.getType();
|
Type collectionType = new TypeToken<Collection<Constraint>>() {}.getType();
|
||||||
constraint = new Gson().fromJson(json, collectionType);
|
constraint = new Gson().fromJson(json, collectionType);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSelection(VerbResolver resolver) {
|
void setSelection(VerbResolver resolver) {
|
||||||
for(Constraint st: constraint){
|
for (Constraint st : constraint) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.setSelection(resolver);
|
st.setSelection(resolver);
|
||||||
|
@ -56,24 +48,20 @@ public class Constraints implements Serializable {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Constraint in and
|
||||||
//Constraint in and
|
|
||||||
public boolean verifyCriteria(final Map<String, List<String>> param) {
|
public boolean verifyCriteria(final Map<String, List<String>> param) {
|
||||||
|
|
||||||
for(Constraint sc : constraint) {
|
for (Constraint sc : constraint) {
|
||||||
boolean verified = false;
|
boolean verified = false;
|
||||||
for(String value : param.get(sc.getField())){
|
for (String value : param.get(sc.getField())) {
|
||||||
if (sc.verifyCriteria(value.trim())){
|
if (sc.verifyCriteria(value.trim())) {
|
||||||
verified = true;
|
verified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!verified)
|
if (!verified) return verified;
|
||||||
return verified;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -4,63 +4,59 @@ import com.google.common.base.Joiner;
|
||||||
import eu.dnetlib.dhp.utils.ISLookupClientFactory;
|
import eu.dnetlib.dhp.utils.ISLookupClientFactory;
|
||||||
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
||||||
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
||||||
|
import java.util.List;
|
||||||
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentException;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class QueryInformationSystem {
|
public class QueryInformationSystem {
|
||||||
private static final String XQUERY = "for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') " +
|
private static final String XQUERY =
|
||||||
" let $subj := $x//CONFIGURATION/context/param[./@name='subject']/text() " +
|
"for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') "
|
||||||
" let $datasources := $x//CONFIGURATION/context/category[./@id=concat($x//CONFIGURATION/context/@id,'::contentproviders')]/concept " +
|
+ " let $subj := $x//CONFIGURATION/context/param[./@name='subject']/text() "
|
||||||
" let $organizations := $x//CONFIGURATION/context/category[./@id=concat($x//CONFIGURATION/context/@id,'::resultorganizations')]/concept " +
|
+ " let $datasources := $x//CONFIGURATION/context/category[./@id=concat($x//CONFIGURATION/context/@id,'::contentproviders')]/concept "
|
||||||
" let $communities := $x//CONFIGURATION/context/category[./@id=concat($x//CONFIGURATION/context/@id,'::zenodocommunities')]/concept " +
|
+ " let $organizations := $x//CONFIGURATION/context/category[./@id=concat($x//CONFIGURATION/context/@id,'::resultorganizations')]/concept "
|
||||||
" where $x//CONFIGURATION/context[./@type='community' or ./@type='ri'] " +
|
+ " let $communities := $x//CONFIGURATION/context/category[./@id=concat($x//CONFIGURATION/context/@id,'::zenodocommunities')]/concept "
|
||||||
" return " +
|
+ " where $x//CONFIGURATION/context[./@type='community' or ./@type='ri'] "
|
||||||
" <community> " +
|
+ " return "
|
||||||
" { $x//CONFIGURATION/context/@id} " +
|
+ " <community> "
|
||||||
" <subjects> " +
|
+ " { $x//CONFIGURATION/context/@id} "
|
||||||
" {for $y in tokenize($subj,',') " +
|
+ " <subjects> "
|
||||||
" return " +
|
+ " {for $y in tokenize($subj,',') "
|
||||||
" <subject>{$y}</subject>} " +
|
+ " return "
|
||||||
" </subjects> " +
|
+ " <subject>{$y}</subject>} "
|
||||||
" <datasources> " +
|
+ " </subjects> "
|
||||||
" {for $d in $datasources " +
|
+ " <datasources> "
|
||||||
" where $d/param[./@name='enabled']/text()='true' " +
|
+ " {for $d in $datasources "
|
||||||
" return " +
|
+ " where $d/param[./@name='enabled']/text()='true' "
|
||||||
" <datasource> " +
|
+ " return "
|
||||||
" <openaireId> " +
|
+ " <datasource> "
|
||||||
" {$d//param[./@name='openaireId']/text()} " +
|
+ " <openaireId> "
|
||||||
" </openaireId> " +
|
+ " {$d//param[./@name='openaireId']/text()} "
|
||||||
" <selcriteria> " +
|
+ " </openaireId> "
|
||||||
" {$d/param[./@name='selcriteria']/text()} " +
|
+ " <selcriteria> "
|
||||||
" </selcriteria> " +
|
+ " {$d/param[./@name='selcriteria']/text()} "
|
||||||
" </datasource> } " +
|
+ " </selcriteria> "
|
||||||
" </datasources> " +
|
+ " </datasource> } "
|
||||||
" <zenodocommunities> " +
|
+ " </datasources> "
|
||||||
" {for $zc in $communities " +
|
+ " <zenodocommunities> "
|
||||||
" return " +
|
+ " {for $zc in $communities "
|
||||||
" <zenodocommunity> " +
|
+ " return "
|
||||||
" <zenodoid> " +
|
+ " <zenodocommunity> "
|
||||||
" {$zc/param[./@name='zenodoid']/text()} " +
|
+ " <zenodoid> "
|
||||||
" </zenodoid> " +
|
+ " {$zc/param[./@name='zenodoid']/text()} "
|
||||||
" <selcriteria> " +
|
+ " </zenodoid> "
|
||||||
" {$zc/param[./@name='selcriteria']/text()} " +
|
+ " <selcriteria> "
|
||||||
" </selcriteria> " +
|
+ " {$zc/param[./@name='selcriteria']/text()} "
|
||||||
" </zenodocommunity>} " +
|
+ " </selcriteria> "
|
||||||
" </zenodocommunities> " +
|
+ " </zenodocommunity>} "
|
||||||
" </community>";
|
+ " </zenodocommunities> "
|
||||||
|
+ " </community>";
|
||||||
|
|
||||||
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);
|
ISLookUpService isLookUp = ISLookupClientFactory.getLookUpService(isLookupUrl);
|
||||||
final List<String> res = isLookUp.quickSearchProfile(XQUERY);
|
final List<String> res = isLookUp.quickSearchProfile(XQUERY);
|
||||||
|
|
||||||
final String xmlConf = "<communities>" + Joiner.on(" ").join(res) + "</communities>";
|
final String xmlConf = "<communities>" + Joiner.on(" ").join(res) + "</communities>";
|
||||||
|
|
||||||
|
|
||||||
return CommunityConfigurationFactory.newInstance(xmlConf);
|
return CommunityConfigurationFactory.newInstance(xmlConf);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,8 @@ public class ResultTagger implements Serializable {
|
||||||
// Verify if the entity is deletedbyinference. In case verify if to clean the context list
|
// Verify if the entity is deletedbyinference. In case verify if to clean the context list
|
||||||
// from all the zenodo communities
|
// from all the zenodo communities
|
||||||
if (result.getDataInfo().getDeletedbyinference()) {
|
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
|
// communities contains all the communities to be added as context for the result
|
||||||
|
@ -118,7 +119,15 @@ public class ResultTagger implements Serializable {
|
||||||
.map(
|
.map(
|
||||||
c -> {
|
c -> {
|
||||||
if (communities.contains(c.getId())) {
|
if (communities.contains(c.getId())) {
|
||||||
List<DataInfo> dataInfoList = c.getDataInfo();
|
Optional<List<DataInfo>> opt_dataInfoList =
|
||||||
|
Optional.ofNullable(c.getDataInfo());
|
||||||
|
List<DataInfo> dataInfoList;
|
||||||
|
if (opt_dataInfoList.isPresent())
|
||||||
|
dataInfoList = opt_dataInfoList.get();
|
||||||
|
else {
|
||||||
|
dataInfoList = new ArrayList<>();
|
||||||
|
c.setDataInfo(dataInfoList);
|
||||||
|
}
|
||||||
if (subjects.contains(c.getId()))
|
if (subjects.contains(c.getId()))
|
||||||
dataInfoList.add(
|
dataInfoList.add(
|
||||||
getDataInfo(
|
getDataInfo(
|
||||||
|
@ -153,7 +162,7 @@ public class ResultTagger implements Serializable {
|
||||||
c -> {
|
c -> {
|
||||||
Context context = new Context();
|
Context context = new Context();
|
||||||
context.setId(c);
|
context.setId(c);
|
||||||
List<DataInfo> dataInfoList = Arrays.asList();
|
List<DataInfo> dataInfoList = new ArrayList<>();
|
||||||
if (subjects.contains(c))
|
if (subjects.contains(c))
|
||||||
dataInfoList.add(
|
dataInfoList.add(
|
||||||
getDataInfo(
|
getDataInfo(
|
||||||
|
|
|
@ -3,8 +3,6 @@ package eu.dnetlib.dhp.community;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import eu.dnetlib.dhp.selectioncriteria.VerbResolver;
|
import eu.dnetlib.dhp.selectioncriteria.VerbResolver;
|
||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -14,9 +12,7 @@ import java.util.Map;
|
||||||
public class SelectionConstraints implements Serializable {
|
public class SelectionConstraints implements Serializable {
|
||||||
private List<Constraints> criteria;
|
private List<Constraints> criteria;
|
||||||
|
|
||||||
public SelectionConstraints() {
|
public SelectionConstraints() {}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public List<Constraints> getCriteria() {
|
public List<Constraints> getCriteria() {
|
||||||
return criteria;
|
return criteria;
|
||||||
|
@ -26,24 +22,25 @@ public class SelectionConstraints implements Serializable {
|
||||||
this.criteria = criteria;
|
this.criteria = criteria;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSc(String json){
|
public void setSc(String json) {
|
||||||
Type collectionType = new TypeToken<Collection<Constraints>>(){}.getType();
|
Type collectionType = new TypeToken<Collection<Constraints>>() {}.getType();
|
||||||
criteria = new Gson().fromJson(json, collectionType);
|
criteria = new Gson().fromJson(json, collectionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Constraints in or
|
// Constraints in or
|
||||||
public boolean verifyCriteria(final Map<String, List<String>> param){
|
public boolean verifyCriteria(final Map<String, List<String>> param) {
|
||||||
for(Constraints selc : criteria) {
|
for (Constraints selc : criteria) {
|
||||||
if(selc.verifyCriteria(param)){
|
if (selc.verifyCriteria(param)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelection(VerbResolver resolver) {
|
public void setSelection(VerbResolver resolver) {
|
||||||
|
|
||||||
for(Constraints cs : criteria){
|
for (Constraints cs : criteria) {
|
||||||
cs.setSelection(resolver);
|
cs.setSelection(resolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package eu.dnetlib.dhp.selectioncriteria;
|
package eu.dnetlib.dhp.selectioncriteria;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
@VerbClass("contains")
|
@VerbClass("contains")
|
||||||
public class ContainsVerb implements Selection {
|
public class ContainsVerb implements Selection, Serializable {
|
||||||
|
|
||||||
private String param;
|
private String param;
|
||||||
|
|
||||||
public ContainsVerb() {
|
public ContainsVerb() {}
|
||||||
}
|
|
||||||
|
|
||||||
public ContainsVerb(final String param) {
|
public ContainsVerb(final String param) {
|
||||||
this.param = param;
|
this.param = param;
|
||||||
|
@ -24,4 +25,4 @@ public class ContainsVerb implements Selection {
|
||||||
public void setParam(String param) {
|
public void setParam(String param) {
|
||||||
this.param = param;
|
this.param = param;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
package eu.dnetlib.dhp.selectioncriteria;
|
package eu.dnetlib.dhp.selectioncriteria;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
@VerbClass("equals")
|
@VerbClass("equals")
|
||||||
public class EqualVerb implements Selection {
|
public class EqualVerb implements Selection, Serializable {
|
||||||
|
|
||||||
private String param;
|
private String param;
|
||||||
|
|
||||||
public EqualVerb() {
|
public EqualVerb() {}
|
||||||
}
|
|
||||||
|
|
||||||
public EqualVerb(final String param) {
|
public EqualVerb(final String param) {
|
||||||
this.param = param;
|
this.param = param;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(String value) {
|
public boolean apply(String value) {
|
||||||
return value.equalsIgnoreCase(param);
|
return value.equalsIgnoreCase(param);
|
||||||
|
@ -26,4 +25,4 @@ public class EqualVerb implements Selection {
|
||||||
public void setParam(String param) {
|
public void setParam(String param) {
|
||||||
this.param = param;
|
this.param = param;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package eu.dnetlib.dhp.selectioncriteria;
|
package eu.dnetlib.dhp.selectioncriteria;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
public class InterfaceAdapter implements JsonSerializer, JsonDeserializer {
|
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 CLASSNAME = "CLASSNAME";
|
||||||
private static final String DATA = "DATA";
|
private static final String DATA = "DATA";
|
||||||
|
|
||||||
public Object deserialize(JsonElement jsonElement, Type type,
|
public Object deserialize(
|
||||||
JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
JsonElement jsonElement,
|
||||||
|
Type type,
|
||||||
|
JsonDeserializationContext jsonDeserializationContext)
|
||||||
|
throws JsonParseException {
|
||||||
|
|
||||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||||
JsonPrimitive prim = (JsonPrimitive) jsonObject.get(CLASSNAME);
|
JsonPrimitive prim = (JsonPrimitive) jsonObject.get(CLASSNAME);
|
||||||
|
@ -18,20 +20,21 @@ public class InterfaceAdapter implements JsonSerializer, JsonDeserializer {
|
||||||
Class klass = getObjectClass(className);
|
Class klass = getObjectClass(className);
|
||||||
return jsonDeserializationContext.deserialize(jsonObject.get(DATA), klass);
|
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 jsonObject = new JsonObject();
|
||||||
jsonObject.addProperty(CLASSNAME, jsonElement.getClass().getName());
|
jsonObject.addProperty(CLASSNAME, jsonElement.getClass().getName());
|
||||||
jsonObject.add(DATA, jsonSerializationContext.serialize(jsonElement));
|
jsonObject.add(DATA, jsonSerializationContext.serialize(jsonElement));
|
||||||
return jsonObject;
|
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) {
|
public Class getObjectClass(String className) {
|
||||||
try {
|
try {
|
||||||
return Class.forName(className);
|
return Class.forName(className);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
//e.printStackTrace();
|
// e.printStackTrace();
|
||||||
throw new JsonParseException(e.getMessage());
|
throw new JsonParseException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package eu.dnetlib.dhp.selectioncriteria;
|
package eu.dnetlib.dhp.selectioncriteria;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
@VerbClass("not_contains")
|
@VerbClass("not_contains")
|
||||||
public class NotContainsVerb implements Selection {
|
public class NotContainsVerb implements Selection, Serializable {
|
||||||
|
|
||||||
private String param;
|
private String param;
|
||||||
|
|
||||||
public NotContainsVerb() {
|
public NotContainsVerb() {}
|
||||||
}
|
|
||||||
|
|
||||||
public NotContainsVerb(final String param) {
|
public NotContainsVerb(final String param) {
|
||||||
this.param = param;
|
this.param = param;
|
||||||
|
@ -24,4 +25,4 @@ public class NotContainsVerb implements Selection {
|
||||||
public void setParam(String param) {
|
public void setParam(String param) {
|
||||||
this.param = param;
|
this.param = param;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
package eu.dnetlib.dhp.selectioncriteria;
|
package eu.dnetlib.dhp.selectioncriteria;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
@VerbClass("not_equals")
|
@VerbClass("not_equals")
|
||||||
public class NotEqualVerb implements Selection {
|
public class NotEqualVerb implements Selection, Serializable {
|
||||||
|
|
||||||
private String param;
|
private String param;
|
||||||
|
|
||||||
|
|
||||||
public NotEqualVerb(final String param) {
|
public NotEqualVerb(final String param) {
|
||||||
this.param = param;
|
this.param = param;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NotEqualVerb() {
|
public NotEqualVerb() {}
|
||||||
}
|
|
||||||
|
|
||||||
public String getParam() {
|
public String getParam() {
|
||||||
return param;
|
return param;
|
||||||
|
@ -26,4 +25,4 @@ public class NotEqualVerb implements Selection {
|
||||||
public boolean apply(String value) {
|
public boolean apply(String value) {
|
||||||
return !value.equalsIgnoreCase(param);
|
return !value.equalsIgnoreCase(param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@ package eu.dnetlib.dhp.selectioncriteria;
|
||||||
public interface Selection {
|
public interface Selection {
|
||||||
|
|
||||||
boolean apply(String value);
|
boolean apply(String value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,57 @@
|
||||||
package eu.dnetlib.dhp.selectioncriteria;
|
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.io.Serializable;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.reflections.Reflections;
|
|
||||||
|
|
||||||
public class VerbResolver implements Serializable {
|
public class VerbResolver implements Serializable {
|
||||||
private final Map<String, Class<Selection>> map;
|
private Map<String, Class<Selection>> map = null; // = new HashMap<>();
|
||||||
|
private final ClassGraph classgraph = new ClassGraph();
|
||||||
|
|
||||||
public VerbResolver() {
|
public VerbResolver() {
|
||||||
|
|
||||||
this.map =
|
try (ScanResult scanResult = // Assign scanResult in try-with-resources
|
||||||
new Reflections("eu.dnetlib")
|
classgraph // Create a new ClassGraph instance
|
||||||
.getTypesAnnotatedWith(VerbClass.class).stream()
|
.verbose() // If you want to enable logging to stderr
|
||||||
.collect(
|
.enableAllInfo() // Scan classes, methods, fields, annotations
|
||||||
Collectors.toMap(
|
.whitelistPackages(
|
||||||
v -> v.getAnnotation(VerbClass.class).value(),
|
"eu.dnetlib.dhp.selectioncriteria") // Scan com.xyz and subpackages
|
||||||
v -> (Class<Selection>) v));
|
.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<Selection>)
|
||||||
|
((ClassInfo) value).loadClass()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Selection getSelectionCriteria(String name, String param)
|
public Selection getSelectionCriteria(String name, String param)
|
||||||
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
|
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
|
||||||
InstantiationException {
|
InstantiationException {
|
||||||
|
|
||||||
|
// return Class.forName(tmp_map.get(name)).
|
||||||
return map.get(name).getDeclaredConstructor((String.class)).newInstance(param);
|
return map.get(name).getDeclaredConstructor((String.class)).newInstance(param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,8 @@ package eu.dnetlib.dhp.selectioncriteria;
|
||||||
|
|
||||||
public class VerbResolverFactory {
|
public class VerbResolverFactory {
|
||||||
|
|
||||||
public static VerbResolver newInstance(){
|
public static VerbResolver newInstance() {
|
||||||
|
|
||||||
return new VerbResolver();
|
return new VerbResolver();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue