add plan case for annotation events

This commit is contained in:
amentis 2024-07-15 13:18:14 +03:00
parent d1e3508854
commit 992d9c2f45
7 changed files with 149 additions and 53 deletions

View File

@ -0,0 +1,33 @@
package org.opencdmp.commons.enums.annotation;
import com.fasterxml.jackson.annotation.JsonValue;
import org.opencdmp.commons.enums.EnumUtils;
import org.opencdmp.data.converters.enums.DatabaseEnum;
import java.util.Map;
public enum AnnotationEntityType implements DatabaseEnum<String> {
Description(EntityType.description),
Plan(EntityType.plan);
private final String value;
public static class EntityType {
public static final String description = "description";
public static final String plan = "plan";
}
AnnotationEntityType(String value) {
this.value = value;
}
@JsonValue
public String getValue() {
return this.value;
}
private static final Map<String, AnnotationEntityType> map = EnumUtils.getEnumValueMap(AnnotationEntityType.class);
public static AnnotationEntityType of(String i) {
return map.get(i);
}
}

View File

@ -11,11 +11,13 @@ public class NotificationProperties {
private UUID planInvitationExistingUserType;
private UUID planModifiedType;
private UUID planFinalisedType;
private UUID planAnnotationCreatedType;
private UUID planAnnotationStatusChangedType;
private UUID descriptionCreatedType;
private UUID descriptionModifiedType;
private UUID descriptionFinalisedType;
private UUID descriptionAnnotationCreated;
private UUID descriptionAnnotationStatusChanged;
private UUID descriptionAnnotationCreatedType;
private UUID descriptionAnnotationStatusChangedType;
private UUID mergeAccountConfirmationType;
private UUID removeCredentialConfirmationType;
private UUID planDepositType;
@ -59,6 +61,22 @@ public class NotificationProperties {
this.planFinalisedType = planFinalisedType;
}
public UUID getPlanAnnotationCreatedType() {
return planAnnotationCreatedType;
}
public void setPlanAnnotationCreatedType(UUID planAnnotationCreatedType) {
this.planAnnotationCreatedType = planAnnotationCreatedType;
}
public UUID getPlanAnnotationStatusChangedType() {
return planAnnotationStatusChangedType;
}
public void setPlanAnnotationStatusChangedType(UUID planAnnotationStatusChangedType) {
this.planAnnotationStatusChangedType = planAnnotationStatusChangedType;
}
public UUID getDescriptionCreatedType() {
return descriptionCreatedType;
}
@ -147,20 +165,20 @@ public class NotificationProperties {
this.contactSupportEmail = contactSupportEmail;
}
public UUID getDescriptionAnnotationCreated() {
return descriptionAnnotationCreated;
public UUID getDescriptionAnnotationCreatedType() {
return descriptionAnnotationCreatedType;
}
public void setDescriptionAnnotationCreated(UUID descriptionAnnotationCreated) {
this.descriptionAnnotationCreated = descriptionAnnotationCreated;
public void setDescriptionAnnotationCreatedType(UUID descriptionAnnotationCreatedType) {
this.descriptionAnnotationCreatedType = descriptionAnnotationCreatedType;
}
public UUID getDescriptionAnnotationStatusChanged() {
return descriptionAnnotationStatusChanged;
public UUID getDescriptionAnnotationStatusChangedType() {
return descriptionAnnotationStatusChangedType;
}
public void setDescriptionAnnotationStatusChanged(UUID descriptionAnnotationStatusChanged) {
this.descriptionAnnotationStatusChanged = descriptionAnnotationStatusChanged;
public void setDescriptionAnnotationStatusChangedType(UUID descriptionAnnotationStatusChangedType) {
this.descriptionAnnotationStatusChangedType = descriptionAnnotationStatusChangedType;
}
public UUID getTenantSpecificInvitationExternalUserType() {

View File

@ -2,6 +2,7 @@ package org.opencdmp.integrationevent.inbox.annotationentitycreated;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.enums.annotation.AnnotationEntityType;
import org.opencdmp.commons.enums.annotation.AnnotationProtectionType;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
@ -25,7 +26,7 @@ public class AnnotationEntityCreatedIntegrationEvent extends TrackedEvent {
private UUID entityId;
public static final String _entityId = "entityId";
private String entityType;
private AnnotationEntityType entityType;
public static final String _entityType = "entityType";
private String anchor;
@ -65,11 +66,11 @@ public class AnnotationEntityCreatedIntegrationEvent extends TrackedEvent {
this.entityId = entityId;
}
public String getEntityType() {
public AnnotationEntityType getEntityType() {
return entityType;
}
public void setEntityType(String entityType) {
public void setEntityType(AnnotationEntityType entityType) {
this.entityType = entityType;
}
@ -167,11 +168,14 @@ public class AnnotationEntityCreatedIntegrationEvent extends TrackedEvent {
.must(() -> this.isValidGuid(item.getEntityId()))
.failOn(AnnotationEntityCreatedIntegrationEvent._entityId).failWith(messageSource.getMessage("validation.invalidid", new Object[]{AnnotationEntityCreatedIntegrationEvent._entityId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getEntityType()))
.must(() -> !this.isNull(item.getEntityType()))
.failOn(AnnotationEntityCreatedIntegrationEvent._entityType).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationEntityCreatedIntegrationEvent._entityType}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getPayload()))
.failOn(AnnotationEntityCreatedIntegrationEvent._payload).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationEntityCreatedIntegrationEvent._payload}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getAnchor()))
.failOn(AnnotationEntityCreatedIntegrationEvent._anchor).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationEntityCreatedIntegrationEvent._anchor}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getThreadId()))
.must(() -> this.isValidGuid(item.getThreadId()))

View File

@ -13,6 +13,7 @@ import gr.cite.tools.validation.ValidatorFactory;
import org.opencdmp.audit.AuditableAction;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.annotation.AnnotationEntityType;
import org.opencdmp.commons.notification.NotificationProperties;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope;
@ -28,10 +29,8 @@ import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent;
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler;
import org.opencdmp.model.Tenant;
import org.opencdmp.model.description.Description;
import org.opencdmp.query.DescriptionQuery;
import org.opencdmp.query.PlanUserQuery;
import org.opencdmp.query.TenantQuery;
import org.opencdmp.query.UserQuery;
import org.opencdmp.model.plan.Plan;
import org.opencdmp.query.*;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
@ -125,14 +124,26 @@ public class AnnotationEntityCreatedIntegrationEventHandlerImpl implements Annot
private void sendNotification(AnnotationEntityCreatedIntegrationEvent event) throws InvalidApplicationException {
DescriptionEntity descriptionEntity = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(event.getEntityId()).first();
List<PlanUserEntity> existingUsers = new ArrayList<>();
DescriptionEntity descriptionEntity = null;
PlanEntity planEntity = null;
if (event.getEntityType().equals(AnnotationEntityType.Description)){
descriptionEntity = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(event.getEntityId()).first();
if (descriptionEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{event.getEntityId(), Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (descriptionEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{event.getEntityId(), Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
existingUsers = this.queryFactory.query(PlanUserQuery.class).disableTracking()
.planIds(descriptionEntity.getPlanId())
.isActives(IsActive.Active)
.collect();
} else {
planEntity = this.queryFactory.query(PlanQuery.class).disableTracking().ids(event.getEntityId()).first();
List<PlanUserEntity> existingUsers = this.queryFactory.query(PlanUserQuery.class).disableTracking()
.planIds(descriptionEntity.getPlanId())
.isActives(IsActive.Active)
.collect();
if (planEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{event.getEntityId(), Plan.class.getSimpleName()}, LocaleContextHolder.getLocale()));
existingUsers = this.queryFactory.query(PlanUserQuery.class).disableTracking()
.planIds(planEntity.getId())
.isActives(IsActive.Active)
.collect();
}
if (existingUsers == null || existingUsers.size() <= 1){
return;
@ -150,24 +161,32 @@ public class AnnotationEntityCreatedIntegrationEventHandlerImpl implements Annot
UserEntity user = this.queryFactory.query(UserQuery.class).disableTracking().ids(planUserId).first();
if (user == null || user.getIsActive().equals(IsActive.Inactive))
throw new MyValidationException(this.errors.getPlanInactiveUser().getCode(), this.errors.getPlanInactiveUser().getMessage());
this.createAnnotationNotificationEvent(user, descriptionEntity, sender.getName(), event.getAnchor());
this.createAnnotationNotificationEvent(user, descriptionEntity, planEntity, sender.getName(), event);
}
}
private void createAnnotationNotificationEvent(UserEntity user, DescriptionEntity description, String reasonName, String anchor) throws InvalidApplicationException, InvalidApplicationException {
private void createAnnotationNotificationEvent(UserEntity user, DescriptionEntity description, PlanEntity plan, String reasonName, AnnotationEntityCreatedIntegrationEvent event) throws InvalidApplicationException, InvalidApplicationException {
NotifyIntegrationEvent notifyIntegrationEvent = new NotifyIntegrationEvent();
notifyIntegrationEvent.setUserId(user.getId());
notifyIntegrationEvent.setNotificationType(this.notificationProperties.getDescriptionAnnotationCreated());
if (plan != null && description == null) notifyIntegrationEvent.setNotificationType(this.notificationProperties.getPlanAnnotationCreatedType());
else notifyIntegrationEvent.setNotificationType(this.notificationProperties.getDescriptionAnnotationCreatedType());
NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{recipient}", DataType.String, user.getName()));
fieldInfoList.add(new FieldInfo("{reasonName}", DataType.String, reasonName));
fieldInfoList.add(new FieldInfo("{name}", DataType.String, description.getLabel()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, description.getId().toString()));
String anchorUrl = "f/"+anchor+"/annotation";
if (plan != null && description == null) {
fieldInfoList.add(new FieldInfo("{name}", DataType.String, plan.getLabel()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, plan.getId().toString()));
} else {
fieldInfoList.add(new FieldInfo("{name}", DataType.String, description.getLabel()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, description.getId().toString()));
}
String anchorUrl = "f/"+event.getAnchor()+"/annotation";
fieldInfoList.add(new FieldInfo("{anchor}", DataType.String, anchorUrl));
if(this.tenantScope.getTenantCode() != null && !this.tenantScope.getTenantCode().equals(this.tenantScope.getDefaultTenantCode())){
fieldInfoList.add(new FieldInfo("{tenant-url-path}", DataType.String, String.format("/t/%s", this.tenantScope.getTenantCode())));

View File

@ -2,6 +2,7 @@ package org.opencdmp.integrationevent.inbox.annotationstatusentitychanged;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.enums.annotation.AnnotationEntityType;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
@ -33,7 +34,7 @@ public class AnnotationStatusEntityChangedIntegrationEvent extends TrackedEvent
private UUID entityId;
public static final String _entityId = "entityId";
private String entityType;
private AnnotationEntityType entityType;
public static final String _entityType = "entityType";
private String anchor;
@ -82,11 +83,11 @@ public class AnnotationStatusEntityChangedIntegrationEvent extends TrackedEvent
this.entityId = entityId;
}
public String getEntityType() {
public AnnotationEntityType getEntityType() {
return entityType;
}
public void setEntityType(String entityType) {
public void setEntityType(AnnotationEntityType entityType) {
this.entityType = entityType;
}
@ -146,7 +147,7 @@ public class AnnotationStatusEntityChangedIntegrationEvent extends TrackedEvent
.must(() -> this.isValidGuid(item.getEntityId()))
.failOn(AnnotationStatusEntityChangedIntegrationEvent._entityId).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationStatusEntityChangedIntegrationEvent._entityId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getEntityType()))
.must(() -> !this.isNull(item.getEntityType()))
.failOn(AnnotationStatusEntityChangedIntegrationEvent._entityType).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationStatusEntityChangedIntegrationEvent._entityType}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getAnchor()))

View File

@ -13,6 +13,7 @@ import gr.cite.tools.validation.ValidatorFactory;
import org.opencdmp.audit.AuditableAction;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.annotation.AnnotationEntityType;
import org.opencdmp.commons.notification.NotificationProperties;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope;
@ -28,10 +29,8 @@ import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent;
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler;
import org.opencdmp.model.Tenant;
import org.opencdmp.model.description.Description;
import org.opencdmp.query.DescriptionQuery;
import org.opencdmp.query.PlanUserQuery;
import org.opencdmp.query.TenantQuery;
import org.opencdmp.query.UserQuery;
import org.opencdmp.model.plan.Plan;
import org.opencdmp.query.*;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
@ -125,14 +124,26 @@ public class AnnotationStatusEntityChangedIntegrationEventHandlerImpl implements
private void sendNotification(AnnotationStatusEntityChangedIntegrationEvent event) throws InvalidApplicationException {
DescriptionEntity descriptionEntity = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(event.getEntityId()).first();
List<PlanUserEntity> existingUsers = new ArrayList<>();
DescriptionEntity descriptionEntity = null;
PlanEntity planEntity = null;
if (event.getEntityType().equals(AnnotationEntityType.Description)){
descriptionEntity = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(event.getEntityId()).first();
if (descriptionEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{event.getEntityId(), Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (descriptionEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{event.getEntityId(), Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
existingUsers = this.queryFactory.query(PlanUserQuery.class).disableTracking()
.planIds(descriptionEntity.getPlanId())
.isActives(IsActive.Active)
.collect();
} else {
planEntity = this.queryFactory.query(PlanQuery.class).disableTracking().ids(event.getEntityId()).first();
List<PlanUserEntity> existingUsers = this.queryFactory.query(PlanUserQuery.class).disableTracking()
.planIds(descriptionEntity.getPlanId())
.isActives(IsActive.Active)
.collect();
if (planEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{event.getEntityId(), Plan.class.getSimpleName()}, LocaleContextHolder.getLocale()));
existingUsers = this.queryFactory.query(PlanUserQuery.class).disableTracking()
.planIds(planEntity.getId())
.isActives(IsActive.Active)
.collect();
}
if (existingUsers == null || existingUsers.size() <= 1){
return;
@ -150,25 +161,33 @@ public class AnnotationStatusEntityChangedIntegrationEventHandlerImpl implements
UserEntity user = this.queryFactory.query(UserQuery.class).disableTracking().ids(planUserId).first();
if (user == null || user.getIsActive().equals(IsActive.Inactive))
throw new MyValidationException(this.errors.getPlanInactiveUser().getCode(), this.errors.getPlanInactiveUser().getMessage());
this.createAnnotationStatusChangedNotificationEvent(user, descriptionEntity, sender.getName(), event.getAnchor(), event.getStatusLabel());
this.createAnnotationStatusChangedNotificationEvent(user, descriptionEntity, planEntity, sender.getName(), event);
}
}
private void createAnnotationStatusChangedNotificationEvent(UserEntity user, DescriptionEntity description, String reasonName, String anchor, String statusLabel) throws InvalidApplicationException, InvalidApplicationException {
private void createAnnotationStatusChangedNotificationEvent(UserEntity user, DescriptionEntity description, PlanEntity plan, String reasonName, AnnotationStatusEntityChangedIntegrationEvent event) throws InvalidApplicationException, InvalidApplicationException {
NotifyIntegrationEvent notifyIntegrationEvent = new NotifyIntegrationEvent();
notifyIntegrationEvent.setUserId(user.getId());
notifyIntegrationEvent.setNotificationType(this.notificationProperties.getDescriptionAnnotationStatusChanged());
if (plan != null && description == null) notifyIntegrationEvent.setNotificationType(this.notificationProperties.getPlanAnnotationStatusChangedType());
else notifyIntegrationEvent.setNotificationType(this.notificationProperties.getDescriptionAnnotationStatusChangedType());
NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{recipient}", DataType.String, user.getName()));
fieldInfoList.add(new FieldInfo("{reasonName}", DataType.String, reasonName));
fieldInfoList.add(new FieldInfo("{name}", DataType.String, description.getLabel()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, description.getId().toString()));
fieldInfoList.add(new FieldInfo("{status}", DataType.String, statusLabel));
String anchorUrl = "f/"+anchor+"/annotation";
if (plan != null && description == null) {
fieldInfoList.add(new FieldInfo("{name}", DataType.String, plan.getLabel()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, plan.getId().toString()));
} else {
fieldInfoList.add(new FieldInfo("{name}", DataType.String, description.getLabel()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, description.getId().toString()));
}
fieldInfoList.add(new FieldInfo("{status}", DataType.String, event.getStatusLabel()));
String anchorUrl = "f/"+event.getAnchor()+"/annotation";
fieldInfoList.add(new FieldInfo("{anchor}", DataType.String, anchorUrl));
if(this.tenantScope.getTenantCode() != null && !this.tenantScope.getTenantCode().equals(this.tenantScope.getDefaultTenantCode())){
fieldInfoList.add(new FieldInfo("{tenant-url-path}", DataType.String, String.format("/t/%s", this.tenantScope.getTenantCode())));

View File

@ -3,11 +3,13 @@ notification:
planInvitationExistingUserType: 4904dea2-5079-46d3-83be-3a19c9ab45dc
planModifiedType: 4542262A-22F8-4BAA-9DB6-1C8E70AC1DBB
planFinalisedType: 90DB0B46-42DE-BD89-AEBF-6F27EFEB256E
planAnnotationCreatedType: 1cca80f5-2ea9-41ae-a204-9b4332216c24
planAnnotationStatusChangedType: 0c8a5c62-e48f-4eca-99ee-a7f262477061
descriptionCreatedType: 8965b1d5-99a6-4acf-9016-c0d0ce341364
descriptionModifiedType: 4FDBFA80-7A71-4A69-B854-67CBB70648F1
descriptionFinalisedType: 33790bad-94d4-488a-8ee2-7f6295ca18ea
descriptionAnnotationCreated: db1e99d2-a240-4e75-9bb2-ef25b234c1f0
descriptionAnnotationStatusChanged: 3189e3a6-91e6-40c6-8ff8-275a68445aec
descriptionAnnotationCreatedType: db1e99d2-a240-4e75-9bb2-ef25b234c1f0
descriptionAnnotationStatusChangedType: 3189e3a6-91e6-40c6-8ff8-275a68445aec
mergeAccountConfirmationType: BFE68845-CB05-4C5A-A03D-29161A7C9660
removeCredentialConfirmationType: C9BC3F16-057E-4BBA-8A5F-36BD835E5604
planDepositType: 55736F7A-83AB-4190-AF43-9D031A6F9612