Skip to content

Commit

Permalink
Include ext ids on notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Jul 1, 2024
1 parent 264b484 commit 0c2996e
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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<Item> createItemList(ProfileFundingEntity profileFundingEntity, ActionType type) {
private List<Item> 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<String, Object> additionalInfo = new HashMap<String, Object>();
additionalInfo.put("external_identifiers", extIds);
item.setAdditionalInfo(additionalInfo);
}

return Arrays.asList(item);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public class WorkManagerImpl extends WorkManagerReadOnlyImpl implements WorkMana
@Resource
private SourceNameCacheManager sourceNameCacheManager;


@Resource(name = "contributorUtils")
private ContributorUtils contributorUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -483,7 +483,7 @@ private void setIncomingWorkPrivacy(OrgAffiliationRelationEntity orgAffiliationR
}
}

private List<Item> createItemList(OrgAffiliationRelationEntity orgAffiliationEntity, ActionType type) {
private List<Item> createItemList(OrgAffiliationRelationEntity orgAffiliationEntity, ExternalIDs extIds, ActionType type) {
Item item = new Item();
if (!StringUtils.isBlank(orgAffiliationEntity.getTitle())) {
item.setItemName(orgAffiliationEntity.getTitle());
Expand All @@ -510,6 +510,11 @@ private List<Item> createItemList(OrgAffiliationRelationEntity orgAffiliationEnt
Map<String, Object> additionalInfo = new HashMap<String, Object>();
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -225,9 +226,6 @@ private void validateGroupId(PeerReview peerReview) {
}
}

private List<Item> createItemList(PeerReviewEntity peerReviewEntity, ActionType type) {
return createItemList(peerReviewEntity, type, null, null);
}
private List<Item> createItemList(PeerReviewEntity peerReviewEntity, ActionType type, ExternalIDs extIds, ExternalID subjectExtId) {
Item item = new Item();
item.setItemType(ItemType.PEER_REVIEW);
Expand Down
Loading

0 comments on commit 0c2996e

Please sign in to comment.