Skip to content

Commit 293204e

Browse files
committed
fix: Stop sending work notification if there is no changes in API V2, move logic from controller to manager
1 parent d403050 commit 293204e

9 files changed

Lines changed: 445 additions & 110 deletions

File tree

orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@
129129
import org.orcid.jaxb.model.v3.release.record.summary.Works;
130130
import org.orcid.jaxb.model.v3.release.search.Search;
131131
import org.orcid.jaxb.model.v3.release.search.expanded.ExpandedSearch;
132-
import org.orcid.pojo.ajaxForm.WorkForm;
133-
import org.springframework.beans.factory.annotation.Value;
134132
import org.springframework.context.MessageSource;
135133
import org.springframework.stereotype.Component;
136134

@@ -271,9 +269,6 @@ public class MemberV3ApiServiceDelegatorImpl implements
271269

272270
@Resource
273271
private OrcidUrlManager orcidUrlManager;
274-
275-
@Value("${org.orcid.core.work.contributors.ui.max:50}")
276-
private int maxContributorsForUI;
277272

278273
public Boolean getFilterVersionOfIdentifiers() {
279274
return filterVersionOfIdentifiers;
@@ -393,20 +388,8 @@ public Response updateWork(String orcid, Long putCode, Work work) {
393388
throw new MismatchedPutCodeException(addParmsMismatchedPutCode(putCode, work.getPutCode()));
394389
}
395390
clearSource(work);
396-
Work w = work;
397-
398-
WorkForm newWorkForm = WorkForm.valueOf(work, maxContributorsForUI);
399-
Work workSaved = workManager.getWork(orcid, putCode);
400-
WorkForm workFormSaved = WorkForm.valueOf(workSaved, maxContributorsForUI);
401-
402-
if (Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED.isActive()) {
403-
if (!workFormSaved.compare(newWorkForm)) {
404-
w = updateWork(orcid, work);
405-
}
406-
} else {
407-
w = updateWork(orcid, work);
408-
}
409-
391+
Work w = workManager.updateWork(orcid, work, true);
392+
sourceUtils.setSourceName(w);
410393
return Response.ok(w).build();
411394
}
412395

@@ -1584,10 +1567,4 @@ private Map<String, String> addParmsMismatchedPutCode(Long urlPutCode, Long body
15841567
return params;
15851568
}
15861569

1587-
private Work updateWork(String orcid, Work work) {
1588-
Work w = workManager.updateWork(orcid, work, true);
1589-
sourceUtils.setSourceName(w);
1590-
return w;
1591-
}
1592-
15931570
}

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/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();

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

Lines changed: 180 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,139 @@ public static WorkForm valueOf(WorkSummary work) {
335335
return w;
336336
}
337337

