added description workflow table and some other fixes

This commit is contained in:
CITE\spapacharalampous 2024-08-26 14:09:35 +03:00
parent f823083689
commit 96a565543e
37 changed files with 1715 additions and 18 deletions

View File

@ -211,5 +211,10 @@ public class AuditableAction {
public static final EventId PlanWorkflow_Lookup = new EventId(500001, "PlanWorkflow_Lookup");
public static final EventId PlanWorkflow_Persist = new EventId(500002, "PlanWorkflow_Persist");
public static final EventId PlanWorkflow_Delete = new EventId(500003, "PlanWorkflow_Delete");
public static final EventId DescriptionWorkflow_Query = new EventId(600000, "DescriptionWorkflow_Query");
public static final EventId DescriptionWorkflow_Lookup = new EventId(600001, "DescriptionWorkflow_Lookup");
public static final EventId DescriptionWorkflow_Persist = new EventId(600002, "DescriptionWorkflow_Persist");
public static final EventId DescriptionWorkflow_Delete = new EventId(600003, "DescriptionWorkflow_Delete");
}

View File

@ -105,6 +105,11 @@ public final class Permission {
public static String EditDescriptionStatus = "EditDescriptionStatus";
public static String DeleteDescriptionStatus = "DeleteDescriptionStatus";
//DescriptionWorkflow
public static String BrowseDescriptionWorkflow = "BrowseDescriptionWorkflow";
public static String EditDescriptionWorkflow = "EditDescriptionWorkflow";
public static String DeleteDescriptionWorkflow = "DeleteDescriptionWorkflow";
//PlanBlueprint
public static String BrowsePlanBlueprint = "BrowsePlanBlueprint";
public static String EditPlanBlueprint = "EditPlanBlueprint";

View File

@ -15,6 +15,7 @@ public enum UsageLimitTargetMetric implements DatabaseEnum<String> {
DESCRIPTION_STATUS_COUNT(TargetMetrics.DescriptionStatusCount),
DESCRIPTION_TEMPLATE_COUNT(TargetMetrics.DescriptionTemplateCount),
DESCRIPTION_TEMPLATE_TYPE_COUNT(TargetMetrics.DescriptionTemplateTypeCount),
DESCRIPTION_STATUS_WORKFLOW_COUNT(TargetMetrics.DescriptionStatusWorkflowCount),
PREFILLING_SOURCES_COUNT(TargetMetrics.PrefillingSourcesCount),
REFERENCE_TYPE_COUNT(TargetMetrics.ReferenceTypeCount),
DEPOSIT_EXECUTION_COUNT(TargetMetrics.DepositExecutionCount),
@ -44,6 +45,7 @@ public enum UsageLimitTargetMetric implements DatabaseEnum<String> {
public static final String DescriptionStatusCount = "description_status_count";
public static final String DescriptionTemplateCount = "description_template_count";
public static final String DescriptionTemplateTypeCount = "description_template_type_count";
public static final String DescriptionStatusWorkflowCount = "description_status_workflow_count";
public static final String PrefillingSourcesCount = "prefilling_sources_count";
public static final String ReferenceTypeCount = "reference_type_count";
public static final String DepositExecutionCount = "deposit_execution_count";

View File

@ -0,0 +1,27 @@
package org.opencdmp.commons.types.descriptionworkflow;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlRootElement;
import java.util.List;
import java.util.UUID;
@XmlRootElement(name = "definition")
@XmlAccessorType(XmlAccessType.FIELD)
public class DescriptionWorkflowDefinitionEntity {
private UUID startingStatusId;
public final static String _startingStatusId = "startingStatusId";
private List<DescriptionWorkflowDefinitionTransitionEntity> statusTransitions;
public final static String _statusTransitions = "statusTransitions";
public UUID getStartingStatusId() { return startingStatusId; }
public void setStartingStatusId(UUID startingStatusId) { this.startingStatusId = startingStatusId; }
public List<DescriptionWorkflowDefinitionTransitionEntity> getStatusTransitions() { return statusTransitions; }
public void setStatusTransitions(List<DescriptionWorkflowDefinitionTransitionEntity> statusTransitions) { this.statusTransitions = statusTransitions; }
}

View File

@ -0,0 +1,29 @@
package org.opencdmp.commons.types.descriptionworkflow;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import java.util.UUID;
@XmlRootElement(name = "statusTransitions")
@XmlAccessorType(XmlAccessType.FIELD)
public class DescriptionWorkflowDefinitionTransitionEntity {
@XmlElement(name = "fromStatusId")
private UUID fromStatusId;
public final static String _fromStatusId = "fromStatusId";
@XmlElement(name = "toStatusId")
private UUID toStatusId;
public final static String _toStatusId = "toStatusId";
public UUID getFromStatusId() { return fromStatusId; }
public void setFromStatusId(UUID fromStatusId) { this.fromStatusId = fromStatusId; }
public UUID getToStatusId() { return toStatusId; }
public void setToStatusId(UUID toStatusId) { this.toStatusId = toStatusId; }
}

View File

@ -0,0 +1,76 @@
package org.opencdmp.data;
import jakarta.persistence.*;
import org.hibernate.annotations.Type;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.data.converters.enums.IsActiveConverter;
import org.opencdmp.data.tenant.TenantScopedBaseEntity;
import org.opencdmp.data.types.SQLXMLType;
import java.time.Instant;
import java.util.UUID;
@Entity
@Table(name = "\"DescriptionWorkflowEntity\"")
public class DescriptionWorkflowEntity extends TenantScopedBaseEntity {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id;
public static final String _id = "id";
@Column(name = "name", length = DescriptionWorkflowEntity._nameLength, nullable = false)
private String name;
public static final String _name = "name";
public static final int _nameLength = 250;
@Column(name = "description", nullable = true)
private String description;
public static final String _description = "description";
@Column(name = "created_at", nullable = true)
private Instant createdAt;
public static final String _createdAt = "createdAt";
@Column(name = "updated_at", nullable = true)
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
@Column(name = "is_active", nullable = false)
@Convert(converter = IsActiveConverter.class)
private IsActive isActive;
public static final String _isActive = "isActive";
@Type(SQLXMLType.class)
@Column(name = "definition", nullable = false, columnDefinition = "xml")
private String definition;
public static final String _definition = "definition";
public UUID getId() { return id; }
public void setId(UUID id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public Instant getCreatedAt() { return createdAt; }
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
public Instant getUpdatedAt() { return updatedAt; }
public void setUpdatedAt(Instant updatedAt) { this.updatedAt = updatedAt; }
public IsActive getIsActive() { return isActive; }
public void setIsActive(IsActive isActive) { this.isActive = isActive; }
public String getDefinition() { return definition; }
public void setDefinition(String definition) { this.definition = definition; }
}

View File

@ -0,0 +1,73 @@
package org.opencdmp.model.builder.descriptionworkflow;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.types.descriptionworkflow.DescriptionWorkflowDefinitionEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.DescriptionWorkflowEntity;
import org.opencdmp.model.builder.BaseBuilder;
import org.opencdmp.model.descriptionworkflow.DescriptionWorkflow;
import org.opencdmp.model.descriptionworkflow.DescriptionWorkflowDefinition;
import org.slf4j.LoggerFactory;
import java.util.*;
public class DescriptionWorkflowBuilder extends BaseBuilder<DescriptionWorkflow, DescriptionWorkflowEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final TenantScope tenantScope;
private final BuilderFactory builderFactory;
private final XmlHandlingService xmlHandlingService;
public DescriptionWorkflowBuilder(ConventionService conventionService, TenantScope tenantScope, BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionWorkflowBuilder.class)));
this.tenantScope = tenantScope;
this.builderFactory = builderFactory;
this.xmlHandlingService = xmlHandlingService;
}
public DescriptionWorkflowBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<DescriptionWorkflow> build(FieldSet fields, List<DescriptionWorkflowEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || fields.isEmpty() || data == null)
return new ArrayList<>();
List<DescriptionWorkflow> models = new ArrayList<>();
FieldSet definitionFields = fields.extractPrefixed(this.asPrefix(DescriptionWorkflow._definition));
for (DescriptionWorkflowEntity d : data) {
DescriptionWorkflow m = new DescriptionWorkflow();
if (fields.hasField(this.asIndexer(DescriptionWorkflow._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(DescriptionWorkflow._name))) m.setName(d.getName());
if (fields.hasField(this.asIndexer(DescriptionWorkflow._description))) m.setDescription(d.getDescription());
if (fields.hasField(this.asIndexer(DescriptionWorkflow._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(DescriptionWorkflow._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(DescriptionWorkflow._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(DescriptionWorkflow._belongsToCurrentTenant))) m.setBelongsToCurrentTenant(this.getBelongsToCurrentTenant(d, this.tenantScope));
if (fields.hasField(this.asIndexer(DescriptionWorkflow._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (fields.hasField(this.asIndexer(DescriptionWorkflow._definition))) {
DescriptionWorkflowDefinitionEntity definitionData = this.xmlHandlingService.fromXmlSafe(DescriptionWorkflowDefinitionEntity.class, d.getDefinition());
m.setDefinition(this.builderFactory.builder(DescriptionWorkflowDefinitionBuilder.class).build(definitionFields, definitionData));
}
models.add(m);
}
return models;
}
}

View File

@ -0,0 +1,87 @@
package org.opencdmp.model.builder.descriptionworkflow;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.types.descriptionworkflow.DescriptionWorkflowDefinitionEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.BaseBuilder;
import org.opencdmp.model.builder.descriptionstatus.DescriptionStatusBuilder;
import org.opencdmp.model.descriptionstatus.DescriptionStatus;
import org.opencdmp.model.descriptionworkflow.DescriptionWorkflowDefinition;
import org.opencdmp.query.DescriptionStatusQuery;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.stream.Collectors;
public class DescriptionWorkflowDefinitionBuilder extends BaseBuilder<DescriptionWorkflowDefinition, DescriptionWorkflowDefinitionEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
public DescriptionWorkflowDefinitionBuilder(ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionWorkflowDefinitionBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
}
public DescriptionWorkflowDefinitionBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<DescriptionWorkflowDefinition> build(FieldSet fields, List<DescriptionWorkflowDefinitionEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || fields.isEmpty() || data == null)
return new ArrayList<>();
List<DescriptionWorkflowDefinition> models = new ArrayList<>();
FieldSet transitionsFields = fields.extractPrefixed(this.asPrefix(DescriptionWorkflowDefinition._statusTransitions));
FieldSet startingStatusFields = fields.extractPrefixed(this.asPrefix(DescriptionWorkflowDefinition._startingStatus));
Map<UUID, DescriptionStatus> startingStatusMap = this.collectDescriptionStatuses(startingStatusFields, data);
for (DescriptionWorkflowDefinitionEntity d : data) {
DescriptionWorkflowDefinition m = new DescriptionWorkflowDefinition();
if (!startingStatusFields.isEmpty() && startingStatusMap != null && startingStatusMap.containsKey(d.getStartingStatusId()))
m.setStartingStatus(startingStatusMap.get(d.getStartingStatusId()));
if (!transitionsFields.isEmpty() && d.getStatusTransitions() != null && !d.getStatusTransitions().isEmpty())
m.setStatusTransitions(this.builderFactory.builder(DescriptionWorkflowDefinitionTransitionBuilder.class).build(transitionsFields, d.getStatusTransitions()));
models.add(m);
}
return models;
}
private Map<UUID, DescriptionStatus> collectDescriptionStatuses(FieldSet fields, List<DescriptionWorkflowDefinitionEntity> data) {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", DescriptionStatus.class.getSimpleName());
Map<UUID, DescriptionStatus> itemMap;
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DescriptionStatus._id));
DescriptionStatusQuery q = this.queryFactory.query(DescriptionStatusQuery.class).disableTracking().authorize(this.authorize).ids(data.stream().map(DescriptionWorkflowDefinitionEntity::getStartingStatusId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DescriptionStatusBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DescriptionStatus::getId);
if (!fields.hasField(this.asIndexer(DescriptionStatus._id)))
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> { x.setId(null); });
return itemMap;
}
}

View File

@ -0,0 +1,89 @@
package org.opencdmp.model.builder.descriptionworkflow;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.types.descriptionworkflow.DescriptionWorkflowDefinitionTransitionEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.BaseBuilder;
import org.opencdmp.model.builder.descriptionstatus.DescriptionStatusBuilder;
import org.opencdmp.model.descriptionstatus.DescriptionStatus;
import org.opencdmp.model.descriptionworkflow.DescriptionWorkflowDefinitionTransition;
import org.opencdmp.query.DescriptionStatusQuery;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionWorkflowDefinitionTransitionBuilder extends BaseBuilder<DescriptionWorkflowDefinitionTransition, DescriptionWorkflowDefinitionTransitionEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final QueryFactory queryFactory;
private final BuilderFactory builderFactory;
public DescriptionWorkflowDefinitionTransitionBuilder(ConventionService conventionService, QueryFactory queryFactory, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionWorkflowDefinitionTransitionBuilder.class)));
this.queryFactory = queryFactory;
this.builderFactory = builderFactory;
}
public DescriptionWorkflowDefinitionTransitionBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<DescriptionWorkflowDefinitionTransition> build(FieldSet fields, List<DescriptionWorkflowDefinitionTransitionEntity> data) throws MyApplicationException {
if (fields == null || fields.isEmpty() || data == null)
return new ArrayList<>();
List<DescriptionWorkflowDefinitionTransition> models = new ArrayList<>();
FieldSet fromStatusFields = fields.extractPrefixed(this.asPrefix(DescriptionWorkflowDefinitionTransition._fromStatus));
Map<UUID, DescriptionStatus> fromStatusMap = this.collectDescriptionStatuses(fromStatusFields, data, data.stream().map(DescriptionWorkflowDefinitionTransitionEntity::getFromStatusId).distinct().collect(Collectors.toList()));
FieldSet toStatusFields = fields.extractPrefixed(this.asPrefix(DescriptionWorkflowDefinitionTransition._toStatus));
Map<UUID, DescriptionStatus> toStatusMap = this.collectDescriptionStatuses(fromStatusFields, data, data.stream().map(DescriptionWorkflowDefinitionTransitionEntity::getToStatusId).distinct().collect(Collectors.toList()));
for (DescriptionWorkflowDefinitionTransitionEntity d : data) {
DescriptionWorkflowDefinitionTransition m = new DescriptionWorkflowDefinitionTransition();
if (!fromStatusFields.isEmpty() && fromStatusMap != null && fromStatusMap.containsKey(d.getFromStatusId())) m.setFromStatus(fromStatusMap.get(d.getFromStatusId()));
if (!toStatusFields.isEmpty() && toStatusMap != null && toStatusMap.containsKey(d.getToStatusId())) m.setToStatus(toStatusMap.get(d.getToStatusId()));
models.add(m);
}
return models;
}
private Map<UUID, DescriptionStatus> collectDescriptionStatuses(FieldSet fields, List<DescriptionWorkflowDefinitionTransitionEntity> data, Collection<UUID> descriptionStatusIds) {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || fields.isEmpty() || data == null)
return null;
this.logger.debug("checking related - {}", DescriptionStatus.class.getSimpleName());
Map<UUID, DescriptionStatus> itemMap;
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DescriptionStatus._id));
DescriptionStatusQuery q = this.queryFactory.query(DescriptionStatusQuery.class).disableTracking().authorize(this.authorize).ids(descriptionStatusIds);
itemMap = this.builderFactory.builder(DescriptionStatusBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DescriptionStatus::getId);
if (!fields.hasField(this.asIndexer(DescriptionStatus._id)))
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> { x.setId(null); });
return itemMap;
}
}

