Skip to content

Commit

Permalink
When a peer review is created, add the ext id to the notification
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Jun 26, 2024
1 parent e69191a commit bdb6d1c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
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.ExternalID;
import org.orcid.jaxb.model.record_v2.ExternalIDs;
import org.orcid.jaxb.model.record_v2.PeerReview;
import org.orcid.persistence.jpa.entities.OrgEntity;
import org.orcid.persistence.jpa.entities.PeerReviewEntity;
Expand Down Expand Up @@ -127,7 +129,7 @@ public PeerReview createPeerReview(String orcid, PeerReview peerReview, boolean

peerReviewDao.persist(entity);
peerReviewDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(entity, ActionType.CREATE));
notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(entity, ActionType.CREATE, peerReview.getExternalIdentifiers(), peerReview.getSubjectExternalIdentifier()));
return jpaJaxbPeerReviewAdapter.toPeerReview(entity);
}

Expand Down Expand Up @@ -236,6 +238,10 @@ 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);
item.setPutCode(String.valueOf(peerReviewEntity.getId()));
Expand All @@ -254,6 +260,14 @@ private List<Item> createItemList(PeerReviewEntity peerReviewEntity, ActionType
}
}

if(extIds != null) {
additionalInfo.put("external_identifiers", extIds);
}

if(subjectExtId != null) {
additionalInfo.put("subject_external_identifiers", subjectExtId);
}

item.setItemName(itemName);
item.setAdditionalInfo(additionalInfo);
return Arrays.asList(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
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.ExternalID;
import org.orcid.jaxb.model.v3.release.record.ExternalIDs;
import org.orcid.jaxb.model.v3.release.record.PeerReview;
import org.orcid.persistence.jpa.entities.OrgEntity;
import org.orcid.persistence.jpa.entities.PeerReviewEntity;
Expand Down Expand Up @@ -123,7 +125,8 @@ public PeerReview createPeerReview(String orcid, PeerReview peerReview, boolean

peerReviewDao.persist(entity);
peerReviewDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(entity, ActionType.CREATE));

notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(entity, ActionType.CREATE, peerReview.getExternalIdentifiers(), peerReview.getSubjectExternalIdentifier()));
return jpaJaxbPeerReviewAdapter.toPeerReview(entity);
}

Expand Down Expand Up @@ -171,7 +174,7 @@ public PeerReview updatePeerReview(String orcid, PeerReview peerReview, boolean

existingEntity = peerReviewDao.merge(existingEntity);
peerReviewDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(existingEntity, ActionType.UPDATE));
notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(existingEntity, ActionType.UPDATE, peerReview.getExternalIdentifiers(), peerReview.getSubjectExternalIdentifier()));
return jpaJaxbPeerReviewAdapter.toPeerReview(existingEntity);
}

Expand Down Expand Up @@ -223,6 +226,9 @@ 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);
item.setPutCode(String.valueOf(peerReviewEntity.getId()));
Expand All @@ -231,7 +237,6 @@ private List<Item> createItemList(PeerReviewEntity peerReviewEntity, ActionType
additionalInfo.put("subject_container_name", peerReviewEntity.getSubjectContainerName());

String itemName = null;

Optional<GroupIdRecord> optional = groupIdRecordManager.findByGroupId(peerReviewEntity.getGroupId());
if (optional.isPresent()) {
GroupIdRecord groupId = optional.get();
Expand All @@ -240,6 +245,13 @@ private List<Item> createItemList(PeerReviewEntity peerReviewEntity, ActionType
itemName = optional.get().getName();
}
}
if(extIds != null) {
additionalInfo.put("external_identifiers", extIds);
}

if(subjectExtId != null) {
additionalInfo.put("subject_external_identifiers", subjectExtId);
}

item.setItemName(itemName);
item.setAdditionalInfo(additionalInfo);
Expand Down

0 comments on commit bdb6d1c

Please sign in to comment.