From 0c53ac367e88387be01c9dfc9545555477e7a511 Mon Sep 17 00:00:00 2001 From: nmacedo Date: Tue, 25 Oct 2016 09:29:44 +0100 Subject: [PATCH 01/13] mvn rc2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ac6ab6e..c09222d 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ UTF-8 - 2.0-rc1 + 2.0-rc2 2.4 4.12 From 6f4b002d085ff11a49091b7565d7ddcce3ebbbc9 Mon Sep 17 00:00:00 2001 From: nmacedo Date: Tue, 25 Oct 2016 10:13:18 +0100 Subject: [PATCH 02/13] updated to rc2 methods (external ids) --- pom.xml | 9 ++- src/main/java/pt/ptcris/PTCRISync.java | 28 +++---- .../java/pt/ptcris/utils/ExternalIdsDiff.java | 36 ++++----- .../java/pt/ptcris/utils/ORCIDHelper.java | 63 +++++++-------- .../java/pt/ptcris/test/PTCRISExample.java | 57 +++++++------ src/test/java/pt/ptcris/test/TestHelper.java | 79 +++++++++---------- 6 files changed, 135 insertions(+), 137 deletions(-) diff --git a/pom.xml b/pom.xml index c09222d..1f68bbe 100644 --- a/pom.xml +++ b/pom.xml @@ -40,9 +40,12 @@ org.apache.maven.plugins maven-jar-plugin - 2.6 - - + 3.3 + + 1.7 + 1.7 + + maven-compiler-plugin 3.3 diff --git a/src/main/java/pt/ptcris/PTCRISync.java b/src/main/java/pt/ptcris/PTCRISync.java index 5afaf18..6c9afc0 100644 --- a/src/main/java/pt/ptcris/PTCRISync.java +++ b/src/main/java/pt/ptcris/PTCRISync.java @@ -12,9 +12,9 @@ import org.um.dsi.gavea.orcid.client.exception.OrcidClientException; import org.um.dsi.gavea.orcid.model.activities.WorkGroup; -import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier; +import org.um.dsi.gavea.orcid.model.common.ExternalId; +import org.um.dsi.gavea.orcid.model.common.ExternalIds; import org.um.dsi.gavea.orcid.model.work.Work; -import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers; import org.um.dsi.gavea.orcid.model.work.WorkSummary; import pt.ptcris.exceptions.InvalidWorkException; @@ -264,10 +264,10 @@ private static Map exportBase(ORCIDClient client, L // the remote work has spurious external identifiers if (!update.eidsDiff.more.isEmpty()) { Work localWork = update.preWork; - WorkExternalIdentifiers weids = new WorkExternalIdentifiers(); - List ids = new ArrayList(update.eidsDiff.same); - weids.setWorkExternalIdentifier(ids); - localWork.setExternalIdentifiers(weids); + ExternalIds weids = new ExternalIds(); + List ids = new ArrayList(update.eidsDiff.same); + weids.setExternalId(ids); + localWork.setExternalIds(weids); try { helper.updateWork(update.posWork.getPutCode(), localWork); result.put(ORCIDHelper.getActivityLocalKey(localWork), PTCRISyncResult.OK_UPD_RESULT); @@ -287,11 +287,11 @@ private static Map exportBase(ORCIDClient client, L UpdateRecord update = toUpdate.get(c); if (!update.eidsDiff.less.isEmpty() || update.eidsDiff.more.isEmpty()) { Work localWork = update.preWork; - WorkExternalIdentifiers weids = new WorkExternalIdentifiers(); - List ids = new ArrayList(update.eidsDiff.same); + ExternalIds weids = new ExternalIds(); + List ids = new ArrayList(update.eidsDiff.same); ids.addAll(update.eidsDiff.less); - weids.setWorkExternalIdentifier(ids); - localWork.setExternalIdentifiers(weids); + weids.setExternalId(ids); + localWork.setExternalIds(weids); try { helper.updateWork(update.posWork.getPutCode(), localWork); result.put(ORCIDHelper.getActivityLocalKey(localWork), PTCRISyncResult.OK_UPD_RESULT); @@ -658,11 +658,11 @@ public static List importUpdates(ORCIDClient client, List localWorks for (Work mathingLocalWork : matchingLocalWorks.keySet()) { if (!ORCIDHelper.hasNewIDs(mathingLocalWork, orcidWork)) { Work workUpdate = ORCIDHelper.clone(mathingLocalWork); - WorkExternalIdentifiers weids = new WorkExternalIdentifiers(); - List neids = new ArrayList(matchingLocalWorks.get(mathingLocalWork).more); - weids.setWorkExternalIdentifier(neids); + ExternalIds weids = new ExternalIds(); + List neids = new ArrayList(matchingLocalWorks.get(mathingLocalWork).more); + weids.setExternalId(neids); ORCIDHelper.setWorkLocalKey(workUpdate, ORCIDHelper.getActivityLocalKey(mathingLocalWork)); - workUpdate.setExternalIdentifiers(weids); + workUpdate.setExternalIds(weids); workUpdate.setTitle(null); workUpdate.setType(null); workUpdate.setPublicationDate(null); diff --git a/src/main/java/pt/ptcris/utils/ExternalIdsDiff.java b/src/main/java/pt/ptcris/utils/ExternalIdsDiff.java index c4b6925..5d481c6 100644 --- a/src/main/java/pt/ptcris/utils/ExternalIdsDiff.java +++ b/src/main/java/pt/ptcris/utils/ExternalIdsDiff.java @@ -5,9 +5,9 @@ import java.util.List; import java.util.Set; +import org.um.dsi.gavea.orcid.model.common.ExternalId; +import org.um.dsi.gavea.orcid.model.common.ExternalIds; import org.um.dsi.gavea.orcid.model.common.RelationshipType; -import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier; -import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers; /** * Calculates and stores the symmetric difference between two sets of @@ -19,17 +19,17 @@ public final class ExternalIdsDiff { /** * External identifiers removed from the first set. */ - public final Set less = new HashSet(); + public final Set less = new HashSet(); /** * External identifiers preserved in both sets. */ - public final Set same = new HashSet(); + public final Set same = new HashSet(); /** * External identifiers inserted in the second set. */ - public final Set more = new HashSet(); + public final Set more = new HashSet(); /** * Calculates and stores the symmetric difference between two sets of @@ -40,15 +40,15 @@ public final class ExternalIdsDiff { * @param eids2 * the second set of external identifiers */ - public ExternalIdsDiff(WorkExternalIdentifiers weids1, WorkExternalIdentifiers weids2) { - List eids1 = new LinkedList(); - List eids2 = new LinkedList(); + public ExternalIdsDiff(ExternalIds weids1, ExternalIds weids2) { + List eids1 = new LinkedList(); + List eids2 = new LinkedList(); - if (weids1 != null && weids1.getWorkExternalIdentifier() != null) - eids1.addAll(weids1.getWorkExternalIdentifier()); + if (weids1 != null && weids1.getExternalId() != null) + eids1.addAll(weids1.getExternalId()); - if (weids2 != null && weids2.getWorkExternalIdentifier() != null) - eids2.addAll(weids2.getWorkExternalIdentifier()); + if (weids2 != null && weids2.getExternalId() != null) + eids2.addAll(weids2.getExternalId()); calculateDifference(eids1, eids2); } @@ -68,14 +68,14 @@ public ExternalIdsDiff(WorkExternalIdentifiers weids1, WorkExternalIdentifiers w * @param eids2 * another set of UIDs */ - private void calculateDifference(List eids1, List eids2) { + private void calculateDifference(List eids1, List eids2) { less.addAll(eids1); more.addAll(eids2); - for (final ExternalIdentifier eid2 : eids2) { - for (final ExternalIdentifier eid1 : eids1) { - if (sameButNotBothPartOf(eid2.getRelationship(),eid1.getRelationship()) - && eid1.getExternalIdentifierId().equals(eid2.getExternalIdentifierId()) - && eid1.getExternalIdentifierType().equals(eid2.getExternalIdentifierType())) { + for (final ExternalId eid2 : eids2) { + for (final ExternalId eid1 : eids1) { + if (sameButNotBothPartOf(eid2.getExternalIdRelationship(),eid1.getExternalIdRelationship()) + && eid1.getExternalIdValue().equals(eid2.getExternalIdValue()) + && eid1.getExternalIdType().equals(eid2.getExternalIdType())) { same.add(eid2); less.remove(eid1); more.remove(eid2); diff --git a/src/main/java/pt/ptcris/utils/ORCIDHelper.java b/src/main/java/pt/ptcris/utils/ORCIDHelper.java index c2c4e3a..453c89d 100644 --- a/src/main/java/pt/ptcris/utils/ORCIDHelper.java +++ b/src/main/java/pt/ptcris/utils/ORCIDHelper.java @@ -17,15 +17,13 @@ import org.apache.logging.log4j.Logger; import org.um.dsi.gavea.orcid.client.exception.OrcidClientException; import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary; -import org.um.dsi.gavea.orcid.model.activities.Identifier; import org.um.dsi.gavea.orcid.model.activities.WorkGroup; -import org.um.dsi.gavea.orcid.model.common.ActivitySummary; import org.um.dsi.gavea.orcid.model.common.ClientId; +import org.um.dsi.gavea.orcid.model.common.ElementSummary; +import org.um.dsi.gavea.orcid.model.common.ExternalId; +import org.um.dsi.gavea.orcid.model.common.ExternalIds; import org.um.dsi.gavea.orcid.model.common.RelationshipType; -import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier; -import org.um.dsi.gavea.orcid.model.work.ExternalIdentifierType; import org.um.dsi.gavea.orcid.model.work.Work; -import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers; import org.um.dsi.gavea.orcid.model.work.WorkSummary; import pt.ptcris.ORCIDClient; @@ -213,7 +211,7 @@ public Work getFullWork(WorkSummary mergedWork) * the original summary */ static void finalizeGet(Work fullWork, WorkSummary sumWork) { - fullWork.setExternalIdentifiers(sumWork.getExternalIdentifiers()); + fullWork.setExternalIds(sumWork.getExternalIds()); cleanWorkLocalKey(fullWork); } @@ -340,7 +338,7 @@ public boolean waitWorkers() throws InterruptedException { * @throws NullPointerException * if the activity is null */ - public static BigInteger getActivityLocalKey(ActivitySummary act) throws NullPointerException { + public static BigInteger getActivityLocalKey(ElementSummary act) throws NullPointerException { if (act == null) throw new NullPointerException("Can't get local key."); @@ -356,7 +354,7 @@ public static BigInteger getActivityLocalKey(ActivitySummary act) throws NullPoi * @throws NullPointerException * if the activity is null */ - public static void setWorkLocalKey(ActivitySummary act, BigInteger key) throws NullPointerException { + public static void setWorkLocalKey(ElementSummary act, BigInteger key) throws NullPointerException { if (act == null) throw new NullPointerException("Can't set local key."); @@ -372,7 +370,7 @@ public static void setWorkLocalKey(ActivitySummary act, BigInteger key) throws N * @throws NullPointerException * if the activity is null */ - private static void cleanWorkLocalKey(ActivitySummary act) throws NullPointerException { + private static void cleanWorkLocalKey(ElementSummary act) throws NullPointerException { if (act == null) throw new NullPointerException("Can't clear local key."); @@ -400,7 +398,7 @@ public static Map getExternalIdsDiff(WorkSummary work, Co final Map matches = new HashMap(); for (Work match : works) { final ExternalIdsDiff diff = - new ExternalIdsDiff(match.getExternalIdentifiers(), work.getExternalIdentifiers()); + new ExternalIdsDiff(match.getExternalIds(), work.getExternalIds()); if (!diff.same.isEmpty()) matches.put(match, diff); } @@ -424,8 +422,8 @@ public static Map getExternalIdsDiff(WorkSummary work, Co */ public static boolean hasNewIDs(Work preWork, WorkSummary posWork) { final ExternalIdsDiff diff = new ExternalIdsDiff( - preWork.getExternalIdentifiers(), - posWork.getExternalIdentifiers()); + preWork.getExternalIds(), + posWork.getExternalIds()); return diff.more.isEmpty(); } @@ -482,8 +480,8 @@ private static boolean isIDsUpToDate(Work preWork, WorkSummary posWork) throw new NullPointerException("Can't test null works."); final ExternalIdsDiff diff = new ExternalIdsDiff( - preWork.getExternalIdentifiers(), - posWork.getExternalIdentifiers()); + preWork.getExternalIds(), + posWork.getExternalIds()); return diff.more.isEmpty() && diff.less.isEmpty(); } @@ -504,8 +502,8 @@ private static boolean isIDsUpToDate(Work preWork, Work posWork) throw new NullPointerException("Can't test null works."); final ExternalIdsDiff diff = new ExternalIdsDiff( - preWork.getExternalIdentifiers(), - posWork.getExternalIdentifiers()); + preWork.getExternalIds(), + posWork.getExternalIds()); return diff.more.isEmpty() && diff.less.isEmpty(); } @@ -598,10 +596,10 @@ public static Set testMinimalQuality(Work work) throws NullPointerExcept throw new NullPointerException("Can't test null work."); final Set res = new HashSet(); - if (work.getExternalIdentifiers() == null) + if (work.getExternalIds() == null) res.add(INVALID_EXTERNALIDENTIFIERS); - else if (work.getExternalIdentifiers().getWorkExternalIdentifier() == null - || work.getExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) + else if (work.getExternalIds().getExternalId() == null + || work.getExternalIds().getExternalId().isEmpty()) res.add(INVALID_WORKEXTERNALIDENTIFIERS); if (work.getTitle() == null) res.add(INVALID_TITLE); @@ -638,10 +636,10 @@ public static Set testMinimalQuality(WorkSummary work) throws NullPointe throw new NullPointerException("Can't test null work."); final Set res = new HashSet(); - if (work.getExternalIdentifiers() == null) + if (work.getExternalIds() == null) res.add(INVALID_EXTERNALIDENTIFIERS); - else if (work.getExternalIdentifiers().getWorkExternalIdentifier() == null - || work.getExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) + else if (work.getExternalIds().getExternalId() == null + || work.getExternalIds().getExternalId().isEmpty()) res.add(INVALID_WORKEXTERNALIDENTIFIERS); if (work.getTitle() == null) res.add(INVALID_TITLE); @@ -728,16 +726,15 @@ private static WorkSummary groupToWork(WorkGroup group) final WorkSummary preferred = group.getWorkSummary().get(0); final WorkSummary dummy = clone(preferred); - final List eids = new ArrayList(); - for (Identifier id : group.getIdentifiers().getIdentifier()) { - final ExternalIdentifier eid = new ExternalIdentifier(); - eid.setRelationship(RelationshipType.SELF); - eid.setExternalIdentifierType(ExternalIdentifierType.fromValue(id - .getExternalIdentifierType().toLowerCase())); - eid.setExternalIdentifierId(id.getExternalIdentifierId()); + final List eids = new ArrayList(); + for (ExternalId id : group.getExternalIds().getExternalId()) { + final ExternalId eid = new ExternalId(); + eid.setExternalIdRelationship(RelationshipType.SELF); + eid.setExternalIdType(id.getExternalIdType().toLowerCase()); + eid.setExternalIdValue(id.getExternalIdValue()); eids.add(eid); } - dummy.setExternalIdentifiers(new WorkExternalIdentifiers(eids)); + dummy.setExternalIds(new ExternalIds(eids)); return dummy; } @@ -808,7 +805,7 @@ private static String getPubYear(WorkSummary work) { * the target summary * @throws NullPointerException if either argument is null */ - private static void copy(ActivitySummary from, ActivitySummary to) + private static void copy(ElementSummary from, ElementSummary to) throws NullPointerException { if (from == null || to == null) throw new NullPointerException("Can't copy null works."); @@ -837,7 +834,7 @@ public static WorkSummary clone(WorkSummary work) { dummy.setPublicationDate(work.getPublicationDate()); dummy.setTitle(work.getTitle()); dummy.setType(work.getType()); - dummy.setExternalIdentifiers(work.getExternalIdentifiers()); + dummy.setExternalIds(work.getExternalIds()); return dummy; } @@ -856,7 +853,7 @@ public static Work clone(Work work) { dummy.setPublicationDate(work.getPublicationDate()); dummy.setTitle(work.getTitle()); dummy.setType(work.getType()); - dummy.setExternalIdentifiers(work.getExternalIdentifiers()); + dummy.setExternalIds(work.getExternalIds()); dummy.setContributors(work.getContributors()); dummy.setCitation(work.getCitation()); diff --git a/src/test/java/pt/ptcris/test/PTCRISExample.java b/src/test/java/pt/ptcris/test/PTCRISExample.java index 5bf1d55..8f46597 100644 --- a/src/test/java/pt/ptcris/test/PTCRISExample.java +++ b/src/test/java/pt/ptcris/test/PTCRISExample.java @@ -11,11 +11,10 @@ import java.util.logging.SimpleFormatter; import org.um.dsi.gavea.orcid.client.exception.OrcidClientException; +import org.um.dsi.gavea.orcid.model.common.ExternalId; +import org.um.dsi.gavea.orcid.model.common.ExternalIds; import org.um.dsi.gavea.orcid.model.common.RelationshipType; -import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier; -import org.um.dsi.gavea.orcid.model.work.ExternalIdentifierType; import org.um.dsi.gavea.orcid.model.work.Work; -import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers; import org.um.dsi.gavea.orcid.model.work.WorkTitle; import org.um.dsi.gavea.orcid.model.work.WorkType; @@ -91,16 +90,16 @@ private static Work work0() { title.setTitle("Yet Another Work Updated Once"); work.setTitle(title); - ExternalIdentifier e = new ExternalIdentifier(); - e.setRelationship(RelationshipType.SELF); - e.setExternalIdentifierId("3000"); - e.setExternalIdentifierType(ExternalIdentifierType.DOI); + ExternalId e = new ExternalId(); + e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdValue("3000"); + e.setExternalIdType("DOI"); - WorkExternalIdentifiers uids = new WorkExternalIdentifiers(); + ExternalIds uids = new ExternalIds(); - uids.getWorkExternalIdentifier().add(e); + uids.getExternalId().add(e); - work.setExternalIdentifiers(uids); + work.setExternalIds(uids); work.setType(WorkType.CONFERENCE_PAPER); @@ -113,22 +112,22 @@ private static Work work1() { title.setTitle("A Work Updated Once"); work.setTitle(title); - ExternalIdentifier e = new ExternalIdentifier(); - e.setRelationship(RelationshipType.SELF); - e.setExternalIdentifierId("4000"); - e.setExternalIdentifierType(ExternalIdentifierType.EID); + ExternalId e = new ExternalId(); + e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdValue("4000"); + e.setExternalIdType("EID"); - ExternalIdentifier e1 = new ExternalIdentifier(); - e1.setRelationship(RelationshipType.SELF); - e1.setExternalIdentifierId("00001"); - e1.setExternalIdentifierType(ExternalIdentifierType.DOI); + ExternalId e1 = new ExternalId(); + e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdValue("00001"); + e1.setExternalIdType("DOI"); - WorkExternalIdentifiers uids = new WorkExternalIdentifiers(); + ExternalIds uids = new ExternalIds(); - uids.getWorkExternalIdentifier().add(e); - uids.getWorkExternalIdentifier().add(e1); + uids.getExternalId().add(e); + uids.getExternalId().add(e1); - work.setExternalIdentifiers(uids); + work.setExternalIds(uids); work.setType(WorkType.CONFERENCE_PAPER); @@ -141,18 +140,18 @@ private static Work work2() { title.setTitle("Another Work Updated Twice"); work.setTitle(title); - ExternalIdentifier e = new ExternalIdentifier(); - e.setRelationship(RelationshipType.SELF); + ExternalId e = new ExternalId(); + e.setExternalIdRelationship(RelationshipType.SELF); // avoids conflicts - e.setExternalIdentifierId(String.valueOf(System.currentTimeMillis())); + e.setExternalIdValue(String.valueOf(System.currentTimeMillis())); - e.setExternalIdentifierType(ExternalIdentifierType.DOI); + e.setExternalIdType("DOI"); - WorkExternalIdentifiers uids = new WorkExternalIdentifiers(); + ExternalIds uids = new ExternalIds(); - uids.getWorkExternalIdentifier().add(e); + uids.getExternalId().add(e); - work.setExternalIdentifiers(uids); + work.setExternalIds(uids); work.setType(WorkType.JOURNAL_ARTICLE); diff --git a/src/test/java/pt/ptcris/test/TestHelper.java b/src/test/java/pt/ptcris/test/TestHelper.java index dc812c0..f51b484 100644 --- a/src/test/java/pt/ptcris/test/TestHelper.java +++ b/src/test/java/pt/ptcris/test/TestHelper.java @@ -6,13 +6,12 @@ import java.util.logging.Logger; import java.util.logging.SimpleFormatter; +import org.um.dsi.gavea.orcid.model.common.ExternalId; +import org.um.dsi.gavea.orcid.model.common.ExternalIds; import org.um.dsi.gavea.orcid.model.common.FuzzyDate; import org.um.dsi.gavea.orcid.model.common.FuzzyDate.Year; import org.um.dsi.gavea.orcid.model.common.RelationshipType; -import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier; -import org.um.dsi.gavea.orcid.model.work.ExternalIdentifierType; import org.um.dsi.gavea.orcid.model.work.Work; -import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers; import org.um.dsi.gavea.orcid.model.work.WorkTitle; import org.um.dsi.gavea.orcid.model.work.WorkType; @@ -26,8 +25,8 @@ public class TestHelper { public static Work work(BigInteger key, String meta) { Work work = new Work(); - WorkExternalIdentifiers uids = new WorkExternalIdentifiers(); - work.setExternalIdentifiers(uids); + ExternalIds uids = new ExternalIds(); + work.setExternalIds(uids); work.setPutCode(key); @@ -51,12 +50,12 @@ public static Work work(BigInteger key, String meta) { public static Work workDOI(BigInteger key, String meta, String doi) { Work work = work(key, meta); - ExternalIdentifier e1 = new ExternalIdentifier(); - e1.setRelationship(RelationshipType.SELF); - e1.setExternalIdentifierId(doi); - e1.setExternalIdentifierType(ExternalIdentifierType.DOI); + ExternalId e1 = new ExternalId(); + e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdValue(doi); + e1.setExternalIdType("DOI"); - work.getExternalIdentifiers().getWorkExternalIdentifier().add(e1); + work.getExternalIds().getExternalId().add(e1); return work; } @@ -64,12 +63,12 @@ public static Work workDOI(BigInteger key, String meta, String doi) { public static Work workHANDLE(BigInteger key, String meta, String handle) { Work work = work(key, meta); - ExternalIdentifier e1 = new ExternalIdentifier(); - e1.setRelationship(RelationshipType.SELF); - e1.setExternalIdentifierId(handle); - e1.setExternalIdentifierType(ExternalIdentifierType.HANDLE); + ExternalId e1 = new ExternalId(); + e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdValue(handle); + e1.setExternalIdType("HANDLE"); - work.getExternalIdentifiers().getWorkExternalIdentifier().add(e1); + work.getExternalIds().getExternalId().add(e1); return work; } @@ -77,12 +76,12 @@ public static Work workHANDLE(BigInteger key, String meta, String handle) { public static Work workDOIEID(BigInteger key, String meta, String doi, String eid) { Work work = workDOI(key, meta, doi); - ExternalIdentifier e = new ExternalIdentifier(); - e.setRelationship(RelationshipType.SELF); - e.setExternalIdentifierId(eid); - e.setExternalIdentifierType(ExternalIdentifierType.EID); + ExternalId e = new ExternalId(); + e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdValue(eid); + e.setExternalIdType("EID"); - work.getExternalIdentifiers().getWorkExternalIdentifier().add(e); + work.getExternalIds().getExternalId().add(e); return work; } @@ -90,12 +89,12 @@ public static Work workDOIEID(BigInteger key, String meta, String doi, String ei public static Work workDOIHANDLE(BigInteger key, String meta, String doi, String handle) { Work work = workDOI(key, meta, doi); - ExternalIdentifier e = new ExternalIdentifier(); - e.setRelationship(RelationshipType.SELF); - e.setExternalIdentifierId(handle); - e.setExternalIdentifierType(ExternalIdentifierType.HANDLE); + ExternalId e = new ExternalId(); + e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdValue(handle); + e.setExternalIdType("HANDLE"); - work.getExternalIdentifiers().getWorkExternalIdentifier().add(e); + work.getExternalIds().getExternalId().add(e); return work; } @@ -103,12 +102,12 @@ public static Work workDOIHANDLE(BigInteger key, String meta, String doi, String public static Work workEIDHANDLE(BigInteger key, String meta, String eid, String handle) { Work work = workHANDLE(key, meta, handle); - ExternalIdentifier e = new ExternalIdentifier(); - e.setRelationship(RelationshipType.SELF); - e.setExternalIdentifierId(eid); - e.setExternalIdentifierType(ExternalIdentifierType.EID); + ExternalId e = new ExternalId(); + e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdValue(eid); + e.setExternalIdType("EID"); - work.getExternalIdentifiers().getWorkExternalIdentifier().add(e); + work.getExternalIds().getExternalId().add(e); return work; } @@ -116,12 +115,12 @@ public static Work workEIDHANDLE(BigInteger key, String meta, String eid, String public static Work workDOIEIDHANDLE(BigInteger key, String meta, String doi, String eid, String handle) { Work work = workDOIEID(key, meta, doi, eid); - ExternalIdentifier e2 = new ExternalIdentifier(); - e2.setRelationship(RelationshipType.SELF); - e2.setExternalIdentifierId(handle); - e2.setExternalIdentifierType(ExternalIdentifierType.HANDLE); + ExternalId e2 = new ExternalId(); + e2.setExternalIdRelationship(RelationshipType.SELF); + e2.setExternalIdValue(handle); + e2.setExternalIdType("HANDLE"); - work.getExternalIdentifiers().getWorkExternalIdentifier().add(e2); + work.getExternalIds().getExternalId().add(e2); return work; } @@ -129,12 +128,12 @@ public static Work workDOIEIDHANDLE(BigInteger key, String meta, String doi, Str public static Work workDOIDOIEIDHANDLE(BigInteger key, String meta, String doi1, String doi2, String eid, String handle) { Work work = workDOIEIDHANDLE(key, meta, doi1, eid, handle); - ExternalIdentifier e1 = new ExternalIdentifier(); - e1.setRelationship(RelationshipType.SELF); - e1.setExternalIdentifierId(doi2); - e1.setExternalIdentifierType(ExternalIdentifierType.DOI); + ExternalId e1 = new ExternalId(); + e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdValue(doi2); + e1.setExternalIdType("DOI"); - work.getExternalIdentifiers().getWorkExternalIdentifier().add(e1); + work.getExternalIds().getExternalId().add(e1); return work; } From 63562315ee32d17040b639bdc2d7318e5a0b7883 Mon Sep 17 00:00:00 2001 From: nmacedo Date: Tue, 25 Oct 2016 10:31:47 +0100 Subject: [PATCH 03/13] fixed bug on eids case --- src/test/java/pt/ptcris/test/TestHelper.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/test/java/pt/ptcris/test/TestHelper.java b/src/test/java/pt/ptcris/test/TestHelper.java index f51b484..71db736 100644 --- a/src/test/java/pt/ptcris/test/TestHelper.java +++ b/src/test/java/pt/ptcris/test/TestHelper.java @@ -53,7 +53,7 @@ public static Work workDOI(BigInteger key, String meta, String doi) { ExternalId e1 = new ExternalId(); e1.setExternalIdRelationship(RelationshipType.SELF); e1.setExternalIdValue(doi); - e1.setExternalIdType("DOI"); + e1.setExternalIdType("doi"); work.getExternalIds().getExternalId().add(e1); @@ -66,7 +66,7 @@ public static Work workHANDLE(BigInteger key, String meta, String handle) { ExternalId e1 = new ExternalId(); e1.setExternalIdRelationship(RelationshipType.SELF); e1.setExternalIdValue(handle); - e1.setExternalIdType("HANDLE"); + e1.setExternalIdType("handle"); work.getExternalIds().getExternalId().add(e1); @@ -79,10 +79,9 @@ public static Work workDOIEID(BigInteger key, String meta, String doi, String ei ExternalId e = new ExternalId(); e.setExternalIdRelationship(RelationshipType.SELF); e.setExternalIdValue(eid); - e.setExternalIdType("EID"); - + e.setExternalIdType("eid"); + work.getExternalIds().getExternalId().add(e); - return work; } @@ -92,8 +91,8 @@ public static Work workDOIHANDLE(BigInteger key, String meta, String doi, String ExternalId e = new ExternalId(); e.setExternalIdRelationship(RelationshipType.SELF); e.setExternalIdValue(handle); - e.setExternalIdType("HANDLE"); - + e.setExternalIdType("handle"); + work.getExternalIds().getExternalId().add(e); return work; @@ -105,7 +104,7 @@ public static Work workEIDHANDLE(BigInteger key, String meta, String eid, String ExternalId e = new ExternalId(); e.setExternalIdRelationship(RelationshipType.SELF); e.setExternalIdValue(eid); - e.setExternalIdType("EID"); + e.setExternalIdType("eid"); work.getExternalIds().getExternalId().add(e); @@ -118,7 +117,7 @@ public static Work workDOIEIDHANDLE(BigInteger key, String meta, String doi, Str ExternalId e2 = new ExternalId(); e2.setExternalIdRelationship(RelationshipType.SELF); e2.setExternalIdValue(handle); - e2.setExternalIdType("HANDLE"); + e2.setExternalIdType("handle"); work.getExternalIds().getExternalId().add(e2); @@ -131,7 +130,7 @@ public static Work workDOIDOIEIDHANDLE(BigInteger key, String meta, String doi1, ExternalId e1 = new ExternalId(); e1.setExternalIdRelationship(RelationshipType.SELF); e1.setExternalIdValue(doi2); - e1.setExternalIdType("DOI"); + e1.setExternalIdType("doi"); work.getExternalIds().getExternalId().add(e1); From e5736264a00287ac52979271fba3af7dcd4a033e Mon Sep 17 00:00:00 2001 From: nmacedo Date: Wed, 2 Nov 2016 22:27:30 +0000 Subject: [PATCH 04/13] test for valid external identifiers --- .../java/pt/ptcris/utils/ORCIDHelper.java | 58 +++++++++++++++---- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/src/main/java/pt/ptcris/utils/ORCIDHelper.java b/src/main/java/pt/ptcris/utils/ORCIDHelper.java index 453c89d..d378ea8 100644 --- a/src/main/java/pt/ptcris/utils/ORCIDHelper.java +++ b/src/main/java/pt/ptcris/utils/ORCIDHelper.java @@ -25,6 +25,7 @@ import org.um.dsi.gavea.orcid.model.common.RelationshipType; import org.um.dsi.gavea.orcid.model.work.Work; import org.um.dsi.gavea.orcid.model.work.WorkSummary; +import org.um.dsi.gavea.orcid.model.work.WorkType; import pt.ptcris.ORCIDClient; import pt.ptcris.exceptions.InvalidWorkException; @@ -40,11 +41,25 @@ public class ORCIDHelper { public static final String INVALID_EXTERNALIDENTIFIERS = "ExternalIdentifiers"; - public static final String INVALID_WORKEXTERNALIDENTIFIERS = "WorkExternalIdentifiers"; public static final String INVALID_TITLE = "Title"; public static final String INVALID_PUBLICATIONDATE = "PublicationDate"; public static final String INVALID_YEAR = "Year"; public static final String INVALID_TYPE = "Type"; + + public enum EIdType { + OTHER_ID("other-id"), AGR("agr"), ARXIV("arxiv"), ASIN("asin"), + BIBCODE("bibcode"), CBA("cba"), CIT("cit"), CTX("ctx"), DOI("doi"), + EID("eid"), ETHOS("ethos"), HANDLE("handle"), HIR("hir"), ISBN("isbn"), + ISSN("issn"), JFM("jfm"), JSTOR("jstor"), LCCN("lccn"), MR("mr"), + OCLC("oclc"), OL("ol"), OSTI("osti"), PAT("pat"), PMC("pmc"), PMID("pmid"), + RFC("rfc"), SOURCE_WORK_ID("source-work-id"), SSRN("ssrn"), URI("uri"), + URN("urn"), WOSUID("wosuid"), ZBL("zbl"); + + String value; + private EIdType(String value) { + this.value = value; + } + } /** * Whether to multi-thread the "get" of full works. @@ -600,21 +615,36 @@ public static Set testMinimalQuality(Work work) throws NullPointerExcept res.add(INVALID_EXTERNALIDENTIFIERS); else if (work.getExternalIds().getExternalId() == null || work.getExternalIds().getExternalId().isEmpty()) - res.add(INVALID_WORKEXTERNALIDENTIFIERS); + res.add(INVALID_EXTERNALIDENTIFIERS); + else + for (ExternalId eid : work.getExternalIds().getExternalId()) + if (!validEIdType(eid.getExternalIdType())) res.add(INVALID_EXTERNALIDENTIFIERS); if (work.getTitle() == null) res.add(INVALID_TITLE); else if (work.getTitle().getTitle() == null) res.add(INVALID_TITLE); - if (work.getPublicationDate() == null) - res.add(INVALID_PUBLICATIONDATE); - else if (work.getPublicationDate().getYear() == null) - res.add(INVALID_YEAR); if (work.getType() == null) res.add(INVALID_TYPE); + if (work.getType() == null || + (work.getType() != WorkType.DATA_SET && work.getType() != WorkType.RESEARCH_TECHNIQUE)) { + if (work.getPublicationDate() == null) + res.add(INVALID_PUBLICATIONDATE); + else if (work.getPublicationDate().getYear() == null) + res.add(INVALID_YEAR); + } return res; } + private static boolean validEIdType(String eid) { + try { + EIdType.valueOf(eid.replace('-', '_').toUpperCase()); + return true; + } catch (Exception e) { + return false; + } + } + /** * Tests whether a work has minimal quality to be synchronized, by * inspecting its meta-data, returns the detected invalid fields. @@ -640,17 +670,23 @@ public static Set testMinimalQuality(WorkSummary work) throws NullPointe res.add(INVALID_EXTERNALIDENTIFIERS); else if (work.getExternalIds().getExternalId() == null || work.getExternalIds().getExternalId().isEmpty()) - res.add(INVALID_WORKEXTERNALIDENTIFIERS); + res.add(INVALID_EXTERNALIDENTIFIERS); + else + for (ExternalId eid : work.getExternalIds().getExternalId()) + if (!validEIdType(eid.getExternalIdType())) res.add(INVALID_EXTERNALIDENTIFIERS); if (work.getTitle() == null) res.add(INVALID_TITLE); else if (work.getTitle().getTitle() == null) res.add(INVALID_TITLE); - if (work.getPublicationDate() == null) - res.add(INVALID_PUBLICATIONDATE); - else if (work.getPublicationDate().getYear() == null) - res.add(INVALID_YEAR); if (work.getType() == null) res.add(INVALID_TYPE); + if (work.getType() == null || + (work.getType() != WorkType.DATA_SET && work.getType() != WorkType.RESEARCH_TECHNIQUE)) { + if (work.getPublicationDate() == null) + res.add(INVALID_PUBLICATIONDATE); + else if (work.getPublicationDate().getYear() == null) + res.add(INVALID_YEAR); + } return res; } From 39ccd6c8fde8c18531cb4e438084e964144fb32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Lopes?= Date: Thu, 3 Nov 2016 11:41:59 +0000 Subject: [PATCH 05/13] Test scenarios fix --- src/test/java/pt/ptcris/test/scenarios/Scenario01.java | 2 +- src/test/java/pt/ptcris/test/scenarios/Scenario02.java | 2 +- src/test/java/pt/ptcris/test/scenarios/Scenario03.java | 2 +- src/test/java/pt/ptcris/test/scenarios/Scenario15.java | 2 +- src/test/java/pt/ptcris/test/scenarios/Scenario16.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario01.java b/src/test/java/pt/ptcris/test/scenarios/Scenario01.java index 01da1f6..81e2d8e 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario01.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario01.java @@ -53,7 +53,7 @@ List expectedImportedInvalidWorks() { @Override Set expectedInvalidCodes(BigInteger putCode) { Set res = new HashSet(); - res.add(ORCIDHelper.INVALID_WORKEXTERNALIDENTIFIERS); + res.add(ORCIDHelper.INVALID_EXTERNALIDENTIFIERS); return res; } diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario02.java b/src/test/java/pt/ptcris/test/scenarios/Scenario02.java index 9ee6d33..ea8741a 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario02.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario02.java @@ -57,7 +57,7 @@ List expectedImportedInvalidWorks() { @Override Set expectedInvalidCodes(BigInteger putCode) { Set res = new HashSet(); - res.add(ORCIDHelper.INVALID_WORKEXTERNALIDENTIFIERS); + res.add(ORCIDHelper.INVALID_EXTERNALIDENTIFIERS); return res; } diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario03.java b/src/test/java/pt/ptcris/test/scenarios/Scenario03.java index 8da2bf4..46399c9 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario03.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario03.java @@ -49,7 +49,7 @@ List expectedImportedInvalidWorks() { @Override Set expectedInvalidCodes(BigInteger putCode) { Set res = new HashSet(); - res.add(ORCIDHelper.INVALID_WORKEXTERNALIDENTIFIERS); + res.add(ORCIDHelper.INVALID_EXTERNALIDENTIFIERS); return res; } diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario15.java b/src/test/java/pt/ptcris/test/scenarios/Scenario15.java index 6425339..b7ccd82 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario15.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario15.java @@ -47,7 +47,7 @@ List expectedImportedInvalidWorks() { @Override Set expectedInvalidCodes(BigInteger putCode) { Set res = new HashSet(); - res.add(ORCIDHelper.INVALID_WORKEXTERNALIDENTIFIERS); + res.add(ORCIDHelper.INVALID_EXTERNALIDENTIFIERS); return res; } diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario16.java b/src/test/java/pt/ptcris/test/scenarios/Scenario16.java index 1b94434..54818f8 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario16.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario16.java @@ -57,7 +57,7 @@ List expectedImportedInvalidWorks() { @Override Set expectedInvalidCodes(BigInteger putCode) { Set res = new HashSet(); - res.add(ORCIDHelper.INVALID_WORKEXTERNALIDENTIFIERS); + res.add(ORCIDHelper.INVALID_EXTERNALIDENTIFIERS); return res; } From 3b363c03c233984e2a3fc61ac1a90bcd5427a2d2 Mon Sep 17 00:00:00 2001 From: nmacedo Date: Thu, 3 Nov 2016 13:31:18 +0000 Subject: [PATCH 06/13] tests updated --- src/test/java/pt/ptcris/test/TestHelper.java | 25 +++++++++++++++++++ .../pt/ptcris/test/scenarios/Scenario01.java | 2 +- .../pt/ptcris/test/scenarios/Scenario02.java | 2 +- .../pt/ptcris/test/scenarios/Scenario03.java | 2 +- .../pt/ptcris/test/scenarios/Scenario15.java | 2 +- .../pt/ptcris/test/scenarios/Scenario16.java | 2 +- 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/test/java/pt/ptcris/test/TestHelper.java b/src/test/java/pt/ptcris/test/TestHelper.java index 71db736..460fc36 100644 --- a/src/test/java/pt/ptcris/test/TestHelper.java +++ b/src/test/java/pt/ptcris/test/TestHelper.java @@ -59,6 +59,31 @@ public static Work workDOI(BigInteger key, String meta, String doi) { return work; } + + public static Work workUnk(BigInteger key, String meta, String doi) { + Work work = work(key, meta); + + ExternalId e1 = new ExternalId(); + e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdValue(doi); + e1.setExternalIdType("ukn"); + + work.getExternalIds().getExternalId().add(e1); + + return work; + } + + public static Work workDOIUnk(BigInteger key, String meta, String doi, String eid) { + Work work = workDOI(key, meta, doi); + + ExternalId e = new ExternalId(); + e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdValue(eid); + e.setExternalIdType("wosuid-"); + + work.getExternalIds().getExternalId().add(e); + return work; + } public static Work workHANDLE(BigInteger key, String meta, String handle) { Work work = work(key, meta); diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario01.java b/src/test/java/pt/ptcris/test/scenarios/Scenario01.java index 01da1f6..81e2d8e 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario01.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario01.java @@ -53,7 +53,7 @@ List expectedImportedInvalidWorks() { @Override Set expectedInvalidCodes(BigInteger putCode) { Set res = new HashSet(); - res.add(ORCIDHelper.INVALID_WORKEXTERNALIDENTIFIERS); + res.add(ORCIDHelper.INVALID_EXTERNALIDENTIFIERS); return res; } diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario02.java b/src/test/java/pt/ptcris/test/scenarios/Scenario02.java index 9ee6d33..ea8741a 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario02.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario02.java @@ -57,7 +57,7 @@ List expectedImportedInvalidWorks() { @Override Set expectedInvalidCodes(BigInteger putCode) { Set res = new HashSet(); - res.add(ORCIDHelper.INVALID_WORKEXTERNALIDENTIFIERS); + res.add(ORCIDHelper.INVALID_EXTERNALIDENTIFIERS); return res; } diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario03.java b/src/test/java/pt/ptcris/test/scenarios/Scenario03.java index 8da2bf4..46399c9 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario03.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario03.java @@ -49,7 +49,7 @@ List expectedImportedInvalidWorks() { @Override Set expectedInvalidCodes(BigInteger putCode) { Set res = new HashSet(); - res.add(ORCIDHelper.INVALID_WORKEXTERNALIDENTIFIERS); + res.add(ORCIDHelper.INVALID_EXTERNALIDENTIFIERS); return res; } diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario15.java b/src/test/java/pt/ptcris/test/scenarios/Scenario15.java index 6425339..b7ccd82 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario15.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario15.java @@ -47,7 +47,7 @@ List expectedImportedInvalidWorks() { @Override Set expectedInvalidCodes(BigInteger putCode) { Set res = new HashSet(); - res.add(ORCIDHelper.INVALID_WORKEXTERNALIDENTIFIERS); + res.add(ORCIDHelper.INVALID_EXTERNALIDENTIFIERS); return res; } diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario16.java b/src/test/java/pt/ptcris/test/scenarios/Scenario16.java index 1b94434..54818f8 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario16.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario16.java @@ -57,7 +57,7 @@ List expectedImportedInvalidWorks() { @Override Set expectedInvalidCodes(BigInteger putCode) { Set res = new HashSet(); - res.add(ORCIDHelper.INVALID_WORKEXTERNALIDENTIFIERS); + res.add(ORCIDHelper.INVALID_EXTERNALIDENTIFIERS); return res; } From 89102b0d1ab122e9d04818513da1e9ad0b599c98 Mon Sep 17 00:00:00 2001 From: nmacedo Date: Thu, 3 Nov 2016 21:51:01 +0000 Subject: [PATCH 07/13] scenarios cleaned up --- .../java/pt/ptcris/test/scenarios/Scenario.java | 5 ++++- .../java/pt/ptcris/test/scenarios/Scenario01.java | 15 +++++++++------ .../java/pt/ptcris/test/scenarios/Scenario02.java | 12 ++++++++++-- .../java/pt/ptcris/test/scenarios/Scenario03.java | 9 ++++++++- .../java/pt/ptcris/test/scenarios/Scenario04.java | 9 ++++++++- .../java/pt/ptcris/test/scenarios/Scenario05.java | 12 ++++++++++-- .../java/pt/ptcris/test/scenarios/Scenario06.java | 12 ++++++++++-- .../java/pt/ptcris/test/scenarios/Scenario07.java | 15 ++++++++++++++- .../java/pt/ptcris/test/scenarios/Scenario08.java | 10 +++++++++- .../java/pt/ptcris/test/scenarios/Scenario09.java | 11 +++++++++-- .../java/pt/ptcris/test/scenarios/Scenario10.java | 12 ++++++++++-- .../java/pt/ptcris/test/scenarios/Scenario11.java | 9 ++++++++- .../java/pt/ptcris/test/scenarios/Scenario12.java | 9 +++++++-- .../java/pt/ptcris/test/scenarios/Scenario13.java | 10 ++++++++-- .../java/pt/ptcris/test/scenarios/Scenario14.java | 8 +++++++- .../java/pt/ptcris/test/scenarios/Scenario15.java | 6 +++++- .../java/pt/ptcris/test/scenarios/Scenario16.java | 9 +++++++-- .../java/pt/ptcris/test/scenarios/Scenario17.java | 9 +++++++-- .../java/pt/ptcris/test/scenarios/Scenario18.java | 8 +++++++- .../java/pt/ptcris/test/scenarios/Scenario19.java | 7 ++++++- .../java/pt/ptcris/test/scenarios/Scenario20.java | 5 ++++- 21 files changed, 167 insertions(+), 35 deletions(-) diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario.java b/src/test/java/pt/ptcris/test/scenarios/Scenario.java index b061fc6..93d9305 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario.java @@ -26,7 +26,10 @@ /* TODO: Scenarios with notifications in the pre-state (7 and 16) must * be handled with caution, since modifications are not explicit in the - * current version of the system. */ + * current version of the system. + * + * TODO: Scenarios that deal with promotion/demotion of preferred (10) + */ public abstract class Scenario { private List localWorks, exportWorks; diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario01.java b/src/test/java/pt/ptcris/test/scenarios/Scenario01.java index 81e2d8e..48b6453 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario01.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario01.java @@ -14,15 +14,18 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: + * Scenario 1 of the PTCRISync specification v0.4.3, tests import. + * + * Features: * creation notification * - * TODO: this scenario does not exactly represent the one - * from the specification as this would require that the - * fixture work was set as the preferred, which is impossible - * programmatically. + * TODO: this scenario does not exactly represent the one from the specification + * as this would require that the fixture work was set as the preferred, which + * is impossible programmatically. This does not affect the scenario and one of + * the user-sourced is selected instead. + * + * @see Scenario */ - public class Scenario01 extends Scenario { /** {@inheritDoc} */ diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario02.java b/src/test/java/pt/ptcris/test/scenarios/Scenario02.java index ea8741a..046b0d2 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario02.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario02.java @@ -14,10 +14,18 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: modification notifications with {same,more} + * Scenario 2 of the PTCRISync specification v0.4.3, tests import. * + * Features: + * modification notifications with {same,more} + * + * TODO: this scenario does not exactly represent the one from the specification + * as this would require that the fixture work was set as the preferred, which + * is impossible programmatically. This does not affect the scenario and one of + * the user-sourced is selected instead. + * + * @see Scenario */ - public class Scenario02 extends Scenario { /** {@inheritDoc} */ diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario03.java b/src/test/java/pt/ptcris/test/scenarios/Scenario03.java index 46399c9..a13a14f 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario03.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario03.java @@ -14,10 +14,17 @@ import pt.ptcris.utils.ORCIDHelper; /** + * Scenario 3 of the PTCRISync specification v0.4.3, tests import. + * * Features: * + * TODO: this scenario does not exactly represent the one from the specification + * as this would require that the fixture work was set as the preferred, which + * is impossible programmatically. This does not affect the scenario and one of + * the user-sourced is selected instead. + * + * @see Scenario */ - public class Scenario03 extends Scenario { /** {@inheritDoc} */ diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario04.java b/src/test/java/pt/ptcris/test/scenarios/Scenario04.java index f4ea0af..28b20f3 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario04.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario04.java @@ -12,10 +12,17 @@ import pt.ptcris.utils.ORCIDHelper; /** + * Scenario 4 of the PTCRISync specification v0.4.3, tests import. + * * Features: * + * TODO: this scenario does not exactly represent the one from the specification + * as this would require that the fixture work was set as the preferred, which + * is impossible programmatically. This does not affect the scenario and one of + * the user-sourced is selected instead. + * + * @see Scenario */ - public class Scenario04 extends Scenario { /** {@inheritDoc} */ diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario05.java b/src/test/java/pt/ptcris/test/scenarios/Scenario05.java index ca49566..db22445 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario05.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario05.java @@ -12,10 +12,18 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: creation notification + * Scenario 5 of the PTCRISync specification v0.4.3, tests import. * + * Features: + * creation notification + * + * TODO: this scenario does not exactly represent the one from the specification + * as this would require that the fixture work was set as the preferred, which + * is impossible programmatically. This does not affect the scenario and one of + * the user-sourced is selected instead. + * + * @see Scenario */ - public class Scenario05 extends Scenario { /** {@inheritDoc} */ diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario06.java b/src/test/java/pt/ptcris/test/scenarios/Scenario06.java index 8db4d34..69b7149 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario06.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario06.java @@ -12,10 +12,18 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: modification notifications with {same,more} + * Scenario 6 of the PTCRISync specification v0.4.3, tests import. * + * Features: + * modification notifications with {same,more} + * + * TODO: this scenario does not exactly represent the one from the specification + * as this would require that the fixture work was set as the preferred, which + * is impossible programmatically. This does not affect the scenario and one of + * the user-sourced is selected instead. + * + * @see Scenario */ - public class Scenario06 extends Scenario { /** {@inheritDoc} */ diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario07.java b/src/test/java/pt/ptcris/test/scenarios/Scenario07.java index 5421ed7..f57834d 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario07.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario07.java @@ -12,8 +12,21 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: modification notifications at the pre-state + * Scenario 7 of the PTCRISync specification v0.4.3, tests import. * + * Features: + * modification notifications at the pre-state + * + * TODO: this scenario does not exactly represent the one from the specification + * since notifications are not passed to the procedures, thus notifications at + * pre-state cannot be represented. + * + * TODO: this scenario does not exactly represent the one from the specification + * as this would require that the fixture work was set as the preferred, which + * is impossible programmatically. This does not affect the scenario and one of + * the user-sourced is selected instead. + * + * @see Scenario */ public class Scenario07 extends Scenario { diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario08.java b/src/test/java/pt/ptcris/test/scenarios/Scenario08.java index 82ff7f8..0cf3342 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario08.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario08.java @@ -12,9 +12,17 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: + * Scenario 8 of the PTCRISync specification v0.4.3, tests export. + * + * Features: * export add * + * TODO: this scenario does not exactly represent the one from the specification + * as this would require that the fixture work was set as the preferred, which + * is impossible programmatically. This does not affect the scenario and one of + * the user-sourced is selected instead. + * + * @see Scenario */ public class Scenario08 extends Scenario { diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario09.java b/src/test/java/pt/ptcris/test/scenarios/Scenario09.java index ad1b126..02cea52 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario09.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario09.java @@ -12,11 +12,18 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: + * Scenario 9 of the PTCRISync specification v0.4.3, tests export. + * + * Features: * export add * + * TODO: this scenario does not exactly represent the one from the specification + * as this would require that the fixture work was set as the preferred, which + * is impossible programmatically. This does not affect the scenario and one of + * the user-sourced is selected instead. + * + * @see Scenario */ - public class Scenario09 extends Scenario { /** {@inheritDoc} */ diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario10.java b/src/test/java/pt/ptcris/test/scenarios/Scenario10.java index 50daef4..df9ef03 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario10.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario10.java @@ -12,11 +12,19 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: + * Scenario 10 of the PTCRISync specification v0.4.3, tests export. + * + * Features: * export rem + * preferred consequences + * + * TODO: this scenario does not exactly represent the one from the specification + * as this would require that the fixture work was set as the preferred, which + * is impossible programmatically. This affects the scenario since its goal + * is to depict the promotion of a work to preferred. * + * @see Scenario */ - public class Scenario10 extends Scenario { /** {@inheritDoc} */ diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario11.java b/src/test/java/pt/ptcris/test/scenarios/Scenario11.java index 8bb19ca..4602682 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario11.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario11.java @@ -12,11 +12,18 @@ import pt.ptcris.utils.ORCIDHelper; /** + * Scenario 11 of the PTCRISync specification v0.4.3, tests export. + * * Features: * export update with {same} * + * TODO: this scenario does not exactly represent the one from the specification + * as this would require that the CRIS-sourced work was set as the preferred, which + * is impossible programmatically. This does not affect the scenario and one of + * the user-sourced is selected instead. + * + * @see Scenario */ - public class Scenario11 extends Scenario { /** {@inheritDoc} */ diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario12.java b/src/test/java/pt/ptcris/test/scenarios/Scenario12.java index 2f7349c..adc4ed5 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario12.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario12.java @@ -12,10 +12,15 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: export add modification notifications with {same,more} + * Scenario 12 of the PTCRISync specification v0.4.3, tests export and import. * + * Features: + * export breaks import + * export add + * modification notifications with {same,more} + * + * @see Scenario */ - public class Scenario12 extends Scenario { /** {@inheritDoc} */ diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario13.java b/src/test/java/pt/ptcris/test/scenarios/Scenario13.java index 3852bb8..484c1b6 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario13.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario13.java @@ -14,9 +14,15 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: export del export update {same,more} modification notifications - * with {same,more} + * Scenario 13 of the PTCRISync specification v0.4.3, tests export and import. * + * Features: + * export breaks import + * export del + * export update {same,more} + * modification notifications with {same,more} + * + * @see Scenario */ public class Scenario13 extends Scenario { diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario14.java b/src/test/java/pt/ptcris/test/scenarios/Scenario14.java index 935c017..1142b1d 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario14.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario14.java @@ -14,8 +14,14 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: export add export update {same,less} + * Scenario 14 of the PTCRISync specification v0.4.3, tests export. * + * Features: + * export fixes import + * export add + * export update {same,less} + * + * @see Scenario */ public class Scenario14 extends Scenario { diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario15.java b/src/test/java/pt/ptcris/test/scenarios/Scenario15.java index b7ccd82..038faa2 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario15.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario15.java @@ -14,8 +14,12 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: modification notifications with {same,more,less} + * Scenario 15 of the PTCRISync specification v0.4.3, tests import. * + * Features: + * modification notifications with {same,more,less} + * + * @see Scenario */ public class Scenario15 extends Scenario { diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario16.java b/src/test/java/pt/ptcris/test/scenarios/Scenario16.java index 54818f8..98c7378 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario16.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario16.java @@ -14,9 +14,14 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: modification notifications at pre-state multiple modification - * notifications modification notifications with {same,more,less} + * Scenario 16 of the PTCRISync specification v0.4.3, tests import. * + * Features: + * modification notifications at pre-state + * multiple modification notifications + * modification notifications with {same,more,less} + * + * @see Scenario */ public class Scenario16 extends Scenario { diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario17.java b/src/test/java/pt/ptcris/test/scenarios/Scenario17.java index 55dd9b5..1786ee4 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario17.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario17.java @@ -14,8 +14,13 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: creation notifications at pre-state export updates with - * {less,same,more} + * Scenario 17 of the PTCRISync specification v0.4.3, tests export and import. + * + * Features: + * creation notifications at pre-state + * export updates with {less,same,more} + * + * @see Scenario */ public class Scenario17 extends Scenario { diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario18.java b/src/test/java/pt/ptcris/test/scenarios/Scenario18.java index aace50c..988d51e 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario18.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario18.java @@ -14,7 +14,13 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: export updates with {less,same,more} + * Scenario 18 of the PTCRISync specification v0.4.3, tests export. + * + * Features: + * export fixes import + * export updates with {less,same,more} + * + * @see Scenario */ public class Scenario18 extends Scenario { diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario19.java b/src/test/java/pt/ptcris/test/scenarios/Scenario19.java index 4f9fdb8..8e0bf56 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario19.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario19.java @@ -15,7 +15,12 @@ import pt.ptcris.utils.ORCIDHelper; /** - * Features: export updates with {less,same,more} + * Scenario 19 of the PTCRISync specification v0.4.3, tests export. + * + * Features: + * export updates with {same} + * + * @see Scenario */ public class Scenario19 extends Scenario { diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario20.java b/src/test/java/pt/ptcris/test/scenarios/Scenario20.java index be4f96e..0b979b6 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario20.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario20.java @@ -5,9 +5,12 @@ import pt.ptcris.utils.ORCIDHelper; /** + * Scenario 20 of the PTCRISync specification v0.4.3, tests export. + * * Features: empty profile + * + * @see Scenario */ - public class Scenario20 extends Scenario { /** {@inheritDoc} */ From fba30546ba4cf41b3ccb6fd46a7e8120c9ae0627 Mon Sep 17 00:00:00 2001 From: nmacedo Date: Thu, 3 Nov 2016 22:06:19 +0000 Subject: [PATCH 08/13] scenarios cleaned up --- .../pt/ptcris/test/scenarios/Scenario.java | 19 ++++++++++++++----- .../pt/ptcris/test/scenarios/Scenario11.java | 6 +++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario.java b/src/test/java/pt/ptcris/test/scenarios/Scenario.java index 93d9305..19ef9f7 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario.java @@ -24,13 +24,22 @@ import pt.ptcris.test.TestHelper; import pt.ptcris.utils.ORCIDHelper; -/* TODO: Scenarios with notifications in the pre-state (7 and 16) must - * be handled with caution, since modifications are not explicit in the - * current version of the system. +/** + * Represents a scenario as defined in the PTCRISync specification. Each + * scenario consists of a pre-state for the CRIS and ORCID profiles, an update + * on either profile and the result of running the import and/or export + * procedures to restore consistency. * - * TODO: Scenarios that deal with promotion/demotion of preferred (10) + * TODO: Scenarios with notifications in the pre-state (7 and 16) must be + * handled with caution, since modifications are not explicit in the current + * version of the system. + * + * TODO: Scenarios that consider the promotion/demotion of preferred works (10 + * and 11) are not to be tested programmatically as they cannot be selected this + * way. + * + * @see https://ptcris.pt/hub-ptcris/ */ - public abstract class Scenario { private List localWorks, exportWorks; private static ORCIDHelper externalClient, crisClient; diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario11.java b/src/test/java/pt/ptcris/test/scenarios/Scenario11.java index 4602682..3985322 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario11.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario11.java @@ -18,9 +18,9 @@ * export update with {same} * * TODO: this scenario does not exactly represent the one from the specification - * as this would require that the CRIS-sourced work was set as the preferred, which - * is impossible programmatically. This does not affect the scenario and one of - * the user-sourced is selected instead. + * as this would require that the fixture work was set as the preferred, which + * is impossible programmatically. This affects the scenario since its goal + * is to depict the promotion of a work to preferred. * * @see Scenario */ From 0b9ad6df04f6f550fd18dec02e5e8e05013323c4 Mon Sep 17 00:00:00 2001 From: nmacedo Date: Thu, 3 Nov 2016 22:08:36 +0000 Subject: [PATCH 09/13] documentation updated --- src/main/java/pt/ptcris/PTCRISync.java | 2 +- .../java/pt/ptcris/utils/ORCIDHelper.java | 48 ++++++++++++------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/main/java/pt/ptcris/PTCRISync.java b/src/main/java/pt/ptcris/PTCRISync.java index 6c9afc0..0dfbd22 100644 --- a/src/main/java/pt/ptcris/PTCRISync.java +++ b/src/main/java/pt/ptcris/PTCRISync.java @@ -47,7 +47,7 @@ *

* The implementation of the service assumes that the local CRIS communicates * the local productions following the established ORCID schema, according to - * the Member API 2.0rc1. This uniforms the API and simplifies the + * the Member API 2.0rc2. This uniforms the API and simplifies the * synchronization process. The current version focuses on synchronizing * research productions, which must be encoded as ORCID {@link Work works}. *

diff --git a/src/main/java/pt/ptcris/utils/ORCIDHelper.java b/src/main/java/pt/ptcris/utils/ORCIDHelper.java index d378ea8..7bf5c8a 100644 --- a/src/main/java/pt/ptcris/utils/ORCIDHelper.java +++ b/src/main/java/pt/ptcris/utils/ORCIDHelper.java @@ -48,14 +48,15 @@ public class ORCIDHelper { public enum EIdType { OTHER_ID("other-id"), AGR("agr"), ARXIV("arxiv"), ASIN("asin"), - BIBCODE("bibcode"), CBA("cba"), CIT("cit"), CTX("ctx"), DOI("doi"), - EID("eid"), ETHOS("ethos"), HANDLE("handle"), HIR("hir"), ISBN("isbn"), - ISSN("issn"), JFM("jfm"), JSTOR("jstor"), LCCN("lccn"), MR("mr"), - OCLC("oclc"), OL("ol"), OSTI("osti"), PAT("pat"), PMC("pmc"), PMID("pmid"), - RFC("rfc"), SOURCE_WORK_ID("source-work-id"), SSRN("ssrn"), URI("uri"), - URN("urn"), WOSUID("wosuid"), ZBL("zbl"); - + BIBCODE("bibcode"), CBA("cba"), CIT("cit"), CTX("ctx"), DOI("doi"), + EID("eid"), ETHOS("ethos"), HANDLE("handle"), HIR("hir"), ISBN("isbn"), + ISSN("issn"), JFM("jfm"), JSTOR("jstor"), LCCN("lccn"), MR("mr"), + OCLC("oclc"), OL("ol"), OSTI("osti"), PAT("pat"), PMC("pmc"), + PMID("pmid"), RFC("rfc"), SOURCE_WORK_ID("source-work-id"), + SSRN("ssrn"), URI("uri"), URN("urn"), WOSUID("wosuid"), ZBL("zbl"); + String value; + private EIdType(String value) { this.value = value; } @@ -339,8 +340,6 @@ public boolean waitWorkers() throws InterruptedException { executor = Executors.newFixedThreadPool(100); return timeout; } - - /** @@ -596,6 +595,8 @@ private static boolean isMetaUpToDate(Work preWork, Work posWork) * * The considered fields are: external identifiers, title, publication date * (year), work type. All these meta-data is available in work summaries. + * The publication date is not necessary for data sets and research + * techniques. * * TODO: contributors are not being considered as they are not contained in * the summaries. @@ -635,15 +636,6 @@ else if (work.getPublicationDate().getYear() == null) return res; } - - private static boolean validEIdType(String eid) { - try { - EIdType.valueOf(eid.replace('-', '_').toUpperCase()); - return true; - } catch (Exception e) { - return false; - } - } /** * Tests whether a work has minimal quality to be synchronized, by @@ -651,6 +643,8 @@ private static boolean validEIdType(String eid) { * * The considered fields are: external identifiers, title, publication date * (year), work type. All these meta-data is available in work summaries. + * The publication date is not necessary for data sets and research + * techniques. * * TODO: contributors are not being considered as they are not contained in * the summaries. @@ -739,6 +733,24 @@ public static void tryMinimalQuality(WorkSummary work) throws InvalidWorkExcepti } } + /** + * Test whether a give external identifiers type is valid. Elements of the + * enum {@link EIdType} take the shape of upper-case valid EId types, with + * slashes replaced by underscores. + * + * @param eid + * a potential EId type + * @return whether the string is a valid EId type + */ + private static boolean validEIdType(String eid) { + try { + EIdType.valueOf(eid.replace('-', '_').toUpperCase()); + return true; + } catch (Exception e) { + return false; + } + } + /** * Merges a work group into a single work summary. Simply selects the * meta-data from the first work of the group (i.e., the preferred one) and From 796f0ef581b154a9fdbafb2b892669deab150ec4 Mon Sep 17 00:00:00 2001 From: nmacedo Date: Wed, 23 Nov 2016 11:16:38 +0000 Subject: [PATCH 10/13] flexible number of orcid worker threads --- src/main/java/pt/ptcris/ORCIDClient.java | 8 ++++++++ src/main/java/pt/ptcris/ORCIDClientImpl.java | 14 +++++++++++++- src/main/java/pt/ptcris/utils/ORCIDHelper.java | 12 ++++-------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/pt/ptcris/ORCIDClient.java b/src/main/java/pt/ptcris/ORCIDClient.java index 6dffab1..b71dc1e 100644 --- a/src/main/java/pt/ptcris/ORCIDClient.java +++ b/src/main/java/pt/ptcris/ORCIDClient.java @@ -77,4 +77,12 @@ public interface ORCIDClient { */ public ActivitiesSummary getActivitiesSummary() throws OrcidClientException; + /** + * The number of worker threads that will be used to communicate with the + * ORCID API. + * + * @return the number of ORCID worker threads + */ + public int threads(); + } \ No newline at end of file diff --git a/src/main/java/pt/ptcris/ORCIDClientImpl.java b/src/main/java/pt/ptcris/ORCIDClientImpl.java index 128c717..c34b31e 100644 --- a/src/main/java/pt/ptcris/ORCIDClientImpl.java +++ b/src/main/java/pt/ptcris/ORCIDClientImpl.java @@ -22,6 +22,7 @@ public class ORCIDClientImpl implements ORCIDClient { private final OrcidAccessToken orcidToken; private final OrcidOAuthClient orcidClient; private final String clientId; + private final int threads; /** * Instantiates an ORCID client to communicate with the ORCID API. @@ -38,12 +39,15 @@ public class ORCIDClientImpl implements ORCIDClient { * the redirect URI for requesting the access token * @param orcidToken * the access token to the user ORCID profile + * @param threads + * the number of ORCID worker threads */ public ORCIDClientImpl(String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri, OrcidAccessToken orcidToken) { this.orcidToken = orcidToken; this.clientId = clientId; - + // TODO: allow to be defined by the caller + this.threads = Runtime.getRuntime().availableProcessors() + 2; this.orcidClient = new OrcidOAuthClient(loginUri, apiUri, clientId, clientSecret, redirectUri); } @@ -95,4 +99,12 @@ public ActivitiesSummary getActivitiesSummary() throws OrcidClientException { return orcidClient.readActivitiesSummary(orcidToken); } + /** + * {@inheritDoc} + */ + @Override + public int threads() { + return threads; + } + } diff --git a/src/main/java/pt/ptcris/utils/ORCIDHelper.java b/src/main/java/pt/ptcris/utils/ORCIDHelper.java index 7bf5c8a..05205b8 100644 --- a/src/main/java/pt/ptcris/utils/ORCIDHelper.java +++ b/src/main/java/pt/ptcris/utils/ORCIDHelper.java @@ -62,11 +62,6 @@ private EIdType(String value) { } } - /** - * Whether to multi-thread the "get" of full works. - */ - private final boolean threaded = true; - private static final Logger _log = LogManager.getLogger(ORCIDHelper.class); /** @@ -75,7 +70,7 @@ private EIdType(String value) { */ public final ORCIDClient client; - private ExecutorService executor = Executors.newFixedThreadPool(10); + private ExecutorService executor; /** * Initializes the helper with a given ORCID client. @@ -87,6 +82,7 @@ private EIdType(String value) { */ public ORCIDHelper(ORCIDClient orcidClient) { this.client = orcidClient; + if (client.threads() > 1) executor = Executors.newFixedThreadPool(client.threads()); } /** @@ -174,7 +170,7 @@ public void getFullWork(WorkSummary mergedWork, Map cb) if (mergedWork == null) throw new NullPointerException("Can't get null work."); _log.debug("[getFullWork] " + mergedWork.getPutCode()); - if (threaded) { + if (client.threads() > 1) { final ORCIDGetWorker worker = new ORCIDGetWorker(mergedWork,client, cb, _log); executor.execute(worker); } else { @@ -333,7 +329,7 @@ public void deleteWork(BigInteger putcode) * if the process was interrupted */ public boolean waitWorkers() throws InterruptedException { - if (!threaded) return true; + if (client.threads() <= 1) return true; executor.shutdown(); final boolean timeout = executor.awaitTermination(100, TimeUnit.SECONDS); From 302f483f5e04278a3e97cd9582d235de1d279f7a Mon Sep 17 00:00:00 2001 From: nmacedo Date: Wed, 23 Nov 2016 11:24:09 +0000 Subject: [PATCH 11/13] parametrizable number of orcid worker threads --- src/main/java/pt/ptcris/ORCIDClientImpl.java | 26 +++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/pt/ptcris/ORCIDClientImpl.java b/src/main/java/pt/ptcris/ORCIDClientImpl.java index c34b31e..95dcc86 100644 --- a/src/main/java/pt/ptcris/ORCIDClientImpl.java +++ b/src/main/java/pt/ptcris/ORCIDClientImpl.java @@ -43,13 +43,33 @@ public class ORCIDClientImpl implements ORCIDClient { * the number of ORCID worker threads */ public ORCIDClientImpl(String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri, - OrcidAccessToken orcidToken) { + OrcidAccessToken orcidToken, int threads) { this.orcidToken = orcidToken; this.clientId = clientId; - // TODO: allow to be defined by the caller - this.threads = Runtime.getRuntime().availableProcessors() + 2; + this.threads = threads; this.orcidClient = new OrcidOAuthClient(loginUri, apiUri, clientId, clientSecret, redirectUri); } + + /** + * Instantiates an ORCID client to communicate with the ORCID API. + * + * @param loginUri + * the login URI of the ORCID service + * @param apiUri + * the URI of the ORCID API + * @param clientId + * the id of the ORCID Member API client + * @param clientSecret + * the secret of the ORCID Member API client + * @param redirectUri + * the redirect URI for requesting the access token + * @param orcidToken + * the access token to the user ORCID profile + */ + public ORCIDClientImpl(String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri, + OrcidAccessToken orcidToken) { + this(loginUri, apiUri, clientId, clientSecret, redirectUri, orcidToken, Runtime.getRuntime().availableProcessors() + 2); + } /** * {@inheritDoc} From 8f348c452be3c351a8a38c1976980a2756d7c3f6 Mon Sep 17 00:00:00 2001 From: nmacedo Date: Fri, 25 Nov 2016 13:53:20 +0000 Subject: [PATCH 12/13] add ok code updated --- src/main/java/pt/ptcris/PTCRISyncResult.java | 2 +- src/main/java/pt/ptcris/utils/ORCIDHelper.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/pt/ptcris/PTCRISyncResult.java b/src/main/java/pt/ptcris/PTCRISyncResult.java index 6e04aec..f051e1d 100644 --- a/src/main/java/pt/ptcris/PTCRISyncResult.java +++ b/src/main/java/pt/ptcris/PTCRISyncResult.java @@ -12,7 +12,7 @@ */ public final class PTCRISyncResult { - public static final int ADDOK = -10; + public static final int ADDOK = -5; public static final int UPDATEOK = -10; public static final int UPTODATE = -20; public static final int INVALID = -30; diff --git a/src/main/java/pt/ptcris/utils/ORCIDHelper.java b/src/main/java/pt/ptcris/utils/ORCIDHelper.java index 05205b8..376867d 100644 --- a/src/main/java/pt/ptcris/utils/ORCIDHelper.java +++ b/src/main/java/pt/ptcris/utils/ORCIDHelper.java @@ -55,7 +55,7 @@ public enum EIdType { PMID("pmid"), RFC("rfc"), SOURCE_WORK_ID("source-work-id"), SSRN("ssrn"), URI("uri"), URN("urn"), WOSUID("wosuid"), ZBL("zbl"); - String value; + public final String value; private EIdType(String value) { this.value = value; From 21fee19ac6312d75c32c0601c17802b9f858b18d Mon Sep 17 00:00:00 2001 From: nmacedo Date: Wed, 30 Nov 2016 10:57:50 +0000 Subject: [PATCH 13/13] tests for OTHER IDs --- src/test/java/pt/ptcris/test/TestHelper.java | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/java/pt/ptcris/test/TestHelper.java b/src/test/java/pt/ptcris/test/TestHelper.java index 460fc36..d3ef3e7 100644 --- a/src/test/java/pt/ptcris/test/TestHelper.java +++ b/src/test/java/pt/ptcris/test/TestHelper.java @@ -17,6 +17,7 @@ import pt.ptcris.handlers.ProgressHandler; import pt.ptcris.utils.ORCIDHelper; +import pt.ptcris.utils.ORCIDHelper.EIdType; public class TestHelper { @@ -84,6 +85,27 @@ public static Work workDOIUnk(BigInteger key, String meta, String doi, String ei work.getExternalIds().getExternalId().add(e); return work; } + + public static Work workOtherOtherDOI(BigInteger key, String meta, String doi, String eid, String eid2) { + Work work = workDOI(key, meta, doi); + + ExternalId e = new ExternalId(); + e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdValue(eid); + e.setExternalIdType(EIdType.OTHER_ID.value); + + work.getExternalIds().getExternalId().add(e); + + ExternalId e1 = new ExternalId(); + e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdValue(eid2); + e1.setExternalIdType(EIdType.OTHER_ID.value); + + work.getExternalIds().getExternalId().add(e1); + + return work; + } + public static Work workHANDLE(BigInteger key, String meta, String handle) { Work work = work(key, meta);