View File

@ -52,7 +52,7 @@ public class PlanWorkflowBuilder extends BaseBuilder<PlanWorkflow, PlanWorkflowE
List<PlanWorkflow> models = new ArrayList<>();
FieldSet definitionFields = fields.extractPrefixed(this.asIndexer(PlanWorkflow._definition));
FieldSet definitionFields = fields.extractPrefixed(this.asPrefix(PlanWorkflow._definition));
for (PlanWorkflowEntity d : data) {
PlanWorkflow m = new PlanWorkflow();
@ -62,6 +62,7 @@ public class PlanWorkflowBuilder extends BaseBuilder<PlanWorkflow, PlanWorkflowE
if (fields.hasField(this.asIndexer(PlanWorkflow._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(PlanWorkflow._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(PlanWorkflow._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(PlanWorkflow._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (fields.hasField(this.asIndexer(PlanWorkflow._belongsToCurrentTenant))) m.setBelongsToCurrentTenant(this.getBelongsToCurrentTenant(d, this.tenantScope));
if (definitionFields != null && d.getDefinition() != null && !d.getDefinition().isBlank()) {

View File

@ -13,6 +13,7 @@ import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.BaseBuilder;
import org.opencdmp.model.builder.planstatus.PlanStatusBuilder;
import org.opencdmp.model.planstatus.PlanStatus;
import org.opencdmp.model.planworkflow.PlanWorkflow;
import org.opencdmp.model.planworkflow.PlanWorkflowDefinition;
import org.opencdmp.query.PlanStatusQuery;
import org.slf4j.LoggerFactory;
@ -52,7 +53,7 @@ public class PlanWorkflowDefinitionBuilder extends BaseBuilder<PlanWorkflowDefin
List<PlanWorkflowDefinition> models = new ArrayList<>();
FieldSet startingStatusFields = fields.extractPrefixed(PlanWorkflowDefinition._startingStatus);
FieldSet startingStatusFields = fields.extractPrefixed(this.asPrefix(PlanWorkflowDefinition._startingStatus));
Map<UUID, PlanStatus> startingStatusItemsMap = this.collectPlanStatuses(startingStatusFields, data);
FieldSet transitionsFields = fields.extractPrefixed(this.asPrefix(PlanWorkflowDefinition._statusTransitions));

View File

@ -53,10 +53,10 @@ public class PlanWorkflowDefinitionTransitionBuilder extends BaseBuilder<PlanWor
List<PlanWorkflowDefinitionTransition> models = new ArrayList<>();
FieldSet fromStatusFields = fields.extractPrefixed(PlanWorkflowDefinitionTransition._fromStatus);
FieldSet fromStatusFields = fields.extractPrefixed(this.asPrefix(PlanWorkflowDefinitionTransition._fromStatus));
Map<UUID, PlanStatus> fromStatusItemsMap = this.collectPlanStatuses(fromStatusFields, data, data.stream().map(PlanWorkflowDefinitionTransitionEntity::getFromStatusId).distinct().collect(Collectors.toList()));
FieldSet toStatusFields = fields.extractPrefixed(PlanWorkflowDefinitionTransition._fromStatus);
FieldSet toStatusFields = fields.extractPrefixed(this.asPrefix(PlanWorkflowDefinitionTransition._fromStatus));
Map<UUID, PlanStatus> toStatusItemsMap = this.collectPlanStatuses(toStatusFields, data, data.stream().map(PlanWorkflowDefinitionTransitionEntity::getToStatusId).distinct().collect(Collectors.toList()));
for (PlanWorkflowDefinitionTransitionEntity d : data) {

View File

@ -0,0 +1,43 @@
package org.opencdmp.model.censorship.descriptionworkflow;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.Permission;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.censorship.BaseCensor;
import org.opencdmp.model.descriptionworkflow.DescriptionWorkflow;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionWorkflowCensor extends BaseCensor {
private final static LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionWorkflowCensor.class));
private final AuthorizationService authService;
private final CensorFactory censorFactory;
public DescriptionWorkflowCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseDescriptionWorkflow);
FieldSet definitionFields = fields.extractPrefixed(this.asIndexerPrefix(DescriptionWorkflow._definition));
this.censorFactory.censor(DescriptionWorkflowCensor.class).censor(definitionFields, userId);
}
}

View File

@ -0,0 +1,43 @@
package org.opencdmp.model.censorship.descriptionworkflow;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.Permission;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.censorship.BaseCensor;
import org.opencdmp.model.descriptionworkflow.DescriptionWorkflowDefinition;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionWorkflowDefinitionCensor extends BaseCensor {
private final static LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionWorkflowDefinitionCensor.class));
private final AuthorizationService authService;
private final CensorFactory censorFactory;
public DescriptionWorkflowDefinitionCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor (FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseDescriptionWorkflow);
FieldSet transiotionsFields = fields.extractPrefixed(this.asIndexerPrefix(DescriptionWorkflowDefinition._statusTransitions));
this.censorFactory.censor(DescriptionWorkflowDefinitionTransitionCensor.class).censor(transiotionsFields, userId);
}
}

View File

@ -0,0 +1,37 @@
package org.opencdmp.model.censorship.descriptionworkflow;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.Permission;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.censorship.BaseCensor;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionWorkflowDefinitionTransitionCensor extends BaseCensor {
private final static LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionWorkflowDefinitionTransitionCensor.class));
protected final AuthorizationService authService;
public DescriptionWorkflowDefinitionTransitionCensor(ConventionService conventionService, AuthorizationService authService) {
super(conventionService);
this.authService = authService;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseDescriptionWorkflow);
}
}

