From c22cb5a3c6575daa656aefa493853f2f787cd52f Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Fri, 12 Jun 2020 09:47:55 +0200 Subject: [PATCH] refactoring --- .../dhp/broker/oa/matchers/UpdateMatcher.java | 39 +++++++++++++++++-- .../AbstractEnrichMissingDataset.java | 33 +++------------- .../relatedProjects/EnrichMissingProject.java | 27 +++---------- .../relatedProjects/EnrichMoreProject.java | 25 +++--------- .../AbstractEnrichMissingPublication.java | 33 ++++------------ .../EnrichMissingSoftware.java | 25 +++--------- .../relatedSoftware/EnrichMoreSoftware.java | 25 +++--------- .../simple/EnrichMissingAbstract.java | 27 ++++--------- .../simple/EnrichMissingAuthorOrcid.java | 31 ++++----------- .../simple/EnrichMissingOpenAccess.java | 24 +++--------- .../oa/matchers/simple/EnrichMissingPid.java | 24 +++--------- .../simple/EnrichMissingPublicationDate.java | 28 ++++--------- .../matchers/simple/EnrichMissingSubject.java | 25 +++--------- .../matchers/simple/EnrichMoreOpenAccess.java | 24 +++--------- .../oa/matchers/simple/EnrichMorePid.java | 24 +++--------- .../oa/matchers/simple/EnrichMoreSubject.java | 25 +++--------- 16 files changed, 130 insertions(+), 309 deletions(-) diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/UpdateMatcher.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/UpdateMatcher.java index fd87d81dd..0e57f32f9 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/UpdateMatcher.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/UpdateMatcher.java @@ -6,10 +6,14 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; +import eu.dnetlib.broker.objects.Publication; +import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; import eu.dnetlib.dhp.schema.oaf.Field; @@ -18,9 +22,17 @@ import eu.dnetlib.pace.config.DedupConfig; public abstract class UpdateMatcher { private final boolean multipleUpdate; + private final Function topicFunction; + private final BiConsumer compileHighlightFunction; + private final Function highlightToStringFunction; - public UpdateMatcher(final boolean multipleUpdate) { + public UpdateMatcher(final boolean multipleUpdate, final Function topicFunction, + final BiConsumer compileHighlightFunction, + final Function highlightToStringFunction) { this.multipleUpdate = multipleUpdate; + this.topicFunction = topicFunction; + this.compileHighlightFunction = compileHighlightFunction; + this.highlightToStringFunction = highlightToStringFunction; } public Collection> searchUpdatesForRecord(final ResultWithRelations res, @@ -31,7 +43,11 @@ public abstract class UpdateMatcher { for (final ResultWithRelations source : others) { if (source != res) { - for (final UpdateInfo info : findUpdates(source, res, dedupConfig)) { + for (final T hl : findDifferences(source, res)) { + final Topic topic = getTopicFunction().apply(hl); + final UpdateInfo info = new UpdateInfo<>(topic, hl, source, res, getCompileHighlightFunction(), + getHighlightToStringFunction(), + dedupConfig); final String s = DigestUtils.md5Hex(info.getHighlightValueAsString()); if (!infoMap.containsKey(s) || infoMap.get(s).getTrust() < info.getTrust()) { } else { @@ -55,8 +71,7 @@ public abstract class UpdateMatcher { } } - protected abstract List> findUpdates(ResultWithRelations source, ResultWithRelations target, - DedupConfig dedupConfig); + protected abstract List findDifferences(ResultWithRelations source, ResultWithRelations target); protected static boolean isMissing(final List> list) { return list == null || list.isEmpty() || StringUtils.isBlank(list.get(0).getValue()); @@ -66,4 +81,20 @@ public abstract class UpdateMatcher { return field == null || StringUtils.isBlank(field.getValue()); } + public boolean isMultipleUpdate() { + return multipleUpdate; + } + + public Function getTopicFunction() { + return topicFunction; + } + + public BiConsumer getCompileHighlightFunction() { + return compileHighlightFunction; + } + + public Function getHighlightToStringFunction() { + return highlightToStringFunction; + } + } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedDatasets/AbstractEnrichMissingDataset.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedDatasets/AbstractEnrichMissingDataset.java index a2ce32a9d..a8e0a2c42 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedDatasets/AbstractEnrichMissingDataset.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedDatasets/AbstractEnrichMissingDataset.java @@ -8,29 +8,26 @@ import java.util.stream.Collectors; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; import eu.dnetlib.dhp.broker.oa.util.ConversionUtils; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.RelatedDataset; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; import eu.dnetlib.dhp.schema.oaf.Dataset; -import eu.dnetlib.pace.config.DedupConfig; public abstract class AbstractEnrichMissingDataset extends UpdateMatcher { - private final Topic topic; - public AbstractEnrichMissingDataset(final Topic topic) { - super(true); - this.topic = topic; + super(true, + rel -> topic, + (p, rel) -> p.getDatasets().add(rel), + rel -> rel.getInstances().get(0).getUrl()); } protected abstract boolean filterByType(String relType); @Override - protected final List> findUpdates( + protected final List findDifferences( final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + final ResultWithRelations target) { final Set existingDatasets = target .getDatasets() @@ -47,26 +44,8 @@ public abstract class AbstractEnrichMissingDataset .map(RelatedDataset::getRelDataset) .filter(d -> !existingDatasets.contains(d.getId())) .map(ConversionUtils::oafDatasetToBrokerDataset) - .map(i -> generateUpdateInfo(i, source, target, dedupConfig)) .collect(Collectors.toList()); } - protected final UpdateInfo generateUpdateInfo( - final eu.dnetlib.broker.objects.Dataset highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - getTopic(), - highlightValue, source, target, - (p, rel) -> p.getDatasets().add(rel), - rel -> rel.getInstances().get(0).getUrl(), - dedupConfig); - } - - public Topic getTopic() { - return topic; - } - } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedProjects/EnrichMissingProject.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedProjects/EnrichMissingProject.java index 546287795..ab4325c1e 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedProjects/EnrichMissingProject.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedProjects/EnrichMissingProject.java @@ -5,26 +5,25 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import eu.dnetlib.broker.objects.Project; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; import eu.dnetlib.dhp.broker.oa.util.ConversionUtils; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.RelatedProject; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMissingProject extends UpdateMatcher { public EnrichMissingProject() { - super(true); + super(true, + prj -> Topic.ENRICH_MISSING_PROJECT, + (p, prj) -> p.getProjects().add(prj), + prj -> prj.getFunder() + "::" + prj.getFundingProgram() + prj.getCode()); } @Override - protected List> findUpdates(final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - + protected List findDifferences(final ResultWithRelations source, final ResultWithRelations target) { if (source.getProjects().isEmpty()) { return Arrays.asList(); } else { @@ -33,21 +32,7 @@ public class EnrichMissingProject .stream() .map(RelatedProject::getRelProject) .map(ConversionUtils::oafProjectToBrokerProject) - .map(p -> generateUpdateInfo(p, source, target, dedupConfig)) .collect(Collectors.toList()); } } - - public UpdateInfo generateUpdateInfo( - final eu.dnetlib.broker.objects.Project highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - Topic.ENRICH_MISSING_PROJECT, - highlightValue, source, target, - (p, prj) -> p.getProjects().add(prj), - prj -> prj.getFunder() + "::" + prj.getFundingProgram() + prj.getCode(), dedupConfig); - } - } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedProjects/EnrichMoreProject.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedProjects/EnrichMoreProject.java index 54ebe7b71..3bf23a36b 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedProjects/EnrichMoreProject.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedProjects/EnrichMoreProject.java @@ -8,22 +8,22 @@ import java.util.stream.Collectors; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; import eu.dnetlib.dhp.broker.oa.util.ConversionUtils; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.RelatedProject; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; import eu.dnetlib.dhp.schema.oaf.Project; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMoreProject extends UpdateMatcher { public EnrichMoreProject() { - super(true); + super(true, + prj -> Topic.ENRICH_MORE_PROJECT, + (p, prj) -> p.getProjects().add(prj), + prj -> prj.getFunder() + "::" + prj.getFundingProgram() + prj.getCode()); } @Override - protected List> findUpdates(final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + protected List findDifferences(final ResultWithRelations source, + final ResultWithRelations target) { final Set existingProjects = source .getProjects() @@ -38,20 +38,7 @@ public class EnrichMoreProject extends UpdateMatcher !existingProjects.contains(p.getId())) .map(ConversionUtils::oafProjectToBrokerProject) - .map(p -> generateUpdateInfo(p, source, target, dedupConfig)) .collect(Collectors.toList()); } - public UpdateInfo generateUpdateInfo( - final eu.dnetlib.broker.objects.Project highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - Topic.ENRICH_MORE_PROJECT, - highlightValue, source, target, - (p, prj) -> p.getProjects().add(prj), - prj -> prj.getFunder() + "::" + prj.getFundingProgram() + prj.getCode(), dedupConfig); - } - } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedPublications/AbstractEnrichMissingPublication.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedPublications/AbstractEnrichMissingPublication.java index 8793d38dc..bba3e9648 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedPublications/AbstractEnrichMissingPublication.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedPublications/AbstractEnrichMissingPublication.java @@ -8,29 +8,27 @@ import java.util.stream.Collectors; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; import eu.dnetlib.dhp.broker.oa.util.ConversionUtils; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.RelatedPublication; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; import eu.dnetlib.dhp.schema.oaf.Publication; -import eu.dnetlib.pace.config.DedupConfig; public abstract class AbstractEnrichMissingPublication extends UpdateMatcher { - private final Topic topic; - public AbstractEnrichMissingPublication(final Topic topic) { - super(true); - this.topic = topic; + super(true, + rel -> topic, + (p, rel) -> p.getPublications().add(rel), + rel -> rel.getInstances().get(0).getUrl()); + } protected abstract boolean filterByType(String relType); @Override - protected final List> findUpdates( + protected final List findDifferences( final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + final ResultWithRelations target) { final Set existingPublications = target .getPublications() @@ -47,24 +45,7 @@ public abstract class AbstractEnrichMissingPublication .map(RelatedPublication::getRelPublication) .filter(d -> !existingPublications.contains(d.getId())) .map(ConversionUtils::oafResultToBrokerPublication) - .map(i -> generateUpdateInfo(i, source, target, dedupConfig)) .collect(Collectors.toList()); - } - protected final UpdateInfo generateUpdateInfo( - final eu.dnetlib.broker.objects.Publication highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - getTopic(), - highlightValue, source, target, - (p, rel) -> p.getPublications().add(rel), - rel -> rel.getInstances().get(0).getUrl(), dedupConfig); - } - - public Topic getTopic() { - return topic; - } } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedSoftware/EnrichMissingSoftware.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedSoftware/EnrichMissingSoftware.java index 1ce5415d5..6090939dc 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedSoftware/EnrichMissingSoftware.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedSoftware/EnrichMissingSoftware.java @@ -8,23 +8,23 @@ import java.util.stream.Collectors; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; import eu.dnetlib.dhp.broker.oa.util.ConversionUtils; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.RelatedSoftware; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMissingSoftware extends UpdateMatcher { public EnrichMissingSoftware() { - super(true); + super(true, + s -> Topic.ENRICH_MISSING_SOFTWARE, + (p, s) -> p.getSoftwares().add(s), + s -> s.getName()); } @Override - protected List> findUpdates( + protected List findDifferences( final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + final ResultWithRelations target) { if (source.getSoftwares().isEmpty()) { return Arrays.asList(); @@ -34,21 +34,8 @@ public class EnrichMissingSoftware .stream() .map(RelatedSoftware::getRelSoftware) .map(ConversionUtils::oafSoftwareToBrokerSoftware) - .map(p -> generateUpdateInfo(p, source, target, dedupConfig)) .collect(Collectors.toList()); } } - public UpdateInfo generateUpdateInfo( - final eu.dnetlib.broker.objects.Software highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - Topic.ENRICH_MISSING_SOFTWARE, - highlightValue, source, target, - (p, s) -> p.getSoftwares().add(s), - s -> s.getName(), dedupConfig); - } - } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedSoftware/EnrichMoreSoftware.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedSoftware/EnrichMoreSoftware.java index 4d1f4f23f..ba422f436 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedSoftware/EnrichMoreSoftware.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedSoftware/EnrichMoreSoftware.java @@ -8,24 +8,24 @@ import java.util.stream.Collectors; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; import eu.dnetlib.dhp.broker.oa.util.ConversionUtils; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.RelatedSoftware; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; import eu.dnetlib.dhp.schema.oaf.Software; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMoreSoftware extends UpdateMatcher { public EnrichMoreSoftware() { - super(true); + super(true, + s -> Topic.ENRICH_MORE_SOFTWARE, + (p, s) -> p.getSoftwares().add(s), + s -> s.getName()); } @Override - protected List> findUpdates( + protected List findDifferences( final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + final ResultWithRelations target) { final Set existingSoftwares = source .getSoftwares() @@ -40,20 +40,7 @@ public class EnrichMoreSoftware .map(RelatedSoftware::getRelSoftware) .filter(p -> !existingSoftwares.contains(p.getId())) .map(ConversionUtils::oafSoftwareToBrokerSoftware) - .map(p -> generateUpdateInfo(p, source, target, dedupConfig)) .collect(Collectors.toList()); } - public UpdateInfo generateUpdateInfo( - final eu.dnetlib.broker.objects.Software highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - Topic.ENRICH_MORE_SOFTWARE, - highlightValue, source, target, - (p, s) -> p.getSoftwares().add(s), - s -> s.getName(), dedupConfig); - } - } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingAbstract.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingAbstract.java index db9972479..25d5f9d8a 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingAbstract.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingAbstract.java @@ -7,38 +7,25 @@ import java.util.List; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMissingAbstract extends UpdateMatcher { public EnrichMissingAbstract() { - super(false); + super(false, + s -> Topic.ENRICH_MISSING_ABSTRACT, + (p, s) -> p.getAbstracts().add(s), + s -> s); } @Override - protected List> findUpdates(final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + protected List findDifferences(final ResultWithRelations source, + final ResultWithRelations target) { if (isMissing(target.getResult().getDescription()) && !isMissing(source.getResult().getDescription())) { return Arrays - .asList( - generateUpdateInfo( - source.getResult().getDescription().get(0).getValue(), source, target, dedupConfig)); + .asList(source.getResult().getDescription().get(0).getValue()); } return new ArrayList<>(); } - public UpdateInfo generateUpdateInfo(final String highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - Topic.ENRICH_MISSING_ABSTRACT, - highlightValue, source, target, - (p, s) -> p.getAbstracts().add(s), - s -> s, dedupConfig); - } - } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingAuthorOrcid.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingAuthorOrcid.java index 14021480d..eed2d0be8 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingAuthorOrcid.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingAuthorOrcid.java @@ -8,22 +8,22 @@ import java.util.stream.Collectors; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; import eu.dnetlib.dhp.schema.oaf.Author; import eu.dnetlib.dhp.schema.oaf.StructuredProperty; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMissingAuthorOrcid extends UpdateMatcher { public EnrichMissingAuthorOrcid() { - super(true); + super(true, + aut -> Topic.ENRICH_MISSING_AUTHOR_ORCID, + (p, aut) -> p.getCreators().add(aut), + aut -> aut); } @Override - protected List> findUpdates(final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + protected List findDifferences(final ResultWithRelations source, + final ResultWithRelations target) { final Set existingOrcids = target .getResult() @@ -35,7 +35,7 @@ public class EnrichMissingAuthorOrcid extends UpdateMatcher { .map(pid -> pid.getValue()) .collect(Collectors.toSet()); - final List> list = new ArrayList<>(); + final List list = new ArrayList<>(); for (final Author author : source.getResult().getAuthor()) { final String name = author.getFullname(); @@ -43,26 +43,11 @@ public class EnrichMissingAuthorOrcid extends UpdateMatcher { for (final StructuredProperty pid : author.getPid()) { if (pid.getQualifier().getClassid().equalsIgnoreCase("orcid") && !existingOrcids.contains(pid.getValue())) { - list - .add( - generateUpdateInfo(name + " [ORCID: " + pid.getValue() + "]", source, target, dedupConfig)); - ; + list.add(name + " [ORCID: " + pid.getValue() + "]"); } } } return list; } - - public UpdateInfo generateUpdateInfo(final String highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - Topic.ENRICH_MISSING_AUTHOR_ORCID, - highlightValue, source, target, - (p, aut) -> p.getCreators().add(aut), - aut -> aut, - dedupConfig); - } } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingOpenAccess.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingOpenAccess.java index 69bd3630a..e8ca18ae9 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingOpenAccess.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingOpenAccess.java @@ -10,20 +10,20 @@ import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; import eu.dnetlib.dhp.broker.oa.util.BrokerConstants; import eu.dnetlib.dhp.broker.oa.util.ConversionUtils; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMissingOpenAccess extends UpdateMatcher { public EnrichMissingOpenAccess() { - super(true); + super(true, + i -> Topic.ENRICH_MISSING_OA_VERSION, + (p, i) -> p.getInstances().add(i), + Instance::getUrl); } @Override - protected List> findUpdates(final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + protected List findDifferences(final ResultWithRelations source, + final ResultWithRelations target) { final long count = target .getResult() .getInstance() @@ -43,19 +43,7 @@ public class EnrichMissingOpenAccess extends UpdateMatcher { .filter(i -> i.getAccessright().getClassid().equals(BrokerConstants.OPEN_ACCESS)) .map(ConversionUtils::oafInstanceToBrokerInstances) .flatMap(List::stream) - .map(i -> generateUpdateInfo(i, source, target, dedupConfig)) .collect(Collectors.toList()); } - public UpdateInfo generateUpdateInfo(final Instance highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - Topic.ENRICH_MISSING_OA_VERSION, - highlightValue, source, target, - (p, i) -> p.getInstances().add(i), - Instance::getUrl, dedupConfig); - } - } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingPid.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingPid.java index 4b7b1735b..6c061a2e8 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingPid.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingPid.java @@ -9,20 +9,20 @@ import eu.dnetlib.broker.objects.Pid; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; import eu.dnetlib.dhp.broker.oa.util.ConversionUtils; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMissingPid extends UpdateMatcher { public EnrichMissingPid() { - super(true); + super(true, + pid -> Topic.ENRICH_MISSING_PID, + (p, pid) -> p.getPids().add(pid), + pid -> pid.getType() + "::" + pid.getValue()); } @Override - protected List> findUpdates(final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + protected List findDifferences(final ResultWithRelations source, + final ResultWithRelations target) { final long count = target.getResult().getPid().size(); if (count > 0) { @@ -34,19 +34,7 @@ public class EnrichMissingPid extends UpdateMatcher { .getPid() .stream() .map(ConversionUtils::oafPidToBrokerPid) - .map(i -> generateUpdateInfo(i, source, target, dedupConfig)) .collect(Collectors.toList()); } - public UpdateInfo generateUpdateInfo(final Pid highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - Topic.ENRICH_MISSING_PID, - highlightValue, source, target, - (p, pid) -> p.getPids().add(pid), - pid -> pid.getType() + "::" + pid.getValue(), dedupConfig); - } - } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingPublicationDate.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingPublicationDate.java index ecf8da157..27a71740c 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingPublicationDate.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingPublicationDate.java @@ -7,39 +7,25 @@ import java.util.List; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMissingPublicationDate extends UpdateMatcher { public EnrichMissingPublicationDate() { - super(false); + super(false, + date -> Topic.ENRICH_MISSING_PUBLICATION_DATE, + (p, date) -> p.setPublicationdate(date), + s -> s); } @Override - protected List> findUpdates(final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + protected List findDifferences(final ResultWithRelations source, + final ResultWithRelations target) { if (isMissing(target.getResult().getDateofacceptance()) && !isMissing(source.getResult().getDateofacceptance())) { - return Arrays - .asList( - generateUpdateInfo( - source.getResult().getDateofacceptance().getValue(), source, target, dedupConfig)); + return Arrays.asList(source.getResult().getDateofacceptance().getValue()); } return new ArrayList<>(); } - public UpdateInfo generateUpdateInfo(final String highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - Topic.ENRICH_MISSING_PUBLICATION_DATE, - highlightValue, source, target, - (p, date) -> p.setPublicationdate(date), - s -> s, dedupConfig); - } - } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingSubject.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingSubject.java index 9d3a3aa44..04de30089 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingSubject.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMissingSubject.java @@ -10,22 +10,22 @@ import org.apache.commons.lang3.tuple.Pair; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; import eu.dnetlib.dhp.broker.oa.util.ConversionUtils; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; import eu.dnetlib.dhp.schema.oaf.Qualifier; import eu.dnetlib.dhp.schema.oaf.StructuredProperty; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMissingSubject extends UpdateMatcher> { public EnrichMissingSubject() { - super(true); + super(true, + pair -> Topic.fromPath("ENRICH/MISSING/SUBJECT/" + pair.getLeft()), + (p, pair) -> p.getSubjects().add(pair.getRight()), + pair -> pair.getLeft() + "::" + pair.getRight()); } @Override - protected List>> findUpdates(final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + protected List> findDifferences(final ResultWithRelations source, + final ResultWithRelations target) { final Set existingTypes = target .getResult() .getSubject() @@ -40,20 +40,7 @@ public class EnrichMissingSubject extends UpdateMatcher> { .stream() .filter(pid -> !existingTypes.contains(pid.getQualifier().getClassid())) .map(ConversionUtils::oafSubjectToPair) - .map(i -> generateUpdateInfo(i, source, target, dedupConfig)) .collect(Collectors.toList()); } - public UpdateInfo> generateUpdateInfo(final Pair highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - - return new UpdateInfo<>( - Topic.fromPath("ENRICH/MISSING/SUBJECT/" + highlightValue.getLeft()), - highlightValue, source, target, - (p, pair) -> p.getSubjects().add(pair.getRight()), - pair -> pair.getLeft() + "::" + pair.getRight(), dedupConfig); - } - } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMoreOpenAccess.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMoreOpenAccess.java index fc1112d73..3ee4c8bdd 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMoreOpenAccess.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMoreOpenAccess.java @@ -10,20 +10,20 @@ import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; import eu.dnetlib.dhp.broker.oa.util.BrokerConstants; import eu.dnetlib.dhp.broker.oa.util.ConversionUtils; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMoreOpenAccess extends UpdateMatcher { public EnrichMoreOpenAccess() { - super(true); + super(true, + i -> Topic.ENRICH_MORE_OA_VERSION, + (p, i) -> p.getInstances().add(i), + Instance::getUrl); } @Override - protected List> findUpdates(final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + protected List findDifferences(final ResultWithRelations source, + final ResultWithRelations target) { final Set urls = target .getResult() .getInstance() @@ -41,19 +41,7 @@ public class EnrichMoreOpenAccess extends UpdateMatcher { .map(ConversionUtils::oafInstanceToBrokerInstances) .flatMap(List::stream) .filter(i -> !urls.contains(i.getUrl())) - .map(i -> generateUpdateInfo(i, source, target, dedupConfig)) .collect(Collectors.toList()); } - public UpdateInfo generateUpdateInfo(final Instance highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - Topic.ENRICH_MORE_OA_VERSION, - highlightValue, source, target, - (p, i) -> p.getInstances().add(i), - Instance::getUrl, dedupConfig); - } - } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMorePid.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMorePid.java index 7984cc521..694c9460a 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMorePid.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMorePid.java @@ -9,20 +9,20 @@ import eu.dnetlib.broker.objects.Pid; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; import eu.dnetlib.dhp.broker.oa.util.ConversionUtils; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMorePid extends UpdateMatcher { public EnrichMorePid() { - super(true); + super(true, + pid -> Topic.ENRICH_MORE_PID, + (p, pid) -> p.getPids().add(pid), + pid -> pid.getType() + "::" + pid.getValue()); } @Override - protected List> findUpdates(final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + protected List findDifferences(final ResultWithRelations source, + final ResultWithRelations target) { final Set existingPids = target .getResult() .getPid() @@ -36,19 +36,7 @@ public class EnrichMorePid extends UpdateMatcher { .stream() .filter(pid -> !existingPids.contains(pid.getQualifier().getClassid() + "::" + pid.getValue())) .map(ConversionUtils::oafPidToBrokerPid) - .map(i -> generateUpdateInfo(i, source, target, dedupConfig)) .collect(Collectors.toList()); } - public UpdateInfo generateUpdateInfo(final Pid highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - return new UpdateInfo<>( - Topic.ENRICH_MORE_PID, - highlightValue, source, target, - (p, pid) -> p.getPids().add(pid), - pid -> pid.getType() + "::" + pid.getValue(), dedupConfig); - } - } diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMoreSubject.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMoreSubject.java index 1a522c745..7d0b1a65e 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMoreSubject.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/simple/EnrichMoreSubject.java @@ -10,20 +10,20 @@ import org.apache.commons.lang3.tuple.Pair; import eu.dnetlib.dhp.broker.model.Topic; import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher; import eu.dnetlib.dhp.broker.oa.util.ConversionUtils; -import eu.dnetlib.dhp.broker.oa.util.UpdateInfo; import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations; -import eu.dnetlib.pace.config.DedupConfig; public class EnrichMoreSubject extends UpdateMatcher> { public EnrichMoreSubject() { - super(true); + super(true, + pair -> Topic.fromPath("ENRICH/MORE/SUBJECT/" + pair.getLeft()), + (p, pair) -> p.getSubjects().add(pair.getRight()), + pair -> pair.getLeft() + "::" + pair.getRight()); } @Override - protected List>> findUpdates(final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { + protected List> findDifferences(final ResultWithRelations source, + final ResultWithRelations target) { final Set existingSubjects = target .getResult() .getSubject() @@ -37,20 +37,7 @@ public class EnrichMoreSubject extends UpdateMatcher> { .stream() .filter(pid -> !existingSubjects.contains(pid.getQualifier().getClassid() + "::" + pid.getValue())) .map(ConversionUtils::oafSubjectToPair) - .map(i -> generateUpdateInfo(i, source, target, dedupConfig)) .collect(Collectors.toList()); } - public UpdateInfo> generateUpdateInfo(final Pair highlightValue, - final ResultWithRelations source, - final ResultWithRelations target, - final DedupConfig dedupConfig) { - - return new UpdateInfo<>( - Topic.fromPath("ENRICH/MORE/SUBJECT/" + highlightValue.getLeft()), - highlightValue, source, target, - (p, pair) -> p.getSubjects().add(pair.getRight()), - pair -> pair.getLeft() + "::" + pair.getRight(), dedupConfig); - } - }