Commit b7ec6e4dce6578763c339087e3d1b493465c278c

Authored by Paulo Graça
1 parent a3289b5b60
Exists in tests

Remove ptcrisync lib from source

README.md
... ... @@ -1 +0,0 @@
1   -# PTCRISync Framework Test
ptcrisync/.gitignore
... ... @@ -1 +0,0 @@
1   -/bin
ptcrisync/README.md
... ... @@ -1 +0,0 @@
1   -# PTCRISync
2 0 \ No newline at end of file
ptcrisync/lib/.gitignore
... ... @@ -1,2 +0,0 @@
1   -# ignore compiled jars in the directory
2   -*.jar
ptcrisync/pom.xml
... ... @@ -1,69 +0,0 @@
1   -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2   - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3   - <modelVersion>4.0.0</modelVersion>
4   - <groupId>pt.ptcris</groupId>
5   - <artifactId>ptcrisync</artifactId>
6   - <version>0.0.1</version>
7   -
8   - <properties>
9   - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10   - <orcid-api-client.version>2.0-rc1</orcid-api-client.version>
11   - </properties>
12   -
13   - <dependencies>
14   - <!-- Degois ORCID Client -->
15   - <dependency>
16   - <groupId>org.um.dsi.gavea</groupId>
17   - <artifactId>degois-orcid-client</artifactId>
18   - <version>${orcid-api-client.version}</version>
19   - </dependency>
20   - </dependencies>
21   -
22   - <!-- Build Settings -->
23   - <build>
24   - <plugins>
25   - <plugin>
26   - <groupId>org.apache.maven.plugins</groupId>
27   - <artifactId>maven-jar-plugin</artifactId>
28   - <version>2.6</version>
29   - <configuration />
30   - </plugin>
31   - <plugin>
32   - <artifactId>maven-compiler-plugin</artifactId>
33   - <version>3.3</version>
34   - <configuration>
35   - <source />
36   - <target />
37   - </configuration>
38   - </plugin>
39   - <plugin>
40   - <inherited>true</inherited>
41   - <artifactId>maven-deploy-plugin</artifactId>
42   - <version>2.8.2</version>
43   - <configuration>
44   - <updateReleaseInfo>true</updateReleaseInfo>
45   - </configuration>
46   - </plugin>
47   - </plugins>
48   - </build>
49   -
50   - <distributionManagement>
51   - <repository>
52   - <id>internal.repo</id>
53   - <name>Temporary Staging Repository</name>
54   - <url>file:///tmp/mvn-repo</url>
55   - </repository>
56   - </distributionManagement>
57   -
58   - <!-- Environment Settings -->
59   - <repositories>
60   - <repository>
61   - <id>internal.staging.repo</id>
62   - <url>file:///tmp/mvn-repo</url>
63   - </repository>
64   - </repositories>
65   -
66   - <!-- More Project Information -->
67   - <name>PTCRISync</name>
68   - <description>This project aims to help the syncronization between ORCID and local systems.</description>
69   -</project>
ptcrisync/src/main/MainTester.java
... ... @@ -1,66 +0,0 @@
1   -package main;
2   -
3   -import java.util.LinkedList;
4   -import java.util.List;
5   -import java.util.logging.ConsoleHandler;
6   -import java.util.logging.Level;
7   -import java.util.logging.Logger;
8   -import java.util.logging.SimpleFormatter;
9   -
10   -import org.um.dsi.gavea.orcid.client.OrcidAccessToken;
11   -import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
12   -import org.um.dsi.gavea.orcid.model.work.Work;
13   -
14   -import pt.ptcris.ORCIDClientImpl;
15   -import pt.ptcris.PTCRISync;
16   -import pt.ptcris.handlers.ProgressHandler;
17   -
18   -public class MainTester implements ProgressHandler {
19   - private static Logger logger = Logger.getLogger(MainTester.class.getName());
20   -
21   - private static final String orcidID = "0000-0000-0000-0000";
22   - private static final String accessToken = "3d38cae4-0c2a-4ef8-8d55-7b6a9863dbbf";
23   - private static final String loginUri = "https://sandbox.orcid.org";
24   - private static final String apiUri = "https://api.sandbox.orcid.org";
25   - private static final String clientId = "3d38cae4-0c2a-4ef8-8d55-7b6a9863dbbf";
26   - private static final String clientSecret = "3d38cae4-0c2a-4ef8-8d55-7b6a9863dbbf";
27   - private static final String redirectUri = "https://developers.google.com/oauthplayground";
28   -
29   - public static void main(String[] args) throws OrcidClientException {
30   - ConsoleHandler handler = new ConsoleHandler();
31   - handler.setFormatter(new SimpleFormatter());
32   - handler.setLevel(Level.ALL);
33   - logger.setLevel(Level.ALL);
34   - logger.addHandler(handler);
35   -
36   - List<Work> works = new LinkedList<Work>();
37   - MainTester progressHandler = new MainTester();
38   -
39   - OrcidAccessToken orcidToken = new OrcidAccessToken();
40   - orcidToken.setAccess_token(accessToken);
41   - orcidToken.setOrcid(orcidID);
42   -
43   - ORCIDClientImpl client = new ORCIDClientImpl(loginUri, apiUri, clientId, clientSecret, redirectUri, orcidToken);
44   -
45   -
46   - PTCRISync.export(client, works, progressHandler);
47   - List<Work> worksToImport = PTCRISync.importWorks(client, works, progressHandler);
48   - List<Work> worksToUpdate = PTCRISync.importUpdates(client, works, progressHandler);
49   - }
50   -
51   - public void setProgress(int progress) {
52   - logger.fine("Current progress: " + progress + "%");
53   - }
54   -
55   - public void setCurrentStatus(String message) {
56   - logger.fine("Task: " + message);
57   - }
58   -
59   - public void sendError(String message) {
60   - logger.log(Level.SEVERE, "ERROR: " + message);
61   - }
62   -
63   - public void done() {
64   - logger.fine("Done.");
65   - }
66   -}
ptcrisync/src/main/MainTester2.java
... ... @@ -1,152 +0,0 @@
1   -package main;
2   -
3   -import java.util.LinkedList;
4   -import java.util.List;
5   -import java.util.logging.ConsoleHandler;
6   -import java.util.logging.Level;
7   -import java.util.logging.Logger;
8   -import java.util.logging.SimpleFormatter;
9   -
10   -import org.um.dsi.gavea.orcid.client.OrcidAccessToken;
11   -import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
12   -import org.um.dsi.gavea.orcid.model.common.RelationshipType;
13   -import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier;
14   -import org.um.dsi.gavea.orcid.model.work.ExternalIdentifierType;
15   -import org.um.dsi.gavea.orcid.model.work.Work;
16   -import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers;
17   -import org.um.dsi.gavea.orcid.model.work.WorkTitle;
18   -import org.um.dsi.gavea.orcid.model.work.WorkType;
19   -
20   -import pt.ptcris.ORCIDClientImpl;
21   -import pt.ptcris.PTCRISync;
22   -import pt.ptcris.handlers.ProgressHandler;
23   -
24   -public class MainTester2 implements ProgressHandler {
25   - private static Logger logger = Logger.getLogger(MainTester2.class.getName());
26   -
27   - private static final String serviceSourceName = "HASLab, INESC TEC & University of Minho";
28   - // An account that has provided read-limited and activities-update access to this source.
29   - // Full access to an account is granted through read-limited, activities-update and bio-update.
30   - private static final String orcidID = "0000-0002-5507-2082";
31   - private static final String accessToken = "3d38cae4-0c2a-4ef8-8d55-7b6a9863dbbf";
32   - private static final String loginUri = "https://sandbox.orcid.org";
33   - private static final String apiUri = "https://api.sandbox.orcid.org";
34   - private static final String clientId = "3d38cae4-0c2a-4ef8-8d55-7b6a9863dbbf";
35   - private static final String clientSecret = "3d38cae4-0c2a-4ef8-8d55-7b6a9863dbbf";
36   - private static final String redirectUri = "https://developers.google.com/oauthplayground";
37   -
38   - public static void main(String[] args) throws OrcidClientException {
39   - ConsoleHandler handler = new ConsoleHandler();
40   - handler.setFormatter(new SimpleFormatter());
41   - handler.setLevel(Level.ALL);
42   - logger.setLevel(Level.ALL);
43   - logger.addHandler(handler);
44   -
45   - OrcidAccessToken orcidToken = new OrcidAccessToken();
46   - orcidToken.setAccess_token(accessToken);
47   - orcidToken.setOrcid(orcidID);
48   -
49   - ORCIDClientImpl client = new ORCIDClientImpl(loginUri, apiUri, clientId, clientSecret, redirectUri, orcidToken);
50   -
51   - List<Work> works = new LinkedList<Work>();
52   - works.add(work0());
53   - works.add(work1());
54   - works.add(work2());
55   - MainTester2 progressHandler = new MainTester2();
56   -
57   - List<Work> worksToImport = PTCRISync.importWorks(client, works, progressHandler);
58   - PTCRISync.export(client, works, progressHandler);
59   -
60   - progressHandler.setCurrentStatus(worksToImport.toString());
61   - progressHandler.done();
62   - }
63   -
64   -
65   - public void setProgress(int progress) {
66   - logger.fine("Current progress: " + progress + "%");
67   - }
68   -
69   - public void setCurrentStatus(String message) {
70   - logger.fine("Task: " + message);
71   - }
72   -
73   - public void sendError(String message) {
74   - logger.log(Level.SEVERE, "ERROR: " + message);
75   - }
76   -
77   - public void done() {
78   - logger.fine("Done.");
79   - }
80   -
81   - private static Work work0() {
82   - Work work = new Work();
83   - WorkTitle title = new WorkTitle();
84   - title.setTitle("Yet Another Work Updated Once");
85   - work.setTitle(title);
86   -
87   - ExternalIdentifier e = new ExternalIdentifier();
88   - e.setRelationship(RelationshipType.SELF);
89   - e.setExternalIdentifierId("3000");
90   - e.setExternalIdentifierType(ExternalIdentifierType.DOI);
91   -
92   -
93   - WorkExternalIdentifiers uids = new WorkExternalIdentifiers();
94   - uids.getWorkExternalIdentifier().add(e);
95   -
96   - work.setExternalIdentifiers(uids);
97   -
98   - work.setType(WorkType.CONFERENCE_PAPER);
99   -
100   - return work;
101   - }
102   -
103   - private static Work work1() {
104   - Work work = new Work();
105   - WorkTitle title = new WorkTitle();
106   - title.setTitle("A Work Updated Once");
107   - work.setTitle(title);
108   -
109   - ExternalIdentifier e = new ExternalIdentifier();
110   - e.setRelationship(RelationshipType.SELF);
111   - e.setExternalIdentifierId("4000");
112   - e.setExternalIdentifierType(ExternalIdentifierType.EID);
113   -
114   - ExternalIdentifier e1 = new ExternalIdentifier();
115   - e1.setRelationship(RelationshipType.SELF);
116   - e1.setExternalIdentifierId("00001");
117   - e1.setExternalIdentifierType(ExternalIdentifierType.DOI);
118   -
119   - WorkExternalIdentifiers uids = new WorkExternalIdentifiers();
120   - uids.getWorkExternalIdentifier().add(e);
121   - uids.getWorkExternalIdentifier().add(e1);
122   -
123   - work.setExternalIdentifiers(uids);
124   -
125   - work.setType(WorkType.CONFERENCE_PAPER);
126   -
127   - return work;
128   - }
129   -
130   - private static Work work2() {
131   - Work work = new Work();
132   - WorkTitle title = new WorkTitle();
133   - title.setTitle("Another Work Updated Twice");
134   - work.setTitle(title);
135   -
136   - ExternalIdentifier e = new ExternalIdentifier();
137   - e.setRelationship(RelationshipType.SELF);
138   - e.setExternalIdentifierId(String.valueOf(System.currentTimeMillis())); // will always create
139   - e.setExternalIdentifierType(ExternalIdentifierType.DOI);
140   -
141   - WorkExternalIdentifiers uids = new WorkExternalIdentifiers();
142   -
143   - uids.getWorkExternalIdentifier().add(e);
144   -
145   - work.setExternalIdentifiers(uids);
146   -
147   - work.setType(WorkType.JOURNAL_ARTICLE);
148   -
149   - return work;
150   - }
151   -
152   -}
ptcrisync/src/main/java/pt/ptcris/ORCIDClient.java
... ... @@ -1,67 +0,0 @@
1   -package pt.ptcris;
2   -
3   -import java.math.BigInteger;
4   -
5   -import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
6   -import org.um.dsi.gavea.orcid.model.work.Work;
7   -import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary;
8   -
9   -public interface ORCIDClient {
10   -
11   -
12   - /**
13   - * Retrieves a full work from the ORCID profile.
14   - *
15   - * @param putCode The put-code of the work.
16   - * @return The full work.
17   - * @throws ORCIDException
18   - */
19   - public Work getWork(BigInteger putCode) throws OrcidClientException;
20   -
21   - /**
22   - * Add a work to the ORCID profile.
23   - *
24   - * @param work
25   - * The work to be added to the ORCID profile
26   - * @return the put-code in the ORCID profile of the newly created work.
27   - * @throws ORCIDException
28   - */
29   - public String addWork(Work work) throws OrcidClientException;
30   -
31   - /**
32   - * Delete a work from the ORCID profile.
33   - *
34   - * @param putCode
35   - * The put-code of the work to be deleted.
36   - * @throws ORCIDException
37   - */
38   - public void deleteWork(BigInteger putCode) throws OrcidClientException;
39   -
40   - /**
41   - * Update a work in the ORCID profile.
42   - *
43   - * @param putCode
44   - * The put-code of the work to be updated.
45   - * @param work
46   - * the new state of the work.
47   - * @return the updated work as represented in the ORCID profile.
48   - * @throws ORCIDException
49   - */
50   - public void updateWork(BigInteger putCode, Work work) throws OrcidClientException;
51   -
52   - /**
53   - * Retrieves every activity summary of the ORCID profile.
54   - *
55   - * @return The activities summary of the ORCID profile.
56   - * @throws ORCIDException
57   - */
58   - public ActivitiesSummary getActivitiesSummary() throws OrcidClientException;
59   -
60   - /**
61   - * Returns the ORCID's client id
62   - *
63   - * @return String with cliend id.
64   - */
65   - public String getClientId();
66   -
67   -}
68 0 \ No newline at end of file
ptcrisync/src/main/java/pt/ptcris/ORCIDClientImpl.java
... ... @@ -1,83 +0,0 @@
1   -package pt.ptcris;
2   -
3   -import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
4   -
5   -import java.math.BigInteger;
6   -
7   -import org.um.dsi.gavea.orcid.client.OrcidAccessToken;
8   -import org.um.dsi.gavea.orcid.client.OrcidOAuthClient;
9   -import org.um.dsi.gavea.orcid.model.work.Work;
10   -import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary;
11   -
12   -
13   -public class ORCIDClientImpl implements ORCIDClient {
14   -
15   - private final OrcidAccessToken orcidToken;
16   - private final OrcidOAuthClient orcidClient;
17   - private final String clientId;
18   -
19   - public ORCIDClientImpl(String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri, OrcidAccessToken orcidToken) {
20   - this.orcidToken = orcidToken;
21   - this.clientId = clientId;
22   -
23   - // Instantiate the Orcid Client
24   - this.orcidClient = new OrcidOAuthClient(loginUri, apiUri, clientId, clientSecret, redirectUri);
25   - }
26   -
27   - /**
28   - * @see pt.ptcris.ORCIDClient#getFullWork(java.lang.Long)
29   - */
30   - public Work getWork(BigInteger putCode) throws OrcidClientException {
31   - return this.orcidClient.readWork(this.orcidToken, putCode.toString());
32   - }
33   -
34   - /**
35   - * @see pt.ptcris.ORCIDClient#addWork(org.orcid.jaxb.model.record_rc2.Work)
36   - */
37   - public String addWork(Work work) throws OrcidClientException {
38   - return this.orcidClient.addWork(this.orcidToken, work);
39   - }
40   -
41   - /**
42   - * @see pt.ptcris.ORCIDClient#deleteWork(java.lang.Long)
43   - */
44   - public void deleteWork(BigInteger putCode) throws OrcidClientException {
45   - this.orcidClient.deleteWork(this.orcidToken, putCode.toString());
46   -
47   - // NOTE: according to the ORCID API, to delete a work, one must provide
48   - // the entire list of works in the ORCID profile minus the work(s) that
49   - // should be deleted. This means that this operation must be done in
50   - // three steps: first, retrieve the entire set of works; second, remove
51   - // the
52   - // work to be deleted from the list of works; and three, send the
53   - // updated list to the ORCID API.
54   - }
55   -
56   - /**
57   - * @see pt.ptcris.ORCIDClient#updateWork(java.lang.Long,
58   - * org.orcid.jaxb.model.record_rc2.Work)
59   - */
60   - public void updateWork(BigInteger putCode, Work work) throws OrcidClientException {
61   - this.orcidClient.updateWork(this.orcidToken, putCode.toString(), work);
62   -
63   - // NOTE: according to the ORCID API, to update a work, one must provide
64   - // the entire list of works in the ORCID profile including the work(s)
65   - // that should be updated. This means that this operation must be done
66   - // in three steps: first, retrieve the entire set of works; second,
67   - // replace the work to be updated with the new record in the list of
68   - // works; and three, send the updated list to the ORCID API.
69   - }
70   -
71   - /**
72   - * @see pt.ptcris.ORCIDClient#getActivitiesSummary()
73   - */
74   - public ActivitiesSummary getActivitiesSummary() throws OrcidClientException {
75   - return orcidClient.readActivitiesSummary(orcidToken);
76   - }
77   -
78   - public String getClientId() {
79   - return this.clientId;
80   - }
81   -
82   -
83   -}
ptcrisync/src/main/java/pt/ptcris/ORCIDHelper.java
... ... @@ -1,275 +0,0 @@
1   -package pt.ptcris;
2   -
3   -import java.math.BigInteger;
4   -import java.util.LinkedList;
5   -import java.util.List;
6   -
7   -import org.um.dsi.gavea.orcid.model.work.Work;
8   -import org.um.dsi.gavea.orcid.model.work.WorkSummary;
9   -import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary;
10   -import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary.Works;
11   -import org.um.dsi.gavea.orcid.model.activities.WorkGroup;
12   -import org.um.dsi.gavea.orcid.model.common.RelationshipType;
13   -import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers;
14   -import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier;
15   -import org.apache.logging.log4j.LogManager;
16   -import org.apache.logging.log4j.Logger;
17   -import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
18   -
19   -public class ORCIDHelper {
20   -
21   - public final ORCIDClient client;
22   - private static final Logger _log = LogManager.getLogger(ORCIDHelper.class);
23   -
24   - public ORCIDHelper(ORCIDClient orcidClient) throws OrcidClientException {
25   - this.client = orcidClient;
26   - }
27   -
28   - /**
29   - * Retrieves the entire set of work summaries in the ORCID profile. Merges
30   - * each ORCID group into a single summary, following {@link #groupToWork}.
31   - *
32   - * @return The set of work summaries in the ORCID profile
33   - * @throws OrcidClientException
34   - */
35   - public List<WorkSummary> getAllWorkSummaries() throws OrcidClientException, NullPointerException {
36   - ActivitiesSummary activitiesSummary = client.getActivitiesSummary();
37   - List<WorkGroup> workGroupList = activitiesSummary.getWorks().getGroup();
38   - List<WorkSummary> workSummaryList = new LinkedList<WorkSummary>();
39   - for (WorkGroup group:workGroupList) {
40   - workSummaryList.add(groupToWork(group));
41   - }
42   - return workSummaryList;
43   - }
44   -
45   - /**
46   - * Retrieves the entire set of works in the ORCID profile whose source is
47   - * the local CRIS service.
48   - *
49   - * @return The set of work summaries in the ORCID profile whose source is
50   - * useDefault.
51   - * @throws OrcidClientException
52   - */
53   - public List<WorkSummary> getSourcedWorkSummaries() throws OrcidClientException, NullPointerException {
54   -
55   - ActivitiesSummary activitiesSummary = client.getActivitiesSummary();
56   - String sourceClientID = client.getClientId();
57   - Works works = activitiesSummary.getWorks();
58   - List<WorkSummary> returnedWorkSummary = new LinkedList<WorkSummary>();
59   -
60   - if (works == null) {
61   - return returnedWorkSummary;
62   - }
63   - List<WorkGroup> workGroupList = works.getGroup();
64   -
65   - for (WorkGroup workGroup:workGroupList) {
66   - for (WorkSummary workSummary:workGroup.getWorkSummary()) {
67   - if (workSummary.getSource().getSourceOrcid().getUriPath().equals(sourceClientID)) {
68   - returnedWorkSummary.add(workSummary);
69   - }
70   - }
71   - }
72   -
73   - return returnedWorkSummary;
74   - }
75   -
76   -
77   - /**
78   - * Delete all works from a specific Source
79   - * @throws OrcidClientException
80   - */
81   - public void deleteAllSourcedWorks () throws OrcidClientException {
82   - List<WorkSummary> workSummaryList = this.getSourcedWorkSummaries();
83   -
84   - for (WorkSummary workSummary : workSummaryList) {
85   - client.deleteWork(workSummary.getPutCode());
86   - }
87   -
88   - }
89   -
90   -
91   - /**
92   - * Retrieves the entire set of putCodes from an Activities Summary it's source independent
93   - *
94   - * @return a list of putCodes
95   - */
96   - public static List<BigInteger> getWorkSummaryPutCodes (ActivitiesSummary activitiesSummary) throws NullPointerException {
97   - List<BigInteger> pubCodesList = new LinkedList<BigInteger>();
98   - List<WorkSummary> workSummaryList;
99   - BigInteger putCode;
100   -
101   - for (WorkGroup workGroup : activitiesSummary.getWorks().getGroup()) {
102   - workSummaryList = workGroup.getWorkSummary();
103   - for (WorkSummary workSummary : workSummaryList) {
104   - putCode = workSummary.getPutCode();
105   - pubCodesList.add(putCode);
106   - }
107   - //putCode = workGroup.getWorkSummary().get(0).getPutCode();
108   - //pubCodesList.add(putCode);
109   -
110   - }
111   -
112   - return pubCodesList;
113   - }
114   -
115   -
116   - /**
117   - * @param work
118   - * @return String with title
119   - * @throws NullPointerException
120   - */
121   - public static String getWorkTitle(Work work) throws NullPointerException {
122   - return work.getTitle().getTitle();
123   - }
124   -
125   -
126   - /**
127   - * @param work
128   - * @return BigInteger with putcode
129   - * @throws NullPointerException
130   - */
131   - public static BigInteger getWorkPutCode(Work work) throws NullPointerException {
132   - return work.getPutCode();
133   - }
134   -
135   -
136   - /**
137   - * Retrieves the set of productions (from works) that share some UIDs with a
138   - * work summary.
139   - *
140   - * @param summary
141   - * The work summary to compare with the list of works.
142   - * @param works
143   - * The set of works to search for productions with shared UIDs.
144   - * @return The set of works with matching UIDs.
145   - */
146   - public static List<Work> getWorksWithSharedUIDs(WorkSummary summary, List<Work> works) {
147   - List<Work> matches = new LinkedList<Work>();
148   - for (Work match : works) {
149   - if (checkDuplicateUIDs(match.getExternalIdentifiers(), summary.getExternalIdentifiers()))
150   - matches.add(match);
151   - }
152   - return matches;
153   - }
154   -
155   - /**
156   - * Tests whether two sets of external IDs have duplicates. The algorithm is
157   - * the same as the one implemented by ORCID. Only considered duplicate if
158   - * UIDs have the same relationship and are not "part of".
159   - *
160   - * @param uids1
161   - * @param uids2
162   - * @return
163   - */
164   - private static boolean checkDuplicateUIDs(WorkExternalIdentifiers uids1, WorkExternalIdentifiers uids2) {
165   - if (uids2 != null && uids1 != null) {
166   -
167   - for (ExternalIdentifier uid2 : uids2.getWorkExternalIdentifier()) {
168   - for (ExternalIdentifier uid1 : uids1.getWorkExternalIdentifier()) {
169   -
170   - if (sameButNotBothPartOf(uid2.getRelationship(), uid1.getRelationship()) &&
171   - uid1.getExternalIdentifierId().equals(uid2.getExternalIdentifierId()) &&
172   - uid1.getExternalIdentifierType().equals(uid2.getExternalIdentifierType())) {
173   - return true;
174   - }
175   - }
176   - }
177   - }
178   - return false;
179   - }
180   -
181   - /**
182   - * Tests whether two UIDs relationships are the same but not part of.
183   - *
184   - * @param r1
185   - * @param r2
186   - * @return
187   - */
188   - private static boolean sameButNotBothPartOf(RelationshipType r1, RelationshipType r2) {
189   - if (r1 == null && r2 == null)
190   - return true;
191   - if (r1 != null && r1.equals(r2) && !r1.equals(RelationshipType.PART_OF))
192   - return true;
193   - return false;
194   - }
195   -
196   - /**
197   - * Merges a group into a work. Simply selects the first of the group and
198   - * assigns it any extra UIDs.
199   - *
200   - * @param group
201   - * The group to be merged.
202   - * @return The resulting work summary.
203   - */
204   - public static WorkSummary groupToWork(WorkGroup group) {
205   - WorkSummary aux = group.getWorkSummary().get(0);
206   - WorkSummary dummy = new WorkSummary();
207   - dummy.setCreatedDate(aux.getCreatedDate());
208   - dummy.setDisplayIndex(aux.getDisplayIndex());
209   - dummy.setExternalIdentifiers(aux.getExternalIdentifiers());
210   - dummy.setLastModifiedDate(aux.getLastModifiedDate());
211   - dummy.setPath(aux.getPath());
212   - dummy.setPublicationDate(aux.getPublicationDate());
213   - dummy.setPutCode(aux.getPutCode());
214   - dummy.setSource(aux.getSource());
215   - dummy.setTitle(aux.getTitle());
216   - dummy.setType(aux.getType());
217   - dummy.setVisibility(aux.getVisibility());
218   - // TODO: add the other UIDs of the group
219   - return dummy;
220   - }
221   -
222   - /**
223   - * Checks if localWork is already up to date on the information from
224   - * remoteWork, i.e., localWork already has the same UIDs as remoteWork
225   - *
226   - * @param localWork
227   - * The local work to check if it is up to date
228   - * @param remoteWork
229   - * The remote work to use when checking if the local work is up
230   - * to date
231   - * @return true if all the UIDs between the two works are the same, false
232   - * otherwise
233   - */
234   - public static boolean isAlreadyUpToDate(Work localWork, Work remoteWork) {
235   - // TODO Compare the two records to check if they are equal (when it
236   - // comes to matching UIDs)
237   - return false;
238   - }
239   -
240   - public void deleteWork(BigInteger putCode) throws OrcidClientException {
241   - _log.debug("[deleteWork] " + putCode);
242   - client.deleteWork(putCode);
243   - }
244   -
245   - public Work getFullWork(BigInteger putCode) throws OrcidClientException {
246   - _log.debug("[getFullWork] " + putCode);
247   - return client.getWork(putCode);
248   - }
249   -
250   - public void updateWork(BigInteger putCode, Work work) throws OrcidClientException {
251   - _log.debug("[updateWork] " + putCode);
252   - client.updateWork(putCode, work);
253   - }
254   -
255   - public Work addWork(Work work) throws OrcidClientException {
256   - _log.debug("[addWork]" + getWorkTitle(work));
257   -
258   - //Remove any putCode if exists
259   - work.setPutCode(null);
260   - BigInteger putCode = new BigInteger(client.addWork(work));
261   - work.setPutCode(putCode);
262   - _log.debug("[addWork] " + putCode);
263   - return work;
264   - }
265   -
266   - public ActivitiesSummary getActivitiesSummary() throws OrcidClientException {
267   - _log.debug("[getActivitiesSummary]");
268   - return client.getActivitiesSummary();
269   - }
270   -
271   - public ORCIDClient getClient () {
272   - return this.client;
273   - }
274   -
275   -}
ptcrisync/src/main/java/pt/ptcris/PTCRISync.java
... ... @@ -1,177 +0,0 @@
1   -package pt.ptcris;
2   -
3   -import java.util.LinkedList;
4   -import java.util.List;
5   -
6   -import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
7   -import org.um.dsi.gavea.orcid.model.work.Work;
8   -import org.um.dsi.gavea.orcid.model.work.WorkSummary;
9   -
10   -import pt.ptcris.handlers.ProgressHandler;
11   -import pt.ptcris.utils.UpdateRecord;
12   -
13   -import pt.ptcris.ORCIDHelper;
14   -
15   -public class PTCRISync {
16   -
17   - private static ORCIDHelper helper;
18   -
19   - /**
20   - * Export a list of works to an ORCID profile.
21   - *
22   - * @param orcidClient
23   - * The ORCID client to access to the profile.
24   - * @param local_work
25   - * The list of works to be exported (those marked as synced).
26   - * @param progressHandler
27   - * The implementation of the ProgressHandler interface
28   - * responsible for receiving progress updates.
29   - * @throws ORCIDException
30   - */
31   - public static void export(ORCIDClient orcidClient, List<Work> localWorks, ProgressHandler progressHandler)
32   - throws OrcidClientException {
33   -
34   - int progress = 0;
35   - progressHandler.setProgress(progress);
36   - progressHandler.setCurrentStatus("ORCID_SYNC_EXPORT_STARTED");
37   -
38   - helper = new ORCIDHelper(orcidClient);
39   -
40   - List<WorkSummary> orcidWorks = helper.getSourcedWorkSummaries();
41   - List<UpdateRecord> recordsToUpdate = new LinkedList<UpdateRecord>();
42   -
43   - progressHandler.setCurrentStatus("ORCID_SYNC_EXPORT_WORKS_ITERATION");
44   - for (int counter = 0; counter != orcidWorks.size(); counter++) {
45   - progress = (int) ((double) ((double) counter / orcidWorks.size()) * 100);
46   - progressHandler.setProgress(progress);
47   -
48   - List<Work> matchingWorks = ORCIDHelper.getWorksWithSharedUIDs(orcidWorks.get(counter), localWorks);
49   - if (matchingWorks.isEmpty()) {
50   - helper.deleteWork(orcidWorks.get(counter).getPutCode());
51   - } else {
52   - for (Work localWork : matchingWorks) {
53   - Work orcidWork = helper.getFullWork(orcidWorks.get(counter).getPutCode());
54   - recordsToUpdate.add(new UpdateRecord(localWork, orcidWork));
55   - localWorks.remove(localWork);
56   - }
57   - }
58   - }
59   -
60   - progressHandler.setCurrentStatus("ORCID_SYNC_EXPORT_UPDATING_WORKS");
61   - for (int counter = 0; counter != recordsToUpdate.size(); counter++) {
62   - progress = (int) ((double) ((double) counter / recordsToUpdate.size()) * 100);
63   - progressHandler.setProgress(progress);
64   -
65   - helper.updateWork(ORCIDHelper.getWorkPutCode(recordsToUpdate.get(counter).getRemoteWork()),
66   - recordsToUpdate.get(counter).getLocalWork());
67   - }
68   -
69   - progressHandler.setCurrentStatus("ORCID_SYNC_EXPORT_ADDING_WORKS");
70   - for (int counter = 0; counter != localWorks.size(); counter++) {
71   - progress = (int) ((double) ((double) counter / localWorks.size()) * 100);
72   - progressHandler.setProgress(progress);
73   -
74   - helper.addWork(localWorks.get(counter));
75   - }
76   -
77   - progressHandler.done();
78   -
79   - }
80   -
81   - /**
82   - * Discover new works in an ORCID profile.
83   - *
84   - * @param orcidClient
85   - * The ORCID client to access to the profile.
86   - * @param localWorks
87   - * The full list of works in the local profile. In fact, for each
88   - * work only the external identifiers are needed, so the
89   - * remaining attributes may be left null.
90   - * @param progressHandler
91   - * The implementation of the ProgressHandler interface
92   - * responsible for receiving progress updates
93   - * @return The list of new works found in the ORCID profile.
94   - * @throws ORCIDException
95   - */
96   - public static List<Work> importWorks(ORCIDClient orcidClient, List<Work> localWorks,
97   - ProgressHandler progressHandler) throws OrcidClientException {
98   - int progress = 0;
99   - progressHandler.setProgress(progress);
100   - progressHandler.setCurrentStatus("ORCID_SYNC_IMPORT_WORKS_STARTED");
101   -
102   - List<Work> worksToImport = new LinkedList<Work>();
103   -
104   - helper = new ORCIDHelper(orcidClient);
105   -
106   - List<WorkSummary> orcidWorks = helper.getAllWorkSummaries();
107   -
108   - progressHandler.setCurrentStatus("ORCID_SYNC_IMPORT_WORKS_ITERATION");
109   - for (int counter = 0; counter != orcidWorks.size(); counter++) {
110   - progress = (int) ((double) ((double) counter / orcidWorks.size()) * 100);
111   - progressHandler.setProgress(progress);
112   -
113   - List<Work> matchingWorks = ORCIDHelper.getWorksWithSharedUIDs(orcidWorks.get(counter), localWorks);
114   - if (matchingWorks.isEmpty()) {
115   - Work orcidWork = helper.getFullWork(orcidWorks.get(counter).getPutCode());
116   - worksToImport.add(orcidWork);
117   - }
118   - }
119   -
120   - progressHandler.done();
121   -
122   - return worksToImport;
123   - }
124   -
125   - /**
126   - * Discover updates to existing works in an ORCID profile.
127   - *
128   - * @param orcidClient
129   - * The ORCID client to access to the profile.
130   - * @param localWorks
131   - * The list of works for which we wish to discover updates (those
132   - * marked as synced). For the moment, only new external
133   - * identifiers will be found, so, for each work only the external
134   - * identifiers are needed, so the remaining attributes may be
135   - * left null. Also the putcode attribute should be used to store
136   - * the local key of each work.
137   - * @param progressHandler
138   - * The implementation of the ProgressHandler interface
139   - * responsible for receiving progress updates
140   - * @return The list of updated works. Only the works that have changes are
141   - * returned. Also, for each of them, only the attributes that
142   - * changed are set. For the moment, only new external identifiers
143   - * will be returned.
144   - * @throws ORCIDException
145   - */
146   - public static List<Work> importUpdates(ORCIDClient orcidClient, List<Work> localWorks,
147   - ProgressHandler progressHandler) throws OrcidClientException {
148   - int progress = 0;
149   - progressHandler.setProgress(progress);
150   - progressHandler.setCurrentStatus("ORCID_SYNC_IMPORT_UPDATES_STARTED");
151   -
152   - List<Work> worksToUpdate = new LinkedList<Work>();
153   - helper = new ORCIDHelper(orcidClient);
154   - List<WorkSummary> orcidWorks = helper.getAllWorkSummaries();
155   -
156   - progressHandler.setCurrentStatus("ORCID_SYNC_IMPORT_UPDATES_ITERATION");
157   - for (int counter = 0; counter != orcidWorks.size(); counter++) {
158   - progress = (int) ((double) ((double) counter / orcidWorks.size()) * 100);
159   - progressHandler.setProgress(progress);
160   -
161   - List<Work> matchingWorks = ORCIDHelper.getWorksWithSharedUIDs(orcidWorks.get(counter), localWorks);
162   - if (!matchingWorks.isEmpty()) {
163   - for (Work localWork : matchingWorks) {
164   - Work orcidWork = helper.getFullWork(orcidWorks.get(counter).getPutCode());
165   - if (!ORCIDHelper.isAlreadyUpToDate(localWork, orcidWork)) {
166   - worksToUpdate.add(orcidWork);
167   - }
168   - }
169   - }
170   - }
171   -
172   - progressHandler.done();
173   -
174   - return worksToUpdate;
175   - }
176   -
177   -}
ptcrisync/src/main/java/pt/ptcris/handlers/ProgressHandler.java
... ... @@ -1,29 +0,0 @@
1   -package pt.ptcris.handlers;
2   -
3   -public interface ProgressHandler {
4   - /**
5   - * Used to set the progress of a task, by using percentual values (between 0 and 100). It can be used to start a task, where progress = 0
6   - */
7   - public void setProgress(int progress);
8   -
9   - /**
10   - * Used to set the text of the current task
11   - *
12   - * @param message
13   - * The message to be sent to the progress handler
14   - */
15   - public void setCurrentStatus(String message);
16   -
17   - /**
18   - * Used to send an error message to the progress handler
19   - *
20   - * @param message
21   - * The error message to be sent to the progress handler
22   - */
23   - public void sendError(String message);
24   -
25   - /**
26   - * Used to set the current task as finalized
27   - */
28   - public void done();
29   -}
ptcrisync/src/main/java/pt/ptcris/utils/UpdateRecord.java
... ... @@ -1,30 +0,0 @@
1   -package pt.ptcris.utils;
2   -
3   -import org.um.dsi.gavea.orcid.model.work.Work;
4   -
5   -public class UpdateRecord {
6   -
7   - private Work localWork;
8   - private Work remoteWork;
9   -
10   - public UpdateRecord(Work localWork, Work remoteWork) {
11   - this.localWork = localWork;
12   - this.remoteWork = remoteWork;
13   - }
14   -
15   - public Work getLocalWork() {
16   - return localWork;
17   - }
18   -
19   - public void setLocalWork(Work localWork) {
20   - this.localWork = localWork;
21   - }
22   -
23   - public Work getRemoteWork() {
24   - return remoteWork;
25   - }
26   -
27   - public void setRemoteWork(Work remoteWork) {
28   - this.remoteWork = remoteWork;
29   - }
30   -}