View File

@ -5,8 +5,10 @@ import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.Permission;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.censorship.BaseCensor;
import org.opencdmp.model.planworkflow.PlanWorkflowDefinition;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
@ -35,6 +37,9 @@ public class PlanWorkflowDefinitionCensor extends BaseCensor {
if (fields == null || fields.isEmpty())
return;
this.authService.authorize(Permission.BrowsePlanWorkflow);
FieldSet transitionsFields = fields.extractPrefixed(this.asIndexerPrefix(PlanWorkflowDefinition._statusTransitions));
this.censorFactory.censor(PlanWorkflowDefinitionTransitionCensor.class).censor(transitionsFields, userId);
}
}

View File

@ -37,8 +37,5 @@ public class PlanWorkflowDefinitionTransitionCensor extends BaseCensor {
return;
this.authService.authorizeForce(Permission.BrowsePlanWorkflow);
FieldSet transitionsFields = fields.extractPrefixed(this.asIndexerPrefix(PlanWorkflowDefinition._statusTransitions));
this.censorFactory.censor(PlanWorkflowDefinitionTransitionCensor.class).censor(transitionsFields, userId);
}
}

View File

@ -0,0 +1,75 @@
package org.opencdmp.model.deleter;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.UsageLimitTargetMetric;
import org.opencdmp.data.DescriptionWorkflowEntity;
import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.query.DescriptionWorkflowQuery;
import org.opencdmp.service.accounting.AccountingService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionWorkflowDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionWorkflowDeleter.class));
private final TenantEntityManager entityManager;
private final QueryFactory queryFactory;
private final DeleterFactory deleterFactory;
private final AccountingService accountingService;
@Autowired
public DescriptionWorkflowDeleter(TenantEntityManager entityManager, QueryFactory queryFactory, DeleterFactory deleterFactory, AccountingService accountingService){
this.entityManager = entityManager;
this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory;
this.accountingService = accountingService;
}
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
List<DescriptionWorkflowEntity> data = this.queryFactory.query(DescriptionWorkflowQuery.class).ids(ids).collect();
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.deleteAndSave(data);
}
public void deleteAndSave(List<DescriptionWorkflowEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
this.entityManager.flush();
logger.trace("changes saved");
}
public void delete(List<DescriptionWorkflowEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty()) return;
Instant now = Instant.now();
for (DescriptionWorkflowEntity item : data) {
logger.trace("deleting item {}", item.getId());
item.setUpdatedAt(now);
item.setIsActive(IsActive.Inactive);
logger.trace("updating item");
this.entityManager.merge(item);
logger.trace("updated item");
this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_STATUS_WORKFLOW_COUNT.getValue());
}
}
}

View File

