implement plan status logic (in progress)
This commit is contained in:
parent
c08af8c4c3
commit
a7a223d2c6
|
@ -47,6 +47,10 @@ public class PlanEntity extends TenantScopedBaseEntity {
|
||||||
|
|
||||||
public static final String _status = "status";
|
public static final String _status = "status";
|
||||||
|
|
||||||
|
@Column(name = "status_id", nullable = true)
|
||||||
|
private UUID statusId;
|
||||||
|
public static final String _statusId = "statusId";
|
||||||
|
|
||||||
@Column(name = "properties", nullable = true)
|
@Column(name = "properties", nullable = true)
|
||||||
private String properties;
|
private String properties;
|
||||||
|
|
||||||
|
@ -141,6 +145,14 @@ public class PlanEntity extends TenantScopedBaseEntity {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UUID getStatusId() {
|
||||||
|
return statusId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatusId(UUID statusId) {
|
||||||
|
this.statusId = statusId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getProperties() {
|
public String getProperties() {
|
||||||
return this.properties;
|
return this.properties;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,12 @@ import org.opencdmp.model.builder.*;
|
||||||
import org.opencdmp.model.builder.description.DescriptionBuilder;
|
import org.opencdmp.model.builder.description.DescriptionBuilder;
|
||||||
import org.opencdmp.model.builder.planblueprint.PlanBlueprintBuilder;
|
import org.opencdmp.model.builder.planblueprint.PlanBlueprintBuilder;
|
||||||
import org.opencdmp.model.builder.planreference.PlanReferenceBuilder;
|
import org.opencdmp.model.builder.planreference.PlanReferenceBuilder;
|
||||||
|
import org.opencdmp.model.builder.planstatus.PlanStatusBuilder;
|
||||||
import org.opencdmp.model.description.Description;
|
import org.opencdmp.model.description.Description;
|
||||||
import org.opencdmp.model.plan.Plan;
|
import org.opencdmp.model.plan.Plan;
|
||||||
import org.opencdmp.model.planblueprint.PlanBlueprint;
|
import org.opencdmp.model.planblueprint.PlanBlueprint;
|
||||||
import org.opencdmp.model.planreference.PlanReference;
|
import org.opencdmp.model.planreference.PlanReference;
|
||||||
|
import org.opencdmp.model.planstatus.PlanStatus;
|
||||||
import org.opencdmp.model.user.User;
|
import org.opencdmp.model.user.User;
|
||||||
import org.opencdmp.query.*;
|
import org.opencdmp.query.*;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -85,6 +87,9 @@ public class PlanBuilder extends BaseBuilder<Plan, PlanEntity> {
|
||||||
|
|
||||||
List<Plan> models = new ArrayList<>();
|
List<Plan> models = new ArrayList<>();
|
||||||
|
|
||||||
|
FieldSet statusFields = fields.extractPrefixed(this.asPrefix(Description._status));
|
||||||
|
Map<UUID, PlanStatus> statusItemsMap = this.collectPlanStatuses(statusFields, data);
|
||||||
|
|
||||||
FieldSet entityDoisFields = fields.extractPrefixed(this.asPrefix(Plan._entityDois));
|
FieldSet entityDoisFields = fields.extractPrefixed(this.asPrefix(Plan._entityDois));
|
||||||
Map<UUID, List<EntityDoi>> entityDoisMap = this.collectEntityDois(entityDoisFields, data);
|
Map<UUID, List<EntityDoi>> entityDoisMap = this.collectEntityDois(entityDoisFields, data);
|
||||||
|
|
||||||
|
@ -121,7 +126,7 @@ public class PlanBuilder extends BaseBuilder<Plan, PlanEntity> {
|
||||||
if (fields.hasField(this.asIndexer(Plan._tenantId))) m.setTenantId(d.getTenantId());
|
if (fields.hasField(this.asIndexer(Plan._tenantId))) m.setTenantId(d.getTenantId());
|
||||||
if (fields.hasField(this.asIndexer(Plan._label))) m.setLabel(d.getLabel());
|
if (fields.hasField(this.asIndexer(Plan._label))) m.setLabel(d.getLabel());
|
||||||
if (fields.hasField(this.asIndexer(Plan._version))) m.setVersion(d.getVersion());
|
if (fields.hasField(this.asIndexer(Plan._version))) m.setVersion(d.getVersion());
|
||||||
if (fields.hasField(this.asIndexer(Plan._status))) m.setStatus(d.getStatus());
|
if (!statusFields.isEmpty() && statusItemsMap != null && statusItemsMap.containsKey(d.getStatusId())) m.setStatus(statusItemsMap.get(d.getStatusId()));
|
||||||
if (fields.hasField(this.asIndexer(Plan._groupId))) m.setGroupId(d.getGroupId());
|
if (fields.hasField(this.asIndexer(Plan._groupId))) m.setGroupId(d.getGroupId());
|
||||||
if (fields.hasField(this.asIndexer(Plan._description))) m.setDescription(d.getDescription());
|
if (fields.hasField(this.asIndexer(Plan._description))) m.setDescription(d.getDescription());
|
||||||
if (fields.hasField(this.asIndexer(Plan._createdAt))) m.setCreatedAt(d.getCreatedAt());
|
if (fields.hasField(this.asIndexer(Plan._createdAt))) m.setCreatedAt(d.getCreatedAt());
|
||||||
|
@ -157,6 +162,36 @@ public class PlanBuilder extends BaseBuilder<Plan, PlanEntity> {
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<UUID, PlanStatus> collectPlanStatuses(FieldSet fields, List<PlanEntity> data) throws MyApplicationException {
|
||||||
|
if (fields.isEmpty() || data.isEmpty())
|
||||||
|
return null;
|
||||||
|
this.logger.debug("checking related - {}", PlanStatus.class.getSimpleName());
|
||||||
|
|
||||||
|
Map<UUID, PlanStatus> itemMap;
|
||||||
|
if (!fields.hasOtherField(this.asIndexer(PlanStatus._id))) {
|
||||||
|
itemMap = this.asEmpty(
|
||||||
|
data.stream().map(PlanEntity::getStatusId).distinct().collect(Collectors.toList()),
|
||||||
|
x -> {
|
||||||
|
PlanStatus item = new PlanStatus();
|
||||||
|
item.setId(x);
|
||||||
|
return item;
|
||||||
|
},
|
||||||
|
PlanStatus::getId);
|
||||||
|
} else {
|
||||||
|
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(PlanStatus._id);
|
||||||
|
PlanStatusQuery q = this.queryFactory.query(PlanStatusQuery.class).disableTracking().authorize(this.authorize).ids(data.stream().map(PlanEntity::getStatusId).distinct().collect(Collectors.toList()));
|
||||||
|
itemMap = this.builderFactory.builder(PlanStatusBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PlanStatus::getId);
|
||||||
|
}
|
||||||
|
if (!fields.hasField(PlanStatus._id)) {
|
||||||
|
itemMap.forEach((id, item) -> {
|
||||||
|
if (item != null)
|
||||||
|
item.setId(null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemMap;
|
||||||
|
}
|
||||||
|
|
||||||
private Map<UUID, List<PlanReference>> collectPlanReferences(FieldSet fields, List<PlanEntity> data) throws MyApplicationException {
|
private Map<UUID, List<PlanReference>> collectPlanReferences(FieldSet fields, List<PlanEntity> data) throws MyApplicationException {
|
||||||
if (fields.isEmpty() || data.isEmpty()) return null;
|
if (fields.isEmpty() || data.isEmpty()) return null;
|
||||||
this.logger.debug("checking related - {}", PlanReference.class.getSimpleName());
|
this.logger.debug("checking related - {}", PlanReference.class.getSimpleName());
|
||||||
|
|
|
@ -36,9 +36,9 @@ public class PlanPersist {
|
||||||
|
|
||||||
public static final String _label = "label";
|
public static final String _label = "label";
|
||||||
|
|
||||||
private PlanStatus status;
|
private UUID statusId;
|
||||||
|
|
||||||
public static final String _status = "status";
|
public static final String _statusId = "statusId";
|
||||||
|
|
||||||
private PlanPropertiesPersist properties;
|
private PlanPropertiesPersist properties;
|
||||||
|
|
||||||
|
@ -84,12 +84,12 @@ public class PlanPersist {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlanStatus getStatus() {
|
public UUID getStatusId() {
|
||||||
return this.status;
|
return statusId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(PlanStatus status) {
|
public void setStatusId(UUID statusId) {
|
||||||
this.status = status;
|
this.statusId = statusId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlanPropertiesPersist getProperties() {
|
public PlanPropertiesPersist getProperties() {
|
||||||
|
@ -186,9 +186,10 @@ public class PlanPersist {
|
||||||
@Override
|
@Override
|
||||||
protected List<Specification> specifications(PlanPersist item) {
|
protected List<Specification> specifications(PlanPersist item) {
|
||||||
PlanBlueprintEntity planBlueprintEntity = null;
|
PlanBlueprintEntity planBlueprintEntity = null;
|
||||||
|
PlanStatusEntity statusEntity = null;
|
||||||
try {
|
try {
|
||||||
planBlueprintEntity = this.isValidGuid(item.getBlueprint()) ? this.entityManager.find(PlanBlueprintEntity.class, item.getBlueprint(), true) : null;
|
planBlueprintEntity = this.isValidGuid(item.getBlueprint()) ? this.entityManager.find(PlanBlueprintEntity.class, item.getBlueprint(), true) : null;
|
||||||
|
statusEntity = this.isValidGuid(item.getStatusId()) ? this.entityManager.find(PlanStatusEntity.class, item.getStatusId(), true) : null;
|
||||||
} catch (InvalidApplicationException e) {
|
} catch (InvalidApplicationException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -203,6 +204,7 @@ public class PlanPersist {
|
||||||
accessFieldLabel = this.getSystemFieldLabel(definition, PlanBlueprintSystemFieldType.AccessRights);
|
accessFieldLabel = this.getSystemFieldLabel(definition, PlanBlueprintSystemFieldType.AccessRights);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlanStatusEntity finalStatusEntity = statusEntity;
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(() -> this.isValidGuid(item.getId()))
|
.iff(() -> this.isValidGuid(item.getId()))
|
||||||
|
@ -220,40 +222,41 @@ public class PlanPersist {
|
||||||
.must(() -> this.lessEqualLength(item.getLabel(), PlanEntity._labelLength))
|
.must(() -> this.lessEqualLength(item.getLabel(), PlanEntity._labelLength))
|
||||||
.failOn(PlanPersist._label).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{PlanPersist._label}, LocaleContextHolder.getLocale())),
|
.failOn(PlanPersist._label).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{PlanPersist._label}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(() -> item.getStatus() == PlanStatus.Finalized)
|
.iff(() -> finalStatusEntity != null && finalStatusEntity.getInternalStatus() != null && finalStatusEntity.getInternalStatus() == PlanStatus.Finalized)
|
||||||
.must(() -> !this.isEmpty(item.getDescription()))
|
.must(() -> !this.isEmpty(item.getDescription()))
|
||||||
.failOn(PlanPersist._description).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PlanPersist._description}, LocaleContextHolder.getLocale())),
|
.failOn(PlanPersist._description).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PlanPersist._description}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.must(() -> !this.isNull(item.getStatus()))
|
.iff(() -> this.isValidGuid(item.getId()))
|
||||||
.failOn(PlanPersist._status).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PlanPersist._status}, LocaleContextHolder.getLocale())),
|
.must(() -> !this.isNull(item.getStatusId()))
|
||||||
|
.failOn(PlanPersist._statusId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PlanPersist._statusId}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(() -> item.getStatus() == PlanStatus.Finalized)
|
.iff(() -> finalStatusEntity != null && finalStatusEntity.getInternalStatus() != null && finalStatusEntity.getInternalStatus() == PlanStatus.Finalized)
|
||||||
.must(() -> this.isValidGuid(item.getBlueprint()))
|
.must(() -> this.isValidGuid(item.getBlueprint()))
|
||||||
.failOn(PlanPersist._blueprint).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PlanPersist._blueprint}, LocaleContextHolder.getLocale())),
|
.failOn(PlanPersist._blueprint).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PlanPersist._blueprint}, LocaleContextHolder.getLocale())),
|
||||||
|
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(() -> item.getStatus() == PlanStatus.Finalized)
|
.iff(() -> finalStatusEntity != null && finalStatusEntity.getInternalStatus() != null && finalStatusEntity.getInternalStatus() == PlanStatus.Finalized)
|
||||||
.must(() -> !this.isNull(item.getProperties()))
|
.must(() -> !this.isNull(item.getProperties()))
|
||||||
.failOn(PlanPersist._properties).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PlanPersist._properties}, LocaleContextHolder.getLocale())),
|
.failOn(PlanPersist._properties).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PlanPersist._properties}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(() -> item.getStatus() == PlanStatus.Finalized)
|
.iff(() -> finalStatusEntity != null && finalStatusEntity.getInternalStatus() != null && finalStatusEntity.getInternalStatus() == PlanStatus.Finalized)
|
||||||
.must(() -> this.isDescriptionTemplateMultiplicityValid(finalPlanBlueprintEntity, item.getId()))
|
.must(() -> this.isDescriptionTemplateMultiplicityValid(finalPlanBlueprintEntity, item.getId()))
|
||||||
.failOn(PlanPersist._descriptionTemplates).failWith(this.messageSource.getMessage("Validation.InvalidDescriptionTemplateMultiplicityOnPlan", new Object[]{PlanPersist._descriptionTemplates}, LocaleContextHolder.getLocale())),
|
.failOn(PlanPersist._descriptionTemplates).failWith(this.messageSource.getMessage("Validation.InvalidDescriptionTemplateMultiplicityOnPlan", new Object[]{PlanPersist._descriptionTemplates}, LocaleContextHolder.getLocale())),
|
||||||
this.refSpec()
|
this.refSpec()
|
||||||
.iff(() -> !this.isNull(item.getProperties()))
|
.iff(() -> !this.isNull(item.getProperties()))
|
||||||
.on(PlanPersist._properties)
|
.on(PlanPersist._properties)
|
||||||
.over(item.getProperties())
|
.over(item.getProperties())
|
||||||
.using(() -> this.validatorFactory.validator(PlanPropertiesPersist.PlanPropertiesPersistValidator.class).setStatus(item.getStatus()).withDefinition(definition)),
|
.using(() -> this.validatorFactory.validator(PlanPropertiesPersist.PlanPropertiesPersistValidator.class).setStatus(finalStatusEntity.getInternalStatus()).withDefinition(definition)),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(() -> item.getStatus() == PlanStatus.Finalized)
|
.iff(() -> finalStatusEntity != null && finalStatusEntity.getInternalStatus() != null && finalStatusEntity.getInternalStatus() == PlanStatus.Finalized)
|
||||||
.must(() -> !this.isNull(item.getLanguage()))
|
.must(() -> !this.isNull(item.getLanguage()))
|
||||||
.failOn(PlanPersist._language).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{languageFieldLabel != null ? languageFieldLabel : PlanBlueprintSystemFieldType.Language.name()}, LocaleContextHolder.getLocale())),
|
.failOn(PlanPersist._language).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{languageFieldLabel != null ? languageFieldLabel : PlanBlueprintSystemFieldType.Language.name()}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(() -> item.getStatus() == PlanStatus.Finalized)
|
.iff(() -> finalStatusEntity != null && finalStatusEntity.getInternalStatus() != null && finalStatusEntity.getInternalStatus() == PlanStatus.Finalized)
|
||||||
.must(() -> !this.isNull(item.getAccessType()))
|
.must(() -> !this.isNull(item.getAccessType()))
|
||||||
.failOn(PlanPersist._accessType).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{accessFieldLabel != null ? accessFieldLabel : PlanBlueprintSystemFieldType.AccessRights.name()}, LocaleContextHolder.getLocale())),
|
.failOn(PlanPersist._accessType).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{accessFieldLabel != null ? accessFieldLabel : PlanBlueprintSystemFieldType.AccessRights.name()}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(() -> item.getStatus() == PlanStatus.Finalized)
|
.iff(() -> finalStatusEntity != null && finalStatusEntity.getInternalStatus() != null && finalStatusEntity.getInternalStatus() == PlanStatus.Finalized)
|
||||||
.must(() -> !this.isListNullOrEmpty(item.getDescriptionTemplates()))
|
.must(() -> !this.isListNullOrEmpty(item.getDescriptionTemplates()))
|
||||||
.failOn(PlanPersist._descriptionTemplates).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PlanPersist._descriptionTemplates}, LocaleContextHolder.getLocale())),
|
.failOn(PlanPersist._descriptionTemplates).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PlanPersist._descriptionTemplates}, LocaleContextHolder.getLocale())),
|
||||||
this.navSpec()
|
this.navSpec()
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package org.opencdmp.model.plan;
|
package org.opencdmp.model.plan;
|
||||||
|
|
||||||
import org.opencdmp.commons.enums.PlanAccessType;
|
import org.opencdmp.commons.enums.PlanAccessType;
|
||||||
import org.opencdmp.commons.enums.PlanStatus;
|
|
||||||
import org.opencdmp.commons.enums.PlanVersionStatus;
|
import org.opencdmp.commons.enums.PlanVersionStatus;
|
||||||
import org.opencdmp.commons.enums.IsActive;
|
import org.opencdmp.commons.enums.IsActive;
|
||||||
import org.opencdmp.model.*;
|
import org.opencdmp.model.*;
|
||||||
import org.opencdmp.model.description.Description;
|
import org.opencdmp.model.description.Description;
|
||||||
import org.opencdmp.model.planblueprint.PlanBlueprint;
|
import org.opencdmp.model.planblueprint.PlanBlueprint;
|
||||||
import org.opencdmp.model.planreference.PlanReference;
|
import org.opencdmp.model.planreference.PlanReference;
|
||||||
|
import org.opencdmp.model.planstatus.PlanStatus;
|
||||||
import org.opencdmp.model.user.User;
|
import org.opencdmp.model.user.User;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
|
@ -88,9 +88,9 @@ public class DashboardServiceImpl implements DashboardService {
|
||||||
planLookup.getPage().setOffset(0);
|
planLookup.getPage().setOffset(0);
|
||||||
planLookup.getPage().setSize(model.getPage().getSize()+model.getPage().getOffset());
|
planLookup.getPage().setSize(model.getPage().getSize()+model.getPage().getOffset());
|
||||||
|
|
||||||
QueryResult<Plan> plans = this.elasticQueryHelperService.collect(planLookup, AuthorizationFlags.AllExceptPublic, new BaseFieldSet().ensure(Plan._id).ensure(Plan._updatedAt).ensure(Plan._label).ensure(Plan._status));
|
QueryResult<Plan> plans = this.elasticQueryHelperService.collect(planLookup, AuthorizationFlags.AllExceptPublic, new BaseFieldSet().ensure(Plan._id).ensure(Plan._updatedAt).ensure(Plan._label).ensure(String.join(".",Plan._status, org.opencdmp.model.planstatus.PlanStatus._internalStatus)));
|
||||||
if (!this.conventionService.isListNullOrEmpty(plans.getItems())) {
|
if (!this.conventionService.isListNullOrEmpty(plans.getItems())) {
|
||||||
for (Plan plan : plans.getItems()) recentActivityItemEntities.add(new RecentActivityItemEntity(RecentActivityItemType.Plan, plan.getId(), plan.getUpdatedAt(), plan.getLabel(), plan.getStatus().getValue()));
|
for (Plan plan : plans.getItems()) recentActivityItemEntities.add(new RecentActivityItemEntity(RecentActivityItemType.Plan, plan.getId(), plan.getUpdatedAt(), plan.getLabel(), plan.getStatus().getInternalStatus().getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,7 @@ import org.opencdmp.service.descriptionworkflow.DescriptionWorkflowService;
|
||||||
import org.opencdmp.service.elastic.ElasticService;
|
import org.opencdmp.service.elastic.ElasticService;
|
||||||
import org.opencdmp.service.filetransformer.FileTransformerService;
|
import org.opencdmp.service.filetransformer.FileTransformerService;
|
||||||
import org.opencdmp.service.planblueprint.PlanBlueprintService;
|
import org.opencdmp.service.planblueprint.PlanBlueprintService;
|
||||||
|
import org.opencdmp.service.planworkflow.PlanWorkflowServiceImpl;
|
||||||
import org.opencdmp.service.responseutils.ResponseUtilsService;
|
import org.opencdmp.service.responseutils.ResponseUtilsService;
|
||||||
import org.opencdmp.service.usagelimit.UsageLimitService;
|
import org.opencdmp.service.usagelimit.UsageLimitService;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -185,6 +186,7 @@ public class PlanServiceImpl implements PlanService {
|
||||||
private final UsageLimitService usageLimitService;
|
private final UsageLimitService usageLimitService;
|
||||||
private final AccountingService accountingService;
|
private final AccountingService accountingService;
|
||||||
private final DescriptionWorkflowService descriptionWorkflowService;
|
private final DescriptionWorkflowService descriptionWorkflowService;
|
||||||
|
private final PlanWorkflowServiceImpl planWorkflowService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public PlanServiceImpl(
|
public PlanServiceImpl(
|
||||||
|
@ -207,7 +209,7 @@ public class PlanServiceImpl implements PlanService {
|
||||||
FileTransformerService fileTransformerService,
|
FileTransformerService fileTransformerService,
|
||||||
ValidatorFactory validatorFactory,
|
ValidatorFactory validatorFactory,
|
||||||
ElasticService elasticService, DescriptionTemplateService descriptionTemplateService,
|
ElasticService elasticService, DescriptionTemplateService descriptionTemplateService,
|
||||||
AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, AuthorizationContentResolver authorizationContentResolver, TenantScope tenantScope, ResponseUtilsService responseUtilsService, PlanBlueprintService planBlueprintService, UsageLimitService usageLimitService, AccountingService accountingService, DescriptionWorkflowService descriptionWorkflowService) {
|
AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, AuthorizationContentResolver authorizationContentResolver, TenantScope tenantScope, ResponseUtilsService responseUtilsService, PlanBlueprintService planBlueprintService, UsageLimitService usageLimitService, AccountingService accountingService, DescriptionWorkflowService descriptionWorkflowService, PlanWorkflowServiceImpl planWorkflowService) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
|
@ -237,6 +239,7 @@ public class PlanServiceImpl implements PlanService {
|
||||||
this.usageLimitService = usageLimitService;
|
this.usageLimitService = usageLimitService;
|
||||||
this.accountingService = accountingService;
|
this.accountingService = accountingService;
|
||||||
this.descriptionWorkflowService = descriptionWorkflowService;
|
this.descriptionWorkflowService = descriptionWorkflowService;
|
||||||
|
this.planWorkflowService = planWorkflowService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plan persist(PlanPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, IOException {
|
public Plan persist(PlanPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, IOException {
|
||||||
|
@ -1314,9 +1317,13 @@ public class PlanServiceImpl implements PlanService {
|
||||||
data = this.entityManager.find(PlanEntity.class, model.getId());
|
data = this.entityManager.find(PlanEntity.class, model.getId());
|
||||||
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Plan.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Plan.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
|
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
|
||||||
if (model.getStatus() != null && model.getStatus() == PlanStatus.Finalized && data.getStatus() != PlanStatus.Finalized) {
|
PlanStatusEntity oldPlanStatusEntity = this.entityManager.find(PlanStatusEntity.class, data.getStatusId(), true);
|
||||||
|
if (oldPlanStatusEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getStatusId(), PlanStatusEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
PlanStatusEntity newPlanStatusEntity = this.entityManager.find(PlanStatusEntity.class, model.getStatusId(), true);
|
||||||
|
if (newPlanStatusEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getStatusId(), PlanStatusEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
if (newPlanStatusEntity.getInternalStatus() != null && newPlanStatusEntity.getInternalStatus().equals(PlanStatus.Finalized) && oldPlanStatusEntity.getInternalStatus() != null && oldPlanStatusEntity.getInternalStatus().equals(PlanStatus.Finalized)) {
|
||||||
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.planAffiliation(model.getId())), Permission.FinalizePlan);
|
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.planAffiliation(model.getId())), Permission.FinalizePlan);
|
||||||
data.setStatus(model.getStatus());
|
data.setStatusId(model.getStatusId());
|
||||||
data.setFinalizedAt(Instant.now());
|
data.setFinalizedAt(Instant.now());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1325,6 +1332,7 @@ public class PlanServiceImpl implements PlanService {
|
||||||
data.setGroupId(UUID.randomUUID());
|
data.setGroupId(UUID.randomUUID());
|
||||||
data.setVersion((short) 1);
|
data.setVersion((short) 1);
|
||||||
data.setStatus(PlanStatus.Draft);
|
data.setStatus(PlanStatus.Draft);
|
||||||
|
data.setStatusId(this.planWorkflowService.getWorkFlowDefinition().getStartingStatusId());
|
||||||
data.setVersionStatus(PlanVersionStatus.NotFinalized);
|
data.setVersionStatus(PlanVersionStatus.NotFinalized);
|
||||||
data.setCreatorId(this.userScope.getUserId());
|
data.setCreatorId(this.userScope.getUserId());
|
||||||
data.setBlueprintId(model.getBlueprint());
|
data.setBlueprintId(model.getBlueprint());
|
||||||
|
@ -1713,7 +1721,8 @@ public class PlanServiceImpl implements PlanService {
|
||||||
persist.setId(data.getId());
|
persist.setId(data.getId());
|
||||||
persist.setHash(data.getId().toString());
|
persist.setHash(data.getId().toString());
|
||||||
persist.setLabel(data.getLabel());
|
persist.setLabel(data.getLabel());
|
||||||
persist.setStatus(PlanStatus.Finalized);
|
//TODO status PlanStatusEntity statusEntity = this.queryFactory.query(DescriptionStatusQuery.class).disableTracking().internalStatuses(DescriptionStatus.Finalized).isActive(IsActive.Active).firstAs(new BaseFieldSet().ensure(org.opencdmp.model.descriptionstatus.DescriptionStatus._id));
|
||||||
|
// persist.setStatus(PlanStatus.Finalized);
|
||||||
persist.setDescription(data.getDescription());
|
persist.setDescription(data.getDescription());
|
||||||
persist.setBlueprint(data.getBlueprintId());
|
persist.setBlueprint(data.getBlueprintId());
|
||||||
persist.setAccessType(data.getAccessType());
|
persist.setAccessType(data.getAccessType());
|
||||||
|
@ -2307,7 +2316,7 @@ public class PlanServiceImpl implements PlanService {
|
||||||
|
|
||||||
PlanPersist persist = new PlanPersist();
|
PlanPersist persist = new PlanPersist();
|
||||||
persist.setLabel(label);
|
persist.setLabel(label);
|
||||||
persist.setStatus(PlanStatus.Draft);
|
//TODO status persist.setStatus(PlanStatus.Draft);
|
||||||
persist.setDescription(planXml.getDescription());
|
persist.setDescription(planXml.getDescription());
|
||||||
persist.setAccessType(planXml.getAccess());
|
persist.setAccessType(planXml.getAccess());
|
||||||
persist.setLanguage(planXml.getLanguage());
|
persist.setLanguage(planXml.getLanguage());
|
||||||
|
@ -2609,7 +2618,7 @@ public class PlanServiceImpl implements PlanService {
|
||||||
PlanPersist persist = new PlanPersist();
|
PlanPersist persist = new PlanPersist();
|
||||||
|
|
||||||
persist.setLabel(planCommonModelConfig.getLabel());
|
persist.setLabel(planCommonModelConfig.getLabel());
|
||||||
persist.setStatus(PlanStatus.Draft);
|
// TODO status persist.setStatus(PlanStatus.Draft);
|
||||||
persist.setDescription(model.getDescription());
|
persist.setDescription(model.getDescription());
|
||||||
switch (model.getAccessType()) {
|
switch (model.getAccessType()) {
|
||||||
case Public -> persist.setAccessType(PlanAccessType.Public);
|
case Public -> persist.setAccessType(PlanAccessType.Public);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import gr.cite.tools.exception.MyNotFoundException;
|
||||||
import gr.cite.tools.exception.MyValidationException;
|
import gr.cite.tools.exception.MyValidationException;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
import jakarta.xml.bind.JAXBException;
|
import jakarta.xml.bind.JAXBException;
|
||||||
|
import org.opencdmp.commons.types.planworkflow.PlanWorkflowDefinitionEntity;
|
||||||
import org.opencdmp.model.persist.planworkflow.PlanWorkflowPersist;
|
import org.opencdmp.model.persist.planworkflow.PlanWorkflowPersist;
|
||||||
import org.opencdmp.model.planworkflow.PlanWorkflow;
|
import org.opencdmp.model.planworkflow.PlanWorkflow;
|
||||||
|
|
||||||
|
@ -16,4 +17,6 @@ public interface PlanWorkflowService {
|
||||||
PlanWorkflow persist(PlanWorkflowPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException;
|
PlanWorkflow persist(PlanWorkflowPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException;
|
||||||
|
|
||||||
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
|
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
|
||||||
|
|
||||||
|
PlanWorkflowDefinitionEntity getWorkFlowDefinition() throws InvalidApplicationException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.opencdmp.service.planworkflow;
|
||||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||||
import gr.cite.tools.data.builder.BuilderFactory;
|
import gr.cite.tools.data.builder.BuilderFactory;
|
||||||
import gr.cite.tools.data.deleter.DeleterFactory;
|
import gr.cite.tools.data.deleter.DeleterFactory;
|
||||||
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
import gr.cite.tools.exception.MyApplicationException;
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
import gr.cite.tools.exception.MyForbiddenException;
|
import gr.cite.tools.exception.MyForbiddenException;
|
||||||
import gr.cite.tools.exception.MyNotFoundException;
|
import gr.cite.tools.exception.MyNotFoundException;
|
||||||
|
@ -12,9 +13,11 @@ import gr.cite.tools.fieldset.FieldSet;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import gr.cite.tools.logging.MapLogEntry;
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
import jakarta.xml.bind.JAXBException;
|
import jakarta.xml.bind.JAXBException;
|
||||||
|
import org.opencdmp.authorization.AuthorizationFlags;
|
||||||
import org.opencdmp.authorization.Permission;
|
import org.opencdmp.authorization.Permission;
|
||||||
import org.opencdmp.commons.XmlHandlingService;
|
import org.opencdmp.commons.XmlHandlingService;
|
||||||
import org.opencdmp.commons.enums.IsActive;
|
import org.opencdmp.commons.enums.IsActive;
|
||||||
|
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||||
import org.opencdmp.commons.types.planworkflow.PlanWorkflowDefinitionEntity;
|
import org.opencdmp.commons.types.planworkflow.PlanWorkflowDefinitionEntity;
|
||||||
import org.opencdmp.commons.types.planworkflow.PlanWorkflowDefinitionTransitionEntity;
|
import org.opencdmp.commons.types.planworkflow.PlanWorkflowDefinitionTransitionEntity;
|
||||||
import org.opencdmp.convention.ConventionService;
|
import org.opencdmp.convention.ConventionService;
|
||||||
|
@ -27,6 +30,7 @@ import org.opencdmp.model.persist.planworkflow.PlanWorkflowDefinitionPersist;
|
||||||
import org.opencdmp.model.persist.planworkflow.PlanWorkflowDefinitionTransitionPersist;
|
import org.opencdmp.model.persist.planworkflow.PlanWorkflowDefinitionTransitionPersist;
|
||||||
import org.opencdmp.model.persist.planworkflow.PlanWorkflowPersist;
|
import org.opencdmp.model.persist.planworkflow.PlanWorkflowPersist;
|
||||||
import org.opencdmp.model.planworkflow.PlanWorkflow;
|
import org.opencdmp.model.planworkflow.PlanWorkflow;
|
||||||
|
import org.opencdmp.query.PlanWorkflowQuery;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
@ -51,7 +55,10 @@ public class PlanWorkflowServiceImpl implements PlanWorkflowService {
|
||||||
private final DeleterFactory deleterFactory;
|
private final DeleterFactory deleterFactory;
|
||||||
private final MessageSource messageSource;
|
private final MessageSource messageSource;
|
||||||
private final ErrorThesaurusProperties errors;
|
private final ErrorThesaurusProperties errors;
|
||||||
public PlanWorkflowServiceImpl(AuthorizationService authorizationService, ConventionService conventionService, XmlHandlingService xmlHandlingService, TenantEntityManager entityManager, BuilderFactory builderFactory, DeleterFactory deleterFactory, MessageSource messageSource, ErrorThesaurusProperties errors) {
|
private final TenantScope tenantScope;
|
||||||
|
private final QueryFactory queryFactory;
|
||||||
|
|
||||||
|
public PlanWorkflowServiceImpl(AuthorizationService authorizationService, ConventionService conventionService, XmlHandlingService xmlHandlingService, TenantEntityManager entityManager, BuilderFactory builderFactory, DeleterFactory deleterFactory, MessageSource messageSource, ErrorThesaurusProperties errors, TenantScope tenantScope, QueryFactory queryFactory) {
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.conventionService = conventionService;
|
this.conventionService = conventionService;
|
||||||
this.xmlHandlingService = xmlHandlingService;
|
this.xmlHandlingService = xmlHandlingService;
|
||||||
|
@ -60,6 +67,8 @@ public class PlanWorkflowServiceImpl implements PlanWorkflowService {
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
this.messageSource = messageSource;
|
this.messageSource = messageSource;
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
|
this.tenantScope = tenantScope;
|
||||||
|
this.queryFactory = queryFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -136,4 +145,22 @@ public class PlanWorkflowServiceImpl implements PlanWorkflowService {
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlanWorkflowDefinitionEntity getWorkFlowDefinition() throws InvalidApplicationException {
|
||||||
|
PlanWorkflowQuery query = this.queryFactory.query(PlanWorkflowQuery.class).authorize(AuthorizationFlags.AllExceptPublic).isActives(IsActive.Active);
|
||||||
|
|
||||||
|
if (this.tenantScope.isDefaultTenant())
|
||||||
|
query = query.defaultTenant(true);
|
||||||
|
else
|
||||||
|
query = query.tenantIds(this.tenantScope.getTenant());
|
||||||
|
|
||||||
|
PlanWorkflowEntity entity = query.first();
|
||||||
|
if (entity == null) throw new MyApplicationException("Plan workflow not found!");
|
||||||
|
|
||||||
|
PlanWorkflowDefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(PlanWorkflowDefinitionEntity.class, entity.getDefinition());
|
||||||
|
if (definition == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{entity.getId(), PlanWorkflowDefinitionEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
|
||||||
|
return definition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue