Skip to content

Commit 02c993d

Browse files
author
nmacedo
committed
Merge branch 'orcid-rc2'
2 parents 7f0bfa0 + 750d0b8 commit 02c993d

File tree

14 files changed

+286
-165
lines changed

14 files changed

+286
-165
lines changed

pom.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10-
<orcid-api-client.version>2.0-rc1</orcid-api-client.version>
10+
<orcid-api-client.version>2.0-rc2</orcid-api-client.version>
1111
<log4j.version>2.4</log4j.version>
1212
<junit.version>4.12</junit.version>
1313
</properties>
@@ -40,9 +40,12 @@
4040
<plugin>
4141
<groupId>org.apache.maven.plugins</groupId>
4242
<artifactId>maven-jar-plugin</artifactId>
43-
<version>2.6</version>
44-
<configuration />
45-
</plugin>
43+
<version>3.3</version>
44+
<configuration>
45+
<source>1.7</source>
46+
<target>1.7</target>
47+
</configuration>
48+
</plugin>
4649
<plugin>
4750
<artifactId>maven-compiler-plugin</artifactId>
4851
<version>3.3</version>

src/main/java/pt/ptcris/ORCIDClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,12 @@ public interface ORCIDClient {
7777
*/
7878
public ActivitiesSummary getActivitiesSummary() throws OrcidClientException;
7979

80+
/**
81+
* The number of worker threads that will be used to communicate with the
82+
* ORCID API.
83+
*
84+
* @return the number of ORCID worker threads
85+
*/
86+
public int threads();
87+
8088
}

src/main/java/pt/ptcris/ORCIDClientImpl.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class ORCIDClientImpl implements ORCIDClient {
2222
private final OrcidAccessToken orcidToken;
2323
private final OrcidOAuthClient orcidClient;
2424
private final String clientId;
25+
private final int threads;
2526

2627
/**
2728
* Instantiates an ORCID client to communicate with the ORCID API.
@@ -38,14 +39,37 @@ public class ORCIDClientImpl implements ORCIDClient {
3839
* the redirect URI for requesting the access token
3940
* @param orcidToken
4041
* the access token to the user ORCID profile
42+
* @param threads
43+
* the number of ORCID worker threads
4144
*/
4245
public ORCIDClientImpl(String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri,
43-
OrcidAccessToken orcidToken) {
46+
OrcidAccessToken orcidToken, int threads) {
4447
this.orcidToken = orcidToken;
4548
this.clientId = clientId;
46-
49+
this.threads = threads;
4750
this.orcidClient = new OrcidOAuthClient(loginUri, apiUri, clientId, clientSecret, redirectUri);
4851
}
52+
53+
/**
54+
* Instantiates an ORCID client to communicate with the ORCID API.
55+
*
56+
* @param loginUri
57+
* the login URI of the ORCID service
58+
* @param apiUri
59+
* the URI of the ORCID API
60+
* @param clientId
61+
* the id of the ORCID Member API client
62+
* @param clientSecret
63+
* the secret of the ORCID Member API client
64+
* @param redirectUri
65+
* the redirect URI for requesting the access token
66+
* @param orcidToken
67+
* the access token to the user ORCID profile
68+
*/
69+
public ORCIDClientImpl(String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri,
70+
OrcidAccessToken orcidToken) {
71+
this(loginUri, apiUri, clientId, clientSecret, redirectUri, orcidToken, Runtime.getRuntime().availableProcessors() + 2);
72+
}
4973

5074
/**
5175
* {@inheritDoc}
@@ -95,4 +119,12 @@ public ActivitiesSummary getActivitiesSummary() throws OrcidClientException {
95119
return orcidClient.readActivitiesSummary(orcidToken);
96120
}
97121

122+
/**
123+
* {@inheritDoc}
124+
*/
125+
@Override
126+
public int threads() {
127+
return threads;
128+
}
129+
98130
}

src/main/java/pt/ptcris/PTCRISync.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
1414
import org.um.dsi.gavea.orcid.model.activities.WorkGroup;
15-
import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier;
15+
import org.um.dsi.gavea.orcid.model.common.ExternalId;
16+
import org.um.dsi.gavea.orcid.model.common.ExternalIds;
1617
import org.um.dsi.gavea.orcid.model.work.Work;
17-
import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers;
1818
import org.um.dsi.gavea.orcid.model.work.WorkSummary;
1919