@ -44,11 +44,11 @@ public class PlanWorkflowDeleter implements Deleter {
this.accountingService = accountingService;
}
public void deleteAndSaveByIds(List<UUID> ids) {
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
List<PlanWorkflowEntity> data = this.queryFactory.query(PlanWorkflowQuery.class).ids(ids).collect();
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.deleteAndSave(data);
}
public void deleteAndSave(List<PlanWorkflowEntity> data) throws InvalidApplicationException {

View File

@ -0,0 +1,72 @@
package org.opencdmp.model.descriptionworkflow;
import org.opencdmp.commons.enums.IsActive;
import java.time.Instant;
import java.util.UUID;
public class DescriptionWorkflow {
public final static String _id = "id";
private UUID id;
public final static String _name = "name";
private String name;
public final static String _description = "description";
private String description;
public final static String _createdAt = "createdAt";
private Instant createdAt;
public final static String _updatedAt = "updatedAt";
private Instant updatedAt;
public final static String _isActive = "isActive";
private IsActive isActive;
public final static String _definition = "definition";
private DescriptionWorkflowDefinition definition;
public final static String _hash = "hash";
private String hash;
public final static String _belongsToCurrentTenant = "belongsToCurrentTenant";
private Boolean belongsToCurrentTenant;
public UUID getId() { return this.id; }
public void setId(UUID id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public Instant getCreatedAt() { return createdAt; }
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
public Instant getUpdatedAt() { return updatedAt; }
public void setUpdatedAt(Instant updatedAt) { this.updatedAt = updatedAt; }
public IsActive getIsActive() { return isActive; }
public void setIsActive(IsActive isActive) { this.isActive = isActive; }
public DescriptionWorkflowDefinition getDefinition() { return definition; }
public void setDefinition(DescriptionWorkflowDefinition definition) { this.definition = definition; }
public String getHash() { return hash; }
public void setHash(String hash) { this.hash = hash; }
public Boolean getBelongsToCurrentTenant() { return belongsToCurrentTenant; }
public void setBelongsToCurrentTenant(Boolean belongsToCurrentTenant) { this.belongsToCurrentTenant = belongsToCurrentTenant; }
}

View File

@ -0,0 +1,22 @@
package org.opencdmp.model.descriptionworkflow;
import org.opencdmp.model.descriptionstatus.DescriptionStatus;
import java.util.List;
public class DescriptionWorkflowDefinition {
public final static String _startingStatus = "startingStatus";
private DescriptionStatus startingStatus;
public final static String _statusTransitions = "statusTransitions";
private List<DescriptionWorkflowDefinitionTransition> statusTransitions;
public DescriptionStatus getStartingStatus() { return startingStatus; }
public void setStartingStatus(DescriptionStatus startingStatus) { this.startingStatus = startingStatus; }
public List<DescriptionWorkflowDefinitionTransition> getStatusTransitions() { return statusTransitions; }
public void setStatusTransitions(List<DescriptionWorkflowDefinitionTransition> statusTransitions) { this.statusTransitions = statusTransitions; }
}

View File

@ -0,0 +1,21 @@
package org.opencdmp.model.descriptionworkflow;
import org.opencdmp.model.descriptionstatus.DescriptionStatus;
public class DescriptionWorkflowDefinitionTransition {
public final static String _fromStatus = "fromStatus";
private DescriptionStatus fromStatus;
public final static String _toStatus = "toStatus";
private DescriptionStatus toStatus;
public DescriptionStatus getFromStatus() { return fromStatus; }
public void setFromStatus(DescriptionStatus fromStatus) { this.fromStatus = fromStatus; }
public DescriptionStatus getToStatus() { return toStatus; }
public void setToStatus(DescriptionStatus toStatus) { this.toStatus = toStatus; }
}

View File

@ -0,0 +1,71 @@
package org.opencdmp.model.persist.descriptionworkflow;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class DescriptionWorkflowDefinitionPersist {
private UUID startingStatusId;
public final static String _startingStatusId = "startingStatusId";
private List<DescriptionWorkflowDefinitionTransitionPersist> statusTransitions;
public final static String _statusTransitions = "statusTransitions";
public UUID getStartingStatusId() { return startingStatusId; }
public void setStartingStatusId(UUID startingStatusId) { this.startingStatusId = startingStatusId; }
public List<DescriptionWorkflowDefinitionTransitionPersist> getStatusTransitions() { return statusTransitions; }
public void setStatusTransitions(List<DescriptionWorkflowDefinitionTransitionPersist> statusTransitions) { this.statusTransitions = statusTransitions; }
@Component(DescriptionWorkflowDefinitionPersist.DescriptionWorkflowDefinitionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DescriptionWorkflowDefinitionPersistValidator extends BaseValidator<DescriptionWorkflowDefinitionPersist> {
public final static String ValidatorName = "DescriptionWorkflowPersistValidator.DescriptionWorkflowDefinitionPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected DescriptionWorkflowDefinitionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<DescriptionWorkflowDefinitionPersist> modelClass() { return DescriptionWorkflowDefinitionPersist.class; }
@Override
protected List<Specification> specifications(DescriptionWorkflowDefinitionPersist item) {
return Arrays.asList(
this.spec()
.must(() -> this.isValidGuid(item.getStartingStatusId()))
.failOn(DescriptionWorkflowDefinitionPersist._startingStatusId)
.failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionWorkflowDefinitionPersist._statusTransitions}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isListNullOrEmpty(item.getStatusTransitions()))
.failOn(DescriptionWorkflowDefinitionPersist._statusTransitions)
.failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionWorkflowDefinitionPersist._statusTransitions}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff((() -> !this.isListNullOrEmpty(item.getStatusTransitions())))
.on(DescriptionWorkflowDefinitionPersist._statusTransitions)
.over(item.getStatusTransitions())
.using((itm) -> this.validatorFactory.validator(DescriptionWorkflowDefinitionTransitionPersist.DescriptionWorkflowDefinitionTransitionPersistValidator.class))
);
}
}
}

View File

