Skip to content

Commit

Permalink
Merge branch 'orcid-rc2'
Browse files Browse the repository at this point in the history
  • Loading branch information
nmacedo committed Nov 30, 2016
2 parents 7f0bfa0 + 750d0b8 commit 02c993d
Show file tree
Hide file tree
Showing 14 changed files with 286 additions and 165 deletions.
11 changes: 7 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<orcid-api-client.version>2.0-rc1</orcid-api-client.version>
<orcid-api-client.version>2.0-rc2</orcid-api-client.version>
<log4j.version>2.4</log4j.version>
<junit.version>4.12</junit.version>
</properties>
Expand Down Expand Up @@ -40,9 +40,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration />
</plugin>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/pt/ptcris/ORCIDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
36 changes: 34 additions & 2 deletions src/main/java/pt/ptcris/ORCIDClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -38,14 +39,37 @@ 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) {
OrcidAccessToken orcidToken, int threads) {
this.orcidToken = orcidToken;
this.clientId = clientId;

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}
Expand Down Expand Up @@ -95,4 +119,12 @@ public ActivitiesSummary getActivitiesSummary() throws OrcidClientException {
return orcidClient.readActivitiesSummary(orcidToken);
}

/**
* {@inheritDoc}
*/
@Override
public int threads() {
return threads;
}

}
30 changes: 15 additions & 15 deletions src/main/java/pt/ptcris/PTCRISync.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,7 +47,7 @@
* <p>
* 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}.
* </p>
Expand Down Expand Up @@ -264,10 +264,10 @@ private static Map<BigInteger, PTCRISyncResult> 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<ExternalIdentifier> ids = new ArrayList<ExternalIdentifier>(update.eidsDiff.same);
weids.setWorkExternalIdentifier(ids);
localWork.setExternalIdentifiers(weids);
ExternalIds weids = new ExternalIds();
List<ExternalId> ids = new ArrayList<ExternalId>(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);
Expand All @@ -287,11 +287,11 @@ private static Map<BigInteger, PTCRISyncResult> 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<ExternalIdentifier> ids = new ArrayList<ExternalIdentifier>(update.eidsDiff.same);
ExternalIds weids = new ExternalIds();
List<ExternalId> ids = new ArrayList<ExternalId>(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);
Expand Down Expand Up @@ -658,11 +658,11 @@ public static List<Work> importUpdates(ORCIDClient client, List<Work> localWorks
for (Work mathingLocalWork : matchingLocalWorks.keySet()) {
if (!ORCIDHelper.hasNewIDs(mathingLocalWork, orcidWork)) {
Work workUpdate = ORCIDHelper.clone(mathingLocalWork);
WorkExternalIdentifiers weids = new WorkExternalIdentifiers();
List<ExternalIdentifier> neids = new ArrayList<ExternalIdentifier>(matchingLocalWorks.get(mathingLocalWork).more);
weids.setWorkExternalIdentifier(neids);
ExternalIds weids = new ExternalIds();
List<ExternalId> neids = new ArrayList<ExternalId>(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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pt/ptcris/PTCRISyncResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/pt/ptcris/utils/ExternalIdsDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,17 +19,17 @@ public final class ExternalIdsDiff {
/**
* External identifiers removed from the first set.
*/
public final Set<ExternalIdentifier> less = new HashSet<ExternalIdentifier>();
public final Set<ExternalId> less = new HashSet<ExternalId>();

/**
* External identifiers preserved in both sets.
*/
public final Set<ExternalIdentifier> same = new HashSet<ExternalIdentifier>();
public final Set<ExternalId> same = new HashSet<ExternalId>();

/**
* External identifiers inserted in the second set.
*/
public final Set<ExternalIdentifier> more = new HashSet<ExternalIdentifier>();
public final Set<ExternalId> more = new HashSet<ExternalId>();

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

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);
}
Expand All @@ -68,14 +68,14 @@ public ExternalIdsDiff(WorkExternalIdentifiers weids1, WorkExternalIdentifiers w
* @param eids2
* another set of UIDs
*/
private void calculateDifference(List<ExternalIdentifier> eids1, List<ExternalIdentifier> eids2) {
private void calculateDifference(List<ExternalId> eids1, List<ExternalId> 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);
Expand Down
Loading

0 comments on commit 02c993d

Please sign in to comment.