diff --git a/docs/pt/ptcris/TempORCIDClient.html b/docs/pt/ptcris/TempORCIDClient.html new file mode 100644 index 0000000..7d174e9 --- /dev/null +++ b/docs/pt/ptcris/TempORCIDClient.html @@ -0,0 +1,328 @@ + + + + + +TempORCIDClient + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
pt.ptcris
+

Class TempORCIDClient

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/docs/pt/ptcris/class-use/TempORCIDClient.html b/docs/pt/ptcris/class-use/TempORCIDClient.html new file mode 100644 index 0000000..48521d9 --- /dev/null +++ b/docs/pt/ptcris/class-use/TempORCIDClient.html @@ -0,0 +1,124 @@ + + + + + +Uses of Class pt.ptcris.TempORCIDClient + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Uses of Class
pt.ptcris.TempORCIDClient

+
+
No usage of pt.ptcris.TempORCIDClient
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/pom.xml b/pom.xml index 9ec0d36..63541fb 100644 --- a/pom.xml +++ b/pom.xml @@ -3,14 +3,14 @@ 4.0.0 pt.ptcris ptcrisync - 1.1.0 + 1.1 UTF-8 - 2.0 - 1.1.7 - 4.13.1 - 1.7 + 1.8 + 3.0 + 1.1.9 + 4.12 @@ -27,12 +27,6 @@ ${logback-version} compile - - ch.qos.logback - logback-core - ${logback-version} - compile - junit diff --git a/src/main/java/pt/ptcris/ORCIDClientImpl.java b/src/main/java/pt/ptcris/ORCIDClientImpl.java index 7149632..a64535c 100644 --- a/src/main/java/pt/ptcris/ORCIDClientImpl.java +++ b/src/main/java/pt/ptcris/ORCIDClientImpl.java @@ -23,12 +23,11 @@ import org.um.dsi.gavea.orcid.model.activities.Fundings; import org.um.dsi.gavea.orcid.model.activities.Works; import org.um.dsi.gavea.orcid.model.bulk.Bulk; -import org.um.dsi.gavea.orcid.model.common.ElementSummary; -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.error.Error; import org.um.dsi.gavea.orcid.model.funding.Funding; import org.um.dsi.gavea.orcid.model.funding.FundingSummary; +import org.um.dsi.gavea.orcid.model.work.Work; +import org.um.dsi.gavea.orcid.model.work.WorkSummary; import pt.ptcris.utils.ORCIDFundingHelper; import pt.ptcris.utils.ORCIDHelper; @@ -199,10 +198,10 @@ public Fundings getFundingsSummary() throws OrcidClientException { public PTCRISyncResult getWork(WorkSummary putcode) { PTCRISyncResult res; try { - Work fund = orcidClient.readWork(orcidToken, putcode.getPutCode() + Work work = orcidClient.readWork(orcidToken, putcode.getPutCode() .toString()); - finalizeGet(fund, putcode); - res = PTCRISyncResult.ok_get(putcode.getPutCode(), fund); + finalizeGet(work, putcode); + res = PTCRISyncResult.ok_get(putcode.getPutCode(), work); } catch (OrcidClientException e) { res = PTCRISyncResult.fail(e); } @@ -232,25 +231,26 @@ public PTCRISyncResult getFunding(FundingSummary putcode) { @Override public Map> getWorks(List summaries) { List pcs = new ArrayList(); - for (ElementSummary i : summaries) + for (WorkSummary i : summaries) pcs.add(i.getPutCode().toString()); Map> res = new HashMap>(); try { - List bulk = orcidClient.readWorks(orcidToken, pcs) - .getWorkOrError(); + List bulk = orcidClient.readWorks(orcidToken, pcs).getWorkOrError(); + // no guarantee that the bulk results are ordered as the request + Map bulkWs = new HashMap(); + for (Serializable w : bulk) + if (w instanceof Work) + bulkWs.put(((Work) w).getPutCode(), (Work) w); for (int i = 0; i < summaries.size(); i++) { - Serializable w = bulk.get(i); - if (w instanceof Work) { - finalizeGet((Work) w, summaries.get(i)); - res.put(summaries.get(i).getPutCode(), PTCRISyncResult.ok_get( - summaries.get(i).getPutCode(), (Work) w)); + WorkSummary s = summaries.get(i); + Work w = bulkWs.get(s.getPutCode()); + if (w != null) { + finalizeGet(w, s); + res.put(s.getPutCode(), PTCRISyncResult.ok_get(s.getPutCode(), w)); } else { - Error err = (Error) w; - OrcidClientException e = new OrcidClientException( - err.getResponseCode(), err.getUserMessage(), - err.getErrorCode(), err.getDeveloperMessage()); - res.put(summaries.get(i).getPutCode(), - PTCRISyncResult.fail(e)); + // errors have no putcode information, cannot guarantee error message matching + OrcidClientException e = new OrcidClientException(); + res.put(s.getPutCode(),PTCRISyncResult.fail(e)); } } } catch (OrcidClientException e1) { @@ -399,7 +399,7 @@ public int threads() { private static void finalizeGet(Work full, WorkSummary summary) { // External ids are not inherited... full.setExternalIds(new ORCIDWorkHelper(null) - .getNonNullExternalIdsS((WorkSummary) summary)); + .getNonNullExternalIdsS(summary)); ORCIDHelper.cleanWorkLocalKey(full); } @@ -416,7 +416,7 @@ private static void finalizeGet(Work full, WorkSummary summary) { */ private static void finalizeGet(Funding full, FundingSummary summary) { full.setExternalIds(new ORCIDFundingHelper(null) - .getNonNullExternalIdsS((FundingSummary) summary)); + .getNonNullExternalIdsS(summary)); ORCIDHelper.cleanWorkLocalKey(full); } diff --git a/src/main/java/pt/ptcris/PTCRISync.java b/src/main/java/pt/ptcris/PTCRISync.java index 136112c..5b202d4 100644 --- a/src/main/java/pt/ptcris/PTCRISync.java +++ b/src/main/java/pt/ptcris/PTCRISync.java @@ -24,11 +24,12 @@ 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.FundingType; +import org.um.dsi.gavea.orcid.model.common.WorkType; import org.um.dsi.gavea.orcid.model.funding.Funding; -import org.um.dsi.gavea.orcid.model.funding.FundingType; import org.um.dsi.gavea.orcid.model.person.externalidentifier.ExternalIdentifier; import org.um.dsi.gavea.orcid.model.work.Work; -import org.um.dsi.gavea.orcid.model.work.WorkType; +import org.um.dsi.gavea.orcid.model.work.WorkSummary; import pt.ptcris.exceptions.InvalidActivityException; import pt.ptcris.handlers.ProgressHandler; @@ -337,7 +338,7 @@ public static Map> exportForce(ORCIDClient cli * organization (see * {@link ORCIDFundingHelper#testMinimalQuality(ElementSummary)}. *

- * * + * *

* A set of funding types can be provided to allow the independent * synchronization of different types of entries. Local and remote @@ -517,6 +518,7 @@ private static > toUpdate = new LinkedList>(); + List> toUpdateFundedBy = new LinkedList>(); for (int c = 0; c != orcids.size(); c++) { S orcid = orcids.get(c); @@ -528,14 +530,24 @@ private static (local, orcid, worksDiffs.get(local))); + isIncluded = true; + } else result.put(ORCIDHelper.getActivityLocalKey(local, BigInteger.valueOf(c)), PTCRISyncResult.uptodate()); locals.remove(local); + + // if the remote work isn't update in what concerns of FundedBy identifiers + ExternalIdsDiff fundedByExternalIdsDiff = helper.getFundedByExternalIdsDiff(local, orcid); + if (!isIncluded && (forced || !(fundedByExternalIdsDiff.more.isEmpty() && fundedByExternalIdsDiff.less.isEmpty())) ) { + fundedByExternalIdsDiff.same.addAll(worksDiffs.get(local).same); + toUpdateFundedBy.add(new UpdateRecord(local, orcid, fundedByExternalIdsDiff)); + } } handler.step(); } @@ -551,6 +563,7 @@ private static ids = new ArrayList(update.eidsDiff.same); ids.addAll(helper.getPartOfExternalIdsE(local).getExternalId()); + ids.addAll(helper.getFundedByExternalIdsE(local).getExternalId()); weids.setExternalId(ids); helper.setExternalIdsE(local,weids); @@ -559,6 +572,9 @@ private static ids = new ArrayList(update.eidsDiff.same); ids.addAll(update.eidsDiff.less); ids.addAll(helper.getPartOfExternalIdsE(local).getExternalId()); + ids.addAll(helper.getFundedByExternalIdsE(local).getExternalId()); weids.setExternalId(ids); helper.setExternalIdsE(local,weids); @@ -581,6 +598,9 @@ private static > void treatOuputWithChangesOnlyOnFundedBy_2Phase( + ORCIDHelper helper, ProgressHandler handler, Map> result, + List> toUpdateFundedBy) { + for (int c = 0; c != toUpdateFundedBy.size(); c++) { + + // the remote work is missing external identifiers or not updated in the 1st phase + UpdateRecord update = toUpdateFundedBy.get(c); + if (!update.eidsDiff.less.isEmpty() || update.eidsDiff.more.isEmpty()) { + E local = update.preElement; + ExternalIds weids = new ExternalIds(); + List ids = new ArrayList(update.eidsDiff.same); + ids.addAll(update.eidsDiff.less); + ids.addAll(helper.getPartOfExternalIdsE(local).getExternalId()); + weids.setExternalId(ids); + helper.setExternalIdsE(local,weids); + + PTCRISyncResult res = helper.update(update.posElement.getPutCode(), local); + result.put(ORCIDHelper.getActivityLocalKey(local, BigInteger.valueOf(c)),res); + } + handler.step(); + } + } + + private static > void treatOuputWithChangesOnlyOnFundedBy_1Phase( + ORCIDHelper helper, ProgressHandler handler, Map> result, + List> toUpdateFundedBy) { + for (int c = 0; c != toUpdateFundedBy.size(); c++) { + + UpdateRecord update = toUpdateFundedBy.get(c); + // the remote work has spurious external identifiers + if (!update.eidsDiff.more.isEmpty()) { + E local = update.preElement; + ExternalIds weids = new ExternalIds(); + List ids = new ArrayList(update.eidsDiff.same); + ids.addAll(helper.getPartOfExternalIdsE(local).getExternalId()); + weids.setExternalId(ids); + helper.setExternalIdsE(local,weids); + + PTCRISyncResult res = helper.update(update.posElement.getPutCode(), local); + result.put(ORCIDHelper.getActivityLocalKey(local, BigInteger.valueOf(c)),res); + } + handler.step(); + + } + } + /** *

* Discovers new valid works in an ORCID profile given a set of known local @@ -896,8 +962,7 @@ public static Integer importWorkCounter(ORCIDClient client, List locals, P * @param handler * the progress handler responsible for receiving progress * updates - * @return the number of new valid works found in the ORCID - * profile + * @return the number of new valid works found in the ORCID profile * @throws OrcidClientException * if the communication with ORCID fails when getting the * activities summary @@ -1266,9 +1331,14 @@ private static importWorkUpdates(ORCIDClient client, List locals, ProgressHandler handler, List orcids) + throws OrcidClientException, IllegalArgumentException { + return importUpdatesBase(new ORCIDWorkHelper(client), locals, Arrays.asList(WorkType.values()), handler, orcids); + } + public static List importWorkUpdates(ORCIDClient client, List locals, ProgressHandler handler) throws OrcidClientException, IllegalArgumentException { - return importUpdatesBase(new ORCIDWorkHelper(client), locals, Arrays.asList(WorkType.values()), handler); + return importUpdatesBase(new ORCIDWorkHelper(client), locals, Arrays.asList(WorkType.values()), handler, new ArrayList<>()); } /** @@ -1293,7 +1363,7 @@ public static List importWorkUpdates(ORCIDClient client, List locals @Deprecated public static List importUpdates(ORCIDClient client, List locals, ProgressHandler handler) throws OrcidClientException, IllegalArgumentException { - return importWorkUpdates(client, locals, handler); + return importWorkUpdates(client, locals, handler, new ArrayList<>()); } /** @@ -1361,7 +1431,7 @@ public static List importUpdates(ORCIDClient client, List locals, Pr */ public static List importFundingUpdates(ORCIDClient client, List locals, Collection types, ProgressHandler handler) throws OrcidClientException, IllegalArgumentException { - return importUpdatesBase(new ORCIDFundingHelper(client), locals, types, handler); + return importUpdatesBase(new ORCIDFundingHelper(client), locals, types, handler, new ArrayList<>()); } /** @@ -1430,7 +1500,7 @@ public static List importFundingUpdates(ORCIDClient client, List> List importUpdatesBase( ORCIDHelper helper, List locals, - Collection types, ProgressHandler handler) + Collection types, ProgressHandler handler, List toUpdateFundedBy ) throws OrcidClientException, IllegalArgumentException { if (helper == null || locals == null || handler == null) @@ -1456,8 +1526,14 @@ private static { * @return whether the activities match */ private final boolean matches(A act1, A act2) { - return compare(act1, act2) > threshold(); + return compare(act1, act2) >= threshold(); } /** diff --git a/src/main/java/pt/ptcris/utils/ORCIDFundingHelper.java b/src/main/java/pt/ptcris/utils/ORCIDFundingHelper.java index a1290c9..35f438e 100644 --- a/src/main/java/pt/ptcris/utils/ORCIDFundingHelper.java +++ b/src/main/java/pt/ptcris/utils/ORCIDFundingHelper.java @@ -20,9 +20,9 @@ import org.um.dsi.gavea.orcid.model.activities.FundingGroup; 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.FundingType; import org.um.dsi.gavea.orcid.model.funding.Funding; import org.um.dsi.gavea.orcid.model.funding.FundingSummary; -import org.um.dsi.gavea.orcid.model.funding.FundingType; import pt.ptcris.ORCIDClient; import pt.ptcris.PTCRISyncResult; @@ -198,7 +198,7 @@ protected String getYearS(FundingSummary summary) { if (summary.getStartDate() == null || summary.getStartDate().getYear() == null) return null; - return summary.getStartDate().getYear().getValue(); + return String.valueOf(summary.getStartDate().getYear().getValue()); } /** {@inheritDoc} */ @@ -267,7 +267,7 @@ protected boolean isMetaUpToDate(Funding preFunding, FundingSummary posFunding) * the summaries. */ @Override - protected Set testMinimalQuality(FundingSummary funding, Collection others) { + public Set testMinimalQuality(FundingSummary funding, Collection others) { assert funding != null; if (others == null) others = new ArrayList(); @@ -366,7 +366,7 @@ public Funding cloneE(Funding funding) { /** {@inheritDoc} */ @Override - protected FundingSummary summarize(Funding funding) { + public FundingSummary summarize(Funding funding) { assert funding != null; final FundingSummary dummy = new FundingSummary(); diff --git a/src/main/java/pt/ptcris/utils/ORCIDHelper.java b/src/main/java/pt/ptcris/utils/ORCIDHelper.java index e23f81a..8fed826 100644 --- a/src/main/java/pt/ptcris/utils/ORCIDHelper.java +++ b/src/main/java/pt/ptcris/utils/ORCIDHelper.java @@ -31,19 +31,21 @@ 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.FundingType; import org.um.dsi.gavea.orcid.model.common.FuzzyDate; -import org.um.dsi.gavea.orcid.model.common.RelationshipType; +import org.um.dsi.gavea.orcid.model.common.Relationship; +import org.um.dsi.gavea.orcid.model.common.WorkType; import org.um.dsi.gavea.orcid.model.funding.Funding; import org.um.dsi.gavea.orcid.model.funding.FundingSummary; -import org.um.dsi.gavea.orcid.model.funding.FundingType; +import org.um.dsi.gavea.orcid.model.person.externalidentifier.ExternalIdentifier; 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.PTCRISyncResult; import pt.ptcris.exceptions.InvalidActivityException; import pt.ptcris.handlers.ProgressHandler; +import pt.ptcris.utils.ORCIDWorkHelper.EIdType; /** * An abstract helper to help manage ORCID activities and simplify the usage of @@ -687,7 +689,7 @@ private final boolean waitWorkers() throws InterruptedException { * other coexisting activities * @return the set of invalid meta-data, empty if valid */ - abstract Set testMinimalQuality(S summary, Collection others); + public abstract Set testMinimalQuality(S summary, Collection others); /** * Creates an update to an activity given the difference on meta-data. @@ -729,7 +731,7 @@ private final boolean waitWorkers() throws InterruptedException { * the ORCID activity to be summarized * @return the corresponding ORCID activity summary */ - abstract S summarize(E activity); + public abstract S summarize(E activity); /* * Helper static methods that build on the generic methods. @@ -835,7 +837,7 @@ static ExternalId clone(ExternalId id) { final ExternalId eid = new ExternalId(); eid.setExternalIdRelationship(id.getExternalIdRelationship()); eid.setExternalIdType(id.getExternalIdType().toLowerCase()); - eid.setExternalIdValue(id.getExternalIdValue()); + eid.setExternalIdValue(id.getExternalIdValue().replaceAll("\\p{C}", "").trim()); eid.setExternalIdUrl(id.getExternalIdUrl()); return eid; } @@ -891,7 +893,27 @@ final ExternalIds getPartOfExternalIdsS(S summary) { List res = new ArrayList(); for (ExternalId eid : getNonNullExternalIdsS(summary).getExternalId()) - if (eid.getExternalIdRelationship() == RelationshipType.PART_OF) + if (eid.getExternalIdRelationship() == Relationship.PART_OF) + res.add(eid); + return new ExternalIds(res); + } + + /** + * Returns the non-null funded-by external identifiers of an activity summary + * (null becomes empty list). + * + * @param summary + * the ORCID activity summary from which to retrieve the external + * identifiers + * @return the non-null part-of external identifiers + */ + final ExternalIds getFundedByExternalIdsS(S summary) { + if (summary == null) + throw new IllegalArgumentException("Null element."); + + List res = new ArrayList(); + for (ExternalId eid : getNonNullExternalIdsS(summary).getExternalId()) + if (eid.getExternalIdRelationship() == Relationship.FUNDED_BY && eid.getExternalIdType().equalsIgnoreCase(EIdType.DOI.value)) res.add(eid); return new ExternalIds(res); } @@ -925,7 +947,7 @@ final ExternalIds getSelfExternalIdsS(S summary) { List res = new ArrayList(); for (ExternalId eid : getNonNullExternalIdsS(summary).getExternalId()) - if (eid.getExternalIdRelationship() == RelationshipType.SELF) + if (eid.getExternalIdRelationship() == Relationship.SELF) res.add(eid); return new ExternalIds(res); } @@ -972,6 +994,12 @@ public final Map getSelfExternalIdsDiffS(S summary, Collecti } return matches; } + + + public final ExternalIds getFundedByExternalIdsE(E activity) { + return getFundedByExternalIdsS(summarize(activity)); + } + /** * Tests whether two sets of (non-exclusively self or part-of) external @@ -1019,6 +1047,18 @@ public final boolean hasNewSelfIDs(E preElement, S posElement) { return diff.more.isEmpty(); } + + + public final ExternalIdsDiff getFundedByExternalIdsDiff(E preElement, S posElement) { + if (preElement == null || posElement == null) + throw new IllegalArgumentException("Null element."); + + final ExternalIdsDiff diff = new ExternalIdsDiff( + getFundedByExternalIdsE(preElement), + getFundedByExternalIdsS(posElement)); + + return diff; + } /** * Checks whether an activity is already up to date regarding another one, @@ -1142,11 +1182,11 @@ public final Set testMinimalQuality(S summary) { * @return whether the date is well formed */ static boolean testQualityFuzzyDate(FuzzyDate date) { - if (date.getYear() != null && date.getYear().getValue().length() != 4) + if (date.getYear() != null && String.valueOf(date.getYear().getValue()).length() != 4) return false; - if (date.getMonth() != null && date.getMonth().getValue().length() != 2) + if (date.getMonth() != null && date.getMonth().getValue() < 1 && date.getMonth().getValue() > 12 ) return false; - if (date.getDay() != null && date.getDay().getValue().length() != 2) + if (date.getDay() != null && date.getDay().getValue() < 1 && date.getDay().getValue() > 31) return false; return true; diff --git a/src/main/java/pt/ptcris/utils/ORCIDWorkHelper.java b/src/main/java/pt/ptcris/utils/ORCIDWorkHelper.java index dde1a55..256ed58 100644 --- a/src/main/java/pt/ptcris/utils/ORCIDWorkHelper.java +++ b/src/main/java/pt/ptcris/utils/ORCIDWorkHelper.java @@ -17,14 +17,15 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; 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.common.ExternalId; import org.um.dsi.gavea.orcid.model.common.ExternalIds; +import org.um.dsi.gavea.orcid.model.common.WorkType; 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.PTCRISyncResult; @@ -40,14 +41,15 @@ public final class ORCIDWorkHelper extends ORCIDHelper { 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"), CIENCIAIUL("cienciaiul"); + OTHER_ID("other-id"), AGR("agr"), ARXIV("arxiv"), ARK("ark"), ASIN("asin"), + BIBCODE("bibcode"), CBA("cba"), CIT("cit"), CTX("ctx"), DNB("dnb"), 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"), + CIENCIAIUL("cienciaiul"), LENSID("lensid"), PDB("pdb"), KUID("kuid"), + ASIN_TLD("asin-tld"), AUTHENTICUSID("authenticusid"), RRID("rrid"), HAL("hal"); public final String value; @@ -234,7 +236,7 @@ protected String getYearS(WorkSummary summary) { if (summary.getPublicationDate() == null || summary.getPublicationDate().getYear() == null) return null; - return summary.getPublicationDate().getYear().getValue(); + return String.valueOf(summary.getPublicationDate().getYear().getValue()); } /** {@inheritDoc} */ @@ -256,6 +258,9 @@ protected WorkSummary group(WorkGroup group) throws IllegalArgumentException { final List eids = getPartOfExternalIdsS(dummy) .getExternalId(); + + addFundedByEidsFromAllWorkSummaries(group, eids); + for (ExternalId id : group.getExternalIds().getExternalId()) eids.add(clone(id)); dummy.setExternalIds(new ExternalIds(eids)); @@ -263,6 +268,18 @@ protected WorkSummary group(WorkGroup group) throws IllegalArgumentException { return dummy; } + private void addFundedByEidsFromAllWorkSummaries(WorkGroup group, final List eids) { + Set set = new HashSet<>(eids.size()); + for (int i = 0 ; i < group.getWorkSummary().size(); i++){ + WorkSummary cloned = cloneS(group.getWorkSummary().get(i)); + List fundedByEids = getFundedByExternalIdsS(cloned).getExternalId(); + List fundedByEidsWithoutDuplicates = fundedByEids.stream() + .filter(eid -> set.add(eid.getExternalIdValue())) + .collect(Collectors.toList()); + eids.addAll(fundedByEidsWithoutDuplicates); + } + } + /** * {@inheritDoc} * @@ -305,7 +322,7 @@ && getYearS(posWork) != null && getPubYearE(preWork) * the summaries. */ @Override - protected Set testMinimalQuality(WorkSummary work, Collection others) { + public Set testMinimalQuality(WorkSummary work, Collection others) { assert work != null; if (others == null) others = new ArrayList(); @@ -402,7 +419,7 @@ public Work cloneE(Work work) { /** {@inheritDoc} */ @Override - protected WorkSummary summarize(Work work) { + public WorkSummary summarize(Work work) { assert work != null; final WorkSummary dummy = new WorkSummary(); diff --git a/src/test/java/pt/ptcris/test/PTCRISExample.java b/src/test/java/pt/ptcris/test/PTCRISExample.java index 5720d9c..21ea3b0 100644 --- a/src/test/java/pt/ptcris/test/PTCRISExample.java +++ b/src/test/java/pt/ptcris/test/PTCRISExample.java @@ -22,10 +22,10 @@ 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.common.Relationship; +import org.um.dsi.gavea.orcid.model.common.WorkType; import org.um.dsi.gavea.orcid.model.work.Work; import org.um.dsi.gavea.orcid.model.work.WorkTitle; -import org.um.dsi.gavea.orcid.model.work.WorkType; import pt.ptcris.ORCIDClient; import pt.ptcris.PTCRISync; @@ -100,7 +100,7 @@ private static Work work0() { work.setTitle(title); ExternalId e = new ExternalId(); - e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdRelationship(Relationship.SELF); e.setExternalIdValue("3000"); e.setExternalIdType("DOI"); @@ -122,12 +122,12 @@ private static Work work1() { work.setTitle(title); ExternalId e = new ExternalId(); - e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdRelationship(Relationship.SELF); e.setExternalIdValue("4000"); e.setExternalIdType("EID"); ExternalId e1 = new ExternalId(); - e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdRelationship(Relationship.SELF); e1.setExternalIdValue("00001"); e1.setExternalIdType("DOI"); @@ -150,7 +150,7 @@ private static Work work2() { work.setTitle(title); ExternalId e = new ExternalId(); - e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdRelationship(Relationship.SELF); // avoids conflicts e.setExternalIdValue(String.valueOf(System.currentTimeMillis())); diff --git a/src/test/java/pt/ptcris/test/TestClients.java b/src/test/java/pt/ptcris/test/TestClients.java index 57fecd3..7575250 100755 --- a/src/test/java/pt/ptcris/test/TestClients.java +++ b/src/test/java/pt/ptcris/test/TestClients.java @@ -39,24 +39,25 @@ private Profile(int value) { private static final String orcid_api_uri = "https://api.sandbox.orcid.org/"; private static final String orcid_redirect_uri = "https://developers.google.com/oauthplayground"; - private static final String cris_client_id = "APP-X7DMY3AKDXK34RVS"; + private static final String cris_client_id = "APP-X7DMY3AKDXK34RVS"; //PTCRIS private static final String cris_client_secret = "d622a047-deef-4368-a1e8-223101911563"; - private static final String external_client_id = "APP-JFDCD0I82SXO91F9"; + private static final String external_client_id = "APP-JFDCD0I82SXO91F9"; //HASLab, INESC TEC & University of Minho private static final String external_client_secret = "a205bf62-e4b1-4d22-8a4b-2395e493358a"; - private static final String[] profiles = { "0000-0002-4464-361X", - "0000-0002-9007-3574", "0000-0002-5507-2082", "0000-0002-9055-9726" }; + private static final String[] profiles = { "0000-0003-4777-9763", + "0000-0002-1811-9160", "0000-0002-3505-9366", "0000-0002-6134-4419" }; + //ZECA //MANEL //Toze private static final String[] cris_profile_secrets = { - "dd90ad6f-3ec2-4a0a-8762-725f95389b22", - "944a4b86-38ef-4f2b-8c9c-305df02559db", - "c8962118-bd00-4bd2-8784-8b7bf0c3b84b", - "7421f8d5-3173-4344-994e-e669d991c1d9" }; + "ea00bc47-1541-4824-a439-bf4feee40248", + "118f715f-058b-42ff-96a4-8ae015ca53f3", + "ebe045ed-497c-477f-b41b-5e0dee768857", + "e7e76ead-26e0-4d51-b51d-90a5c4085950" }; private static final String[] external_profile_secrets = { - "ba052ca1-b65b-41d4-969a-bc97a0f67386", - "7935697c-5c34-448a-9fad-484ad16867eb", - "59e45d2f-d7e0-47fa-b6a1-31e0066781f3", - "ac790728-36d6-455d-9469-deb6fbaf0589" }; + "f0c619fe-07f6-4713-bc06-02a5aa66c640", + "70022d8d-4bec-400e-9181-4dca0233ce2a", + "54d08408-146f-4150-a360-ee65a2fd8f90", + "34ac7d34-8b95-48e2-b16c-68af144b7a00" }; /** * Retrieves an ORCID client for a given user profile using the local CRIS diff --git a/src/test/java/pt/ptcris/test/TestHelper.java b/src/test/java/pt/ptcris/test/TestHelper.java index f17c5e0..0d07dab 100644 --- a/src/test/java/pt/ptcris/test/TestHelper.java +++ b/src/test/java/pt/ptcris/test/TestHelper.java @@ -15,23 +15,24 @@ import java.util.logging.Logger; import java.util.logging.SimpleFormatter; +import org.um.dsi.gavea.orcid.model.common.DisambiguatedOrganization; 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.FundingType; import org.um.dsi.gavea.orcid.model.common.FuzzyDate; import org.um.dsi.gavea.orcid.model.common.FuzzyDate.Day; import org.um.dsi.gavea.orcid.model.common.FuzzyDate.Month; -import org.um.dsi.gavea.orcid.model.common.Iso3166Country; -import org.um.dsi.gavea.orcid.model.common.OrganizationAddress; import org.um.dsi.gavea.orcid.model.common.FuzzyDate.Year; +import org.um.dsi.gavea.orcid.model.common.Iso3166Country; import org.um.dsi.gavea.orcid.model.common.Organization; -import org.um.dsi.gavea.orcid.model.common.RelationshipType; +import org.um.dsi.gavea.orcid.model.common.OrganizationAddress; +import org.um.dsi.gavea.orcid.model.common.Relationship; +import org.um.dsi.gavea.orcid.model.common.WorkType; import org.um.dsi.gavea.orcid.model.funding.Funding; import org.um.dsi.gavea.orcid.model.funding.FundingTitle; -import org.um.dsi.gavea.orcid.model.funding.FundingType; import org.um.dsi.gavea.orcid.model.work.Work; import org.um.dsi.gavea.orcid.model.work.WorkTitle; -import org.um.dsi.gavea.orcid.model.work.WorkType; import pt.ptcris.handlers.ProgressHandler; import pt.ptcris.utils.ORCIDHelper; @@ -58,7 +59,7 @@ public static Work work(BigInteger key, String meta) { else work.setType(WorkType.CONFERENCE_PAPER); - FuzzyDate date = new FuzzyDate(new Year("201" + meta.charAt(meta.length()-1)), new Month("03"), new Day("21")); + FuzzyDate date = new FuzzyDate(new Year(Integer.valueOf("201" + meta.charAt(meta.length()-1))), new Month(3), new Day(21)); work.setPublicationDate(date); } @@ -70,7 +71,7 @@ public static Work workDOI(BigInteger key, String meta, String doi) { Work work = work(key, meta); ExternalId e1 = new ExternalId(); - e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdRelationship(Relationship.SELF); e1.setExternalIdValue(doi); e1.setExternalIdType("doi"); @@ -83,7 +84,7 @@ public static Work workUnk(BigInteger key, String meta, String doi) { Work work = work(key, meta); ExternalId e1 = new ExternalId(); - e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdRelationship(Relationship.SELF); e1.setExternalIdValue(doi); e1.setExternalIdType("ukn"); @@ -96,7 +97,7 @@ public static Work workDOIUnk(BigInteger key, String meta, String doi, String ei Work work = workDOI(key, meta, doi); ExternalId e = new ExternalId(); - e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdRelationship(Relationship.SELF); e.setExternalIdValue(eid); e.setExternalIdType("wosuid-"); @@ -108,14 +109,14 @@ public static Work workOtherOtherDOI(BigInteger key, String meta, String doi, St Work work = workDOI(key, meta, doi); ExternalId e = new ExternalId(); - e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdRelationship(Relationship.SELF); e.setExternalIdValue(eid); e.setExternalIdType("other-id"); work.getExternalIds().getExternalId().add(e); ExternalId e1 = new ExternalId(); - e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdRelationship(Relationship.SELF); e1.setExternalIdValue(eid2); e1.setExternalIdType("other-id"); @@ -128,7 +129,7 @@ public static Work workHANDLE(BigInteger key, String meta, String handle) { Work work = work(key, meta); ExternalId e1 = new ExternalId(); - e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdRelationship(Relationship.SELF); e1.setExternalIdValue(handle); e1.setExternalIdType("handle"); @@ -136,7 +137,7 @@ public static Work workHANDLE(BigInteger key, String meta, String handle) { // ExternalId e2 = new ExternalId(); -// e2.setExternalIdRelationship(RelationshipType.PART_OF); +// e2.setExternalIdRelationship(Relationship.PART_OF); // e2.setExternalIdValue("11111"); // e2.setExternalIdType("isbn"); // @@ -149,7 +150,7 @@ public static Work workDOIEID(BigInteger key, String meta, String doi, String ei Work work = workDOI(key, meta, doi); ExternalId e = new ExternalId(); - e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdRelationship(Relationship.SELF); e.setExternalIdValue(eid); e.setExternalIdType("eid"); @@ -161,14 +162,14 @@ public static Work workDOIHANDLE(BigInteger key, String meta, String doi, String Work work = workDOI(key, meta, doi); ExternalId e = new ExternalId(); - e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdRelationship(Relationship.SELF); e.setExternalIdValue(handle); e.setExternalIdType("handle"); work.getExternalIds().getExternalId().add(e); ExternalId e2 = new ExternalId(); - e2.setExternalIdRelationship(RelationshipType.PART_OF); + e2.setExternalIdRelationship(Relationship.PART_OF); e2.setExternalIdValue("11111"); e2.setExternalIdType("isbn"); @@ -181,7 +182,7 @@ public static Work workEIDHANDLE(BigInteger key, String meta, String eid, String Work work = workHANDLE(key, meta, handle); ExternalId e = new ExternalId(); - e.setExternalIdRelationship(RelationshipType.SELF); + e.setExternalIdRelationship(Relationship.SELF); e.setExternalIdValue(eid); e.setExternalIdType("eid"); @@ -194,12 +195,12 @@ public static Work workDOIEIDHANDLE(BigInteger key, String meta, String doi, Str Work work = workDOIEID(key, meta, doi, eid); ExternalId e2 = new ExternalId(); - e2.setExternalIdRelationship(RelationshipType.SELF); + e2.setExternalIdRelationship(Relationship.SELF); e2.setExternalIdValue(handle); e2.setExternalIdType("handle"); ExternalId e3 = new ExternalId(); - e3.setExternalIdRelationship(RelationshipType.PART_OF); + e3.setExternalIdRelationship(Relationship.PART_OF); e3.setExternalIdValue("11111"); e3.setExternalIdType("isbn"); work.getExternalIds().getExternalId().add(e3); @@ -213,7 +214,7 @@ public static Work workDOIDOIEIDHANDLE(BigInteger key, String meta, String doi1, Work work = workDOIEIDHANDLE(key, meta, doi1, eid, handle); ExternalId e1 = new ExternalId(); - e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdRelationship(Relationship.SELF); e1.setExternalIdValue(doi2); e1.setExternalIdType("doi"); @@ -235,14 +236,14 @@ public static Funding funding(BigInteger key, String meta) { title.setTitle("Meta-data " + meta); work.setTitle(title); - work.setOrganization(new Organization("Agency", new OrganizationAddress("Braga",null,Iso3166Country.PT), null)); + work.setOrganization(new Organization("Fundação para a Ciência e a Tecnologia", new OrganizationAddress("Lisboa",null,Iso3166Country.PT), new DisambiguatedOrganization("112084", "RINGGOLD"))); if (meta.equals("0")) work.setType(FundingType.CONTRACT); else work.setType(FundingType.GRANT); - FuzzyDate date = new FuzzyDate(new Year("201" + meta.charAt(meta.length()-1)), new Month("02"), null); + FuzzyDate date = new FuzzyDate(new Year(Integer.valueOf("201" + meta.charAt(meta.length()-1))), new Month(2), null); work.setStartDate(date); } @@ -254,7 +255,7 @@ public static Funding fundingNmb(BigInteger key, String meta, String doi) { Funding work = funding(key, meta); ExternalId e1 = new ExternalId(); - e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdRelationship(Relationship.SELF); e1.setExternalIdValue(doi); e1.setExternalIdType("grant_number"); @@ -267,7 +268,7 @@ public static Funding fundingNmbNmb(BigInteger key, String meta, String doi1, St Funding work = fundingNmb(key, meta, doi1); ExternalId e1 = new ExternalId(); - e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdRelationship(Relationship.SELF); e1.setExternalIdValue(doi2); e1.setExternalIdType("grant_number"); @@ -280,13 +281,13 @@ public static Funding fundingNmbNmbNmb(BigInteger key, String meta, String doi1, Funding work = fundingNmbNmb(key, meta, doi1, doi2); ExternalId e1 = new ExternalId(); - e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdRelationship(Relationship.SELF); e1.setExternalIdValue(doi3); e1.setExternalIdType("grant_number"); work.getExternalIds().getExternalId().add(e1); ExternalId e3 = new ExternalId(); - e3.setExternalIdRelationship(RelationshipType.PART_OF); + e3.setExternalIdRelationship(Relationship.PART_OF); e3.setExternalIdValue("11111"); e3.setExternalIdType("grant_number"); work.getExternalIds().getExternalId().add(e3); @@ -298,7 +299,7 @@ public static Funding fundingNmbNmbNmbNmb(BigInteger key, String meta, String do Funding work = fundingNmbNmbNmb(key, meta, doi1, doi2, doi3); ExternalId e1 = new ExternalId(); - e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdRelationship(Relationship.SELF); e1.setExternalIdValue(doi4); e1.setExternalIdType("grant_number"); @@ -325,13 +326,13 @@ public static Funding fundingIgn(BigInteger key, String meta, String nmb) { if (meta.equals("0")) work.setType(FundingType.AWARD); - FuzzyDate date = new FuzzyDate(new Year("201" + meta.charAt(meta.length()-1)), new Month("02"), null); + FuzzyDate date = new FuzzyDate(new Year(Integer.valueOf("201" + meta.charAt(meta.length()-1))), new Month(2), null); work.setStartDate(date); } ExternalId e1 = new ExternalId(); - e1.setExternalIdRelationship(RelationshipType.SELF); + e1.setExternalIdRelationship(Relationship.SELF); e1.setExternalIdValue(nmb); e1.setExternalIdType("grant_number"); work.getExternalIds().getExternalId().add(e1); diff --git a/src/test/java/pt/ptcris/test/scenarios/Scenario.java b/src/test/java/pt/ptcris/test/scenarios/Scenario.java index 6dece5d..747fbd7 100644 --- a/src/test/java/pt/ptcris/test/scenarios/Scenario.java +++ b/src/test/java/pt/ptcris/test/scenarios/Scenario.java @@ -9,7 +9,8 @@ */ package pt.ptcris.test.scenarios; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.math.BigInteger; import java.util.ArrayList; @@ -25,9 +26,9 @@ import org.junit.Test; 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.common.WorkType; 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.PTCRISync; import pt.ptcris.PTCRISyncResult; diff --git a/src/test/java/pt/ptcris/test/scenarios/ScenarioFunding.java b/src/test/java/pt/ptcris/test/scenarios/ScenarioFunding.java index e0f2075..8dec078 100644 --- a/src/test/java/pt/ptcris/test/scenarios/ScenarioFunding.java +++ b/src/test/java/pt/ptcris/test/scenarios/ScenarioFunding.java @@ -9,7 +9,8 @@ */ package pt.ptcris.test.scenarios; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.math.BigInteger; import java.util.ArrayList; @@ -26,9 +27,9 @@ import org.junit.Test; import org.um.dsi.gavea.orcid.client.exception.OrcidClientException; import org.um.dsi.gavea.orcid.model.activities.FundingGroup; +import org.um.dsi.gavea.orcid.model.common.FundingType; import org.um.dsi.gavea.orcid.model.funding.Funding; import org.um.dsi.gavea.orcid.model.funding.FundingSummary; -import org.um.dsi.gavea.orcid.model.funding.FundingType; import pt.ptcris.PTCRISync; import pt.ptcris.PTCRISyncResult;