@ -0,0 +1,69 @@
package org.opencdmp.model.persist.descriptionworkflow;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class DescriptionWorkflowDefinitionTransitionPersist {
private UUID fromStatusId;
public final static String _fromStatusId = "fromStatusId";
private UUID toStatusId;
public final static String _toStatusId = "toStatusId";
public UUID getFromStatusId() { return fromStatusId; }
public void setFromStatusId(UUID fromStatusId) { this.fromStatusId = fromStatusId; }
public UUID getToStatusId() { return toStatusId; }
public void setToStatusId(UUID toStatusId) { this.toStatusId = toStatusId; }
@Component(DescriptionWorkflowDefinitionTransitionPersist.DescriptionWorkflowDefinitionTransitionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DescriptionWorkflowDefinitionTransitionPersistValidator extends BaseValidator<DescriptionWorkflowDefinitionTransitionPersist> {
public static final String ValidatorName = "DescriptionWorkflowPersistValidator.DescriptionWorkflowDefinitionPersistValidator.DescriptionWorkflowDefinitionTransitionPersistValidator";
private final MessageSource messageSource;
protected DescriptionWorkflowDefinitionTransitionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<DescriptionWorkflowDefinitionTransitionPersist> modelClass() {
return DescriptionWorkflowDefinitionTransitionPersist.class;
}
@Override
protected List<Specification> specifications(DescriptionWorkflowDefinitionTransitionPersist item) {
return Arrays.asList(
this.spec()
.must(() -> this.isValidGuid(item.getFromStatusId()))
.failOn(DescriptionWorkflowDefinitionTransitionPersist._fromStatusId)
.failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionWorkflowDefinitionTransitionPersist._fromStatusId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> this.isValidGuid(item.getToStatusId()))
.failOn(DescriptionWorkflowDefinitionTransitionPersist._toStatusId)
.failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionWorkflowDefinitionTransitionPersist._toStatusId}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> this.isValidGuid(item.getFromStatusId()) && this.isValidGuid(item.getToStatusId()))
.must(() -> !item.getFromStatusId().equals(item.getToStatusId()))
.failOn(DescriptionWorkflowDefinitionTransitionPersist._toStatusId)
.failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionWorkflowDefinitionTransitionPersist._toStatusId}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -0,0 +1,110 @@
package org.opencdmp.model.persist.descriptionworkflow;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class DescriptionWorkflowPersist {
private UUID id;
private String name;
public final static String _name = "name";
private String description;
public final static String _description = "description";
private IsActive isActive;
public final static String _isActive = "isActive";
private String hash;
public final static String _hash = "hash";
private DescriptionWorkflowDefinitionPersist definition;
public final static String _definition = "definition";
public UUID getId() { return id; }
public void setId(UUID id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public IsActive getIsActive() { return isActive; }
public void setIsActive(IsActive isActive) { this.isActive = isActive; }
public String getHash() { return hash; }
public void setHash(String hash) { this.hash = hash; }
public DescriptionWorkflowDefinitionPersist getDefinition() { return definition; }
public void setDefinition(DescriptionWorkflowDefinitionPersist definition) { this.definition = definition; }
@Component(DescriptionWorkflowPersist.DescriptionWorkflowPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DescriptionWorkflowPersistValidator extends BaseValidator<DescriptionWorkflowPersist> {
public final static String ValidatorName = "DescriptionWorkflowPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected DescriptionWorkflowPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<DescriptionWorkflowPersist> modelClass() { return DescriptionWorkflowPersist.class; }
@Override
protected List<Specification> specifications(DescriptionWorkflowPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(DescriptionWorkflowPersist._hash)
.failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionWorkflowPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(DescriptionWorkflowPersist._hash)
.failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionWorkflowPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getName()))
.failOn(DescriptionWorkflowPersist._name)
.failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionWorkflowPersist._name}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getIsActive()))
.failOn(DescriptionWorkflowPersist._isActive)
.failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionWorkflowPersist._isActive}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getDefinition()))
.on(DescriptionWorkflowPersist._description)
.over(item.getDefinition())
.using(() -> this.validatorFactory.validator(DescriptionWorkflowDefinitionPersist.DescriptionWorkflowDefinitionPersistValidator.class))
);
}
}
}

View File

@ -57,6 +57,11 @@ public class PlanWorkflowDefinitionTransitionPersist {
this.spec()
.must(() -> this.isValidGuid(item.getToStatusId()))
.failOn(PlanWorkflowDefinitionTransitionPersist._toStatusId)
.failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PlanWorkflowDefinitionTransitionPersist._toStatusId}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> this.isValidGuid(item.getFromStatusId()) && this.isValidGuid(item.getToStatusId()))
.must(() -> !item.getFromStatusId().equals(item.getToStatusId()))
.failOn(PlanWorkflowDefinitionTransitionPersist._toStatusId)
.failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PlanWorkflowDefinitionTransitionPersist._toStatusId}, LocaleContextHolder.getLocale()))
);
}

View File

@ -0,0 +1,233 @@
package org.opencdmp.query;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.data.DescriptionWorkflowEntity;
import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.model.descriptionworkflow.DescriptionWorkflow;
import org.opencdmp.query.utils.QueryUtilsService;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.*;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionWorkflowQuery extends QueryBase<DescriptionWorkflowEntity> {
private String like;
private Collection<UUID> ids;
private Collection<IsActive> isActives;
private Collection<UUID> excludedIds;
private Collection<UUID> tenantIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private boolean defaultTenant;
protected boolean noTracking;
public DescriptionWorkflowQuery like(String value) {
this.like = like;
return this;
}
public DescriptionWorkflowQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public DescriptionWorkflowQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public DescriptionWorkflowQuery ids(Collection<UUID> values) {
this.ids = values;
return this;
}
public DescriptionWorkflowQuery isActives(IsActive value) {
this.isActives = List.of(value);
return this;
}
public DescriptionWorkflowQuery isActives(IsActive... value) {
this.isActives = Arrays.asList(value);
return this;
}
public DescriptionWorkflowQuery isActives(Collection<IsActive> values) {
this.isActives = values;
return this;
}
public DescriptionWorkflowQuery excludedIds(UUID value) {
this.excludedIds = List.of(value);
return this;
}
public DescriptionWorkflowQuery excludedIds(UUID... value) {
this.excludedIds = Arrays.asList(value);
return this;
}
public DescriptionWorkflowQuery excludedIds(Collection<UUID> values) {
this.excludedIds = values;
return this;
}
public DescriptionWorkflowQuery tenantIds(UUID value) {
this.tenantIds = List.of(value);
return this;
}
public DescriptionWorkflowQuery tenantIds(UUID... value) {
this.tenantIds = Arrays.asList(value);
return this;
}
public DescriptionWorkflowQuery tenantIds(Collection<UUID> values) {
this.tenantIds = values;
return this;
}
public DescriptionWorkflowQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
public DescriptionWorkflowQuery defaultTenant(Boolean value) {
this.defaultTenant = value;
return this;
}
public DescriptionWorkflowQuery enableTracking() {
this.noTracking = false;
return this;
}
public DescriptionWorkflowQuery disableTracking() {
this.noTracking = true;
return this;
}
private final QueryUtilsService queryUtilsService;
private final TenantEntityManager entityManager;
public DescriptionWorkflowQuery(QueryUtilsService queryUtilsService, TenantEntityManager entityManager) {
this.queryUtilsService = queryUtilsService;
this.entityManager = entityManager;
}
@Override
protected EntityManager entityManager(){
return this.entityManager.getEntityManager();
}
@Override
protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.isActives);
}
@Override
protected Class<DescriptionWorkflowEntity> entityClass() {
return DescriptionWorkflowEntity.class;
}
@Override
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
List<Predicate> predicates = new ArrayList<>();
if (this.ids != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionWorkflowEntity._id));
for (UUID item : this.ids)
inClause.value(item);
predicates.add(inClause);
}
if (this.like != null && !this.like.isBlank()) {
predicates.add(queryContext.CriteriaBuilder.or(
this.queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(DescriptionWorkflowEntity._name), this.like),
this.queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(DescriptionWorkflowEntity._description), this.like)
));
}
if (this.isActives != null) {
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionWorkflowEntity._isActive));
for (IsActive item : this.isActives)
inClause.value(item);
predicates.add(inClause);
}
if (this.excludedIds != null) {
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionWorkflowEntity._id));
for (UUID item : this.excludedIds)
notInClause.value(item);
predicates.add(notInClause.not());
}
if (this.defaultTenant) {
predicates.add(queryContext.CriteriaBuilder.isNull(queryContext.Root.get(DescriptionWorkflowEntity._tenantId)));
} else if (this.tenantIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionWorkflowEntity._tenantId));
for (UUID item : this.tenantIds)
inClause.value(item);
predicates.add(inClause);
}
if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray);
} else {
return null;
}
}
@Override
protected String fieldNameOf(FieldResolver item) {
if (item.match(DescriptionWorkflow._id))
return DescriptionWorkflowEntity._id;
else if (item.match(DescriptionWorkflow._name))
return DescriptionWorkflowEntity._name;
else if (item.match(DescriptionWorkflow._description))
return DescriptionWorkflowEntity._description;
else if (item.match(DescriptionWorkflow._createdAt))
return DescriptionWorkflowEntity._createdAt;
else if (item.match(DescriptionWorkflow._updatedAt))
return DescriptionWorkflowEntity._updatedAt;
else if (item.match(DescriptionWorkflow._isActive))
return DescriptionWorkflowEntity._isActive;
else if (item.match(DescriptionWorkflow._definition))
return DescriptionWorkflowEntity._definition;
else if (item.match(DescriptionWorkflow._hash))
return DescriptionWorkflowEntity._updatedAt;
else if (item.match(DescriptionWorkflow._belongsToCurrentTenant))
return DescriptionWorkflowEntity._tenantId;
return null;
}
@Override
protected DescriptionWorkflowEntity convert(Tuple tuple, Set<String> columns) {
DescriptionWorkflowEntity item = new DescriptionWorkflowEntity();
item.setId(QueryBase.convertSafe(tuple, columns, DescriptionWorkflowEntity._id, UUID.class));
item.setName(QueryBase.convertSafe(tuple, columns, DescriptionWorkflowEntity._name, String.class));
item.setDescription(QueryBase.convertSafe(tuple, columns, DescriptionWorkflowEntity._description, String.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DescriptionWorkflowEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, DescriptionWorkflowEntity._updatedAt, Instant.class));
item.setIsActive(QueryBase.convertSafe(tuple, columns, DescriptionWorkflowEntity._isActive, IsActive.class));
item.setTenantId(QueryBase.convertSafe(tuple, columns, DescriptionWorkflowEntity._tenantId, UUID.class));
item.setDefinition(QueryBase.convertSafe(tuple, columns, DescriptionWorkflowEntity._definition, String.class));
return item;
}
}