2020
import pt.ptcris.exceptions.InvalidWorkException;
@@ -47,7 +47,7 @@
4747
* <p>
4848
* The implementation of the service assumes that the local CRIS communicates
4949
* the local productions following the established ORCID schema, according to
50-
* the Member API 2.0rc1. This uniforms the API and simplifies the
50+
* the Member API 2.0rc2. This uniforms the API and simplifies the
5151
* synchronization process. The current version focuses on synchronizing
5252
* research productions, which must be encoded as ORCID {@link Work works}.
5353
* </p>
@@ -264,10 +264,10 @@ private static Map<BigInteger, PTCRISyncResult> exportBase(ORCIDClient client, L
264264
// the remote work has spurious external identifiers
265265
if (!update.eidsDiff.more.isEmpty()) {
266266
Work localWork = update.preWork;
267-
WorkExternalIdentifiers weids = new WorkExternalIdentifiers();
268-
List<ExternalIdentifier> ids = new ArrayList<ExternalIdentifier>(update.eidsDiff.same);
269-
weids.setWorkExternalIdentifier(ids);
270-
localWork.setExternalIdentifiers(weids);
267+
ExternalIds weids = new ExternalIds();
268+
List<ExternalId> ids = new ArrayList<ExternalId>(update.eidsDiff.same);
269+
weids.setExternalId(ids);
270+
localWork.setExternalIds(weids);
271271
try {
272272
helper.updateWork(update.posWork.getPutCode(), localWork);
273273
result.put(ORCIDHelper.getActivityLocalKey(localWork), PTCRISyncResult.OK_UPD_RESULT);
@@ -287,11 +287,11 @@ private static Map<BigInteger, PTCRISyncResult> exportBase(ORCIDClient client, L
287287
UpdateRecord update = toUpdate.get(c);
288288
if (!update.eidsDiff.less.isEmpty() || update.eidsDiff.more.isEmpty()) {
289289
Work localWork = update.preWork;
290-
WorkExternalIdentifiers weids = new WorkExternalIdentifiers();
291-
List<ExternalIdentifier> ids = new ArrayList<ExternalIdentifier>(update.eidsDiff.same);
290+
ExternalIds weids = new ExternalIds();
291+
List<ExternalId> ids = new ArrayList<ExternalId>(update.eidsDiff.same);
292292
ids.addAll(update.eidsDiff.less);
293-
weids.setWorkExternalIdentifier(ids);
294-
localWork.setExternalIdentifiers(weids);
293+
weids.setExternalId(ids);
294+
localWork.setExternalIds(weids);
295295
try {
296296
helper.updateWork(update.posWork.getPutCode(), localWork);
297297
result.put(ORCIDHelper.getActivityLocalKey(localWork), PTCRISyncResult.OK_UPD_RESULT);
@@ -658,11 +658,11 @@ public static List<Work> importUpdates(ORCIDClient client, List<Work> localWorks
658658
for (Work mathingLocalWork : matchingLocalWorks.keySet()) {
659659
if (!ORCIDHelper.hasNewIDs(mathingLocalWork, orcidWork)) {
660660
Work workUpdate = ORCIDHelper.clone(mathingLocalWork);
661-
WorkExternalIdentifiers weids = new WorkExternalIdentifiers();
662-
List<ExternalIdentifier> neids = new ArrayList<ExternalIdentifier>(matchingLocalWorks.get(mathingLocalWork).more);
663-
weids.setWorkExternalIdentifier(neids);
661+
ExternalIds weids = new ExternalIds();
662+
List<ExternalId> neids = new ArrayList<ExternalId>(matchingLocalWorks.get(mathingLocalWork).more);
663+
weids.setExternalId(neids);
664664
ORCIDHelper.setWorkLocalKey(workUpdate, ORCIDHelper.getActivityLocalKey(mathingLocalWork));
665-
workUpdate.setExternalIdentifiers(weids);
665+
workUpdate.setExternalIds(weids);
666666
workUpdate.setTitle(null);
667667
workUpdate.setType(null);
668668
workUpdate.setPublicationDate(null);

src/main/java/pt/ptcris/PTCRISyncResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
public final class PTCRISyncResult {
1414

15-
public static final int ADDOK = -10;
15+
public static final int ADDOK = -5;
1616
public static final int UPDATEOK = -10;
1717
public static final int UPTODATE = -20;
1818
public static final int INVALID = -30;

src/main/java/pt/ptcris/utils/ExternalIdsDiff.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import java.util.List;
66
import java.util.Set;
77

8+
import org.um.dsi.gavea.orcid.model.common.ExternalId;
9+
import org.um.dsi.gavea.orcid.model.common.ExternalIds;
810
import org.um.dsi.gavea.orcid.model.common.RelationshipType;
9-
import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier;
10-
import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers;
1111

1212
/**
1313
* Calculates and stores the symmetric difference between two sets of
@@ -19,17 +19,17 @@ public final class ExternalIdsDiff {
1919
/**
2020
* External identifiers removed from the first set.
2121
*/
22-
public final Set<ExternalIdentifier> less = new HashSet<ExternalIdentifier>();
22+
public final Set<ExternalId> less = new HashSet<ExternalId>();
2323

2424
/**
2525
* External identifiers preserved in both sets.
2626
*/
27-
public final Set<ExternalIdentifier> same = new HashSet<ExternalIdentifier>();
27+
public final Set<ExternalId> same = new HashSet<ExternalId>();
2828

2929
/**
3030
* External identifiers inserted in the second set.
3131
*/
32-
public final Set<ExternalIdentifier> more = new HashSet<ExternalIdentifier>();
32+
public final Set<ExternalId> more = new HashSet<ExternalId>();
3333

3434
/**
3535
* Calculates and stores the symmetric difference between two sets of
@@ -40,15 +40,15 @@ public final class ExternalIdsDiff {
4040
* @param eids2
4141
* the second set of external identifiers
4242
*/
43-
public ExternalIdsDiff(WorkExternalIdentifiers weids1, WorkExternalIdentifiers weids2) {
44-
List<ExternalIdentifier> eids1 = new LinkedList<ExternalIdentifier>();
45-
List<ExternalIdentifier> eids2 = new LinkedList<ExternalIdentifier>();
43+
public ExternalIdsDiff(ExternalIds weids1, ExternalIds weids2) {
44+
List<ExternalId> eids1 = new LinkedList<ExternalId>();
45+
List<ExternalId> eids2 = new LinkedList<ExternalId>();
4646

47-
if (weids1 != null && weids1.getWorkExternalIdentifier() != null)
48-
eids1.addAll(weids1.getWorkExternalIdentifier());
47+
if (weids1 != null && weids1.getExternalId() != null)
48+
eids1.addAll(weids1.getExternalId());
4949

50-
if (weids2 != null && weids2.getWorkExternalIdentifier() != null)
51-
eids2.addAll(weids2.getWorkExternalIdentifier());
50+
if (weids2 != null && weids2.getExternalId() != null)
51+
eids2.addAll(weids2.getExternalId());
5252

5353
calculateDifference(eids1, eids2);
5454
}
@@ -68,14 +68,14 @@ public ExternalIdsDiff(WorkExternalIdentifiers weids1, WorkExternalIdentifiers w
6868
* @param eids2
6969
* another set of UIDs
7070
*/
71-
private void calculateDifference(List<ExternalIdentifier> eids1, List<ExternalIdentifier> eids2) {
71+
private void calculateDifference(List<ExternalId> eids1, List<ExternalId> eids2) {
7272
less.addAll(eids1);
7373
more.addAll(eids2);
74-
for (final ExternalIdentifier eid2 : eids2) {
75-
for (final ExternalIdentifier eid1 : eids1) {
76-
if (sameButNotBothPartOf(eid2.getRelationship(),eid1.getRelationship())
77-
&& eid1.getExternalIdentifierId().equals(eid2.getExternalIdentifierId())
78-
&& eid1.getExternalIdentifierType().equals(eid2.getExternalIdentifierType())) {
74+
for (final ExternalId eid2 : eids2) {
75+
for (final ExternalId eid1 : eids1) {
76+
if (sameButNotBothPartOf(eid2.getExternalIdRelationship(),eid1.getExternalIdRelationship())
77+
&& eid1.getExternalIdValue().equals(eid2.getExternalIdValue())
78+
&& eid1.getExternalIdType().equals(eid2.getExternalIdType())) {
7979
same.add(eid2);
8080
less.remove(eid1);
8181
more.remove(eid2);

0 commit comments

Comments
 (0)