Commit b40ef4eb93153f8c3ea781bc9dc3c51f9a2a807a

Authored by Paulo Graça
1 parent 333985a458
Exists in tests

Fix ExternalId matching and log message

ptcrisync/src/pt/ptcris/ORCIDHelper.java
... ... @@ -13,13 +13,14 @@ import org.um.dsi.gavea.orcid.model.activities.WorkGroup;
13 13 import org.um.dsi.gavea.orcid.model.common.RelationshipType;
14 14 import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers;
15 15 import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier;
16   -
17   -
  16 +import org.apache.logging.log4j.LogManager;
  17 +import org.apache.logging.log4j.Logger;
18 18 import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
19 19  
20 20 public class ORCIDHelper {
21 21  
22 22 public final ORCIDClient client;
  23 + private static final Logger _log = LogManager.getLogger(ORCIDHelper.class);
23 24  
24 25 public ORCIDHelper(ORCIDClient orcidClient) throws OrcidClientException {
25 26 this.client = orcidClient;
... ... @@ -33,10 +34,10 @@ public class ORCIDHelper {
33 34 * @throws OrcidClientException
34 35 */
35 36 public List<WorkSummary> getAllWorkSummaries() throws OrcidClientException, NullPointerException {
36   - ActivitiesSummary summs = client.getActivitiesSummary();
37   - Stream<WorkGroup> groups = summs.getWorks().getGroup().stream();
38   - Stream<WorkSummary> works = groups.map(w -> groupToWork(w));
39   - return works.collect(Collectors.toList());
  37 + ActivitiesSummary activitiesSummary = client.getActivitiesSummary();
  38 + Stream<WorkGroup> workGroupList = activitiesSummary.getWorks().getGroup().stream();
  39 + Stream<WorkSummary> workSummaryList = workGroupList.map(w -> groupToWork(w));
  40 + return workSummaryList.collect(Collectors.toList());
40 41 }
41 42  
42 43 /**
... ... @@ -59,6 +60,7 @@ public class ORCIDHelper {
59 60  
60 61 return workSummaryList.collect(Collectors.toList());
61 62 }
  63 +
62 64  
63 65  
64 66 /**
... ... @@ -81,6 +83,27 @@ public class ORCIDHelper {
81 83  
82 84 return pubCodesList;
83 85 }
  86 +
  87 +
  88 + /**
  89 + * @param work
  90 + * @return String with title
  91 + * @throws NullPointerException
  92 + */
  93 + public static String getWorkTitle(Work work) throws NullPointerException {
  94 + return work.getTitle().toString();
  95 + }
  96 +
  97 +
  98 + /**
  99 + * @param work
  100 + * @return String with putcode
  101 + * @throws NullPointerException
  102 + */
  103 + public static String getWorkPutCode(Work work) throws NullPointerException {
  104 + return work.getPutCode().toString();
  105 + }
  106 +
84 107  
85 108 /**
86 109 * Retrieves the set of productions (from works) that share some UIDs with a
... ... @@ -112,9 +135,12 @@ public class ORCIDHelper {
112 135 */
113 136 private static boolean checkDuplicateUIDs(WorkExternalIdentifiers uids1, WorkExternalIdentifiers uids2) {
114 137 if (uids2 != null && uids1 != null) {
  138 +
115 139 for (ExternalIdentifier uid2 : uids2.getWorkExternalIdentifier()) {
116 140 for (ExternalIdentifier uid1 : uids1.getWorkExternalIdentifier()) {
117   - if (sameButNotBothPartOf(uid2.getRelationship(), uid1.getRelationship()) && uid1.equals(uid2)) {
  141 +
  142 + if (sameButNotBothPartOf(uid2.getRelationship(), uid1.getRelationship()) &&
  143 + uid1.getExternalIdentifierId().equals(uid2.getExternalIdentifierId())) {
118 144 return true;
119 145 }
120 146 }
... ... @@ -183,27 +209,32 @@ public class ORCIDHelper {
183 209 }
184 210  
185 211 public void deleteWork(BigInteger putCode) throws OrcidClientException {
  212 + _log.debug("[deleteWork] " + putCode);
186 213 client.deleteWork(putCode.toString());
187 214 }
188 215  
189 216 public Work getFullWork(BigInteger putCode) throws OrcidClientException {
  217 + _log.debug("[getFullWork] " + putCode);
190 218 return client.getWork(putCode.toString());
191 219 }
192 220  
193 221 public void updateWork(BigInteger putCode, Work work) throws OrcidClientException {
  222 + _log.debug("[updateWork] " + putCode);
194 223 client.updateWork(putCode.toString(), work);
195 224 }
196 225  
197 226 public void addWork(Work work) throws OrcidClientException {
  227 + _log.debug("[addWork] " + getWorkTitle(work));
198 228 client.addWork(work);
199 229 }
200 230  
201 231 public ActivitiesSummary getActivitiesSummary() throws OrcidClientException {
  232 + _log.debug("[getActivitiesSummary] ");
202 233 return client.getActivitiesSummary();
203 234 }
204 235  
205 236 public ORCIDClient getClient () {
206 237 return this.client;
207 238 }
208   -
  239 +
209 240 }
... ...
ptcrisync/src/pt/ptcris/PTCRISync.java
... ... @@ -53,7 +53,7 @@ public class PTCRISync {
53 53 helper.deleteWork(orcidWorks.get(counter).getPutCode());
54 54 } else {
55 55 for (Work localWork : matchingWorks) {
56   - _log.debug("[export] Local work " + localWork.toString());
  56 + _log.debug("[export] Local work " + ORCIDHelper.getWorkTitle(localWork));
57 57 Work orcidWork = helper.getFullWork(orcidWorks.get(counter).getPutCode());
58 58 recordsToUpdate.add(new UpdateRecord(localWork, orcidWork));
59 59 localWorks.remove(localWork);
... ...