View File

@ -9,6 +9,7 @@ import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.data.DescriptionWorkflowEntity;
import org.opencdmp.data.PlanWorkflowEntity;
import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.model.planworkflow.PlanWorkflow;
@ -32,8 +33,12 @@ public class PlanWorkflowQuery extends QueryBase<PlanWorkflowEntity> {
private Collection<UUID> excludedIds;
private Collection<UUID> tenantIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private boolean defaultTenant;
protected boolean noTracking;
@ -87,11 +92,31 @@ public class PlanWorkflowQuery extends QueryBase<PlanWorkflowEntity> {
return this;
}
public PlanWorkflowQuery tenantIds(UUID value) {
this.tenantIds = List.of(value);
return this;
}
public PlanWorkflowQuery tenantIds(UUID... value) {
this.tenantIds = Arrays.asList(value);
return this;
}
public PlanWorkflowQuery tenantIds(Collection<UUID> values) {
this.tenantIds = values;
return this;
}
public PlanWorkflowQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
public PlanWorkflowQuery defaultTenant(Boolean value) {
this.defaultTenant = value;
return this;
}
public PlanWorkflowQuery enableTracking() {
this.noTracking = false;
return this;
@ -153,6 +178,14 @@ public class PlanWorkflowQuery extends QueryBase<PlanWorkflowEntity> {
notInClause.value(item);
predicates.add(notInClause.not());
}
if (this.defaultTenant) {
predicates.add(queryContext.CriteriaBuilder.isNull(queryContext.Root.get(PlanWorkflowEntity._tenantId)));
} else if (this.tenantIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(PlanWorkflowEntity._tenantId));
for (UUID item : this.tenantIds)
inClause.value(item);
predicates.add(inClause);
}
if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);

View File

@ -0,0 +1,47 @@
package org.opencdmp.query.lookup;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.query.DescriptionWorkflowQuery;
import java.util.List;
import java.util.UUID;
public class DescriptionWorkflowLookup extends Lookup {
private String like;
private List<UUID> ids;
private List<UUID> excludedIds;
private List<IsActive> isActive;
public String getLike() { return like; }
public void setLike(String like) { this.like = like; }
public List<UUID> getIds() { return ids; }
public void setIds(List<UUID> ids) { this.ids = ids; }
public List<UUID> getExcludedIds() { return excludedIds; }
public void setExcludedIds(List<UUID> excludedIds) { this.excludedIds = excludedIds; }
public List<IsActive> getIsActive() { return isActive; }
public void setIsActive(List<IsActive> isActive) { this.isActive = isActive; }
public DescriptionWorkflowQuery enrich(QueryFactory queryFactory) {
DescriptionWorkflowQuery query = queryFactory.query(DescriptionWorkflowQuery.class);
if (this.like != null) query.like(this.like);
if (this.ids != null) query.ids(this.ids);
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
if (this.isActive != null) query.isActives(isActive);
this.enrichCommon(query);
return query;
}
}

View File

@ -0,0 +1,14 @@
package org.opencdmp.service.descriptionworkflow;
import gr.cite.tools.fieldset.FieldSet;
import org.opencdmp.model.descriptionworkflow.DescriptionWorkflow;
import org.opencdmp.model.persist.descriptionworkflow.DescriptionWorkflowPersist;
import javax.management.InvalidApplicationException;
import java.util.UUID;
public interface DescriptionWorkflowService {
DescriptionWorkflow persist(DescriptionWorkflowPersist persist, FieldSet fields) throws InvalidApplicationException;
void deleteAndSave(UUID id) throws InvalidApplicationException;
}

View File

@ -0,0 +1,134 @@
package org.opencdmp.service.descriptionworkflow;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.types.descriptionworkflow.DescriptionWorkflowDefinitionEntity;
import org.opencdmp.commons.types.descriptionworkflow.DescriptionWorkflowDefinitionTransitionEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.DescriptionWorkflowEntity;
import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.opencdmp.model.builder.descriptionworkflow.DescriptionWorkflowBuilder;
import org.opencdmp.model.deleter.DescriptionWorkflowDeleter;
import org.opencdmp.model.descriptionworkflow.DescriptionWorkflow;
import org.opencdmp.model.persist.descriptionworkflow.DescriptionWorkflowDefinitionPersist;
import org.opencdmp.model.persist.descriptionworkflow.DescriptionWorkflowDefinitionTransitionPersist;
import org.opencdmp.model.persist.descriptionworkflow.DescriptionWorkflowPersist;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Service
public class DescriptionWorkflowServiceImpl implements DescriptionWorkflowService{
private final static LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionWorkflowServiceImpl.class));
private final AuthorizationService authService;
private final ConventionService conventionService;
private final XmlHandlingService xmlHandlingService;
private final BuilderFactory builderFactory;
private final DeleterFactory deleterFactory;
private final TenantEntityManager entityManager;
private final MessageSource messageSource;
private final ErrorThesaurusProperties errors;
public DescriptionWorkflowServiceImpl(AuthorizationService authService, ConventionService conventionService, XmlHandlingService xmlHandlingService, BuilderFactory builderFactory, DeleterFactory deleterFactory, TenantEntityManager entityManager, MessageSource messageSource, ErrorThesaurusProperties errors) {
this.authService = authService;
this.conventionService = conventionService;
this.xmlHandlingService = xmlHandlingService;
this.builderFactory = builderFactory;
this.deleterFactory = deleterFactory;
this.entityManager = entityManager;
this.messageSource = messageSource;
this.errors = errors;
}
@Override
public DescriptionWorkflow persist(DescriptionWorkflowPersist model, FieldSet fields) throws InvalidApplicationException {
logger.debug(new MapLogEntry("persisting data description workflow").And("model", model).And("fields", fields));
this.authService.authorizeForce(Permission.EditDescriptionWorkflow);
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
DescriptionWorkflowEntity data;
if (isUpdate) {
data = this.entityManager.find(DescriptionWorkflowEntity.class, model.getId());
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
} else {
data = new DescriptionWorkflowEntity();
data.setId(UUID.randomUUID());
data.setIsActive(IsActive.Active);
data.setCreatedAt(Instant.now());
}
data.setName(model.getName());
data.setDescription(model.getDescription());
data.setDescription(this.xmlHandlingService.toXmlSafe(this.buildDescriptionWorkflowDefinitionEntity(model.getDefinition())));
if (isUpdate)
this.entityManager.merge(data);
else
this.entityManager.persist(data);
this.entityManager.flush();
return this.builderFactory.builder(DescriptionWorkflowBuilder.class).build(BaseFieldSet.build(fields, DescriptionWorkflow._id), data);
}
@Override
public void deleteAndSave(UUID id) throws InvalidApplicationException {
logger.debug("deleting description workflow: {}", id);
this.authService.authorizeForce(Permission.DeleteDescriptionWorkflow);
this.deleterFactory.deleter(DescriptionWorkflowDeleter.class).deleteAndSaveByIds(List.of(id));
}
private DescriptionWorkflowDefinitionEntity buildDescriptionWorkflowDefinitionEntity(DescriptionWorkflowDefinitionPersist persist) {
DescriptionWorkflowDefinitionEntity data = new DescriptionWorkflowDefinitionEntity();
if (persist == null) return data;
data.setStartingStatusId(data.getStartingStatusId());
List<DescriptionWorkflowDefinitionTransitionEntity> transitionData = this.buildDescriptionWorkflowDefinitionTransitionEntities(persist.getStatusTransitions());
data.setStatusTransitions(transitionData);
return data;
}
private List<DescriptionWorkflowDefinitionTransitionEntity> buildDescriptionWorkflowDefinitionTransitionEntities(List<DescriptionWorkflowDefinitionTransitionPersist> persistData) {
List<DescriptionWorkflowDefinitionTransitionEntity> data = new ArrayList<>();
if (persistData == null || persistData.isEmpty())
return data;
for (DescriptionWorkflowDefinitionTransitionPersist persist : persistData) {
DescriptionWorkflowDefinitionTransitionEntity d = new DescriptionWorkflowDefinitionTransitionEntity();
d.setFromStatusId(persist.getFromStatusId());
d.setToStatusId(persist.getToStatusId());
data.add(d);
}
return data;
}
}

