diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/dashborad/RecentActivityItemEntity.java b/backend/core/src/main/java/org/opencdmp/commons/types/dashborad/RecentActivityItemEntity.java index 8e7b23592..5fd70fdd4 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/dashborad/RecentActivityItemEntity.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/dashborad/RecentActivityItemEntity.java @@ -10,14 +10,14 @@ public class RecentActivityItemEntity { private UUID id; private Instant updatedAt; private String label; - private Short statusValue; + private UUID statusId; - public RecentActivityItemEntity(RecentActivityItemType type, UUID id, Instant updatedAt, String label, Short statusValue) { + public RecentActivityItemEntity(RecentActivityItemType type, UUID id, Instant updatedAt, String label, UUID statusId) { this.type = type; this.id = id; this.updatedAt = updatedAt; this.label = label; - this.statusValue = statusValue; + this.statusId = statusId; } public RecentActivityItemType getType() { @@ -52,11 +52,11 @@ public class RecentActivityItemEntity { this.label = label; } - public Short getStatusValue() { - return statusValue; + public UUID getStatusId() { + return statusId; } - public void setStatusValue(Short statusValue) { - this.statusValue = statusValue; + public void setStatusId(UUID statusId) { + this.statusId = statusId; } } diff --git a/backend/core/src/main/java/org/opencdmp/elastic/data/DescriptionElasticEntity.java b/backend/core/src/main/java/org/opencdmp/elastic/data/DescriptionElasticEntity.java index 5b0d8cc8f..15f38125e 100644 --- a/backend/core/src/main/java/org/opencdmp/elastic/data/DescriptionElasticEntity.java +++ b/backend/core/src/main/java/org/opencdmp/elastic/data/DescriptionElasticEntity.java @@ -33,9 +33,9 @@ public class DescriptionElasticEntity { private String description; public final static String _description = "description"; - @Field(value = DescriptionElasticEntity._status, type = FieldType.Short) - private DescriptionStatus status; - public final static String _status = "status"; + @Field(value = DescriptionElasticEntity._statusId, type = FieldType.Keyword) + private UUID statusId; + public final static String _statusId = "statusId"; @Field(value = DescriptionElasticEntity._finalizedAt, type = FieldType.Date) private Date finalizedAt; @@ -97,12 +97,12 @@ public class DescriptionElasticEntity { this.description = description; } - public DescriptionStatus getStatus() { - return this.status; + public UUID getStatusId() { + return statusId; } - public void setStatus(DescriptionStatus status) { - this.status = status; + public void setStatusId(UUID statusId) { + this.statusId = statusId; } public Date getFinalizedAt() { diff --git a/backend/core/src/main/java/org/opencdmp/elastic/data/PlanElasticEntity.java b/backend/core/src/main/java/org/opencdmp/elastic/data/PlanElasticEntity.java index 3d8e3e8b5..9a2350443 100644 --- a/backend/core/src/main/java/org/opencdmp/elastic/data/PlanElasticEntity.java +++ b/backend/core/src/main/java/org/opencdmp/elastic/data/PlanElasticEntity.java @@ -35,9 +35,9 @@ public class PlanElasticEntity { private Short version; public final static String _version = "version"; - @Field(value = PlanElasticEntity._status, type = FieldType.Short) - private PlanStatus status; - public final static String _status = "status"; + @Field(value = PlanElasticEntity._statusId, type = FieldType.Keyword) + private UUID statusId; + public final static String _statusId = "statusId"; @Field(value = PlanElasticEntity._accessType, type = FieldType.Short) private PlanAccessType accessType; @@ -130,12 +130,12 @@ public class PlanElasticEntity { this.version = version; } - public PlanStatus getStatus() { - return this.status; + public UUID getStatusId() { + return statusId; } - public void setStatus(PlanStatus status) { - this.status = status; + public void setStatusId(UUID statusId) { + this.statusId = statusId; } public PlanAccessType getAccessType() { diff --git a/backend/core/src/main/java/org/opencdmp/elastic/data/nested/NestedPlanElasticEntity.java b/backend/core/src/main/java/org/opencdmp/elastic/data/nested/NestedPlanElasticEntity.java index cd9d84e06..1b1a717eb 100644 --- a/backend/core/src/main/java/org/opencdmp/elastic/data/nested/NestedPlanElasticEntity.java +++ b/backend/core/src/main/java/org/opencdmp/elastic/data/nested/NestedPlanElasticEntity.java @@ -35,9 +35,9 @@ public class NestedPlanElasticEntity { private PlanVersionStatus versionStatus; public final static String _versionStatus = "versionStatus"; - @Field(value = NestedPlanElasticEntity._status, type = FieldType.Short) - private PlanStatus status; - public final static String _status = "status"; + @Field(value = NestedPlanElasticEntity._statusId, type = FieldType.Keyword) + private UUID statusId; + public final static String _statusId = "statusId"; @Field(value = NestedPlanElasticEntity._accessType, type = FieldType.Short) private PlanAccessType accessType; @@ -103,12 +103,12 @@ public class NestedPlanElasticEntity { this.version = version; } - public PlanStatus getStatus() { - return status; + public UUID getStatusId() { + return statusId; } - public void setStatus(PlanStatus status) { - this.status = status; + public void setStatusId(UUID statusId) { + this.statusId = statusId; } public PlanAccessType getAccessType() { diff --git a/backend/core/src/main/java/org/opencdmp/elastic/elasticbuilder/DescriptionElasticBuilder.java b/backend/core/src/main/java/org/opencdmp/elastic/elasticbuilder/DescriptionElasticBuilder.java index 6cc4f11a8..6b8aa3ba4 100644 --- a/backend/core/src/main/java/org/opencdmp/elastic/elasticbuilder/DescriptionElasticBuilder.java +++ b/backend/core/src/main/java/org/opencdmp/elastic/elasticbuilder/DescriptionElasticBuilder.java @@ -63,7 +63,7 @@ public class DescriptionElasticBuilder extends BaseElasticBuilder excludedIds; private Collection tenantIds; - private Collection statuses; + private Collection statusIds; private NestedDescriptionTemplateElasticQuery descriptionTemplateSubQuery; private NestedReferenceElasticQuery referenceSubQuery; private NestedTagElasticQuery tagSubQuery; @@ -133,18 +133,18 @@ public class DescriptionElasticQuery extends ElasticQuery values) { - this.statuses = values; + public DescriptionElasticQuery statusIds(Collection values) { + this.statusIds = values; return this; } @@ -189,7 +189,7 @@ public class DescriptionElasticQuery extends ElasticQuery predicates = new ArrayList<>(); if (usePublic ) { predicates.add(this.and( - this.equals(new ElasticField(DescriptionElasticEntity._plan + "." + PlanElasticEntity._status, this.entityClass()).disableInfer(true), PlanStatus.Finalized.getValue()), + this.equals(new ElasticField(DescriptionElasticEntity._plan + "." + PlanElasticEntity._statusId, this.entityClass()).disableInfer(true), PlanStatus.Finalized.getValue()), this.equals(new ElasticField(DescriptionElasticEntity._plan + "." + PlanElasticEntity._accessType, this.entityClass()).disableInfer(true), PlanAccessType.Public.getValue()) )); } @@ -284,8 +284,8 @@ public class DescriptionElasticQuery extends ElasticQuery ids; private Collection excludedIds; - private Collection statuses; + private Collection statusIds; private Collection versionStatuses; private Collection accessTypes; private Collection versions; @@ -108,18 +108,18 @@ public class InnerObjectPlanElasticQuery extends ElasticInnerObjectQuery values) { - this.statuses = values; + public InnerObjectPlanElasticQuery statusIds(Collection values) { + this.statusIds = values; return this; } @@ -203,8 +203,8 @@ public class InnerObjectPlanElasticQuery extends ElasticInnerObjectQuery x.getValue()).collect(Collectors.toList()).toArray(new Short[this.statuses.size()]))._toQuery()); + if (this.statusIds != null) { + predicates.add(this.containsUUID(this.elasticFieldOf(NestedPlanElasticEntity._id).disableInfer(true), this.statusIds)._toQuery()); } if (this.versionStatuses != null) { predicates.add(this.contains(this.elasticFieldOf(NestedPlanElasticEntity._versionStatus).disableInfer(true), this.versionStatuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[this.versionStatuses.size()]))._toQuery()); @@ -229,7 +229,7 @@ public class InnerObjectPlanElasticQuery extends ElasticInnerObjectQuery { private String like; private Collection ids; private Collection excludedIds; - private Collection statuses; + private Collection statusIds; private Collection versionStatuses; private Collection accessTypes; private Collection versions; @@ -140,18 +140,18 @@ public class PlanElasticQuery extends ElasticQuery { return this; } - public PlanElasticQuery statuses(PlanStatus value) { - this.statuses = List.of(value); + public PlanElasticQuery statuses(UUID value) { + this.statusIds = List.of(value); return this; } - public PlanElasticQuery statuses(PlanStatus... value) { - this.statuses = Arrays.asList(value); + public PlanElasticQuery statuses(UUID... value) { + this.statusIds = Arrays.asList(value); return this; } - public PlanElasticQuery statuses(Collection values) { - this.statuses = values; + public PlanElasticQuery statuses(Collection values) { + this.statusIds = values; return this; } @@ -224,7 +224,7 @@ public class PlanElasticQuery extends ElasticQuery { @Override protected Boolean isFalseQuery() { - return this.isEmpty(this.ids) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.excludedIds) || this.isEmpty(this.accessTypes)|| this.isEmpty(this.statuses); + return this.isEmpty(this.ids) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.excludedIds) || this.isEmpty(this.accessTypes)|| this.isEmpty(this.statusIds); } @Override @@ -265,7 +265,7 @@ public class PlanElasticQuery extends ElasticQuery { List predicates = new ArrayList<>(); if (usePublic) { predicates.add(this.and( - this.equals(this.elasticFieldOf(PlanElasticEntity._status), PlanStatus.Finalized.getValue()), + this.equals(this.elasticFieldOf(PlanElasticEntity._statusId), PlanStatus.Finalized.getValue()), this.equals(this.elasticFieldOf(PlanElasticEntity._accessType), PlanAccessType.Public.getValue()) )); } @@ -328,8 +328,8 @@ public class PlanElasticQuery extends ElasticQuery { if (this.excludedIds != null) { predicates.add(this.not(this.containsUUID(this.elasticFieldOf(PlanElasticEntity._id), this.excludedIds)._toQuery())._toQuery()); } - if (this.statuses != null) { - predicates.add(this.contains(this.elasticFieldOf(PlanElasticEntity._status), this.statuses.stream().map(PlanStatus::getValue).toList().toArray(new Short[this.statuses.size()]))._toQuery()); + if (this.statusIds != null) { + predicates.add(this.containsUUID(this.elasticFieldOf(PlanElasticEntity._statusId), this.statusIds)._toQuery()); } if (this.versionStatuses != null) { predicates.add(this.contains(this.elasticFieldOf(PlanElasticEntity._versionStatus), this.versionStatuses.stream().map(PlanVersionStatus::getValue).toList().toArray(new Short[this.versionStatuses.size()]))._toQuery()); @@ -363,7 +363,7 @@ public class PlanElasticQuery extends ElasticQuery { if (columns.contains(PlanElasticEntity._id)) mocDoc.setId(FieldBasedMapper.shallowSafeConversion(rawData.get(PlanElasticEntity._id), UUID.class)); if (columns.contains(PlanElasticEntity._label)) mocDoc.setLabel(FieldBasedMapper.shallowSafeConversion(rawData.get(PlanElasticEntity._label), String.class)); if (columns.contains(PlanElasticEntity._description)) mocDoc.setDescription(FieldBasedMapper.shallowSafeConversion(rawData.get(PlanElasticEntity._description), String.class)); - if (columns.contains(PlanElasticEntity._status)) mocDoc.setStatus(FieldBasedMapper.shallowSafeConversion(rawData.get(PlanElasticEntity._status), PlanStatus.class)); + if (columns.contains(PlanElasticEntity._statusId)) mocDoc.setStatusId(FieldBasedMapper.shallowSafeConversion(rawData.get(PlanElasticEntity._statusId), UUID.class)); if (columns.contains(PlanElasticEntity._versionStatus)) mocDoc.setVersionStatus(FieldBasedMapper.shallowSafeConversion(rawData.get(PlanElasticEntity._versionStatus), PlanVersionStatus.class)); if (columns.contains(PlanElasticEntity._version)) mocDoc.setVersion(FieldBasedMapper.shallowSafeConversion(rawData.get(PlanElasticEntity._version), Short.class)); if (columns.contains(PlanElasticEntity._groupId)) mocDoc.setGroupId(FieldBasedMapper.shallowSafeConversion(rawData.get(PlanElasticEntity._groupId), UUID.class)); @@ -383,7 +383,7 @@ public class PlanElasticQuery extends ElasticQuery { if (item.match(PlanElasticEntity._id)) return this.elasticFieldOf(PlanElasticEntity._id); else if (item.match(PlanElasticEntity._label)) return item instanceof OrderingFieldResolver ? this.elasticFieldOf(PlanElasticEntity._label).subfield(ElasticConstants.SubFields.keyword) : this.elasticFieldOf(PlanElasticEntity._label); else if (item.match(PlanElasticEntity._description)) return this.elasticFieldOf(PlanElasticEntity._description); - else if (item.match(PlanElasticEntity._status)) return this.elasticFieldOf(PlanElasticEntity._status); + else if (item.match(PlanElasticEntity._statusId)) return this.elasticFieldOf(PlanElasticEntity._statusId); else if (item.match(PlanElasticEntity._version)) return this.elasticFieldOf(PlanElasticEntity._version); else if (item.match(PlanElasticEntity._versionStatus)) return this.elasticFieldOf(PlanElasticEntity._versionStatus); else if (item.match(PlanElasticEntity._groupId)) return this.elasticFieldOf(PlanElasticEntity._groupId); diff --git a/backend/core/src/main/java/org/opencdmp/model/RecentActivityItemLookup.java b/backend/core/src/main/java/org/opencdmp/model/RecentActivityItemLookup.java index 028a96153..7b1d6b499 100644 --- a/backend/core/src/main/java/org/opencdmp/model/RecentActivityItemLookup.java +++ b/backend/core/src/main/java/org/opencdmp/model/RecentActivityItemLookup.java @@ -6,9 +6,7 @@ import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.RecentActivityOrder; import org.opencdmp.model.description.Description; import org.opencdmp.model.plan.Plan; -import org.opencdmp.query.lookup.DescriptionLookup; -import org.opencdmp.query.lookup.PlanLookup; -import org.opencdmp.query.lookup.PlanUserLookup; +import org.opencdmp.query.lookup.*; import gr.cite.tools.data.query.Ordering; import gr.cite.tools.data.query.Paging; import gr.cite.tools.fieldset.BaseFieldSet; @@ -97,8 +95,12 @@ public class RecentActivityItemLookup{ DescriptionLookup lookup = new DescriptionLookup(); lookup.setIsActive(List.of(IsActive.Active)); if (this.like != null) lookup.setLike(this.like); - if (this.onlyDraft != null) lookup.setStatuses(List.of(DescriptionStatus.Draft)); - else lookup.setStatuses(List.of(DescriptionStatus.Draft, DescriptionStatus.Finalized)); + if (this.onlyDraft != null) { + DescriptionStatusLookup descriptionStatusLookup = new DescriptionStatusLookup(); + descriptionStatusLookup.setInternalStatuses(List.of(DescriptionStatus.Draft)); + descriptionStatusLookup.setIsActive(List.of(IsActive.Active)); + lookup.setDescriptionStatusSubQuery(descriptionStatusLookup); + } if (this.userIds != null) { PlanLookup planLookup = new PlanLookup(); PlanUserLookup planUserLookup = new PlanUserLookup(); @@ -131,7 +133,12 @@ public class RecentActivityItemLookup{ PlanLookup lookup = new PlanLookup(); lookup.setIsActive(List.of(IsActive.Active)); if (this.like != null) lookup.setLike(this.like); - if (this.onlyDraft != null) lookup.setStatuses(List.of(PlanStatus.Draft)); + if (this.onlyDraft != null) { + PlanStatusLookup planStatusLookup = new PlanStatusLookup(); + planStatusLookup.setInternalStatuses(List.of(PlanStatus.Draft)); + planStatusLookup.setIsActive(List.of(IsActive.Active)); + lookup.setPlanStatusSubQuery(planStatusLookup); + } if (this.userIds != null) { PlanUserLookup planUserLookup = new PlanUserLookup(); planUserLookup.setUserIds(this.userIds); diff --git a/backend/core/src/main/java/org/opencdmp/model/builder/commonmodels/description/DescriptionCommonModelBuilder.java b/backend/core/src/main/java/org/opencdmp/model/builder/commonmodels/description/DescriptionCommonModelBuilder.java index f8fbb106b..f209e94be 100644 --- a/backend/core/src/main/java/org/opencdmp/model/builder/commonmodels/description/DescriptionCommonModelBuilder.java +++ b/backend/core/src/main/java/org/opencdmp/model/builder/commonmodels/description/DescriptionCommonModelBuilder.java @@ -28,6 +28,7 @@ import org.opencdmp.model.descriptiontemplate.DescriptionTemplate; import org.opencdmp.query.DescriptionTemplateQuery; import org.opencdmp.query.PlanDescriptionTemplateQuery; import org.opencdmp.query.PlanQuery; +import org.opencdmp.query.PlanStatusQuery; import org.opencdmp.service.visibility.VisibilityService; import org.opencdmp.service.visibility.VisibilityServiceImpl; import org.slf4j.LoggerFactory; @@ -197,7 +198,8 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder { private Collection isActives; - private Collection statuses; + private Collection statusIds; private Collection planIds; @@ -72,6 +72,8 @@ public class DescriptionQuery extends QueryBase { private Collection planDescriptionTemplateIds; + private DescriptionStatusQuery descriptionStatusQuery; + private final TenantEntityManager tenantEntityManager; public DescriptionQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) { this.userScope = userScope; @@ -210,18 +212,18 @@ public class DescriptionQuery extends QueryBase { return this; } - public DescriptionQuery statuses(DescriptionStatus value) { - this.statuses = List.of(value); + public DescriptionQuery statusIds(UUID value) { + this.statusIds = List.of(value); return this; } - public DescriptionQuery statuses(DescriptionStatus... value) { - this.statuses = Arrays.asList(value); + public DescriptionQuery statusIds(UUID... value) { + this.statusIds = Arrays.asList(value); return this; } - public DescriptionQuery statuses(Collection values) { - this.statuses = values; + public DescriptionQuery statusIds(Collection values) { + this.statusIds = values; return this; } @@ -250,6 +252,11 @@ public class DescriptionQuery extends QueryBase { return this; } + public DescriptionQuery descriptionStatusSubQuery(DescriptionStatusQuery subQuery) { + this.descriptionStatusQuery = subQuery; + return this; + } + @Override protected EntityManager entityManager(){ return this.tenantEntityManager.getEntityManager(); @@ -261,7 +268,7 @@ public class DescriptionQuery extends QueryBase { this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.createdByIds) || this.isEmpty(this.excludedIds) || this.isFalseQuery(this.planQuery) || - this.isEmpty(this.statuses) || this.isFalseQuery(this.planDescriptionTemplateQuery); + this.isEmpty(this.statusIds) || this.isFalseQuery(this.planDescriptionTemplateQuery); } @Override @@ -349,9 +356,9 @@ public class DescriptionQuery extends QueryBase { inClause.value(item); predicates.add(inClause); } - if (this.statuses != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._status)); - for (DescriptionStatus item : this.statuses) + if (this.statusIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._statusId)); + for (UUID item : this.statusIds) inClause.value(item); predicates.add(inClause); } @@ -381,6 +388,10 @@ public class DescriptionQuery extends QueryBase { inClause.value(item); predicates.add(inClause); } + if (this.descriptionStatusQuery != null) { + QueryContext subQuery = this.applySubQuery(this.descriptionStatusQuery, queryContext, UUID.class, descriptionStatusEntityRoot -> descriptionStatusEntityRoot.get(DescriptionStatusEntity._id)); + predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._statusId)).value(subQuery.Query)); + } if (!predicates.isEmpty()) { Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); diff --git a/backend/core/src/main/java/org/opencdmp/query/PlanQuery.java b/backend/core/src/main/java/org/opencdmp/query/PlanQuery.java index 19ad1f409..aff62586f 100644 --- a/backend/core/src/main/java/org/opencdmp/query/PlanQuery.java +++ b/backend/core/src/main/java/org/opencdmp/query/PlanQuery.java @@ -39,7 +39,7 @@ public class PlanQuery extends QueryBase { private Collection isActives; - private Collection statuses; + private Collection statusIds; private Collection versionStatuses; @@ -61,6 +61,8 @@ public class PlanQuery extends QueryBase { private EntityDoiQuery entityDoiQuery; + private PlanStatusQuery planStatusQuery; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); private final UserScope userScope; @@ -177,18 +179,18 @@ public class PlanQuery extends QueryBase { return this; } - public PlanQuery statuses(PlanStatus value) { - this.statuses = List.of(value); + public PlanQuery statusIds(UUID value) { + this.statusIds = List.of(value); return this; } - public PlanQuery statuses(PlanStatus... value) { - this.statuses = Arrays.asList(value); + public PlanQuery statusIds(UUID... value) { + this.statusIds = Arrays.asList(value); return this; } - public PlanQuery statuses(Collection values) { - this.statuses = values; + public PlanQuery statusIds(Collection values) { + this.statusIds = values; return this; } @@ -253,6 +255,11 @@ public class PlanQuery extends QueryBase { return this; } + public PlanQuery planStatusSubQuery(PlanStatusQuery subQuery) { + this.planStatusQuery = subQuery; + return this; + } + public PlanQuery authorize(EnumSet values) { this.authorize = values; return this; @@ -275,7 +282,7 @@ public class PlanQuery extends QueryBase { @Override protected Boolean isFalseQuery() { - return this.isEmpty(this.ids) || this.isEmpty(this.creatorIds) || this.isEmpty(this.isActives) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.excludedIds) || this.isEmpty(this.accessTypes) || this.isEmpty(this.statuses) || this.isFalseQuery(this.planDescriptionTemplateQuery) || this.isFalseQuery(this.planUserQuery); + return this.isEmpty(this.ids) || this.isEmpty(this.creatorIds) || this.isEmpty(this.isActives) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.excludedIds) || this.isEmpty(this.accessTypes) || this.isEmpty(this.statusIds) || this.isFalseQuery(this.planDescriptionTemplateQuery) || this.isFalseQuery(this.planUserQuery); } @Override @@ -347,9 +354,9 @@ public class PlanQuery extends QueryBase { inClause.value(item); predicates.add(inClause); } - if (this.statuses != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(PlanEntity._status)); - for (PlanStatus item : this.statuses) + if (this.statusIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(PlanEntity._statusId)); + for (UUID item : this.statusIds) inClause.value(item); predicates.add(inClause); } @@ -407,6 +414,11 @@ public class PlanQuery extends QueryBase { predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(PlanEntity._id)).value(subQuery.Query)); } + if (this.planStatusQuery != null) { + QueryContext subQuery = this.applySubQuery(this.planStatusQuery, queryContext, UUID.class, planStatusEntityRoot -> planStatusEntityRoot.get(PlanStatusEntity._id)); + predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(PlanEntity._statusId)).value(subQuery.Query)); + } + if (!predicates.isEmpty()) { Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); return queryContext.CriteriaBuilder.and(predicatesArray); diff --git a/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionLookup.java b/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionLookup.java index 94502c3b3..02efe005e 100644 --- a/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionLookup.java +++ b/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionLookup.java @@ -3,7 +3,6 @@ package org.opencdmp.query.lookup; import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.QueryFactory; import org.apache.commons.lang3.StringUtils; -import org.opencdmp.commons.enums.DescriptionStatus; import org.opencdmp.commons.enums.IsActive; import org.opencdmp.elastic.query.DescriptionElasticQuery; import org.opencdmp.query.DescriptionQuery; @@ -31,7 +30,8 @@ public class DescriptionLookup extends Lookup { private List isActive; - private List statuses; + private List statusIds; + private DescriptionStatusLookup descriptionStatusSubQuery; public String getLike() { return this.like; @@ -65,12 +65,12 @@ public class DescriptionLookup extends Lookup { this.isActive = isActive; } - public List getStatuses() { - return this.statuses; + public List getStatusIds() { + return statusIds; } - public void setStatuses(List statuses) { - this.statuses = statuses; + public void setStatusIds(List statusIds) { + this.statusIds = statusIds; } public PlanLookup getPlanSubQuery() { @@ -127,6 +127,14 @@ public class DescriptionLookup extends Lookup { this.finalizedBefore = finalizedBefore; } + public DescriptionStatusLookup getDescriptionStatusSubQuery() { + return descriptionStatusSubQuery; + } + + public void setDescriptionStatusSubQuery(DescriptionStatusLookup descriptionStatusSubQuery) { + this.descriptionStatusSubQuery = descriptionStatusSubQuery; + } + public DescriptionQuery enrich(QueryFactory queryFactory) { DescriptionQuery query = queryFactory.query(DescriptionQuery.class); if (this.like != null) query.like(this.like); @@ -138,11 +146,12 @@ public class DescriptionLookup extends Lookup { if (this.descriptionReferenceSubQuery != null) query.descriptionReferenceSubQuery(this.descriptionReferenceSubQuery.enrich(queryFactory)); if (this.descriptionTagSubQuery != null) query.descriptionTagSubQuery(this.descriptionTagSubQuery.enrich(queryFactory)); if (this.isActive != null) query.isActive(this.isActive); - if (this.statuses != null) query.statuses(this.statuses); + if (this.statusIds != null) query.statusIds(this.statusIds); if (this.createdAfter != null) query.createdAfter(this.createdAfter); if (this.createdBefore != null) query.createdBefore(this.createdBefore); if (this.finalizedAfter != null) query.finalizedAfter(this.finalizedAfter); if (this.finalizedBefore != null) query.finalizedBefore(this.finalizedBefore); + if (this.descriptionStatusSubQuery != null) query.descriptionStatusSubQuery(this.descriptionStatusSubQuery.enrich(queryFactory)); this.enrichCommon(query); @@ -154,7 +163,7 @@ public class DescriptionLookup extends Lookup { if (this.like != null) query.like(StringUtils.strip(this.like, "%")); if (this.ids != null) query.ids(this.ids); if (this.excludedIds != null) query.excludedIds(this.excludedIds); - if (this.statuses != null) query.statuses(this.statuses); + if (this.statusIds != null) query.statusIds(this.statusIds); if (this.createdAfter != null) query.createdAfter(this.createdAfter); if (this.createdBefore != null) query.createdBefore(this.createdBefore); if (this.finalizedAfter != null) query.finalizedAfter(this.finalizedAfter); diff --git a/backend/core/src/main/java/org/opencdmp/query/lookup/PlanLookup.java b/backend/core/src/main/java/org/opencdmp/query/lookup/PlanLookup.java index de1cb71ae..e36f03054 100644 --- a/backend/core/src/main/java/org/opencdmp/query/lookup/PlanLookup.java +++ b/backend/core/src/main/java/org/opencdmp/query/lookup/PlanLookup.java @@ -4,7 +4,6 @@ import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.QueryFactory; import org.apache.commons.lang3.StringUtils; import org.opencdmp.commons.enums.PlanAccessType; -import org.opencdmp.commons.enums.PlanStatus; import org.opencdmp.commons.enums.PlanVersionStatus; import org.opencdmp.commons.enums.IsActive; import org.opencdmp.elastic.query.PlanElasticQuery; @@ -27,7 +26,7 @@ public class PlanLookup extends Lookup { private List isActive; private List versionStatuses; - private List statuses; + private List statusIds; private List accessTypes; private List versions; @@ -36,6 +35,7 @@ public class PlanLookup extends Lookup { private PlanUserLookup planUserSubQuery; private PlanBlueprintLookup planBlueprintSubQuery; private PlanReferenceLookup planReferenceSubQuery; + private PlanStatusLookup planStatusSubQuery; public String getLike() { return this.like; @@ -73,12 +73,12 @@ public class PlanLookup extends Lookup { this.isActive = isActive; } - public List getStatuses() { - return this.statuses; + public List getStatusIds() { + return statusIds; } - public void setStatuses(List statuses) { - this.statuses = statuses; + public void setStatusIds(List statusIds) { + this.statusIds = statusIds; } public List getVersions() { @@ -138,6 +138,14 @@ public class PlanLookup extends Lookup { public void setPlanReferenceLookup(PlanReferenceLookup planReferenceSubQuery) { this.planReferenceSubQuery = planReferenceSubQuery; } + public PlanStatusLookup getPlanStatusSubQuery() { + return planStatusSubQuery; + } + + public void setPlanStatusSubQuery(PlanStatusLookup planStatusSubQuery) { + this.planStatusSubQuery = planStatusSubQuery; + } + public PlanQuery enrich(QueryFactory queryFactory) { PlanQuery query = queryFactory.query(PlanQuery.class); if (this.like != null) query.like(this.like); @@ -147,13 +155,14 @@ public class PlanLookup extends Lookup { if (this.excludedIds != null) query.excludedIds(this.excludedIds); if (this.accessTypes != null) query.accessTypes(this.accessTypes); if (this.isActive != null) query.isActive(this.isActive); - if (this.statuses != null) query.statuses(this.statuses); + if (this.statusIds != null) query.statusIds(this.statusIds); if (this.versions != null) query.versions(this.versions); if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); if (this.planDescriptionTemplateSubQuery != null) query.planDescriptionTemplateSubQuery(this.planDescriptionTemplateSubQuery.enrich(queryFactory)); if (this.planUserSubQuery != null) query.planUserSubQuery(this.planUserSubQuery.enrich(queryFactory)); if (this.planBlueprintSubQuery != null) query.planBlueprintSubQuery(this.planBlueprintSubQuery.enrich(queryFactory)); if (this.planReferenceSubQuery != null) query.planReferenceSubQuery(this.planReferenceSubQuery.enrich(queryFactory)); + if (this.planStatusSubQuery != null) query.planStatusSubQuery(this.planStatusSubQuery.enrich(queryFactory)); this.enrichCommon(query); @@ -167,7 +176,7 @@ public class PlanLookup extends Lookup { if (this.groupIds != null) query.groupIds(this.groupIds); if (this.excludedIds != null) query.excludedIds(this.excludedIds); if (this.accessTypes != null) query.accessTypes(this.accessTypes); - if (this.statuses != null) query.statuses(this.statuses); + if (this.statusIds != null) query.statuses(this.statusIds); if (this.versions != null) query.versions(this.versions); if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); if (this.planDescriptionTemplateSubQuery != null) query.planDescriptionTemplateSubQuery(this.planDescriptionTemplateSubQuery.enrichElasticInner(queryFactory)); @@ -175,6 +184,7 @@ public class PlanLookup extends Lookup { if (this.planBlueprintSubQuery != null && this.planBlueprintSubQuery.getIds() != null && !this.planBlueprintSubQuery.getIds().isEmpty()) query.blueprintIds(this.planBlueprintSubQuery.getIds()); if (this.planReferenceSubQuery != null) query.referenceSubQuery(this.planReferenceSubQuery.enrichElasticInner(queryFactory)); if (this.tenantSubQuery != null) throw new UnsupportedOperationException(); + if (this.planStatusSubQuery != null) throw new UnsupportedOperationException(); this.enrichCommon(query); @@ -188,7 +198,7 @@ public class PlanLookup extends Lookup { if (this.groupIds != null) query.groupIds(this.groupIds); if (this.excludedIds != null) query.excludedIds(this.excludedIds); if (this.accessTypes != null) query.accessTypes(this.accessTypes); - if (this.statuses != null) query.statuses(this.statuses); + if (this.statusIds != null) query.statusIds(this.statusIds); if (this.versions != null) query.versions(this.versions); if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); if (this.planDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException(""); @@ -196,6 +206,7 @@ public class PlanLookup extends Lookup { if (this.planBlueprintSubQuery != null && this.planBlueprintSubQuery.getIds() != null && !this.planBlueprintSubQuery.getIds().isEmpty()) throw new UnsupportedOperationException(""); if (this.planReferenceSubQuery != null) throw new UnsupportedOperationException(""); if (this.tenantSubQuery != null) throw new UnsupportedOperationException(); + if (this.planStatusSubQuery != null) throw new UnsupportedOperationException(); return query; } diff --git a/backend/core/src/main/java/org/opencdmp/service/dashborad/DashboardServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/dashborad/DashboardServiceImpl.java index 9e5988288..9ae8ad73a 100644 --- a/backend/core/src/main/java/org/opencdmp/service/dashborad/DashboardServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/dashborad/DashboardServiceImpl.java @@ -77,9 +77,9 @@ public class DashboardServiceImpl implements DashboardService { descriptionLookup.getPage().setOffset(0); descriptionLookup.getPage().setSize(model.getPage().getSize()+model.getPage().getOffset()); - QueryResult descriptions = this.elasticQueryHelperService.collect(descriptionLookup, AuthorizationFlags.AllExceptPublic, new BaseFieldSet().ensure(Description._id).ensure(Description._updatedAt).ensure(String.join(".",Description._status, org.opencdmp.model.descriptionstatus.DescriptionStatus._internalStatus)).ensure(Description._label)); + QueryResult descriptions = this.elasticQueryHelperService.collect(descriptionLookup, AuthorizationFlags.AllExceptPublic, new BaseFieldSet().ensure(Description._id).ensure(Description._updatedAt).ensure(String.join(".",Description._status, org.opencdmp.model.descriptionstatus.DescriptionStatus._id)).ensure(Description._label)); if (!this.conventionService.isListNullOrEmpty(descriptions.getItems())) { - for (Description description : descriptions.getItems()) recentActivityItemEntities.add(new RecentActivityItemEntity(RecentActivityItemType.Description, description.getId(), description.getUpdatedAt(), description.getLabel(), description.getStatus().getInternalStatus().getValue())); + for (Description description : descriptions.getItems()) recentActivityItemEntities.add(new RecentActivityItemEntity(RecentActivityItemType.Description, description.getId(), description.getUpdatedAt(), description.getLabel(), description.getStatus().getId())); } } @@ -88,9 +88,9 @@ public class DashboardServiceImpl implements DashboardService { planLookup.getPage().setOffset(0); planLookup.getPage().setSize(model.getPage().getSize()+model.getPage().getOffset()); - QueryResult 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))); + QueryResult 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._id))); 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().getInternalStatus().getValue())); + for (Plan plan : plans.getItems()) recentActivityItemEntities.add(new RecentActivityItemEntity(RecentActivityItemType.Plan, plan.getId(), plan.getUpdatedAt(), plan.getLabel(), plan.getStatus().getId())); } } @@ -100,7 +100,7 @@ public class DashboardServiceImpl implements DashboardService { switch (model.getOrderField()){ case Label -> comparator = Comparator.comparing(RecentActivityItemEntity::getLabel).thenComparing(RecentActivityItemEntity::getUpdatedAt); case UpdatedAt -> comparator = Comparator.comparing(RecentActivityItemEntity::getUpdatedAt); - case Status -> comparator = Comparator.comparing(RecentActivityItemEntity::getStatusValue).thenComparing(RecentActivityItemEntity::getUpdatedAt); + case Status -> comparator = Comparator.comparing(RecentActivityItemEntity::getStatusId).thenComparing(RecentActivityItemEntity::getUpdatedAt); default -> throw new IllegalArgumentException("Type not found" + model.getOrderField()) ; } } @@ -118,10 +118,12 @@ public class DashboardServiceImpl implements DashboardService { DashboardStatisticsCacheService.DashboardStatisticsCacheValue cacheValue = this.dashboardStatisticsCacheService.lookup(this.dashboardStatisticsCacheService.buildKey(DashboardStatisticsCacheService.publicKey)); if (cacheValue == null || cacheValue.getDashboardStatistics() == null) { - PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).disableTracking().isActive(IsActive.Active).versionStatuses(PlanVersionStatus.Current).statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public); + PlanStatusQuery planStatusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).disableTracking().isActive(IsActive.Active).versionStatuses(PlanVersionStatus.Current).planStatusSubQuery(planStatusQuery).accessTypes(PlanAccessType.Public); DashboardStatistics statistics = new DashboardStatistics(); statistics.setPlanCount(planQuery.authorize(EnumSet.of(Public)).count()); - statistics.setDescriptionCount(this.queryFactory.query(DescriptionQuery.class).disableTracking().isActive(IsActive.Active).planSubQuery(planQuery).statuses(DescriptionStatus.Finalized).authorize(EnumSet.of(Public)).count()); + DescriptionStatusQuery descriptionStatusQuery = this.queryFactory.query(DescriptionStatusQuery.class).disableTracking().internalStatuses(DescriptionStatus.Finalized).isActive(IsActive.Active); + statistics.setDescriptionCount(this.queryFactory.query(DescriptionQuery.class).disableTracking().isActive(IsActive.Active).planSubQuery(planQuery).descriptionStatusSubQuery(descriptionStatusQuery).authorize(EnumSet.of(Public)).count()); statistics.setReferenceTypeStatistics(new ArrayList<>()); if (!this.conventionService.isListNullOrEmpty(this.config.getReferenceTypeCounters())){ diff --git a/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java index 61ecc0ee4..5f56e6089 100644 --- a/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java @@ -1200,7 +1200,8 @@ public class DescriptionServiceImpl implements DescriptionService { } else { try { this.entityManager.disableTenantFilters(); - data = this.queryFactory.query(DescriptionQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(id).planSubQuery(this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active).statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public)).first(); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + data = this.queryFactory.query(DescriptionQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(id).planSubQuery(this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active).planStatusSubQuery(statusQuery).accessTypes(PlanAccessType.Public)).first(); this.entityManager.reloadTenantFilters(); } finally { this.entityManager.reloadTenantFilters(); @@ -1233,7 +1234,8 @@ public class DescriptionServiceImpl implements DescriptionService { DescriptionEntity data = null; try { this.entityManager.disableTenantFilters(); - data = this.queryFactory.query(DescriptionQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(id).planSubQuery(this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active).statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public)).first(); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + data = this.queryFactory.query(DescriptionQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(id).planSubQuery(this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active).planStatusSubQuery(statusQuery).accessTypes(PlanAccessType.Public)).first(); this.entityManager.reloadTenantFilters(); } finally { this.entityManager.reloadTenantFilters(); diff --git a/backend/core/src/main/java/org/opencdmp/service/elastic/ElasticServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/elastic/ElasticServiceImpl.java index 3101f10e8..d110e7dca 100644 --- a/backend/core/src/main/java/org/opencdmp/service/elastic/ElasticServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/elastic/ElasticServiceImpl.java @@ -136,7 +136,7 @@ public class ElasticServiceImpl implements ElasticService { propertyMap.put(DescriptionElasticEntity._tenantId, this.createElastic(FieldType.Keyword, false)); propertyMap.put(DescriptionElasticEntity._label, this.createElastic(FieldType.Text, true)); propertyMap.put(DescriptionElasticEntity._description, this.createElastic(FieldType.Text, true)); - propertyMap.put(DescriptionElasticEntity._status, this.createElastic(FieldType.Short, false)); + propertyMap.put(DescriptionElasticEntity._statusId, this.createElastic(FieldType.Keyword, false)); propertyMap.put(DescriptionElasticEntity._finalizedAt, this.createElastic(FieldType.Date, false)); propertyMap.put(DescriptionElasticEntity._createdAt, this.createElastic(FieldType.Date, false)); propertyMap.put(DescriptionElasticEntity._updatedAt, this.createElastic(FieldType.Date, false)); @@ -154,7 +154,7 @@ public class ElasticServiceImpl implements ElasticService { propertyMap.put(PlanElasticEntity._tenantId, this.createElastic(FieldType.Keyword, false)); propertyMap.put(PlanElasticEntity._label, this.createElastic(FieldType.Text, true)); propertyMap.put(PlanElasticEntity._description, this.createElastic(FieldType.Text, false)); - propertyMap.put(PlanElasticEntity._status, this.createElastic(FieldType.Short, false)); + propertyMap.put(PlanElasticEntity._statusId, this.createElastic(FieldType.Keyword, false)); propertyMap.put(PlanElasticEntity._version, this.createElastic(FieldType.Short, false)); propertyMap.put(PlanElasticEntity._language, this.createElastic(FieldType.Keyword, false)); propertyMap.put(PlanElasticEntity._blueprintId, this.createElastic(FieldType.Keyword, false)); @@ -230,7 +230,7 @@ public class ElasticServiceImpl implements ElasticService { propertyMap.put(NestedPlanElasticEntity._id, this.createElastic(FieldType.Keyword, false)); propertyMap.put(NestedPlanElasticEntity._label, this.createElastic(FieldType.Text, true)); propertyMap.put(NestedPlanElasticEntity._description, this.createElastic(FieldType.Text, false)); - propertyMap.put(NestedPlanElasticEntity._status, this.createElastic(FieldType.Short, false)); + propertyMap.put(NestedPlanElasticEntity._statusId, this.createElastic(FieldType.Keyword, false)); propertyMap.put(NestedPlanElasticEntity._version, this.createElastic(FieldType.Short, false)); propertyMap.put(NestedPlanElasticEntity._versionStatus, this.createElastic(FieldType.Short, false)); propertyMap.put(NestedPlanElasticEntity._language, this.createElastic(FieldType.Keyword, false)); diff --git a/backend/core/src/main/java/org/opencdmp/service/filetransformer/FileTransformerServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/filetransformer/FileTransformerServiceImpl.java index 96e8c4860..5c81519f6 100644 --- a/backend/core/src/main/java/org/opencdmp/service/filetransformer/FileTransformerServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/filetransformer/FileTransformerServiceImpl.java @@ -268,7 +268,8 @@ public class FileTransformerServiceImpl implements FileTransformerService { } else { try { this.entityManager.disableTenantFilters(); - entity = this.queryFactory.query(PlanQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(planId).isActive(IsActive.Active).statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public).first(); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + entity = this.queryFactory.query(PlanQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(planId).isActive(IsActive.Active).planStatusSubQuery(statusQuery).accessTypes(PlanAccessType.Public).first(); this.entityManager.reloadTenantFilters(); } finally { this.entityManager.reloadTenantFilters(); @@ -307,7 +308,8 @@ public class FileTransformerServiceImpl implements FileTransformerService { } else { try { this.entityManager.disableTenantFilters(); - entity = this.queryFactory.query(DescriptionQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(descriptionId).planSubQuery(this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active).statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public)).first(); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + entity = this.queryFactory.query(DescriptionQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(descriptionId).planSubQuery(this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active).planStatusSubQuery(statusQuery).accessTypes(PlanAccessType.Public)).first(); this.entityManager.reloadTenantFilters(); } finally { this.entityManager.reloadTenantFilters(); diff --git a/backend/core/src/main/java/org/opencdmp/service/metrics/MetricsServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/metrics/MetricsServiceImpl.java index 617e8b6a5..d8e7b0cb4 100644 --- a/backend/core/src/main/java/org/opencdmp/service/metrics/MetricsServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/metrics/MetricsServiceImpl.java @@ -325,21 +325,24 @@ public class MetricsServiceImpl implements MetricsService { } private double calculateDraftDmps(boolean forNexus) { - PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).disableTracking().statuses(PlanStatus.Draft).isActive(IsActive.Active); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Draft).isActives(IsActive.Active); + PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).disableTracking().planStatusSubQuery(statusQuery).isActive(IsActive.Active); if (forNexus) planQuery.after(this._config.getNexusDate()); return planQuery.count(); } private double calculateFinalizedDmps(boolean forNexus) { - PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).disableTracking().statuses(PlanStatus.Finalized).isActive(IsActive.Active); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).disableTracking().planStatusSubQuery(statusQuery).isActive(IsActive.Active); if (forNexus) planQuery.after(this._config.getNexusDate()); return planQuery.count(); } private double calculatePublishedDmps(boolean forNexus) { - PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).disableTracking().statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public).isActive(IsActive.Active); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).disableTracking().planStatusSubQuery(statusQuery).accessTypes(PlanAccessType.Public).isActive(IsActive.Active); if (forNexus) planQuery.after(this._config.getNexusDate()); return planQuery.count(); @@ -355,8 +358,10 @@ public class MetricsServiceImpl implements MetricsService { return planQuery.count(); } - private double calculateDraftDmpsWithGrant(boolean forNexus) { - PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).statuses(PlanStatus.Draft).disableTracking().isActive(IsActive.Active); + private double calculateDraftDmpsWithGrant(boolean forNexus) + { + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Draft).isActives(IsActive.Active); + PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).planStatusSubQuery(statusQuery).disableTracking().isActive(IsActive.Active); if (forNexus) planQuery.after(this._config.getNexusDate()); ReferenceQuery referenceQuery = this.queryFactory.query(ReferenceQuery.class).disableTracking().typeIds(this._config.getReferenceTypes().getGrantIds()).isActive(IsActive.Active); @@ -366,7 +371,8 @@ public class MetricsServiceImpl implements MetricsService { } private double calculateFinalizedDmpsWithGrant(boolean forNexus) { - PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).disableTracking().statuses(PlanStatus.Finalized).isActive(IsActive.Active); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).disableTracking().planStatusSubQuery(statusQuery).isActive(IsActive.Active); if (forNexus) planQuery.after(this._config.getNexusDate()); ReferenceQuery referenceQuery = this.queryFactory.query(ReferenceQuery.class).disableTracking().typeIds(this._config.getReferenceTypes().getGrantIds()).isActive(IsActive.Active); @@ -376,7 +382,8 @@ public class MetricsServiceImpl implements MetricsService { } private double calculatePublishedDmpsWithGrant(boolean forNexus) { - PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).statuses(PlanStatus.Finalized).disableTracking().accessTypes(PlanAccessType.Public).isActive(IsActive.Active); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).planStatusSubQuery(statusQuery).disableTracking().accessTypes(PlanAccessType.Public).isActive(IsActive.Active); if (forNexus) planQuery.after(this._config.getNexusDate()); ReferenceQuery referenceQuery = this.queryFactory.query(ReferenceQuery.class).disableTracking().typeIds(this._config.getReferenceTypes().getGrantIds()).isActive(IsActive.Active); @@ -426,30 +433,35 @@ public class MetricsServiceImpl implements MetricsService { } private double calculateDraftDatasets(boolean forNexus) { - DescriptionQuery descriptionQuery = this.queryFactory.query(DescriptionQuery.class).disableTracking().statuses(DescriptionStatus.Draft).isActive(IsActive.Active); + DescriptionStatusQuery descriptionStatusQuery = this.queryFactory.query(DescriptionStatusQuery.class).disableTracking().internalStatuses(DescriptionStatus.Draft).isActive(IsActive.Active); + DescriptionQuery descriptionQuery = this.queryFactory.query(DescriptionQuery.class).disableTracking().descriptionStatusSubQuery(descriptionStatusQuery).isActive(IsActive.Active); if (forNexus) descriptionQuery.createdAfter(this._config.getNexusDate()); return descriptionQuery.count(); } private double calculateFinalizedDatasets(boolean forNexus) { - DescriptionQuery descriptionQuery = this.queryFactory.query(DescriptionQuery.class).disableTracking().statuses(DescriptionStatus.Finalized).isActive(IsActive.Active); + DescriptionStatusQuery descriptionStatusQuery = this.queryFactory.query(DescriptionStatusQuery.class).disableTracking().internalStatuses(DescriptionStatus.Finalized).isActive(IsActive.Active); + DescriptionQuery descriptionQuery = this.queryFactory.query(DescriptionQuery.class).disableTracking().descriptionStatusSubQuery(descriptionStatusQuery).isActive(IsActive.Active); if (forNexus) descriptionQuery.createdAfter(this._config.getNexusDate()); return descriptionQuery.count(); } private double calculatePublishedDatasets(boolean forNexus) { - DescriptionQuery descriptionQuery = this.queryFactory.query(DescriptionQuery.class).disableTracking().statuses(DescriptionStatus.Finalized).isActive(IsActive.Active); + DescriptionStatusQuery descriptionStatusQuery = this.queryFactory.query(DescriptionStatusQuery.class).disableTracking().internalStatuses(DescriptionStatus.Finalized).isActive(IsActive.Active); + DescriptionQuery descriptionQuery = this.queryFactory.query(DescriptionQuery.class).disableTracking().descriptionStatusSubQuery(descriptionStatusQuery).isActive(IsActive.Active); if (forNexus) descriptionQuery.createdAfter(this._config.getNexusDate()); - PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active).disableTracking().statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active).disableTracking().planStatusSubQuery(statusQuery).accessTypes(PlanAccessType.Public); descriptionQuery.planSubQuery(planQuery); return descriptionQuery.count(); } private double calculateDoiedDatasets(boolean forNexus) { - DescriptionQuery descriptionQuery = this.queryFactory.query(DescriptionQuery.class).disableTracking().statuses(DescriptionStatus.Finalized).isActive(IsActive.Active); + DescriptionStatusQuery descriptionStatusQuery = this.queryFactory.query(DescriptionStatusQuery.class).disableTracking().internalStatuses(DescriptionStatus.Finalized).isActive(IsActive.Active); + DescriptionQuery descriptionQuery = this.queryFactory.query(DescriptionQuery.class).disableTracking().descriptionStatusSubQuery(descriptionStatusQuery).isActive(IsActive.Active); if (forNexus) descriptionQuery.createdAfter(this._config.getNexusDate()); PlanQuery planQuery = this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active); diff --git a/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java index 2bd711e0e..a162d4a5c 100644 --- a/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java @@ -710,7 +710,8 @@ public class PlanServiceImpl implements PlanService { List tags = new ArrayList<>(); try { this.entityManager.disableTenantFilters(); - existing = this.queryFactory.query(DescriptionQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(descriptionId).planSubQuery(this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active).statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public)).first(); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + existing = this.queryFactory.query(DescriptionQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(descriptionId).planSubQuery(this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active).planStatusSubQuery(statusQuery).accessTypes(PlanAccessType.Public)).first(); if (existing == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionId, Description.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -1040,7 +1041,8 @@ public class PlanServiceImpl implements PlanService { try { this.entityManager.disableTenantFilters(); // query for public plan - existingPlanEntity = this.queryFactory.query(PlanQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(model.getId()).isActive(IsActive.Active).statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public).firstAs(fields); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + existingPlanEntity = this.queryFactory.query(PlanQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(model.getId()).isActive(IsActive.Active).planStatusSubQuery(statusQuery).accessTypes(PlanAccessType.Public).firstAs(fields); if (existingPlanEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), PublicPlan.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -2081,7 +2083,8 @@ public class PlanServiceImpl implements PlanService { } else { try { this.entityManager.disableTenantFilters(); - data = this.queryFactory.query(PlanQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(id).isActive(IsActive.Active).statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public).first(); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + data = this.queryFactory.query(PlanQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(id).isActive(IsActive.Active).planStatusSubQuery(statusQuery).accessTypes(PlanAccessType.Public).first(); this.entityManager.reloadTenantFilters(); } finally { this.entityManager.reloadTenantFilters(); @@ -2115,7 +2118,8 @@ public class PlanServiceImpl implements PlanService { PlanEntity data = null; try { this.entityManager.disableTenantFilters(); - data = this.queryFactory.query(PlanQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(id).isActive(IsActive.Active).statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public).first(); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + data = this.queryFactory.query(PlanQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(id).isActive(IsActive.Active).planStatusSubQuery(statusQuery).accessTypes(PlanAccessType.Public).first(); this.entityManager.reloadTenantFilters(); } finally { this.entityManager.reloadTenantFilters(); diff --git a/backend/web/src/main/java/org/opencdmp/controllers/DescriptionController.java b/backend/web/src/main/java/org/opencdmp/controllers/DescriptionController.java index c657fcb79..72392840b 100644 --- a/backend/web/src/main/java/org/opencdmp/controllers/DescriptionController.java +++ b/backend/web/src/main/java/org/opencdmp/controllers/DescriptionController.java @@ -45,6 +45,7 @@ import org.opencdmp.model.persist.*; import org.opencdmp.model.result.QueryResult; import org.opencdmp.query.DescriptionQuery; import org.opencdmp.query.PlanQuery; +import org.opencdmp.query.PlanStatusQuery; import org.opencdmp.query.lookup.DescriptionLookup; import org.opencdmp.service.description.DescriptionService; import org.opencdmp.service.elastic.ElasticQueryHelperService; @@ -147,7 +148,8 @@ public class DescriptionController { this.censorFactory.censor(PublicDescriptionCensor.class).censor(fieldSet); - DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(id).planSubQuery(this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active).statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public)); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(id).planSubQuery(this.queryFactory.query(PlanQuery.class).isActive(IsActive.Active).planStatusSubQuery(statusQuery).accessTypes(PlanAccessType.Public)); PublicDescription model = this.builderFactory.builder(PublicDescriptionBuilder.class).authorize(EnumSet.of(Public)).build(fieldSet, query.firstAs(fieldSet)); if (model == null) diff --git a/backend/web/src/main/java/org/opencdmp/controllers/PlanController.java b/backend/web/src/main/java/org/opencdmp/controllers/PlanController.java index 309096e3e..c371ededf 100644 --- a/backend/web/src/main/java/org/opencdmp/controllers/PlanController.java +++ b/backend/web/src/main/java/org/opencdmp/controllers/PlanController.java @@ -43,6 +43,7 @@ import org.opencdmp.model.persist.*; import org.opencdmp.model.plan.Plan; import org.opencdmp.model.result.QueryResult; import org.opencdmp.query.PlanQuery; +import org.opencdmp.query.PlanStatusQuery; import org.opencdmp.query.lookup.PlanLookup; import org.opencdmp.service.elastic.ElasticQueryHelperService; import org.opencdmp.service.plan.PlanService; @@ -131,7 +132,8 @@ public class PlanController { this.censorFactory.censor(PublicPlanCensor.class).censor(fieldSet); - PlanQuery query = this.queryFactory.query(PlanQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(id).isActive(IsActive.Active).statuses(PlanStatus.Finalized).accessTypes(PlanAccessType.Public); + PlanStatusQuery statusQuery = this.queryFactory.query(PlanStatusQuery.class).disableTracking().internalStatuses(PlanStatus.Finalized).isActives(IsActive.Active); + PlanQuery query = this.queryFactory.query(PlanQuery.class).disableTracking().authorize(EnumSet.of(Public)).ids(id).isActive(IsActive.Active).planStatusSubQuery(statusQuery).accessTypes(PlanAccessType.Public); PublicPlan model = this.builderFactory.builder(PublicPlanBuilder.class).authorize(EnumSet.of(Public)).build(fieldSet, query.firstAs(fieldSet)); if (model == null) diff --git a/backend/web/src/main/resources/config/permissions.yml b/backend/web/src/main/resources/config/permissions.yml index 51bda04eb..a53416882 100644 --- a/backend/web/src/main/resources/config/permissions.yml +++ b/backend/web/src/main/resources/config/permissions.yml @@ -120,8 +120,11 @@ permissions: BrowseDescriptionStatus: roles: - Admin - - TenantAdmin + - InstallationAdmin + - TenantPlanManager - TenantConfigManager + - TenantAdmin + - TenantUser clients: [ ] allowAnonymous: false allowAuthenticated: false @@ -174,8 +177,11 @@ permissions: BrowsePlanStatus: roles: - Admin - - TenantAdmin + - InstallationAdmin + - TenantPlanManager - TenantConfigManager + - TenantAdmin + - TenantUser clients: [ ] allowAnonymous: false allowAuthenticated: false diff --git a/frontend/src/app/core/query/description.lookup.ts b/frontend/src/app/core/query/description.lookup.ts index 810ff4bd0..68dbde5b3 100644 --- a/frontend/src/app/core/query/description.lookup.ts +++ b/frontend/src/app/core/query/description.lookup.ts @@ -1,7 +1,6 @@ import { Lookup } from '@common/model/lookup'; import { Guid } from '@common/types/guid'; import { IsActive } from '../common/enum/is-active.enum'; -import { DescriptionStatusEnum } from '../common/enum/description-status'; import { PlanLookup } from './plan.lookup'; import { DescriptionReferenceLookup } from './reference.lookup'; import { DescriptionTagLookup } from './tag.lookup'; @@ -17,7 +16,7 @@ export class DescriptionLookup extends Lookup implements DescriptionFilter { finalizedAfter: Date; finalizedBefore: Date; isActive: IsActive[]; - statuses: DescriptionStatusEnum[]; + statusIds: Guid[]; planSubQuery: PlanLookup; tenantSubQuery: TenantLookup; @@ -39,7 +38,7 @@ export interface DescriptionFilter { finalizedAfter: Date; finalizedBefore: Date; isActive: IsActive[]; - statuses: DescriptionStatusEnum[]; + statusIds: Guid[]; planSubQuery: PlanLookup; descriptionTemplateSubQuery: DescriptionTemplateLookup; diff --git a/frontend/src/app/core/query/plan.lookup.ts b/frontend/src/app/core/query/plan.lookup.ts index 25642496e..5d22c2f8c 100644 --- a/frontend/src/app/core/query/plan.lookup.ts +++ b/frontend/src/app/core/query/plan.lookup.ts @@ -1,7 +1,6 @@ import { Lookup } from '@common/model/lookup'; import { Guid } from '@common/types/guid'; import { PlanAccessType } from '../common/enum/plan-access-type'; -import { PlanStatusEnum } from '../common/enum/plan-status'; import { PlanVersionStatus } from '../common/enum/plan-version-status'; import { IsActive } from '../common/enum/is-active.enum'; import { PlanDescriptionTemplateLookup } from './plan-description-template.lookup'; @@ -9,6 +8,7 @@ import { PlanUserLookup } from './plan-user.lookup'; import { PlanBlueprintLookup } from './plan-blueprint.lookup'; import { PlanReferenceLookup } from './reference.lookup'; import { TenantLookup } from './tenant.lookup'; +import { PlanStatusLookup } from './plan-status.lookup'; export class PlanLookup extends Lookup implements PlanFilter { ids: Guid[]; @@ -16,7 +16,7 @@ export class PlanLookup extends Lookup implements PlanFilter { like: string; isActive: IsActive[]; versionStatuses: PlanVersionStatus[]; - statuses: PlanStatusEnum[]; + statusIds: Guid[]; accessTypes: PlanAccessType[]; versions: Number[]; groupIds: Guid[]; @@ -26,6 +26,7 @@ export class PlanLookup extends Lookup implements PlanFilter { planBlueprintSubQuery: PlanBlueprintLookup; planDescriptionTemplateSubQuery: PlanDescriptionTemplateLookup; planReferenceSubQuery: PlanReferenceLookup; + planStatusSubQuery: PlanStatusLookup; constructor() { super(); @@ -38,7 +39,7 @@ export interface PlanFilter { like: string; isActive: IsActive[]; versionStatuses: PlanVersionStatus[]; - statuses: PlanStatusEnum[]; + statusIds: Guid[]; accessTypes: PlanAccessType[]; versions: Number[]; groupIds: Guid[]; @@ -47,4 +48,5 @@ export interface PlanFilter { planBlueprintSubQuery: PlanBlueprintLookup; planDescriptionTemplateSubQuery: PlanDescriptionTemplateLookup; planReferenceSubQuery: PlanReferenceLookup; + planStatusSubQuery: PlanStatusLookup; } diff --git a/frontend/src/app/core/services/description-status/description-status.service.ts b/frontend/src/app/core/services/description-status/description-status.service.ts index 1c3f26282..86e5bb8c8 100644 --- a/frontend/src/app/core/services/description-status/description-status.service.ts +++ b/frontend/src/app/core/services/description-status/description-status.service.ts @@ -3,7 +3,7 @@ import { Injectable } from "@angular/core"; import { BaseHttpV2Service } from "../http/base-http-v2.service"; import { ConfigurationService } from "../configuration/configuration.service"; import { QueryResult } from "@common/model/query-result"; -import { catchError, Observable, throwError } from "rxjs"; +import { catchError, map, Observable, throwError } from "rxjs"; import { Guid } from "@common/types/guid"; import { DescriptionStatusLookup } from "@app/core/query/description-status.lookup"; import { DescriptionStatus } from "@app/core/model/description-status/description-status"; @@ -12,6 +12,8 @@ import { IsActive } from "@app/core/common/enum/is-active.enum"; import { nameof } from "ts-simple-nameof"; import { FilterService } from "@common/modules/text-filter/filter-service"; import { DescriptionStatusEnum } from "@app/core/common/enum/description-status"; +import { SingleAutoCompleteConfiguration } from "@app/library/auto-complete/single/single-auto-complete-configuration"; +import { MultipleAutoCompleteConfiguration } from "@app/library/auto-complete/multiple/multiple-auto-complete-configuration"; @Injectable() export class DescriptionStatusService { @@ -65,6 +67,43 @@ export class DescriptionStatusService { catchError((error: any) => throwError(() => error))); } + // tslint:disable-next-line: member-ordering + singleAutocompleteConfiguration: SingleAutoCompleteConfiguration = { + initialItems: (data?: any) => this.query(this.buildAutocompleteLookup([IsActive.Active])).pipe(map(x => x.items)), + filterFn: (searchQuery: string, data?: any) => this.query(this.buildAutocompleteLookup([IsActive.Active], searchQuery)).pipe(map(x => x.items)), + getSelectedItem: (selectedItem: any) => this.query(this.buildAutocompleteLookup([IsActive.Active, IsActive.Inactive], null, null, [selectedItem])).pipe(map(x => x.items[0])), + displayFn: (item: DescriptionStatus) => item.name, + titleFn: (item: DescriptionStatus) => item.name, + valueAssign: (item: DescriptionStatus) => item.id, + }; + + // tslint:disable-next-line: member-ordering + multipleAutocompleteConfiguration: MultipleAutoCompleteConfiguration = { + initialItems: (excludedItems: any[], data?: any) => this.query(this.buildAutocompleteLookup([IsActive.Active], null, excludedItems ? excludedItems : null)).pipe(map(x => x.items)), + filterFn: (searchQuery: string, excludedItems: any[]) => this.query(this.buildAutocompleteLookup([IsActive.Active],searchQuery, excludedItems)).pipe(map(x => x.items)), + getSelectedItems: (selectedItems: any[]) => this.query(this.buildAutocompleteLookup([IsActive.Active, IsActive.Inactive], null, null, selectedItems)).pipe(map(x => x.items)), + displayFn: (item: DescriptionStatus) => item.name, + titleFn: (item: DescriptionStatus) => item.name, + valueAssign: (item: DescriptionStatus) => item.id, + }; + + public buildAutocompleteLookup(isActive: IsActive[], like?: string, excludedIds?: Guid[], ids?: Guid[]): DescriptionStatusLookup { + const lookup: DescriptionStatusLookup = new DescriptionStatusLookup(); + lookup.page = { size: 100, offset: 0 }; + if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; } + if (ids && ids.length > 0) { lookup.ids = ids; } + lookup.isActive = isActive; + lookup.project = { + fields: [ + nameof(x => x.id), + nameof(x => x.name) + ] + }; + lookup.order = { items: [nameof(x => x.name)] }; + if (like) { lookup.like = this.filterService.transformLike(like); } + return lookup; + } + buildLookup(params: { like?: string, excludedIds?: Guid[], diff --git a/frontend/src/app/core/services/plan/plan-status.service.ts b/frontend/src/app/core/services/plan/plan-status.service.ts index b472ed58d..18decf9bc 100644 --- a/frontend/src/app/core/services/plan/plan-status.service.ts +++ b/frontend/src/app/core/services/plan/plan-status.service.ts @@ -5,14 +5,15 @@ import { ConfigurationService } from "../configuration/configuration.service"; import { PlanStatusLookup } from "@app/core/query/plan-status.lookup"; import { PlanStatus } from "@app/core/model/plan-status/plan-status"; import { QueryResult } from "@common/model/query-result"; -import { catchError, Observable, throwError } from "rxjs"; +import { catchError, map, Observable, throwError } from "rxjs"; import { PlanStatusPersist } from "@app/core/model/plan-status/plan-status-persist"; import { Guid } from "@common/types/guid"; -import { PlanLookup } from "@app/core/query/plan.lookup"; import { FilterService } from "@common/modules/text-filter/filter-service"; import { IsActive } from "@notification-service/core/enum/is-active.enum"; import { nameof } from "ts-simple-nameof"; import { PlanStatusEnum } from "@app/core/common/enum/plan-status"; +import { SingleAutoCompleteConfiguration } from "@app/library/auto-complete/single/single-auto-complete-configuration"; +import { MultipleAutoCompleteConfiguration } from "@app/library/auto-complete/multiple/multiple-auto-complete-configuration"; @Injectable() export class PlanStatusService { @@ -66,6 +67,43 @@ export class PlanStatusService { catchError((error: any) => throwError(() => error))); } + // tslint:disable-next-line: member-ordering + singleAutocompleteConfiguration: SingleAutoCompleteConfiguration = { + initialItems: (data?: any) => this.query(this.buildAutocompleteLookup([IsActive.Active])).pipe(map(x => x.items)), + filterFn: (searchQuery: string, data?: any) => this.query(this.buildAutocompleteLookup([IsActive.Active], searchQuery)).pipe(map(x => x.items)), + getSelectedItem: (selectedItem: any) => this.query(this.buildAutocompleteLookup([IsActive.Active, IsActive.Inactive], null, null, [selectedItem])).pipe(map(x => x.items[0])), + displayFn: (item: PlanStatus) => item.name, + titleFn: (item: PlanStatus) => item.name, + valueAssign: (item: PlanStatus) => item.id, + }; + + // tslint:disable-next-line: member-ordering + multipleAutocompleteConfiguration: MultipleAutoCompleteConfiguration = { + initialItems: (excludedItems: any[], data?: any) => this.query(this.buildAutocompleteLookup([IsActive.Active], null, excludedItems ? excludedItems : null)).pipe(map(x => x.items)), + filterFn: (searchQuery: string, excludedItems: any[]) => this.query(this.buildAutocompleteLookup([IsActive.Active],searchQuery, excludedItems)).pipe(map(x => x.items)), + getSelectedItems: (selectedItems: any[]) => this.query(this.buildAutocompleteLookup([IsActive.Active, IsActive.Inactive], null, null, selectedItems)).pipe(map(x => x.items)), + displayFn: (item: PlanStatus) => item.name, + titleFn: (item: PlanStatus) => item.name, + valueAssign: (item: PlanStatus) => item.id, + }; + + public buildAutocompleteLookup(isActive: IsActive[], like?: string, excludedIds?: Guid[], ids?: Guid[]): PlanStatusLookup { + const lookup: PlanStatusLookup = new PlanStatusLookup(); + lookup.page = { size: 100, offset: 0 }; + if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; } + if (ids && ids.length > 0) { lookup.ids = ids; } + lookup.isActive = isActive; + lookup.project = { + fields: [ + nameof(x => x.id), + nameof(x => x.name) + ] + }; + lookup.order = { items: [nameof(x => x.name)] }; + if (like) { lookup.like = this.filterService.transformLike(like); } + return lookup; + } + buildLookup(params: { like?: string, excludedIds?: Guid[], diff --git a/frontend/src/app/core/services/plan/plan.service.ts b/frontend/src/app/core/services/plan/plan.service.ts index 0758ccb2f..26971d564 100644 --- a/frontend/src/app/core/services/plan/plan.service.ts +++ b/frontend/src/app/core/services/plan/plan.service.ts @@ -251,13 +251,13 @@ export class PlanService { valueAssign: (item: Plan) => item.id, }; - public buildAutocompleteLookup(isActive: IsActive[], like?: string, excludedIds?: Guid[], ids?: Guid[], statuses?: PlanStatusEnum[], planDescriptionTemplateSubQuery?: PlanDescriptionTemplateLookup): PlanLookup { + public buildAutocompleteLookup(isActive: IsActive[], like?: string, excludedIds?: Guid[], ids?: Guid[], statusIds?: Guid[], planDescriptionTemplateSubQuery?: PlanDescriptionTemplateLookup): PlanLookup { const lookup: PlanLookup = new PlanLookup(); lookup.page = { size: 100, offset: 0 }; if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; } if (ids && ids.length > 0) { lookup.ids = ids; } lookup.isActive = isActive; - lookup.statuses = statuses; + lookup.statusIds = statusIds; lookup.project = { fields: [ nameof(x => x.id), diff --git a/frontend/src/app/ui/description/description-copy-dialog/description-copy-dialog.component.ts b/frontend/src/app/ui/description/description-copy-dialog/description-copy-dialog.component.ts index a44c244a3..3992fd4bc 100644 --- a/frontend/src/app/ui/description/description-copy-dialog/description-copy-dialog.component.ts +++ b/frontend/src/app/ui/description/description-copy-dialog/description-copy-dialog.component.ts @@ -19,6 +19,7 @@ import { DescriptionTemplatesInSection, PlanBlueprint, PlanBlueprintDefinition, import { TenantLookup } from '@app/core/query/tenant.lookup'; import { Tenant } from '@app/core/model/tenant/tenant'; import { AuthService } from '@app/core/services/auth/auth.service'; +import { PlanStatusLookup } from '@app/core/query/plan-status.lookup'; @Component({ selector: 'description-copy-dialog-component', @@ -49,7 +50,9 @@ export class DescriptionCopyDialogComponent { if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; } if (ids && ids.length > 0) { lookup.ids = ids; } lookup.isActive = [IsActive.Active]; - lookup.statuses = [PlanStatusEnum.Draft]; + const planStatusLookup: PlanStatusLookup = new PlanStatusLookup(); + planStatusLookup.internalStatuses = [PlanStatusEnum.Draft]; + lookup.planStatusSubQuery = planStatusLookup; lookup.project = { fields: [ nameof(x => x.id), diff --git a/frontend/src/app/ui/description/editor/description-editor.component.html b/frontend/src/app/ui/description/editor/description-editor.component.html index 5c12941e9..36eb1c76d 100644 --- a/frontend/src/app/ui/description/editor/description-editor.component.html +++ b/frontend/src/app/ui/description/editor/description-editor.component.html @@ -67,7 +67,7 @@ - + diff --git a/frontend/src/app/ui/description/editor/description-editor.component.ts b/frontend/src/app/ui/description/editor/description-editor.component.ts index 66c3329bd..057db8b5a 100644 --- a/frontend/src/app/ui/description/editor/description-editor.component.ts +++ b/frontend/src/app/ui/description/editor/description-editor.component.ts @@ -581,6 +581,10 @@ export class DescriptionEditorComponent extends BaseEditor 0; } get hasFilters(): boolean { - return (this.lookup.like != null && this.lookup.like != '') || this.lookup.statuses != null || + return (this.lookup.like != null && this.lookup.like != '') || this.lookup.statusIds != null || this.lookup.planSubQuery != null || this.lookup.descriptionTemplateSubQuery != null || this.lookup.descriptionTagSubQuery != null || this.lookup.descriptionReferenceSubQuery != null || this.lookup.tenantSubQuery != null; @@ -415,7 +415,7 @@ export class DescriptionListingComponent extends BaseListingComponent 0, role: lookup.planSubQuery?.planUserSubQuery?.userRoles?.[0] ?? null, descriptionTemplates: lookup.descriptionTemplateSubQuery?.ids ?? [], diff --git a/frontend/src/app/ui/description/listing/filtering/description-filter.component.html b/frontend/src/app/ui/description/listing/filtering/description-filter.component.html index e493dbcca..581d2121f 100644 --- a/frontend/src/app/ui/description/listing/filtering/description-filter.component.html +++ b/frontend/src/app/ui/description/listing/filtering/description-filter.component.html @@ -11,12 +11,10 @@
{{ 'DESCRIPTION-LISTING.FILTERS.STATUS.NAME' | translate}}
- - {{ 'DESCRIPTION-LISTING.FILTERS.STATUS.TYPES.ANY' | translate }} - {{ 'DESCRIPTION-LISTING.FILTERS.STATUS.TYPES.DRAFT' | translate }} - {{ 'DESCRIPTION-LISTING.FILTERS.STATUS.TYPES.FINALIZED' | translate }} - {{ 'DESCRIPTION-LISTING.FILTERS.STATUS.TYPES.CANCELED' | translate }} - + + {{'DESCRIPTION-LISTING.FILTERS.STATUS.PLACEHOLDER' | translate }} + +
diff --git a/frontend/src/app/ui/description/listing/filtering/description-filter.component.ts b/frontend/src/app/ui/description/listing/filtering/description-filter.component.ts index e5d49e44c..bc9a9bdfc 100644 --- a/frontend/src/app/ui/description/listing/filtering/description-filter.component.ts +++ b/frontend/src/app/ui/description/listing/filtering/description-filter.component.ts @@ -8,6 +8,7 @@ import { Reference } from '@app/core/model/reference/reference'; import { ReferencesWithType } from '@app/core/query/description.lookup'; import { ReferenceLookup } from '@app/core/query/reference.lookup'; import { AuthService } from '@app/core/services/auth/auth.service'; +import { DescriptionStatusService } from '@app/core/services/description-status/description-status.service'; import { DescriptionTemplateService } from '@app/core/services/description-template/description-template.service'; import { PlanService } from '@app/core/services/plan/plan.service'; import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service'; @@ -57,6 +58,7 @@ export class DescriptionFilterComponent extends BaseCriteriaComponent; constructor( @@ -67,6 +69,7 @@ export class DescriptionFilterComponent extends BaseCriteriaComponent({ - status: new FormControl(filters?.status), + statusId: new FormControl(filters?.statusId), viewOnlyTenant: new FormControl(filters.viewOnlyTenant), role: new FormControl(filters.role), descriptionTemplates: new FormControl(filters.descriptionTemplates), @@ -110,7 +113,7 @@ export class DescriptionFilterComponent extends BaseCriteriaComponent, + statusId: FormControl, viewOnlyTenant: FormControl, role: FormControl, descriptionTemplates: FormControl, diff --git a/frontend/src/app/ui/description/listing/listing-item/description-listing-item.component.html b/frontend/src/app/ui/description/listing/listing-item/description-listing-item.component.html index 4c933e0c3..9ae60f621 100644 --- a/frontend/src/app/ui/description/listing/listing-item/description-listing-item.component.html +++ b/frontend/src/app/ui/description/listing/listing-item/description-listing-item.component.html @@ -13,18 +13,18 @@ -
{{description.label}}
-
{{description.label}}
-
{{description.label}}
-
{{description.label}}
+
{{description.label}}
+
{{description.label}}
+
{{description.label}}
+
{{description.label}}
{{ enumUtils.toPlanUserRolesString(planService.getCurrentUserRolesInPlan(description?.plan?.planUsers)) }} . - public{{'DESCRIPTION-LISTING.STATES.PUBLIC' | translate}} - done{{ description.status.name }} - create{{ description.status.name }} - visibility{{ description.status.name }} - {{ description.status.name }} + public{{'DESCRIPTION-LISTING.STATES.PUBLIC' | translate}} + done{{ description.status.name }} + create{{ description.status.name }} + visibility{{ description.status.name }} + {{ description.status?.name }} . {{'DESCRIPTION-LISTING.GRANT' | translate}}: {{referenceService.getReferencesForTypesFirstSafe(description?.plan?.planReferences, [this.referenceTypeService.getGrantReferenceType()])?.reference?.label}}
diff --git a/frontend/src/app/ui/description/overview/description-overview.component.html b/frontend/src/app/ui/description/overview/description-overview.component.html index f1ad94eb9..49d3fea4c 100644 --- a/frontend/src/app/ui/description/overview/description-overview.component.html +++ b/frontend/src/app/ui/description/overview/description-overview.component.html @@ -134,7 +134,7 @@
- +
diff --git a/frontend/src/app/ui/description/overview/description-overview.component.ts b/frontend/src/app/ui/description/overview/description-overview.component.ts index f431b92ea..d1e6ddc47 100644 --- a/frontend/src/app/ui/description/overview/description-overview.component.ts +++ b/frontend/src/app/ui/description/overview/description-overview.component.ts @@ -319,6 +319,10 @@ export class DescriptionOverviewComponent extends BaseComponent implements OnIni return description?.status?.internalStatus != DescriptionStatusEnum.Finalized; } + isNotFinalizedPlan(description: Description) { + return description?.plan?.status?.internalStatus != PlanStatusEnum.Finalized; + } + editClicked(description: Description) { this.router.navigate([this.routerUtils.generateUrl(['/descriptions/edit/', description.id.toString()])]); } diff --git a/frontend/src/app/ui/description/start-new-description-dialog/start-new-description-dialog.component.ts b/frontend/src/app/ui/description/start-new-description-dialog/start-new-description-dialog.component.ts index b2a84a5c1..65c941288 100644 --- a/frontend/src/app/ui/description/start-new-description-dialog/start-new-description-dialog.component.ts +++ b/frontend/src/app/ui/description/start-new-description-dialog/start-new-description-dialog.component.ts @@ -19,6 +19,7 @@ import { nameof } from 'ts-simple-nameof'; import { AuthService } from '@app/core/services/auth/auth.service'; import { TenantLookup } from '@app/core/query/tenant.lookup'; import { Tenant } from '@app/core/model/tenant/tenant'; +import { PlanStatusLookup } from '@app/core/query/plan-status.lookup'; @Component({ selector: 'app-start-new-description-dialog', @@ -41,13 +42,15 @@ export class StartNewDescriptionDialogComponent extends BaseComponent { valueAssign: (item: Plan) => item.id, }; - private buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[], statuses?: PlanStatusEnum[], planDescriptionTemplateSubQuery?: PlanDescriptionTemplateLookup): PlanLookup { + private buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[], planDescriptionTemplateSubQuery?: PlanDescriptionTemplateLookup): PlanLookup { const lookup: PlanLookup = new PlanLookup(); lookup.page = { size: 100, offset: 0 }; if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; } if (ids && ids.length > 0) { lookup.ids = ids; } lookup.isActive = [IsActive.Active]; - lookup.statuses = [PlanStatusEnum.Draft]; + const planStatusLookup: PlanStatusLookup = new PlanStatusLookup(); + planStatusLookup.internalStatuses = [PlanStatusEnum.Draft]; + lookup.planStatusSubQuery = planStatusLookup; lookup.project = { fields: [ nameof(x => x.id), diff --git a/frontend/src/app/ui/plan/listing/filtering/plan-filter-dialog/plan-filter-dialog.component.ts b/frontend/src/app/ui/plan/listing/filtering/plan-filter-dialog/plan-filter-dialog.component.ts index bc22e4d32..737947110 100644 --- a/frontend/src/app/ui/plan/listing/filtering/plan-filter-dialog/plan-filter-dialog.component.ts +++ b/frontend/src/app/ui/plan/listing/filtering/plan-filter-dialog/plan-filter-dialog.component.ts @@ -35,7 +35,7 @@ export class PlanFilterDialogComponent implements OnInit { private _buildPlanFilters(lookup: PlanLookup, references: ReferencesWithType[]): PlanListingFilters { return { - status: lookup.statuses?.[0] ?? null, + statusId: lookup.statusIds?.[0] ?? null, viewOnlyTenant: lookup.tenantSubQuery?.codes?.length > 0, descriptionTemplates: lookup.planDescriptionTemplateSubQuery?.descriptionTemplateGroupIds ? lookup.planDescriptionTemplateSubQuery?.descriptionTemplateGroupIds : [], planBlueprints: lookup.planBlueprintSubQuery?.ids ?? [], diff --git a/frontend/src/app/ui/plan/listing/filtering/plan-filter.component.html b/frontend/src/app/ui/plan/listing/filtering/plan-filter.component.html index aba249b0a..2236cf09e 100644 --- a/frontend/src/app/ui/plan/listing/filtering/plan-filter.component.html +++ b/frontend/src/app/ui/plan/listing/filtering/plan-filter.component.html @@ -9,11 +9,10 @@
{{ 'PLAN-LISTING.FILTERS.STATUS.NAME' | translate }}
- - {{ 'PLAN-LISTING.FILTERS.STATUS.TYPE.ANY' | translate }} - {{ 'PLAN-LISTING.FILTERS.STATUS.TYPE.DRAFT' | translate }} - {{ 'PLAN-LISTING.FILTERS.STATUS.TYPE.FINALIZED' | translate }} - + + {{'PLAN-LISTING.FILTERS.STATUS.PLACEHOLDER' | translate }} + +
diff --git a/frontend/src/app/ui/plan/listing/filtering/plan-filter.component.ts b/frontend/src/app/ui/plan/listing/filtering/plan-filter.component.ts index 8feb5b3ee..202fcbf55 100644 --- a/frontend/src/app/ui/plan/listing/filtering/plan-filter.component.ts +++ b/frontend/src/app/ui/plan/listing/filtering/plan-filter.component.ts @@ -21,6 +21,7 @@ import { Reference } from '@app/core/model/reference/reference'; import { ReferenceType } from '@app/core/model/reference-type/reference-type'; import { QueryResult } from '@common/model/query-result'; import { ReferencesWithType } from '@app/core/query/description.lookup'; +import { PlanStatusService } from '@app/core/services/plan/plan-status.service'; @Component({ selector: 'app-plan-filter-component', @@ -56,6 +57,7 @@ export class PlanFilterComponent extends BaseCriteriaComponent; + planStatusAutoCompleteConfiguration: SingleAutoCompleteConfiguration = this.planStatusService.singleAutocompleteConfiguration; constructor( public language: TranslateService, @@ -65,6 +67,7 @@ export class PlanFilterComponent extends BaseCriteriaComponent({ - status: new FormControl(filters?.status), + statusId: new FormControl(filters?.statusId), descriptionTemplates: new FormControl(filters?.descriptionTemplates), planBlueprints: new FormControl(filters?.planBlueprints), role: new FormControl(filters?.role), @@ -110,7 +113,7 @@ export class PlanFilterComponent extends BaseCriteriaComponent, + statusId: FormControl, viewOnlyTenant: FormControl, descriptionTemplates: FormControl, planBlueprints: FormControl, diff --git a/frontend/src/app/ui/plan/listing/plan-listing.component.ts b/frontend/src/app/ui/plan/listing/plan-listing.component.ts index cdd81557c..5d1397934 100644 --- a/frontend/src/app/ui/plan/listing/plan-listing.component.ts +++ b/frontend/src/app/ui/plan/listing/plan-listing.component.ts @@ -97,7 +97,7 @@ export class PlanListingComponent extends BaseListingComponent 0; } get hasFilters(): boolean { - return (this.lookup.like != null && this.lookup.like != '') || this.lookup.statuses != null || + return (this.lookup.like != null && this.lookup.like != '') || this.lookup.statusIds != null || this.lookup.planReferenceSubQuery != null || this.lookup.planDescriptionTemplateSubQuery != null || this.lookup.planBlueprintSubQuery != null || this.lookup.planUserSubQuery != null || this.lookup.tenantSubQuery != null; @@ -415,7 +415,7 @@ export class PlanListingComponent extends BaseListingComponent