From 0c2996e0cc460925e2a880ef6a236ab7d0cca7a8 Mon Sep 17 00:00:00 2001 From: amontenegro Date: Mon, 1 Jul 2024 13:13:05 -0600 Subject: [PATCH] Include ext ids on notifications --- .../api/common/jaxb/OrcidExceptionMapper.java | 23 +----- .../manager/impl/PeerReviewManagerImpl.java | 3 +- .../impl/ProfileFundingManagerImpl.java | 19 ++++- .../core/manager/impl/WorkManagerImpl.java | 1 - .../v3/impl/AffiliationsManagerImpl.java | 67 ++++++++-------- .../v3/impl/PeerReviewManagerImpl.java | 6 +- .../v3/impl/ProfileFundingManagerImpl.java | 21 +++-- .../v3/impl/ResearchResourceManagerImpl.java | 21 +++-- .../core/manager/v3/impl/WorkManagerImpl.java | 8 -- .../cli/manager/EmailMessageSenderImpl.java | 76 +++++++++++-------- 10 files changed, 131 insertions(+), 114 deletions(-) diff --git a/orcid-api-common/src/main/java/org/orcid/api/common/jaxb/OrcidExceptionMapper.java b/orcid-api-common/src/main/java/org/orcid/api/common/jaxb/OrcidExceptionMapper.java index 13e79e8c3ff..418eceda83f 100644 --- a/orcid-api-common/src/main/java/org/orcid/api/common/jaxb/OrcidExceptionMapper.java +++ b/orcid-api-common/src/main/java/org/orcid/api/common/jaxb/OrcidExceptionMapper.java @@ -21,26 +21,7 @@ import org.orcid.api.common.filter.ApiVersionFilter; import org.orcid.api.common.util.ApiUtils; import org.orcid.core.api.OrcidApiConstants; -import org.orcid.core.exception.ApplicationException; -import org.orcid.core.exception.ClientDeactivatedException; -import org.orcid.core.exception.DeactivatedException; -import org.orcid.core.exception.DuplicatedGroupIdRecordException; -import org.orcid.core.exception.ExceedMaxNumberOfElementsException; -import org.orcid.core.exception.LockedException; -import org.orcid.core.exception.OrcidApiException; -import org.orcid.core.exception.OrcidBadRequestException; -import org.orcid.core.exception.OrcidCoreExceptionMapper; -import org.orcid.core.exception.OrcidDeprecatedException; -import org.orcid.core.exception.OrcidDuplicatedActivityException; -import org.orcid.core.exception.OrcidDuplicatedElementException; -import org.orcid.core.exception.OrcidInvalidScopeException; -import org.orcid.core.exception.OrcidNoBioException; -import org.orcid.core.exception.OrcidNoResultException; -import org.orcid.core.exception.OrcidNonPublicElementException; -import org.orcid.core.exception.OrcidNotClaimedException; -import org.orcid.core.exception.OrcidNotificationException; -import org.orcid.core.exception.OrcidUnauthorizedException; -import org.orcid.core.exception.OrcidValidationException; +import org.orcid.core.exception.*; import org.orcid.core.locale.LocaleManager; import org.orcid.core.manager.OrcidSecurityManager; import org.orcid.core.manager.impl.OrcidUrlManager; @@ -147,6 +128,8 @@ public Response toResponse(Throwable t) { logShortError(t, clientId); } else if (t instanceof OrcidUnauthorizedException) { logShortError(t, clientId); + } else if (t instanceof InvalidPutCodeException) { + logShortError(t, clientId); } else { LOGGER.error("An exception has occured processing request from client " + clientId, t); } diff --git a/orcid-core/src/main/java/org/orcid/core/manager/impl/PeerReviewManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/impl/PeerReviewManagerImpl.java index eb61fcf3a4f..1b66a8ceb4e 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/impl/PeerReviewManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/impl/PeerReviewManagerImpl.java @@ -195,7 +195,8 @@ public boolean checkSourceAndDelete(String orcid, Long peerReviewId) { PeerReviewEntity pr = peerReviewDao.getPeerReview(orcid, peerReviewId); orcidSecurityManager.checkSource(pr); boolean result = deletePeerReview(pr, orcid); - notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(pr, ActionType.DELETE)); + PeerReview model = jpaJaxbPeerReviewAdapter.toPeerReview(pr); + notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(pr, ActionType.DELETE, model.getExternalIdentifiers(), model.getSubjectExternalIdentifier())); return result; } diff --git a/orcid-core/src/main/java/org/orcid/core/manager/impl/ProfileFundingManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/impl/ProfileFundingManagerImpl.java index 89bcc0bb7ea..859da93e66c 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/impl/ProfileFundingManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/impl/ProfileFundingManagerImpl.java @@ -1,7 +1,9 @@ package org.orcid.core.manager.impl; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.annotation.Resource; @@ -19,6 +21,7 @@ import org.orcid.jaxb.model.notification.amended_v2.AmendedSection; import org.orcid.jaxb.model.notification.permission_v2.Item; import org.orcid.jaxb.model.notification.permission_v2.ItemType; +import org.orcid.jaxb.model.record_v2.ExternalIDs; import org.orcid.jaxb.model.record_v2.Funding; import org.orcid.persistence.jpa.entities.OrgEntity; import org.orcid.persistence.jpa.entities.ProfileEntity; @@ -132,7 +135,7 @@ public Funding createFunding(String orcid, Funding funding, boolean isApiRequest profileFundingDao.persist(profileFundingEntity); profileFundingDao.flush(); if (isApiRequest) { - notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(profileFundingEntity, ActionType.CREATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(profileFundingEntity, funding.getExternalIdentifiers(), ActionType.CREATE)); } return jpaJaxbFundingAdapter.toFunding(profileFundingEntity); } @@ -194,7 +197,7 @@ public Funding updateFunding(String orcid, Funding funding, boolean isApiRequest pfe = profileFundingDao.merge(pfe); profileFundingDao.flush(); if (isApiRequest) { - notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(pfe, ActionType.UPDATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(pfe, funding.getExternalIdentifiers(), ActionType.UPDATE)); } return jpaJaxbFundingAdapter.toFunding(pfe); } @@ -215,16 +218,24 @@ public boolean checkSourceAndDelete(String orcid, Long fundingId) { ProfileFundingEntity pfe = profileFundingDao.getProfileFunding(orcid, fundingId); orcidSecurityManager.checkSource(pfe); boolean result = profileFundingDao.removeProfileFunding(orcid, fundingId); - notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(pfe, ActionType.DELETE)); + Funding funding = jpaJaxbFundingAdapter.toFunding(pfe); + notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(pfe, funding.getExternalIdentifiers(), ActionType.DELETE)); return result; } - private List createItemList(ProfileFundingEntity profileFundingEntity, ActionType type) { + private List createItemList(ProfileFundingEntity profileFundingEntity, ExternalIDs extIds, ActionType type) { Item item = new Item(); item.setItemName(profileFundingEntity.getTitle()); item.setItemType(ItemType.FUNDING); item.setPutCode(String.valueOf(profileFundingEntity.getId())); item.setActionType(type); + + if(extIds != null) { + Map additionalInfo = new HashMap(); + additionalInfo.put("external_identifiers", extIds); + item.setAdditionalInfo(additionalInfo); + } + return Arrays.asList(item); } diff --git a/orcid-core/src/main/java/org/orcid/core/manager/impl/WorkManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/impl/WorkManagerImpl.java index 342eda67f77..1b3455e5020 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/impl/WorkManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/impl/WorkManagerImpl.java @@ -89,7 +89,6 @@ public class WorkManagerImpl extends WorkManagerReadOnlyImpl implements WorkMana @Resource private SourceNameCacheManager sourceNameCacheManager; - @Resource(name = "contributorUtils") private ContributorUtils contributorUtils; diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/AffiliationsManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/AffiliationsManagerImpl.java index 63c222e976b..f7a5661af37 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/AffiliationsManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/AffiliationsManagerImpl.java @@ -27,18 +27,11 @@ import org.orcid.jaxb.model.v3.release.notification.amended.AmendedSection; import org.orcid.jaxb.model.v3.release.notification.permission.Item; import org.orcid.jaxb.model.v3.release.notification.permission.ItemType; -import org.orcid.jaxb.model.v3.release.record.Affiliation; -import org.orcid.jaxb.model.v3.release.record.AffiliationType; -import org.orcid.jaxb.model.v3.release.record.Distinction; -import org.orcid.jaxb.model.v3.release.record.Education; -import org.orcid.jaxb.model.v3.release.record.Employment; -import org.orcid.jaxb.model.v3.release.record.InvitedPosition; -import org.orcid.jaxb.model.v3.release.record.Membership; -import org.orcid.jaxb.model.v3.release.record.Qualification; -import org.orcid.jaxb.model.v3.release.record.Service; +import org.orcid.jaxb.model.v3.release.record.*; import org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity; import org.orcid.persistence.jpa.entities.OrgEntity; import org.orcid.persistence.jpa.entities.ProfileEntity; +import org.orcid.pojo.ajaxForm.Member; public class AffiliationsManagerImpl extends AffiliationsManagerReadOnlyImpl implements AffiliationsManager { @@ -313,31 +306,31 @@ private Affiliation createAffiliation(String orcid, Affiliation affiliation, boo Affiliation result = null; switch (type) { case DISTINCTION: - notificationManager.sendAmendEmail(orcid, AmendedSection.DISTINCTION, createItemList(entity, ActionType.CREATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.DISTINCTION, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.CREATE)); result = jpaJaxbDistinctionAdapter.toDistinction(entity); break; case EDUCATION: - notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItemList(entity, ActionType.CREATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.CREATE)); result = jpaJaxbEducationAdapter.toEducation(entity); break; case EMPLOYMENT: - notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItemList(entity, ActionType.CREATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.CREATE)); result = jpaJaxbEmploymentAdapter.toEmployment(entity); break; case INVITED_POSITION: - notificationManager.sendAmendEmail(orcid, AmendedSection.INVITED_POSITION, createItemList(entity, ActionType.CREATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.INVITED_POSITION, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.CREATE)); result = jpaJaxbInvitedPositionAdapter.toInvitedPosition(entity); break; case MEMBERSHIP: - notificationManager.sendAmendEmail(orcid, AmendedSection.MEMBERSHIP, createItemList(entity, ActionType.CREATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.MEMBERSHIP, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.CREATE)); result = jpaJaxbMembershipAdapter.toMembership(entity); break; case QUALIFICATION: - notificationManager.sendAmendEmail(orcid, AmendedSection.QUALIFICATION, createItemList(entity, ActionType.CREATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.QUALIFICATION, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.CREATE)); result = jpaJaxbQualificationAdapter.toQualification(entity); break; case SERVICE: - notificationManager.sendAmendEmail(orcid, AmendedSection.SERVICE, createItemList(entity, ActionType.CREATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.SERVICE, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.CREATE)); result = jpaJaxbServiceAdapter.toService(entity); break; } @@ -407,31 +400,31 @@ public Affiliation updateAffiliation(String orcid, Affiliation affiliation, bool Affiliation result = null; switch (type) { case DISTINCTION: - notificationManager.sendAmendEmail(orcid, AmendedSection.DISTINCTION, createItemList(entity, ActionType.UPDATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.DISTINCTION, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.UPDATE)); result = jpaJaxbDistinctionAdapter.toDistinction(entity); break; case EDUCATION: - notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItemList(entity, ActionType.UPDATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.UPDATE)); result = jpaJaxbEducationAdapter.toEducation(entity); break; case EMPLOYMENT: - notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItemList(entity, ActionType.UPDATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.UPDATE)); result = jpaJaxbEmploymentAdapter.toEmployment(entity); break; case INVITED_POSITION: - notificationManager.sendAmendEmail(orcid, AmendedSection.INVITED_POSITION, createItemList(entity, ActionType.UPDATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.INVITED_POSITION, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.UPDATE)); result = jpaJaxbInvitedPositionAdapter.toInvitedPosition(entity); break; case MEMBERSHIP: - notificationManager.sendAmendEmail(orcid, AmendedSection.MEMBERSHIP, createItemList(entity, ActionType.UPDATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.MEMBERSHIP, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.UPDATE)); result = jpaJaxbMembershipAdapter.toMembership(entity); break; case QUALIFICATION: - notificationManager.sendAmendEmail(orcid, AmendedSection.QUALIFICATION, createItemList(entity, ActionType.UPDATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.QUALIFICATION, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.UPDATE)); result = jpaJaxbQualificationAdapter.toQualification(entity); break; case SERVICE: - notificationManager.sendAmendEmail(orcid, AmendedSection.SERVICE, createItemList(entity, ActionType.UPDATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.SERVICE, createItemList(entity, affiliation.getExternalIdentifiers(), ActionType.UPDATE)); result = jpaJaxbServiceAdapter.toService(entity); break; } @@ -455,19 +448,26 @@ public boolean checkSourceAndDelete(String orcid, Long affiliationId) { boolean result = orgAffiliationRelationDao.removeOrgAffiliationRelation(orcid, affiliationId); if (result) { if (AffiliationType.DISTINCTION.name().equals(affiliationEntity.getAffiliationType())) { - notificationManager.sendAmendEmail(orcid, AmendedSection.DISTINCTION, createItemList(affiliationEntity, ActionType.DELETE)); + Distinction aff = jpaJaxbDistinctionAdapter.toDistinction(affiliationEntity); + notificationManager.sendAmendEmail(orcid, AmendedSection.DISTINCTION, createItemList(affiliationEntity, aff.getExternalIdentifiers(), ActionType.DELETE)); } else if (AffiliationType.EDUCATION.name().equals(affiliationEntity.getAffiliationType())) { - notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItemList(affiliationEntity, ActionType.DELETE)); + Education aff = jpaJaxbEducationAdapter.toEducation(affiliationEntity); + notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItemList(affiliationEntity, aff.getExternalIdentifiers(), ActionType.DELETE)); } else if (AffiliationType.EMPLOYMENT.name().equals(affiliationEntity.getAffiliationType())) { - notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItemList(affiliationEntity, ActionType.DELETE)); + Employment aff = jpaJaxbEmploymentAdapter.toEmployment(affiliationEntity); + notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItemList(affiliationEntity, aff.getExternalIdentifiers(), ActionType.DELETE)); } else if (AffiliationType.INVITED_POSITION.name().equals(affiliationEntity.getAffiliationType())) { - notificationManager.sendAmendEmail(orcid, AmendedSection.INVITED_POSITION, createItemList(affiliationEntity, ActionType.DELETE)); + InvitedPosition aff = jpaJaxbInvitedPositionAdapter.toInvitedPosition(affiliationEntity); + notificationManager.sendAmendEmail(orcid, AmendedSection.INVITED_POSITION, createItemList(affiliationEntity, aff.getExternalIdentifiers(), ActionType.DELETE)); } else if (AffiliationType.MEMBERSHIP.name().equals(affiliationEntity.getAffiliationType())) { - notificationManager.sendAmendEmail(orcid, AmendedSection.MEMBERSHIP, createItemList(affiliationEntity, ActionType.DELETE)); + Membership aff = jpaJaxbMembershipAdapter.toMembership(affiliationEntity); + notificationManager.sendAmendEmail(orcid, AmendedSection.MEMBERSHIP, createItemList(affiliationEntity, aff.getExternalIdentifiers(), ActionType.DELETE)); } else if (AffiliationType.QUALIFICATION.name().equals(affiliationEntity.getAffiliationType())) { - notificationManager.sendAmendEmail(orcid, AmendedSection.QUALIFICATION, createItemList(affiliationEntity, ActionType.DELETE)); + Qualification aff = jpaJaxbQualificationAdapter.toQualification(affiliationEntity); + notificationManager.sendAmendEmail(orcid, AmendedSection.QUALIFICATION, createItemList(affiliationEntity, aff.getExternalIdentifiers(), ActionType.DELETE)); } else if (AffiliationType.SERVICE.name().equals(affiliationEntity.getAffiliationType())) { - notificationManager.sendAmendEmail(orcid, AmendedSection.SERVICE, createItemList(affiliationEntity, ActionType.DELETE)); + Service aff = jpaJaxbServiceAdapter.toService(affiliationEntity); + notificationManager.sendAmendEmail(orcid, AmendedSection.SERVICE, createItemList(affiliationEntity, aff.getExternalIdentifiers(), ActionType.DELETE)); } } return result; @@ -483,7 +483,7 @@ private void setIncomingWorkPrivacy(OrgAffiliationRelationEntity orgAffiliationR } } - private List createItemList(OrgAffiliationRelationEntity orgAffiliationEntity, ActionType type) { + private List createItemList(OrgAffiliationRelationEntity orgAffiliationEntity, ExternalIDs extIds, ActionType type) { Item item = new Item(); if (!StringUtils.isBlank(orgAffiliationEntity.getTitle())) { item.setItemName(orgAffiliationEntity.getTitle()); @@ -510,6 +510,11 @@ private List createItemList(OrgAffiliationRelationEntity orgAffiliationEnt Map additionalInfo = new HashMap(); additionalInfo.put("department", orgAffiliationEntity.getDepartment()); additionalInfo.put("org_name", orgAffiliationEntity.getOrg().getName()); + + if(extIds != null && extIds.getExternalIdentifier() != null && !extIds.getExternalIdentifier().isEmpty()) { + additionalInfo.put("external_identifiers", extIds); + } + item.setAdditionalInfo(additionalInfo); return Arrays.asList(item); } diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/PeerReviewManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/PeerReviewManagerImpl.java index 42345b38493..4cd11615a0e 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/PeerReviewManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/PeerReviewManagerImpl.java @@ -183,7 +183,8 @@ public boolean checkSourceAndDelete(String orcid, Long peerReviewId) { PeerReviewEntity pr = peerReviewDao.getPeerReview(orcid, peerReviewId); orcidSecurityManager.checkSourceAndThrow(pr); boolean result = deletePeerReview(pr, orcid); - notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(pr, ActionType.DELETE)); + PeerReview model = jpaJaxbPeerReviewAdapter.toPeerReview(pr); + notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(pr, ActionType.DELETE, model.getExternalIdentifiers(), model.getSubjectExternalIdentifier())); return result; } @@ -225,9 +226,6 @@ private void validateGroupId(PeerReview peerReview) { } } - private List createItemList(PeerReviewEntity peerReviewEntity, ActionType type) { - return createItemList(peerReviewEntity, type, null, null); - } private List createItemList(PeerReviewEntity peerReviewEntity, ActionType type, ExternalIDs extIds, ExternalID subjectExtId) { Item item = new Item(); item.setItemType(ItemType.PEER_REVIEW); diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ProfileFundingManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ProfileFundingManagerImpl.java index 280cc243c9e..62eb974beb4 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ProfileFundingManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ProfileFundingManagerImpl.java @@ -1,8 +1,6 @@ package org.orcid.core.manager.v3.impl; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; import javax.annotation.Resource; @@ -23,6 +21,7 @@ import org.orcid.jaxb.model.v3.release.notification.amended.AmendedSection; import org.orcid.jaxb.model.v3.release.notification.permission.Item; import org.orcid.jaxb.model.v3.release.notification.permission.ItemType; +import org.orcid.jaxb.model.v3.release.record.ExternalIDs; import org.orcid.jaxb.model.v3.release.record.Funding; import org.orcid.persistence.jpa.entities.OrgEntity; import org.orcid.persistence.jpa.entities.ProfileEntity; @@ -152,7 +151,7 @@ public Funding createFunding(String orcid, Funding funding, boolean isApiRequest profileFundingDao.persist(profileFundingEntity); profileFundingDao.flush(); if (isApiRequest) { - notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(profileFundingEntity, ActionType.CREATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(profileFundingEntity, funding.getExternalIdentifiers(), ActionType.CREATE)); } return jpaJaxbFundingAdapter.toFunding(profileFundingEntity); } @@ -214,7 +213,7 @@ public Funding updateFunding(String orcid, Funding funding, boolean isApiRequest pfe = profileFundingDao.merge(pfe); profileFundingDao.flush(); if (isApiRequest) { - notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(pfe, ActionType.UPDATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(pfe, funding.getExternalIdentifiers(), ActionType.UPDATE)); } return jpaJaxbFundingAdapter.toFunding(pfe); } @@ -235,16 +234,24 @@ public boolean checkSourceAndDelete(String orcid, Long fundingId) { ProfileFundingEntity pfe = profileFundingDao.getProfileFunding(orcid, fundingId); orcidSecurityManager.checkSourceAndThrow(pfe); boolean result = profileFundingDao.removeProfileFunding(orcid, fundingId); - notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(pfe, ActionType.DELETE)); + Funding funding = jpaJaxbFundingAdapter.toFunding(pfe); + notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(pfe, funding.getExternalIdentifiers(), ActionType.DELETE)); return result; } - private List createItemList(ProfileFundingEntity profileFundingEntity, ActionType type) { + private List createItemList(ProfileFundingEntity profileFundingEntity, ExternalIDs extIds, ActionType type) { Item item = new Item(); item.setItemName(profileFundingEntity.getTitle()); item.setItemType(ItemType.FUNDING); item.setPutCode(String.valueOf(profileFundingEntity.getId())); item.setActionType(type); + + if(extIds != null) { + Map additionalInfo = new HashMap(); + additionalInfo.put("external_identifiers", extIds); + item.setAdditionalInfo(additionalInfo); + } + return Arrays.asList(item); } diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ResearchResourceManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ResearchResourceManagerImpl.java index ef13aa8e2ea..457cb357d48 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ResearchResourceManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ResearchResourceManagerImpl.java @@ -1,8 +1,6 @@ package org.orcid.core.manager.v3.impl; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; import javax.annotation.Resource; import javax.transaction.Transactional; @@ -25,6 +23,7 @@ import org.orcid.jaxb.model.v3.release.notification.amended.AmendedSection; import org.orcid.jaxb.model.v3.release.notification.permission.Item; import org.orcid.jaxb.model.v3.release.notification.permission.ItemType; +import org.orcid.jaxb.model.v3.release.record.ExternalIDs; import org.orcid.jaxb.model.v3.release.record.ResearchResource; import org.orcid.persistence.dao.ResearchResourceDao; import org.orcid.persistence.jpa.entities.OrgEntity; @@ -97,7 +96,7 @@ public ResearchResource createResearchResource(String orcid, ResearchResource rr rrDao.persist(researchResourceEntity); rrDao.flush(); if (isApiRequest) { - notificationManager.sendAmendEmail(orcid, AmendedSection.RESEARCH_RESOURCE, createItemList(researchResourceEntity, ActionType.CREATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.RESEARCH_RESOURCE, createItemList(researchResourceEntity, rr.getExternalIdentifiers(), ActionType.CREATE)); } return jpaJaxbResearchResourceAdapter.toModel(researchResourceEntity); } @@ -141,7 +140,7 @@ public ResearchResource updateResearchResource(String orcid, ResearchResource rr rre = rrDao.merge(rre); rrDao.flush(); if (isApiRequest) { - notificationManager.sendAmendEmail(orcid, AmendedSection.RESEARCH_RESOURCE, createItemList(rre, ActionType.UPDATE)); + notificationManager.sendAmendEmail(orcid, AmendedSection.RESEARCH_RESOURCE, createItemList(rre, rr.getExternalIdentifiers(), ActionType.UPDATE)); } return jpaJaxbResearchResourceAdapter.toModel(rre); } @@ -152,7 +151,8 @@ public boolean checkSourceAndRemoveResearchResource(String orcid, Long researchR ResearchResourceEntity rr = rrDao.getResearchResource(orcid, researchResourceId); orcidSecurityManager.checkSourceAndThrow(rr); boolean result = rrDao.removeResearchResource(orcid, researchResourceId); - notificationManager.sendAmendEmail(orcid, AmendedSection.RESEARCH_RESOURCE, createItemList(rr, ActionType.DELETE)); + ResearchResource model = jpaJaxbResearchResourceAdapter.toModel(rr); + notificationManager.sendAmendEmail(orcid, AmendedSection.RESEARCH_RESOURCE, createItemList(rr, model.getExternalIdentifiers(), ActionType.DELETE)); return result; } @@ -177,12 +177,19 @@ private void setIncomingPrivacy(ResearchResourceEntity researchResourceEntity, P } } - private List createItemList(ResearchResourceEntity researchResourceEntity, ActionType type) { + private List createItemList(ResearchResourceEntity researchResourceEntity, ExternalIDs extIds, ActionType type) { Item item = new Item(); item.setItemName(researchResourceEntity.getTitle()); item.setItemType(ItemType.RESEARCH_RESOURCE); item.setPutCode(String.valueOf(researchResourceEntity.getId())); item.setActionType(type); + + if(extIds != null) { + Map additionalInfo = new HashMap(); + additionalInfo.put("external_identifiers", extIds); + item.setAdditionalInfo(additionalInfo); + } + return Arrays.asList(item); } diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/WorkManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/WorkManagerImpl.java index cf22b5b8126..c68d94efe9e 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/WorkManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/WorkManagerImpl.java @@ -271,8 +271,6 @@ public WorkBulk createWorks(String orcid, WorkBulk workBulk) { } } } - - //Save the work WorkEntity workEntity = jpaJaxbWorkAdapter.toWorkEntity(work); workEntity.setOrcid(orcid); @@ -358,17 +356,11 @@ private void addExternalIdsToExistingSet(Map extIDPutCodeMap, @Transactional public Work updateWork(String orcid, Work work, boolean isApiRequest) { WorkEntity workEntity = workDao.getWork(orcid, work.getPutCode()); - Work workSaved = jpaJaxbWorkAdapter.toWork(workEntity); WorkForm workFormSaved = WorkForm.valueOf(workSaved, maxContributorsForUI); - - - Visibility originalVisibility = Visibility.valueOf(workEntity.getVisibility()); Source activeSource = sourceManager.retrieveActiveSource(); - - //Save the original source String existingSourceId = workEntity.getSourceId(); String existingClientSourceId = workEntity.getClientSourceId(); diff --git a/orcid-scheduler-web/src/main/java/org/orcid/scheduler/email/cli/manager/EmailMessageSenderImpl.java b/orcid-scheduler-web/src/main/java/org/orcid/scheduler/email/cli/manager/EmailMessageSenderImpl.java index 1f42d8faa34..810bef3977e 100644 --- a/orcid-scheduler-web/src/main/java/org/orcid/scheduler/email/cli/manager/EmailMessageSenderImpl.java +++ b/orcid-scheduler-web/src/main/java/org/orcid/scheduler/email/cli/manager/EmailMessageSenderImpl.java @@ -23,6 +23,7 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.LocaleUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DurationFormatUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Triple; @@ -317,11 +318,6 @@ public void sendEmailMessages() { if (!notifications.isEmpty()) { LOGGER.info("Found {} messages to send for orcid: {}", notifications.size(), orcid); EmailMessage digestMessage = createDigest(orcid, notifications); - System.out.println("---------------------------------------------------"); - System.out.println(digestMessage.getBodyHtml()); - System.out.println("---------------------------------------------------"); - System.out.println(digestMessage.getBodyText()); - digestMessage.setFrom(EmailConstants.DO_NOT_REPLY_NOTIFY_ORCID_ORG); digestMessage.setTo(primaryEmail.getEmail()); boolean successfullySent = mailGunManager.sendEmail(digestMessage.getFrom(), digestMessage.getTo(), digestMessage.getSubject(), @@ -552,7 +548,9 @@ public void addElement(XMLGregorianCalendar createdDate, Item item) { // Set the external identifiers list String externalIdentifiersList = generateExternalIdentifiersList(item); - value += externalIdentifiersList; + if(externalIdentifiersList != null) { + value += externalIdentifiersList; + } Set elements; if (item.getActionType() != null) { @@ -586,37 +584,38 @@ private String generateExternalIdentifiersList(Item item) { if(item.getAdditionalInfo().containsKey("external_identifiers")) { Map extIds = (Map) item.getAdditionalInfo().get("external_identifiers"); if(extIds != null && extIds.containsKey("externalIdentifier")) { - List extIdsList = (List) extIds.get("externalIdentifier"); - //TODO + List extIdsList = (List) extIds.get("externalIdentifier"); if(extIdsList != null) { - - - - extIdsHtmlList = "
    "; - for(ExternalID extId : ) { - extIdsHtmlList += "
  • " + extId.getType() + ": "; - if(extId.getNormalizedUrl() != null) { - extIdsHtmlList += "" + extId.getNormalizedUrl() + ""; - } else if (extId.getUrl() != null) { - extIdsHtmlList += "" + extId.getUrl() + ""; - } if(extId.getNormalized() != null) { - extIdsHtmlList += extId.getNormalized(); + for(Map extIdMap : extIdsList) { + String extIdType = extIdMap.containsKey("type") ? (String) extIdMap.get("type") : null; + // External id type must not be null, so, in case it is lets log a warning + if(extIdType == null) { + LOGGER.warn("External ID type is null for '" + item.getPutCode() + "', '" + item.getItemName() + "'"); + } + extIdsHtmlList += "
  • " + extIdType + ": "; + // Check if there is an URL + if(extractValue(extIdMap, "url") != null) { + String url = extractValue(extIdMap, "url"); + extIdsHtmlList += "" + url + ""; + } else if (extractValue(extIdMap, "normalized") != null) { + //If there is no URL, check for the normalized value + String value = extractValue(extIdMap, "normalized"); + extIdsHtmlList += value; + } else if(extIdMap.containsKey("value")) { + try { + String value = (String) extIdMap.get("value"); + extIdsHtmlList += value; + } catch (NullPointerException e) { + LOGGER.warn("External ID value is null for '" + item.getPutCode() + "', '" + item.getItemName() + "'"); + } } else { - extIdsHtmlList += extId.getValue(); + extIdsHtmlList += "Unavailable - please contact support"; + LOGGER.warn("Unable to find a printable value for External ID '" + item.getPutCode() + "', '" + item.getItemName() + "'"); } extIdsHtmlList += "
  • "; } - extIdsHtmlList = "
"; - - - - - - - - - + extIdsHtmlList += ""; } } } @@ -625,6 +624,21 @@ private String generateExternalIdentifiersList(Item item) { } } + private String extractValue(Map extIdMap, String keyName) { + if(extIdMap.containsKey(keyName)) { + Map keyMap = (Map) extIdMap.get(keyName); + try { + String value = (String) keyMap.get("value"); + if (StringUtils.isNotBlank(value)) { + return value; + } + } catch(NullPointerException npe) { + // Value might be null, so, just ignore it + } + } + return null; + } + private String getHtmlBody(NotificationAdministrative notificationAdministrative) { int bodyTag = notificationAdministrative.getBodyHtml().indexOf(""); int bodyTagClose = notificationAdministrative.getBodyHtml().indexOf("");