View File

@ -114,15 +114,14 @@ public class PlanWorkflowServiceImpl implements PlanWorkflowService {
data.setStartingStatusId(persist.getStartingStatusId());
if (persist.getStatusTransitions() != null) {
List<PlanWorkflowDefinitionTransitionEntity> transitionsData = this.buildPlanWorkflowDefinitionEntity(persist.getStatusTransitions());
List<PlanWorkflowDefinitionTransitionEntity> transitionsData = this.buildPlanWorkflowDefinitionTransitionEntities(persist.getStatusTransitions());
data.setStatusTransitions(transitionsData);
}
return data;
}
private List<PlanWorkflowDefinitionTransitionEntity> buildPlanWorkflowDefinitionEntity(List<PlanWorkflowDefinitionTransitionPersist> persistData) {
private List<PlanWorkflowDefinitionTransitionEntity> buildPlanWorkflowDefinitionTransitionEntities(List<PlanWorkflowDefinitionTransitionPersist> persistData) {
List<PlanWorkflowDefinitionTransitionEntity> data = new ArrayList<>();
if (persistData == null || persistData.isEmpty())
return data;

View File

@ -45,7 +45,7 @@ import java.util.*;
@RestController
@RequestMapping(path = "api/description-status")
@io.swagger.v3.oas.annotations.tags.Tag(name = "DescriptionStatuses", description = "Manage tags")
@io.swagger.v3.oas.annotations.tags.Tag(name = "DescriptionStatuses", description = "Manage description statuses")
@SwaggerCommonErrorResponses
public class DescriptionStatusController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionStatusController.class));

View File