338+
public static WorkForm valueOf(org.orcid.jaxb.model.record_v2.Work work, int maxContributorsForUI) {
339+
if (work == null)
340+
return null;
341+
342+
WorkForm w = new WorkForm();
343+
344+
// Set work id
345+
if (work.getPutCode() != null) {
346+
w.setPutCode(Text.valueOf(work.getPutCode()));
347+
}
348+
349+
// Set language
350+
if (!PojoUtil.isEmpty(work.getLanguageCode())) {
351+
w.setLanguageCode(Text.valueOf(work.getLanguageCode()));
352+
}
353+
354+
// Set type
355+
if (work.getWorkType() != null) {
356+
w.setWorkType(Text.valueOf(work.getWorkType().value()));
357+
// Set category
358+
org.orcid.jaxb.model.record_v2.WorkCategory category = org.orcid.jaxb.model.record_v2.WorkCategory.fromWorkType(work.getWorkType());
359+
w.setWorkCategory(Text.valueOf(category.value()));
360+
}
361+
362+
if (work.getWorkTitle() != null) {
363+
// Set title
364+
if (work.getWorkTitle().getTitle() != null) {
365+
w.setTitle(Text.valueOf(work.getWorkTitle().getTitle().getContent()));
366+
}
367+
// Set translated title
368+
if (work.getWorkTitle().getTranslatedTitle() != null) {
369+
TranslatedTitleForm tt = new TranslatedTitleForm();
370+
tt.setContent(work.getWorkTitle().getTranslatedTitle().getContent());
371+
tt.setLanguageCode(work.getWorkTitle().getTranslatedTitle().getLanguageCode());
372+
w.setTranslatedTitle(tt);
373+
}
374+
// Set subtitle
375+
if (work.getWorkTitle().getSubtitle() != null) {
376+
w.setSubtitle(Text.valueOf(work.getWorkTitle().getSubtitle().getContent()));
377+
}
378+
}
379+
380+
// Set journal title
381+
if (work.getJournalTitle() != null ) {
382+
w.setJournalTitle(Text.valueOf(work.getJournalTitle().getContent()));
383+
}
384+
385+
// Set description
386+
if (work.getShortDescription() != null) {
387+
w.setShortDescription(Text.valueOf(work.getShortDescription()));
388+
}
389+
390+
// Set url
391+
if (work.getUrl() != null ) {
392+
w.setUrl(Text.valueOf(work.getUrl().getValue()));
393+
}
394+
395+
// Set visibility
396+
if (work.getVisibility() != null) {
397+
w.setVisibility(Visibility.valueOf(work.getVisibility()));
398+
}
399+
400+
// Set country
401+
if (work.getCountry() != null && work.getCountry().getValue() != null) {
402+
w.setCountryCode(Text.valueOf(work.getCountry().getValue().name()));
403+
}
404+
405+
// Set publication date
406+
FuzzyDate fuzzyPublicationDate = null;
407+
if (work.getPublicationDate() != null) {
408+
org.orcid.jaxb.model.common_v2.PublicationDate publicationDate = work.getPublicationDate();
409+
Integer year = PojoUtil.isEmpty(publicationDate.getYear()) ? null : Integer.valueOf(publicationDate.getYear().getValue());
410+
Integer month = PojoUtil.isEmpty(publicationDate.getMonth()) ? null : Integer.valueOf(publicationDate.getMonth().getValue());
411+
Integer day = PojoUtil.isEmpty(publicationDate.getDay()) ? null : Integer.valueOf(publicationDate.getDay().getValue());
412+
if(year != null && year == 0) {
413+
year = null;
414+
}
415+
if(month != null && month == 0) {
416+
month = null;
417+
}
418+
if (day != null && day == 0) {
419+
day = null;
420+
}
421+
fuzzyPublicationDate = FuzzyDate.valueOf(year, month, day);
422+
w.setPublicationDate(Date.valueOf(fuzzyPublicationDate));
423+
}
424+
w.setDateSortString(PojoUtil.createDateSortString(null, fuzzyPublicationDate));
425+
426+
// Set citation
427+
if (work.getWorkCitation() != null) {
428+
Citation citation = new Citation();
429+
if(!PojoUtil.isEmpty(work.getWorkCitation().getCitation())) {
430+
citation.setCitation(Text.valueOf(work.getWorkCitation().getCitation()));
431+
}
432+
if(work.getWorkCitation().getWorkCitationType() != null) {
433+
citation.setCitationType(Text.valueOf(work.getWorkCitation().getWorkCitationType().value()));
434+
}
435+
436+
w.setCitation(citation);
437+
}
438+
// Set contributors
439+
populateContributors(work, w, maxContributorsForUI);
440+
// Set external identifiers
441+
populateExternalIdentifiers(work, w);
442+
443+
// Set created date
444+
w.setCreatedDate(Date.valueOf(work.getCreatedDate()));
445+
446+
// Set last modified
447+
w.setLastModified(Date.valueOf(work.getLastModifiedDate()));
448+
449+
if(work.getSource() != null) {
450+
// Set source
451+
w.setSource(work.getSource().retrieveSourcePath());
452+
if(work.getSource().getSourceName() != null) {
453+
w.setSourceName(work.getSource().getSourceName().getContent());
454+
}
455+
}
456+
return w;
457+
}
458+
338459
private static void populateExternalIdentifiers(Work work, WorkForm workForm) {
339460
if(work.getExternalIdentifiers() != null) {
340461
populateExternalIdentifiers(work.getExternalIdentifiers(), workForm, work.getWorkType());
341462
}
342463
}
343-
464+
465+
private static void populateExternalIdentifiers(org.orcid.jaxb.model.record_v2.Work work, WorkForm workForm) {
466+
if(work.getExternalIdentifiers() != null) {
467+
populateExternalIdentifiers(work.getExternalIdentifiers(), workForm, work.getWorkType());
468+
}
469+
}
470+
344471
public static void populateExternalIdentifiers(ExternalIDs extIds, WorkForm workForm, WorkType workType) {
345472
if (extIds != null) {
346473
List<ActivityExternalIdentifier> workExternalIdentifiersList = new ArrayList<ActivityExternalIdentifier>();
@@ -367,7 +494,34 @@ public static void populateExternalIdentifiers(ExternalIDs extIds, WorkForm work
367494
workForm.setWorkExternalIdentifiers(workExternalIdentifiersList);
368495
}
369496
}
370-
497+
498+
public static void populateExternalIdentifiers(org.orcid.jaxb.model.record_v2.ExternalIDs extIds, WorkForm workForm, org.orcid.jaxb.model.record_v2.WorkType workType) {
499+
if (extIds != null) {
500+
List<ActivityExternalIdentifier> workExternalIdentifiersList = new ArrayList<ActivityExternalIdentifier>();
501+
for (org.orcid.jaxb.model.record_v2.ExternalID extId : extIds.getExternalIdentifier()) {
502+
if(extId.getRelationship() == null) {
503+
if(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ISSN.equals(extId.getType())) {
504+
if(WorkType.BOOK.equals(workType)) {
505+
extId.setRelationship(org.orcid.jaxb.model.record_v2.Relationship.PART_OF);
506+
} else {
507+
extId.setRelationship(org.orcid.jaxb.model.record_v2.Relationship.SELF);
508+
}
509+
} else if(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ISBN.equals(extId.getType())) {
510+
if(WorkType.BOOK_CHAPTER.equals(workType) || WorkType.CONFERENCE_PAPER.equals(workType)) {
511+
extId.setRelationship(org.orcid.jaxb.model.record_v2.Relationship.PART_OF);
512+
} else {
513+
extId.setRelationship(org.orcid.jaxb.model.record_v2.Relationship.SELF);
514+
}
515+
} else {
516+
extId.setRelationship(org.orcid.jaxb.model.record_v2.Relationship.SELF);
517+
}
518+
}
519+
workExternalIdentifiersList.add(ActivityExternalIdentifier.valueOf(extId));
520+
}
521+
workForm.setWorkExternalIdentifiers(workExternalIdentifiersList);
522+
}
523+
}
524+
371525
private static void populateExternalIdentifiers(WorkForm workForm, Work work) {
372526
ExternalIDs workExternalIds = new ExternalIDs();
373527
if(workForm.getWorkExternalIdentifiers() != null && !workForm.getWorkExternalIdentifiers().isEmpty()) {
@@ -394,6 +548,30 @@ private static void populateExternalIdentifiers(WorkForm workForm, Work work) {
394548
work.setWorkExternalIdentifiers(workExternalIds);
395549
}
396550

551+
private static void populateContributors(org.orcid.jaxb.model.record_v2.Work work, WorkForm workForm, int maxContributorsForUI) {
552+
List<Contributor> contributorsList = new ArrayList<Contributor>();
553+
if(work.getWorkContributors() != null) {
554+
List<org.orcid.jaxb.model.common_v2.Contributor> contributors = null;
555+
if (Features.ORCID_ANGULAR_WORKS_CONTRIBUTORS.isActive()) {
556+
if (work.getWorkContributors().getContributor().size() > maxContributorsForUI) {
557+
contributors = work.getWorkContributors().getContributor().subList(0, maxContributorsForUI);
558+
} else {
559+
contributors = work.getWorkContributors().getContributor();
560+
}
561+
} else {
562+
contributors = work.getWorkContributors().getContributor();
563+
}
564+
565+
if (contributors != null) {
566+
for (org.orcid.jaxb.model.common_v2.Contributor contributor : contributors) {
567+
contributorsList.add(Contributor.valueOf(contributor));
568+
}
569+
}
570+
571+
}
572+
workForm.setContributors(contributorsList);
573+
}
574+
397575
private static void populateContributors(Work work, WorkForm workForm, int maxContributorsForUI) {
398576
List<Contributor> contributorsList = new ArrayList<Contributor>();
399577
if(work.getWorkContributors() != null) {

0 commit comments

Comments
 (0)