Commit 90533190bb57cc08bae84bb1b46d61aaa7d16d1f

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

algorithm fixes

ptcrisync/src/pt/ptcris/ORCIDClient.java
1 1 package pt.ptcris;
2 2  
  3 +import java.math.BigInteger;
  4 +
3 5 import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
4 6 import org.um.dsi.gavea.orcid.model.work.Work;
5 7 import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary;
... ... @@ -14,7 +16,7 @@ public interface ORCIDClient {
14 16 * @return The full work.
15 17 * @throws ORCIDException
16 18 */
17   - public Work getWork(String putCode) throws OrcidClientException;
  19 + public Work getWork(BigInteger putCode) throws OrcidClientException;
18 20  
19 21 /**
20 22 * Add a work to the ORCID profile.
... ... @@ -33,7 +35,7 @@ public interface ORCIDClient {
33 35 * The put-code of the work to be deleted.
34 36 * @throws ORCIDException
35 37 */
36   - public void deleteWork(String putCode) throws OrcidClientException;
  38 + public void deleteWork(BigInteger putCode) throws OrcidClientException;
37 39  
38 40 /**
39 41 * Update a work in the ORCID profile.
... ... @@ -45,7 +47,7 @@ public interface ORCIDClient {
45 47 * @return the updated work as represented in the ORCID profile.
46 48 * @throws ORCIDException
47 49 */
48   - public void updateWork(String putCode, Work work) throws OrcidClientException;
  50 + public void updateWork(BigInteger putCode, Work work) throws OrcidClientException;
49 51  
50 52 /**
51 53 * Retrieves every activity summary of the ORCID profile.
... ...
ptcrisync/src/pt/ptcris/ORCIDClientImpl.java
1 1 package pt.ptcris;
2 2  
3 3 import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
  4 +
  5 +import java.math.BigInteger;
  6 +
4 7 import org.um.dsi.gavea.orcid.client.OrcidAccessToken;
5 8 import org.um.dsi.gavea.orcid.client.OrcidOAuthClient;
6 9 import org.um.dsi.gavea.orcid.model.work.Work;
... ... @@ -24,8 +27,8 @@ public class ORCIDClientImpl implements ORCIDClient {
24 27 /**
25 28 * @see pt.ptcris.ORCIDClient#getFullWork(java.lang.Long)
26 29 */
27   - public Work getWork(String putCode) throws OrcidClientException {
28   - return this.orcidClient.readWork(this.orcidToken, putCode);
  30 + public Work getWork(BigInteger putCode) throws OrcidClientException {
  31 + return this.orcidClient.readWork(this.orcidToken, putCode.toString());
29 32 }
30 33  
31 34 /**
... ... @@ -38,8 +41,8 @@ public class ORCIDClientImpl implements ORCIDClient {
38 41 /**
39 42 * @see pt.ptcris.ORCIDClient#deleteWork(java.lang.Long)
40 43 */
41   - public void deleteWork(String putCode) throws OrcidClientException {
42   - this.orcidClient.deleteWork(this.orcidToken, putCode);
  44 + public void deleteWork(BigInteger putCode) throws OrcidClientException {
  45 + this.orcidClient.deleteWork(this.orcidToken, putCode.toString());
43 46  
44 47 // NOTE: according to the ORCID API, to delete a work, one must provide
45 48 // the entire list of works in the ORCID profile minus the work(s) that
... ... @@ -54,8 +57,8 @@ public class ORCIDClientImpl implements ORCIDClient {
54 57 * @see pt.ptcris.ORCIDClient#updateWork(java.lang.Long,
55 58 * org.orcid.jaxb.model.record_rc2.Work)
56 59 */
57   - public void updateWork(String putCode, Work work) throws OrcidClientException {
58   - this.orcidClient.updateWork(this.orcidToken, putCode, work);
  60 + public void updateWork(BigInteger putCode, Work work) throws OrcidClientException {
  61 + this.orcidClient.updateWork(this.orcidToken, putCode.toString(), work);
59 62  
60 63 // NOTE: according to the ORCID API, to update a work, one must provide
61 64 // the entire list of works in the ORCID profile including the work(s)
... ...
ptcrisync/src/pt/ptcris/ORCIDHelper.java
... ... @@ -61,6 +61,19 @@ public class ORCIDHelper {
61 61 return workSummaryList.collect(Collectors.toList());
62 62 }
63 63  
  64 +
  65 + /**
  66 + * Delete all works from a specific Source
  67 + * @throws OrcidClientException
  68 + */
  69 + public void deleteAllSourcedWorks () throws OrcidClientException {
  70 + List<WorkSummary> workSummaryList = this.getSourcedWorkSummaries();
  71 +
  72 + for (WorkSummary workSummary : workSummaryList) {
  73 + client.deleteWork(workSummary.getPutCode());
  74 + }
  75 +
  76 + }
64 77  
65 78  
66 79 /**
... ... @@ -68,15 +81,15 @@ public class ORCIDHelper {
68 81 *
69 82 * @return a list of putCodes
70 83 */
71   - public static List<String> getWorkSummaryPutCodes (ActivitiesSummary activitiesSummary) throws NullPointerException {
72   - List<String> pubCodesList = new LinkedList<String>();
  84 + public static List<BigInteger> getWorkSummaryPutCodes (ActivitiesSummary activitiesSummary) throws NullPointerException {
  85 + List<BigInteger> pubCodesList = new LinkedList<BigInteger>();
73 86 List<WorkSummary> workSummaryList;
74   - String putCode;
  87 + BigInteger putCode;
75 88  
76 89 for (WorkGroup workGroup : activitiesSummary.getWorks().getGroup()) {
77 90 workSummaryList = workGroup.getWorkSummary();
78 91 for (WorkSummary workSummary : workSummaryList) {
79   - putCode = workSummary.getPutCode().toString();
  92 + putCode = workSummary.getPutCode();
80 93 pubCodesList.add(putCode);
81 94 }
82 95 }
... ... @@ -91,17 +104,17 @@ public class ORCIDHelper {
91 104 * @throws NullPointerException
92 105 */
93 106 public static String getWorkTitle(Work work) throws NullPointerException {
94   - return work.getTitle().toString();
  107 + return work.getTitle().getTitle();
95 108 }
96 109  
97 110  
98 111 /**
99 112 * @param work
100   - * @return String with putcode
  113 + * @return BigInteger with putcode
101 114 * @throws NullPointerException
102 115 */
103   - public static String getWorkPutCode(Work work) throws NullPointerException {
104   - return work.getPutCode().toString();
  116 + public static BigInteger getWorkPutCode(Work work) throws NullPointerException {
  117 + return work.getPutCode();
105 118 }
106 119  
107 120  
... ... @@ -140,7 +153,8 @@ public class ORCIDHelper {
140 153 for (ExternalIdentifier uid1 : uids1.getWorkExternalIdentifier()) {
141 154  
142 155 if (sameButNotBothPartOf(uid2.getRelationship(), uid1.getRelationship()) &&
143   - uid1.getExternalIdentifierId().equals(uid2.getExternalIdentifierId())) {
  156 + uid1.getExternalIdentifierId().equals(uid2.getExternalIdentifierId()) &&
  157 + uid1.getExternalIdentifierType().equals(uid2.getExternalIdentifierType())) {
144 158 return true;
145 159 }
146 160 }
... ... @@ -210,26 +224,31 @@ public class ORCIDHelper {
210 224  
211 225 public void deleteWork(BigInteger putCode) throws OrcidClientException {
212 226 _log.debug("[deleteWork] " + putCode);
213   - client.deleteWork(putCode.toString());
  227 + client.deleteWork(putCode);
214 228 }
215 229  
216 230 public Work getFullWork(BigInteger putCode) throws OrcidClientException {
217 231 _log.debug("[getFullWork] " + putCode);
218   - return client.getWork(putCode.toString());
  232 + return client.getWork(putCode);
219 233 }
220 234  
221 235 public void updateWork(BigInteger putCode, Work work) throws OrcidClientException {
222 236 _log.debug("[updateWork] " + putCode);
223   - client.updateWork(putCode.toString(), work);
  237 + client.updateWork(putCode, work);
224 238 }
225 239  
226   - public void addWork(Work work) throws OrcidClientException {
227   - _log.debug("[addWork] " + getWorkTitle(work));
228   - client.addWork(work);
  240 + public Work addWork(Work work) throws OrcidClientException {
  241 + _log.debug("[addWork]");
  242 + //Remove any putCode if exists
  243 + work.setPutCode(null);
  244 + BigInteger putCode = new BigInteger(client.addWork(work));
  245 + work.setPutCode(putCode);
  246 + _log.debug("[addWork] " + putCode);
  247 + return work;
229 248 }
230 249  
231 250 public ActivitiesSummary getActivitiesSummary() throws OrcidClientException {
232   - _log.debug("[getActivitiesSummary] ");
  251 + _log.debug("[getActivitiesSummary]");
233 252 return client.getActivitiesSummary();
234 253 }
235 254  
... ...
ptcrisync/src/pt/ptcris/PTCRISync.java
... ... @@ -67,7 +67,8 @@ public class PTCRISync {
67 67 progress = (int) ((double) ((double) counter / recordsToUpdate.size()) * 100);
68 68 progressHandler.setProgress(progress);
69 69  
70   - helper.updateWork(recordsToUpdate.get(counter).getRemoteWork().getPutCode(),recordsToUpdate.get(counter).getLocalWork());
  70 + helper.updateWork(ORCIDHelper.getWorkPutCode(recordsToUpdate.get(counter).getRemoteWork()),
  71 + recordsToUpdate.get(counter).getLocalWork());
71 72 }
72 73  
73 74 progressHandler.setCurrentStatus("ORCID_SYNC_EXPORT_ADDING_WORKS");
... ... @@ -99,6 +100,7 @@ public class PTCRISync {
99 100 public static List<Work> importWorks(ORCIDClient orcidClient, List<Work> localWorks, ProgressHandler progressHandler) throws OrcidClientException {
100 101 int progress = 0;
101 102 progressHandler.setProgress(progress);
  103 + _log.info("[importWorks] " + "ORCID_SYNC_IMPORT_WORKS_STARTED");
102 104 progressHandler.setCurrentStatus("ORCID_SYNC_IMPORT_WORKS_STARTED");
103 105  
104 106 List<Work> worksToImport = new LinkedList<Work>();
... ... @@ -107,6 +109,7 @@ public class PTCRISync {
107 109  
108 110 List<WorkSummary> orcidWorks = helper.getAllWorkSummaries();
109 111  
  112 + _log.info("[importWorks] " + "ORCID_SYNC_IMPORT_WORKS_ITERATION");
110 113 progressHandler.setCurrentStatus("ORCID_SYNC_IMPORT_WORKS_ITERATION");
111 114 for (int counter = 0; counter != orcidWorks.size(); counter++) {
112 115 progress = (int) ((double) ((double) counter / orcidWorks.size()) * 100);
... ... @@ -142,12 +145,14 @@ public class PTCRISync {
142 145 public static List<Work> importUpdates(ORCIDClient orcidClient, List<Work> localWorks, ProgressHandler progressHandler) throws OrcidClientException {
143 146 int progress = 0;
144 147 progressHandler.setProgress(progress);
  148 + _log.info("[importUpdates] " + "ORCID_SYNC_IMPORT_UPDATES_STARTED");
145 149 progressHandler.setCurrentStatus("ORCID_SYNC_IMPORT_UPDATES_STARTED");
146   -
  150 +
147 151 List<Work> worksToUpdate = new LinkedList<Work>();
148   -
  152 + helper = new ORCIDHelper(orcidClient);
149 153 List<WorkSummary> orcidWorks = helper.getAllWorkSummaries();
150 154  
  155 + _log.info("[importUpdates] " + "ORCID_SYNC_IMPORT_UPDATES_ITERATION");
151 156 progressHandler.setCurrentStatus("ORCID_SYNC_IMPORT_UPDATES_ITERATION");
152 157 for (int counter = 0; counter != orcidWorks.size(); counter++) {
153 158 progress = (int) ((double) ((double) counter / orcidWorks.size()) * 100);
... ...