Skip to content

Commit 625b3ca

Browse files
authored
Merge pull request #6728 from ORCID/feature/8437-for-works-stop-sending-notifications-when-no-updates-to-the-works-has-actually-been-made
feature: Compare work to be updated with the one stored in the database
2 parents ffc89c9 + 293204e commit 625b3ca

8 files changed

Lines changed: 916 additions & 32 deletions

File tree

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.orcid.persistence.jpa.entities.SourceEntity;
4646
import org.orcid.persistence.jpa.entities.WorkEntity;
4747
import org.orcid.pojo.ContributorsRolesAndSequencesV2;
48+
import org.orcid.pojo.ajaxForm.WorkForm;
4849
import org.slf4j.Logger;
4950
import org.slf4j.LoggerFactory;
5051
import org.springframework.beans.factory.annotation.Value;
@@ -350,6 +351,16 @@ private void addExternalIdsToExistingSet(Map<ExternalID, Long> extIDPutCodeMap,
350351
@Transactional
351352
public Work updateWork(String orcid, Work work, boolean isApiRequest) {
352353
WorkEntity workEntity = workDao.getWork(orcid, work.getPutCode());
354+
355+
Work workSaved = jpaJaxbWorkAdapter.toWork(workEntity);
356+
WorkForm workFormSaved = WorkForm.valueOf(workSaved, maxContributorsForUI);
357+
358+
if (Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED.isActive()) {
359+
if (workFormSaved.compare(WorkForm.valueOf(work, maxContributorsForUI))) {
360+
return workSaved;
361+
}
362+
}
363+
353364
String originalVisibility = workEntity.getVisibility();
354365
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
355366

@@ -387,8 +398,7 @@ public Work updateWork(String orcid, Work work, boolean isApiRequest) {
387398
workDao.merge(workEntity);
388399
workDao.flush();
389400
notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItemList(workEntity, work.getExternalIdentifiers(), ActionType.UPDATE));
390-
Work updatedWork = jpaJaxbWorkAdapter.toWork(workEntity);
391-
return updatedWork;
401+
return jpaJaxbWorkAdapter.toWork(workEntity);
392402
}
393403

394404
@Override

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.orcid.persistence.jpa.entities.ProfileEntity;
4242
import org.orcid.persistence.jpa.entities.WorkEntity;
4343
import org.orcid.pojo.ContributorsRolesAndSequences;
44+
import org.orcid.pojo.WorkExtended;
4445
import org.orcid.pojo.ajaxForm.WorkForm;
4546
import org.slf4j.Logger;
4647
import org.slf4j.LoggerFactory;
@@ -358,6 +359,16 @@ private void addExternalIdsToExistingSet(Map<ExternalID, Long> extIDPutCodeMap,
358359
@Transactional
359360
public Work updateWork(String orcid, Work work, boolean isApiRequest) {
360361
WorkEntity workEntity = workDao.getWork(orcid, work.getPutCode());
362+
363+
Work workSaved = jpaJaxbWorkAdapter.toWork(workEntity);
364+
WorkForm workFormSaved = WorkForm.valueOf(workSaved, maxContributorsForUI);
365+
366+
if (Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED.isActive()) {
367+
if (workFormSaved.compare(WorkForm.valueOf(work, maxContributorsForUI))) {
368+
return workSaved;
369+
}
370+
}
371+
361372
Visibility originalVisibility = Visibility.valueOf(workEntity.getVisibility());
362373
Source activeSource = sourceManager.retrieveActiveSource();
363374

@@ -539,6 +550,16 @@ public Work updateWork(String orcid, WorkForm workForm) {
539550
Work work = workForm.toWork();
540551

541552
WorkEntity workEntity = workDao.getWork(orcid, work.getPutCode());
553+
554+
WorkExtended workSaved = jpaJaxbWorkAdapter.toWorkExtended(workEntity);
555+
WorkForm workFormSaved = WorkForm.valueOf(workSaved, maxContributorsForUI);
556+
557+
if (Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED.isActive()) {
558+
if (workFormSaved.compare(workForm)) {
559+
return workSaved;
560+
}
561+
}
562+
542563
Visibility originalVisibility = Visibility.valueOf(workEntity.getVisibility());
543564

544565
//Save the original source

orcid-core/src/main/java/org/orcid/core/togglz/Features.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
public enum Features implements Feature {
88

9+
@Label("Stop sending notification if work has not been updated")
10+
STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED,
11+
912
@Label("Move client from a member to another member")
1013
MOVE_CLIENT,
1114

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,23 @@ public static ActivityExternalIdentifier valueOf(ExternalID externalIdentifier)
6565
return wi;
6666

6767
}
68-
68+
69+
public static ActivityExternalIdentifier valueOf(org.orcid.jaxb.model.record_v2.ExternalID externalIdentifier) {
70+
ActivityExternalIdentifier wi = new ActivityExternalIdentifier();
71+
if (externalIdentifier != null) {
72+
if (externalIdentifier.getValue() != null)
73+
wi.setExternalIdentifierId(Text.valueOf(externalIdentifier.getValue()));
74+
if (externalIdentifier.getType() != null)
75+
wi.setExternalIdentifierType(Text.valueOf(externalIdentifier.getType()));
76+
if(externalIdentifier.getRelationship() != null)
77+
wi.setRelationship(Text.valueOf(externalIdentifier.getRelationship().value()));
78+
if(externalIdentifier.getUrl() != null)
79+
wi.setUrl(Text.valueOf(externalIdentifier.getUrl().getValue()));
80+
}
81+
return wi;
82+
83+
}
84+
6985
public ExternalID toExternalIdentifier() {
7086
ExternalID we = new ExternalID();
7187
if (!PojoUtil.isEmpty(this.getExternalIdentifierId()))

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ public static Date valueOf(LastModifiedDate date) {
8383
return newDate;
8484
}
8585

86+
public static Date valueOf(org.orcid.jaxb.model.common_v2.CreatedDate date) {
87+
Date newDate = new Date();
88+
if (date != null && date.getValue() != null)
89+
return Date.valueOf(date.getValue().toGregorianCalendar().getTime());
90+
return newDate;
91+
}
92+
93+
public static Date valueOf(org.orcid.jaxb.model.common_v2.LastModifiedDate date) {
94+
Date newDate = new Date();
95+
if (date != null && date.getValue() != null)
96+
return Date.valueOf(date.getValue().toGregorianCalendar().getTime());
97+
return newDate;
98+
}
99+
86100
public java.util.Date toJavaDate() {
87101
Calendar gc = toCalendar();
88102
return gc.getTime();

0 commit comments

Comments
 (0)