Skip to content

Commit 614aad7

Browse files
authored
Merge pull request #6734 from ORCID/feature/8437-for-works-stop-sending-notifications-when-no-updates-to-the-works-has-actually-been-made
fix: Compare order of contributors and external identifiers
2 parents 7112c33 + 6834293 commit 614aad7

7 files changed

Lines changed: 235 additions & 112 deletions

File tree

orcid-core/src/main/java/org/orcid/core/manager/impl/WorkManagerImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,15 @@ public Work updateWork(String orcid, Work work, boolean isApiRequest) {
357357

358358
if (Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED.isActive()) {
359359
if (workFormSaved.compare(WorkForm.valueOf(work, maxContributorsForUI))) {
360+
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
361+
String client = null;
362+
if (sourceEntity.getSourceProfile() != null && sourceEntity.getSourceProfile().getId() != null) {
363+
client = sourceEntity.getSourceProfile().getId();
364+
}
365+
if (sourceEntity.getSourceClient() != null && sourceEntity.getSourceClient().getClientName() != null) {
366+
client = sourceEntity.getSourceClient().getClientName();
367+
}
368+
LOGGER.info("There is no changes in the work with putCode " + work.getPutCode() + " send it by " + client);
360369
return workSaved;
361370
}
362371
}

orcid-core/src/main/java/org/orcid/core/manager/v3/impl/WorkManagerImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ public Work updateWork(String orcid, Work work, boolean isApiRequest) {
365365

366366
if (Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED.isActive()) {
367367
if (workFormSaved.compare(WorkForm.valueOf(work, maxContributorsForUI))) {
368+
LOGGER.info("There is no changes in the work with putCode " + work.getPutCode() + " send it by " + getSourceName(sourceManager.retrieveActiveSource()));
368369
return workSaved;
369370
}
370371
}
@@ -556,6 +557,7 @@ public Work updateWork(String orcid, WorkForm workForm) {
556557

557558
if (Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED.isActive()) {
558559
if (workFormSaved.compare(workForm)) {
560+
LOGGER.info("There is no changes in the work with putCode " + work.getPutCode() + " send it by " + getSourceName(sourceManager.retrieveActiveSource()));
559561
return workSaved;
560562
}
561563
}
@@ -643,4 +645,11 @@ private String getTopContributorsJson(WorkForm work) {
643645
return contributorsRolesAndSequencesConverter.convertTo(work.getContributorsGroupedByOrcid(), null);
644646
}
645647

648+
private String getSourceName(Source activeSource) {
649+
String client = null;
650+
if (activeSource.getSourceName() != null && activeSource.getSourceName().getContent() != null) {
651+
client = activeSource.getSourceName().getContent();
652+
}
653+
return client;
654+
}
646655
}

orcid-core/src/main/java/org/orcid/pojo/ContributorsRolesAndSequences.java

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package org.orcid.pojo;
22

3+
import org.orcid.core.contributors.roles.works.WorkContributorRoleConverter;
4+
import org.orcid.core.utils.v3.ContributorUtils;
35
import org.orcid.jaxb.model.v3.release.common.Contributor;
46
import org.orcid.jaxb.model.v3.release.common.ContributorAttributes;
57
import org.orcid.jaxb.model.v3.release.common.ContributorEmail;
68
import org.orcid.jaxb.model.v3.release.common.ContributorOrcid;
79
import org.orcid.jaxb.model.v3.release.common.CreditName;
10+
import org.orcid.pojo.ajaxForm.WorkForm;
811

912
import java.util.ArrayList;
1013
import java.util.List;
14+
import java.util.concurrent.atomic.AtomicBoolean;
1115

1216
public class ContributorsRolesAndSequences extends Contributor {
13-
17+
1418
List<ContributorAttributes> rolesAndSequences = new ArrayList<>();
1519

1620
public List<ContributorAttributes> getRolesAndSequences() {
@@ -20,5 +24,72 @@ public List<ContributorAttributes> getRolesAndSequences() {
2024
public void setRolesAndSequences(List<ContributorAttributes> rolesAndSequences) {
2125
this.rolesAndSequences = rolesAndSequences;
2226
}
27+
28+
public boolean compare(Object obj) {
29+
if (this == obj)
30+
return true;
31+
if (obj == null)
32+
return false;
33+
if (getClass() != obj.getClass())
34+
return false;
35+
ContributorsRolesAndSequences other = (ContributorsRolesAndSequences) obj;
36+
37+
if (creditName != null && other.getCreditName() != null) {
38+
if (!creditName.getContent().equals(other.getCreditName().getContent())) {
39+
return false;
40+
}
41+
} else if (WorkForm.isAnyObjectNotNull(creditName, other.getCreditName())) {
42+
return false;
43+
}
44+
45+
if (contributorOrcid != null && other.getContributorOrcid() != null) {
46+
if (
47+
!WorkForm.isEachObjectNull(contributorOrcid.getPath(), other.getContributorOrcid().getPath()) &&
48+
!contributorOrcid.getPath().equalsIgnoreCase(other.getContributorOrcid().getPath())
49+
) {
50+
return false;
51+
}
52+
} else if (WorkForm.isAnyObjectNotNull(contributorOrcid, other.getContributorOrcid())) {
53+
return false;
54+
}
55+
56+
if (rolesAndSequences != null && other.getRolesAndSequences() != null) {
57+
if (rolesAndSequences.size() != other.getRolesAndSequences().size()) {
58+
return false;
59+
}
60+
AtomicBoolean isDifferent = new AtomicBoolean(false);
61+
WorkContributorRoleConverter roleConverter = new WorkContributorRoleConverter();
62+
ContributorUtils contributorUtils = new ContributorUtils(null);
63+
for (int i = 0; i < rolesAndSequences.size() ; i++) {
64+
if (rolesAndSequences.get(i).getContributorRole() != null && other.rolesAndSequences.get(i).getContributorRole() != null) {
65+
if (!WorkForm.compareStrings(rolesAndSequences.get(i).getContributorRole(), contributorUtils.getCreditRole(roleConverter.toRoleValue(other.rolesAndSequences.get(i).getContributorRole())))) {
66+
isDifferent.set(true);
67+
break;
68+
}
69+
}
70+
if (WorkForm.isAnyObjectNotNull(rolesAndSequences.get(i).getContributorRole(), other.rolesAndSequences.get(i).getContributorRole())) {
71+
isDifferent.set(true);
72+
break;
73+
}
74+
if (rolesAndSequences.get(i).getContributorSequence() != null && other.rolesAndSequences.get(i).getContributorSequence() != null) {
75+
if (!rolesAndSequences.get(i).getContributorSequence().equals(other.rolesAndSequences.get(i).getContributorSequence())) {
76+
isDifferent.set(true);
77+
break;
78+
}
79+
}
80+
if (WorkForm.isAnyObjectNotNull(rolesAndSequences.get(i).getContributorSequence(), other.rolesAndSequences.get(i).getContributorSequence())) {
81+
isDifferent.set(true);
82+
break;
83+
}
84+
}
85+
if (isDifferent.get()) {
86+
return false;
87+
}
88+
} else if (WorkForm.isAnyObjectNotNull(rolesAndSequences, other.getRolesAndSequences())) {
89+
return false;
90+
}
91+
92+
return true;
93+
}
2394
}
2495

orcid-core/src/main/java/org/orcid/pojo/ajaxForm/ActivityExternalIdentifier.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,30 @@ public boolean equals(Object obj) {
178178
} else if (!externalIdentifierType.equals(other.externalIdentifierType))
179179
return false;
180180
return true;
181-
}
181+
}
182+
183+
public boolean compare(Object obj) {
184+
if (this == obj)
185+
return true;
186+
if (obj == null)
187+
return false;
188+
if (getClass() != obj.getClass())
189+
return false;
190+
ActivityExternalIdentifier other = (ActivityExternalIdentifier) obj;
191+
192+
if (!WorkForm.compareTexts(externalIdentifierType, other.getExternalIdentifierType(), false)) {
193+
return false;
194+
}
195+
if (!WorkForm.compareTexts(externalIdentifierId, other.getExternalIdentifierId(), false)) {
196+
return false;
197+
}
198+
if (!WorkForm.compareTexts(url, other.getUrl(), true)) {
199+
return false;
200+
}
201+
if (!WorkForm.compareTexts(relationship, other.getRelationship(), false)) {
202+
return false;
203+
}
204+
205+
return true;
206+
}
182207
}

orcid-core/src/main/java/org/orcid/pojo/ajaxForm/Contributor.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public static Contributor valueOf(org.orcid.jaxb.model.v3.release.common.Contrib
5858
Contributor c = new Contributor();
5959
if (contributor != null) {
6060
if (contributor.getContributorAttributes() != null) {
61-
contributor.getContributorAttributes();
6261
if (contributor.getContributorAttributes().getContributorRole() != null) {
6362
try {
6463
CreditRole cr = CreditRole.fromValue(contributor.getContributorAttributes().getContributorRole());
@@ -86,7 +85,6 @@ public static Contributor valueOf(FundingContributor contributor) {
8685
Contributor c = new Contributor();
8786
if (contributor != null) {
8887
if (contributor.getContributorAttributes() != null) {
89-
contributor.getContributorAttributes();
9088
if (contributor.getContributorAttributes().getContributorRole() != null) {
9189
try {
9290
CreditRole cr = CreditRole.fromValue(contributor.getContributorAttributes().getContributorRole());
@@ -255,5 +253,30 @@ public boolean equals(Object obj) {
255253
} else if (!uri.equals(other.uri))
256254
return false;
257255
return true;
258-
}
256+
}
257+
258+
public boolean compare(Object obj) {
259+
if (this == obj)
260+
return true;
261+
if (obj == null)
262+
return false;
263+
if (getClass() != obj.getClass())
264+
return false;
265+
Contributor other = (Contributor) obj;
266+
267+
if (!WorkForm.compareTexts(creditName, other.getCreditName(), false)) {
268+
return false;
269+
}
270+
if (!WorkForm.compareTexts(orcid, other.getOrcid(), false)) {
271+
return false;
272+
}
273+
if (!WorkForm.compareTexts(contributorRole, other.getContributorRole(), true)) {
274+
return false;
275+
}
276+
if (!WorkForm.compareTexts(contributorSequence, other.getContributorSequence(), true)) {
277+
return false;
278+
}
279+
280+
return true;
281+
}
259282
}

orcid-core/src/main/java/org/orcid/pojo/ajaxForm/WorkForm.java

Lines changed: 25 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,13 +1256,17 @@ public boolean compare(Object obj) {
12561256

12571257
if (!isEachObjectNull(citation, other.citation)) {
12581258
if (isAnyObjectNotNull(citation, other.citation)) {
1259-
return false;
1259+
if (citation == null && other.citation.getCitation() != null && StringUtils.isNotBlank(other.citation.getCitation().getValue())) {
1260+
return false;
1261+
}
12601262
} else if (citation.getCitation() != null && other.citation.getCitation() != null && !compareTexts(citation.getCitation(), other.citation.getCitation(), false))
12611263
return false;
12621264
}
12631265
if (!isEachObjectNull(translatedTitle, other.translatedTitle)) {
12641266
if (isAnyObjectNotNull(translatedTitle, other.translatedTitle)) {
1265-
return false;
1267+
if (translatedTitle == null && StringUtils.isNotBlank(other.translatedTitle.getContent())) {
1268+
return false;
1269+
}
12661270
} else if (other.translatedTitle.getContent() != null && !translatedTitle.getContent().equals(other.translatedTitle.getContent()))
12671271
return false;
12681272
}
@@ -1308,121 +1312,39 @@ private boolean compareExternalIdentifiers(List<ActivityExternalIdentifier> a, L
13081312
if (isEachObjectNull(a, b)) {
13091313
return false;
13101314
}
1311-
AtomicBoolean isDifferent = new AtomicBoolean(false);
1312-
a.forEach(activityA -> b.forEach(activityB -> {
1313-
if (!compareTexts(activityA.getExternalIdentifierType(), activityB.getExternalIdentifierType(), false)) {
1314-
isDifferent.set(true);
1315-
return;
1316-
}
1317-
if (!compareTexts(activityA.getExternalIdentifierId(), activityB.getExternalIdentifierId(), false)) {
1318-
isDifferent.set(true);
1319-
return;
1320-
}
1321-
if (!compareTexts(activityA.getUrl(), activityB.getUrl(), true)) {
1322-
isDifferent.set(true);
1323-
return;
1324-
}
1325-
if (!compareTexts(activityA.getRelationship(), activityB.getRelationship(), false)) {
1326-
isDifferent.set(true);
1327-
return;
1315+
for (int i = 0; i < a.size() ; i++) {
1316+
if (!a.get(i).compare(b.get(i))) {
1317+
return true;
13281318
}
1329-
}));
1330-
return isDifferent.get();
1319+
}
1320+
return false;
13311321
}
13321322

13331323
private boolean compareContributors(List<Contributor> a, List<Contributor> b) {
13341324
if (isEachObjectNull(a, b)) {
13351325
return false;
13361326
}
1337-
AtomicBoolean isDifferent = new AtomicBoolean(false);
1338-
a.forEach(contributorA -> b.forEach(contributorB -> {
1339-
if (!compareTexts(contributorA.getCreditName(), contributorB.getCreditName(), false)) {
1340-
isDifferent.set(true);
1341-
return;
1342-
}
1343-
if (!compareTexts(contributorA.getOrcid(), contributorB.getOrcid(), false)) {
1344-
isDifferent.set(true);
1345-
return;
1346-
}
1347-
if (!compareTexts(contributorA.getContributorRole(), contributorB.getContributorRole(), true)) {
1348-
isDifferent.set(true);
1349-
return;
1350-
}
1351-
if (!compareTexts(contributorA.getContributorSequence(), contributorB.getContributorSequence(), true)) {
1352-
isDifferent.set(true);
1353-
return;
1327+
for (int i = 0; i < a.size() ; i++) {
1328+
if (!a.get(i).compare(b.get(i))) {
1329+
return true;
13541330
}
1355-
}));
1356-
return isDifferent.get();
1331+
}
1332+
return false;
13571333
}
13581334

13591335
private boolean compareContributorsGroupedByOrcid(List<ContributorsRolesAndSequences> a, List<ContributorsRolesAndSequences> b) {
13601336
if (isEachObjectNull(a, b)) {
13611337
return false;
13621338
}
1363-
AtomicBoolean isDifferent = new AtomicBoolean(false);
1364-
a.forEach(contributorA -> b.forEach(contributorB -> {
1365-
if (contributorA.getCreditName() != null && contributorB.getCreditName() != null) {
1366-
if (!contributorA.getCreditName().getContent().equals(contributorB.getCreditName().getContent())) {
1367-
isDifferent.set(true);
1368-
return;
1369-
}
1370-
} else if (isAnyObjectNotNull(contributorA.getCreditName(), contributorB.getCreditName())) {
1371-
isDifferent.set(true);
1372-
return;
1373-
}
1374-
1375-
1376-
if (contributorA.getContributorOrcid() != null && contributorB.getContributorOrcid() != null) {
1377-
if (
1378-
!isEachObjectNull(contributorA.getContributorOrcid().getUri(), contributorB.getContributorOrcid().getUri()) &&
1379-
contributorA.getContributorOrcid().getUri().equalsIgnoreCase(contributorB.getContributorOrcid().getUri())
1380-
) {
1381-
isDifferent.set(true);
1382-
return;
1383-
}
1384-
} else if (isAnyObjectNotNull(contributorA.getContributorOrcid(), contributorB.getContributorOrcid())) {
1385-
isDifferent.set(true);
1386-
return;
1387-
}
1388-
1389-
if (contributorA.getRolesAndSequences() != null && contributorB.getRolesAndSequences() != null) {
1390-
if (contributorA.getRolesAndSequences().size() != contributorB.getRolesAndSequences().size()) {
1391-
isDifferent.set(true);
1392-
return;
1393-
}
1394-
contributorA.getRolesAndSequences().forEach(rolesA -> contributorB.getRolesAndSequences().forEach(rolesB -> {
1395-
if (rolesA.getContributorRole() != null && rolesB.getContributorRole() != null) {
1396-
if (compareStrings(rolesA.getContributorRole(), rolesB.getContributorRole())) {
1397-
isDifferent.set(true);
1398-
return;
1399-
}
1400-
}
1401-
if (isAnyObjectNotNull(rolesA.getContributorRole(), rolesB.getContributorRole())) {
1402-
isDifferent.set(true);
1403-
return;
1404-
}
1405-
if (rolesA.getContributorSequence() != null && rolesB.getContributorSequence() != null) {
1406-
if (rolesA.getContributorSequence().equals(rolesB.getContributorSequence())) {
1407-
isDifferent.set(true);
1408-
return;
1409-
}
1410-
}
1411-
if (isAnyObjectNotNull(rolesA.getContributorSequence(), rolesB.getContributorSequence())) {
1412-
isDifferent.set(true);
1413-
return;
1414-
}
1415-
}));
1416-
1417-
} else if (isAnyObjectNotNull(contributorA.getRolesAndSequences(), contributorB.getRolesAndSequences())) {
1418-
isDifferent.set(true);
1419-
return;
1339+
for (int i = 0; i < a.size() ; i++) {
1340+
if (!a.get(i).compare(b.get(i))) {
1341+
return true;
14201342
}
1421-
}));
1422-
return isDifferent.get();
1343+
}
1344+
return false;
14231345
}
14241346

1425-
private boolean compareTexts(Text a, Text b, boolean ignoreCase) {
1347+
public static boolean compareTexts(Text a, Text b, boolean ignoreCase) {
14261348
if (isEachObjectNull(a, b)) {
14271349
return true;
14281350
} else if (isAnyObjectNotNull(a, b)) {
@@ -1446,7 +1368,7 @@ private boolean compareTexts(Text a, Text b, boolean ignoreCase) {
14461368
return true;
14471369
}
14481370

1449-
private boolean compareStrings(String a, String b) {
1371+
public static boolean compareStrings(String a, String b) {
14501372
if (isEachObjectNull(a, b)) {
14511373
return true;
14521374
} else if (isAnyObjectNotNull(a, b)) {
@@ -1457,11 +1379,11 @@ private boolean compareStrings(String a, String b) {
14571379
} else return a.equalsIgnoreCase(b);
14581380
}
14591381

1460-
private boolean isEachObjectNull(Object a, Object b) {
1382+
public static boolean isEachObjectNull(Object a, Object b) {
14611383
return a == null && b == null;
14621384
}
14631385

1464-
private boolean isAnyObjectNotNull(Object a, Object b) {
1386+
public static boolean isAnyObjectNotNull(Object a, Object b) {
14651387
if (a == null && b != null || a != null && b == null) {
14661388
return true;
14671389
}

0 commit comments

Comments
 (0)