@ -0,0 +1,209 @@
package org.opencdmp.controllers;
import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.ValidationFilterAnnotation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.opencdmp.audit.AuditableAction;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.controllers.swagger.SwaggerHelpers;
import org.opencdmp.controllers.swagger.annotation.OperationWithTenantHeader;
import org.opencdmp.controllers.swagger.annotation.Swagger400;
import org.opencdmp.controllers.swagger.annotation.Swagger404;
import org.opencdmp.controllers.swagger.annotation.SwaggerCommonErrorResponses;
import org.opencdmp.data.DescriptionWorkflowEntity;
import org.opencdmp.model.builder.descriptionworkflow.DescriptionWorkflowBuilder;
import org.opencdmp.model.censorship.descriptionworkflow.DescriptionWorkflowCensor;
import org.opencdmp.model.descriptionworkflow.DescriptionWorkflow;
import org.opencdmp.model.persist.descriptionworkflow.DescriptionWorkflowPersist;
import org.opencdmp.model.result.QueryResult;
import org.opencdmp.query.DescriptionWorkflowQuery;
import org.opencdmp.query.lookup.DescriptionWorkflowLookup;
import org.opencdmp.service.descriptionworkflow.DescriptionWorkflowService;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.management.InvalidApplicationException;
import java.util.*;
@RestController
@RequestMapping(path = "api/description-workflow")
@io.swagger.v3.oas.annotations.tags.Tag(name = "DescriptionWorkflows", description = "Manage description workflows")
@SwaggerCommonErrorResponses
public class DescriptionWorkflowController {
private final static LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionWorkflowController.class));
private final BuilderFactory builderFactory;
private final CensorFactory censorFactory;
private final QueryFactory queryFactory;
private final DescriptionWorkflowService descriptionWorkflowService;
private final AuditService auditService;
private final TenantScope tenantScope;
private final MessageSource messageSource;
public DescriptionWorkflowController(BuilderFactory builderFactory, CensorFactory censorFactory, QueryFactory queryFactory, DescriptionWorkflowService descriptionWorkflowService, AuditService auditService, TenantScope tenantScope, MessageSource messageSource) {
this.builderFactory = builderFactory;
this.censorFactory = censorFactory;
this.queryFactory = queryFactory;
this.descriptionWorkflowService = descriptionWorkflowService;
this.auditService = auditService;
this.tenantScope = tenantScope;
this.messageSource = messageSource;
}
@PostMapping("query")
@OperationWithTenantHeader(summary = "Query all descriptionWorkflows", description = SwaggerHelpers.Tag.endpoint_query, requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = SwaggerHelpers.Tag.endpoint_query_request_body, content = @Content(
examples = {
@ExampleObject(
name = SwaggerHelpers.Commons.pagination_example,
description = SwaggerHelpers.Commons.pagination_example_description,
value = SwaggerHelpers.Tag.endpoint_query_request_body_example
)
}
)), responses = @ApiResponse(description = "OK", responseCode = "200", content = @Content(
array = @ArraySchema(
schema = @Schema(
implementation = DescriptionWorkflow.class
)
),
examples = @ExampleObject(
name = SwaggerHelpers.Commons.pagination_response_example,
description = SwaggerHelpers.Commons.pagination_response_example_description,
value = SwaggerHelpers.Tag.endpoint_query_response_example
))))
public QueryResult<DescriptionWorkflow> Query(@RequestBody DescriptionWorkflowLookup lookup) {
logger.debug("querying {}", DescriptionWorkflow.class.getSimpleName());
this.censorFactory.censor(DescriptionWorkflowCensor.class).censor(lookup.getProject(), null);
DescriptionWorkflowQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.AllExceptPublic);
List<DescriptionWorkflowEntity> data = query.collectAs(lookup.getProject());
List<DescriptionWorkflow> models = this.builderFactory.builder(DescriptionWorkflowBuilder.class).build(lookup.getProject(), data);
long count = ( lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.DescriptionWorkflow_Query);
return new QueryResult<>(models, count);
}
@GetMapping("{id}")
@OperationWithTenantHeader(summary = "Fetch a specific description workflow by id", description = "",
responses = @ApiResponse(description = "OK", responseCode = "200", content = @Content(
schema = @Schema(
implementation = DescriptionWorkflow.class
))
))
@Swagger404
public DescriptionWorkflow Get(
@Parameter(name = "id", description = "The id of a Description Workflow to fetch", example = "c0c163dc-2965-45a5-9608-f76030578609", required = true) @PathVariable UUID id,
@Parameter(name = "fieldSet", description = SwaggerHelpers.Commons.fieldset_description, required = true) FieldSet fieldSet,
Locale locale
) {
logger.debug(new MapLogEntry("retrieving" + DescriptionWorkflow.class.getSimpleName()).And("id", id).And("fieldSet", fieldSet));
this.censorFactory.censor(DescriptionWorkflowCensor.class).censor(fieldSet, null);
DescriptionWorkflowQuery query = this.queryFactory.query(DescriptionWorkflowQuery.class).authorize(AuthorizationFlags.AllExceptPublic).ids(id);
DescriptionWorkflow model = this.builderFactory.builder(DescriptionWorkflowBuilder.class).build(fieldSet, query.firstAs(fieldSet));
if (model == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionWorkflow.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.DescriptionWorkflow_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fieldSet", fieldSet)
));
return model;
}
@GetMapping("current-tenant")
@OperationWithTenantHeader(summary = "Fetch a specific description workflow by current tenant", description = "",
responses = @ApiResponse(description = "OK", responseCode = "200", content = @Content(
schema = @Schema(
implementation = DescriptionWorkflow.class
))
))
@Swagger404
public DescriptionWorkflow GetByCurrentTenant(
@Parameter(name = "fieldSet", description = SwaggerHelpers.Commons.fieldset_description, required = true) FieldSet fieldSet,
Locale locale
) throws InvalidApplicationException {
logger.debug(new MapLogEntry("retrieving" + DescriptionWorkflow.class.getSimpleName()).And("fieldSet", fieldSet));
this.censorFactory.censor(DescriptionWorkflowCensor.class).censor(fieldSet, null);
DescriptionWorkflowQuery query = this.queryFactory.query(DescriptionWorkflowQuery.class).authorize(AuthorizationFlags.AllExceptPublic);
if (this.tenantScope.isDefaultTenant())
query = query.defaultTenant(true);
else
query = query.tenantIds(this.tenantScope.getTenant());
DescriptionWorkflow model = this.builderFactory.builder(DescriptionWorkflowBuilder.class).build(fieldSet, query.firstAs(fieldSet));
if (model == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{DescriptionWorkflow.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.DescriptionWorkflow_Lookup, "fieldSet", fieldSet);
return model;
}
@PostMapping("persist")
@OperationWithTenantHeader(summary = "Create a new or update an existing description workflow", description = "",
responses = @ApiResponse(description = "OK", responseCode = "200", content = @Content(
schema = @Schema(
implementation = DescriptionWorkflow.class
))
))
@Swagger400
@Swagger404
@Transactional
@ValidationFilterAnnotation(validator = DescriptionWorkflowPersist.DescriptionWorkflowPersistValidator.ValidatorName, argumentName = "model")
public DescriptionWorkflow Persist(
@RequestBody DescriptionWorkflowPersist model,
@Parameter(name = "fieldSet", description = SwaggerHelpers.Commons.fieldset_description, required = true) FieldSet fieldSet
) throws InvalidApplicationException {
logger.debug(new MapLogEntry("persisting"+DescriptionWorkflow.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
DescriptionWorkflow persisted = this.descriptionWorkflowService.persist(model, fieldSet);
this.auditService.track(AuditableAction.DescriptionWorkflow_Persist, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fieldSet", fieldSet)
));
return persisted;
}
@DeleteMapping("{id}")
@OperationWithTenantHeader(summary = "Delete a description workflow by id", description = "",
responses = @ApiResponse(description = "OK", responseCode = "200"))
@Swagger404
@Transactional
public void Delete(
@Parameter(name = "id", description = "The id of description workflow to delete", example = "c0c163dc-2965-45a5-9608-f76030578609", required = true) @PathVariable UUID id
) throws InvalidApplicationException {
logger.debug(new MapLogEntry("deleting"+DescriptionWorkflow.class.getSimpleName()).And("id", id));
this.descriptionWorkflowService.deleteAndSave(id);
this.auditService.track(AuditableAction.DescriptionWorkflow_Delete, "id", id);
}
}

View File

@ -45,7 +45,7 @@ import java.util.*;
@RestController
@RequestMapping(path = "api/plan-status")
@io.swagger.v3.oas.annotations.tags.Tag(name = "PlanStatuses", description = "Manage tags")
@io.swagger.v3.oas.annotations.tags.Tag(name = "PlanStatuses", description = "Manage plan statuses")
@SwaggerCommonErrorResponses
public class PlanStatusController {

View File

@ -20,6 +20,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.xml.bind.JAXBException;
import org.opencdmp.audit.AuditableAction;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.controllers.swagger.SwaggerHelpers;
import org.opencdmp.controllers.swagger.annotation.OperationWithTenantHeader;
import org.opencdmp.controllers.swagger.annotation.Swagger400;
@ -45,7 +46,7 @@ import java.util.*;
@RestController
@RequestMapping(path = "api/plan-workflow")
@io.swagger.v3.oas.annotations.tags.Tag(name = "PlanWorkflows", description = "Manage tags")
@io.swagger.v3.oas.annotations.tags.Tag(name = "PlanWorkflows", description = "Manage plan workflows")
@SwaggerCommonErrorResponses
public class PlanWorkflowController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PlanWorkflowController.class));
@ -60,6 +61,8 @@ public class PlanWorkflowController {
private final QueryFactory queryFactory;
private final TenantScope tenantScope;
private final MessageSource messageSource;
public PlanWorkflowController(
@ -67,13 +70,14 @@ public class PlanWorkflowController {
AuditService auditService,
PlanWorkflowService planWorkflowService,
CensorFactory censorFactory,
QueryFactory queryFactory,
QueryFactory queryFactory, TenantScope tenantScope,
MessageSource messageSource) {
this.builderFactory = builderFactory;
this.auditService = auditService;
this.planWorkflowService = planWorkflowService;
this.censorFactory = censorFactory;
this.queryFactory = queryFactory;
this.tenantScope = tenantScope;
this.messageSource = messageSource;
}
@ -143,6 +147,38 @@ public class PlanWorkflowController {
return model;
}
@GetMapping("current-tenant")
@OperationWithTenantHeader(summary = "Fetch a specific plan workflow by current tenant", description = "",
responses = @ApiResponse(description = "OK", responseCode = "200", content = @Content(
schema = @Schema(
implementation = PlanWorkflow.class
))
))
@Swagger404
public PlanWorkflow GetByCurrentTenant(
@Parameter(name = "fieldSet", description = SwaggerHelpers.Commons.fieldset_description, required = true) FieldSet fieldSet,
Locale locale
) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
logger.debug(new MapLogEntry("retrieving" + PlanWorkflow.class.getSimpleName()).And("fields", fieldSet));
this.censorFactory.censor(PlanWorkflowCensor.class).censor(fieldSet, null);
PlanWorkflowQuery query = this.queryFactory.query(PlanWorkflowQuery.class).disableTracking().authorize(AuthorizationFlags.AllExceptPublic);
if (this.tenantScope.isDefaultTenant())
query = query.defaultTenant(true);
else
query = query.tenantIds(this.tenantScope.getTenant());
PlanWorkflow model = this.builderFactory.builder(PlanWorkflowBuilder.class).build(fieldSet, query.firstAs(fieldSet));
if (model == null)
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{PlanWorkflow.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.PlanWorkflow_Lookup, "fields", fieldSet);
return model;
}
@PostMapping("persist")
@OperationWithTenantHeader(summary = "Create a new or update an existing PlanWorkflow", description = "",
responses = @ApiResponse(description = "OK", responseCode = "200", content = @Content(
@ -156,7 +192,7 @@ public class PlanWorkflowController {
@ValidationFilterAnnotation(validator = PlanWorkflowPersist.PlanWorkflowPersistValidator.ValidatorName, argumentName = "model")
public PlanWorkflow Persist(
@RequestBody PlanWorkflowPersist model,
@Parameter(name = "fieldSet",description = SwaggerHelpers.Commons.fieldset_description, required = true) FieldSet fieldSet
@Parameter(name = "fieldSet", description = SwaggerHelpers.Commons.fieldset_description, required = true) FieldSet fieldSet
) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException {
logger.debug(new MapLogEntry("persisting"+PlanWorkflow.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
PlanWorkflow persisted = this.planWorkflowService.persist(model, fieldSet);

View File

@ -0,0 +1,27 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.075';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
CREATE TABLE public."DescriptionWorkflow"
(
id uuid NOT NULL,
name character varying(250) COLLATE pg_catalog."default" NOT NULL,
description text COLLATE pg_catalog."default",
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
is_active smallint NOT NULL,
definition xml,
tenant uuid,
CONSTRAINT "DescriptionWorkflow_pkey" PRIMARY KEY (id),
CONSTRAINT "DescriptionWorkflow_tenant_fkey" FOREIGN KEY (tenant)
REFERENCES public."Tenant" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID
);
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.075', '2024-08-26 12:00:00.000000+02', now(), 'Add description workflow table.');
END$$;