tenant filter fixes on plan listing
This commit is contained in:
parent
2a66a69f1e
commit
6fee2264d8
|
@ -31,7 +31,7 @@ public class PlanQuery extends QueryBase<PlanEntity> {
|
||||||
|
|
||||||
private Collection<UUID> ids;
|
private Collection<UUID> ids;
|
||||||
|
|
||||||
private Collection<UUID> tenantIds;
|
private TenantQuery tenantQuery;
|
||||||
|
|
||||||
private Collection<UUID> creatorIds;
|
private Collection<UUID> creatorIds;
|
||||||
|
|
||||||
|
@ -97,18 +97,8 @@ public class PlanQuery extends QueryBase<PlanEntity> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlanQuery tenantIds(UUID value) {
|
public PlanQuery tenantSubQuery(TenantQuery tenantQuery) {
|
||||||
this.tenantIds = List.of(value);
|
this.tenantQuery = tenantQuery;
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlanQuery tenantIds(UUID... value) {
|
|
||||||
this.tenantIds = Arrays.asList(value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlanQuery tenantIds(Collection<UUID> values) {
|
|
||||||
this.tenantIds = values;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,11 +325,9 @@ public class PlanQuery extends QueryBase<PlanEntity> {
|
||||||
inClause.value(item);
|
inClause.value(item);
|
||||||
predicates.add(inClause);
|
predicates.add(inClause);
|
||||||
}
|
}
|
||||||
if (this.tenantIds != null) {
|
if (this.tenantQuery != null) {
|
||||||
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(PlanEntity._tenantId));
|
QueryContext<TenantEntity, UUID> subQuery = this.applySubQuery(this.tenantQuery, queryContext, UUID.class, tenantEntityRoot -> tenantEntityRoot.get(TenantEntity._id));
|
||||||
for (UUID item : this.tenantIds)
|
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(PlanEntity._tenantId)).value(subQuery.Query));
|
||||||
inClause.value(item);
|
|
||||||
predicates.add(inClause);
|
|
||||||
}
|
}
|
||||||
if (this.creatorIds != null) {
|
if (this.creatorIds != null) {
|
||||||
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(PlanEntity._creatorId));
|
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(PlanEntity._creatorId));
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class PlanLookup extends Lookup {
|
||||||
private String like;
|
private String like;
|
||||||
|
|
||||||
private List<UUID> ids;
|
private List<UUID> ids;
|
||||||
private List<UUID> tenantIds;
|
private TenantLookup tenantSubQuery;
|
||||||
|
|
||||||
private List<UUID> excludedIds;
|
private List<UUID> excludedIds;
|
||||||
private List<UUID> groupIds;
|
private List<UUID> groupIds;
|
||||||
|
@ -53,9 +53,9 @@ public class PlanLookup extends Lookup {
|
||||||
this.ids = ids;
|
this.ids = ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UUID> getTenantIds() { return this.tenantIds; }
|
public TenantLookup getTenantSubQuery() { return this.tenantSubQuery; }
|
||||||
|
|
||||||
public void setTenantIds(List<UUID> tenantIds) { this.tenantIds = tenantIds; }
|
public void setTenantSubQuery(TenantLookup tenantSubQuery) { this.tenantSubQuery = tenantSubQuery; }
|
||||||
|
|
||||||
public List<UUID> getExcludedIds() {
|
public List<UUID> getExcludedIds() {
|
||||||
return this.excludedIds;
|
return this.excludedIds;
|
||||||
|
@ -142,7 +142,7 @@ public class PlanLookup extends Lookup {
|
||||||
PlanQuery query = queryFactory.query(PlanQuery.class);
|
PlanQuery query = queryFactory.query(PlanQuery.class);
|
||||||
if (this.like != null) query.like(this.like);
|
if (this.like != null) query.like(this.like);
|
||||||
if (this.ids != null) query.ids(this.ids);
|
if (this.ids != null) query.ids(this.ids);
|
||||||
if (this.tenantIds != null) query.tenantIds(this.tenantIds);
|
if (this.tenantSubQuery != null) query.tenantSubQuery(this.tenantSubQuery.enrich(queryFactory));
|
||||||
if (this.groupIds != null) query.groupIds(this.groupIds);
|
if (this.groupIds != null) query.groupIds(this.groupIds);
|
||||||
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
|
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
|
||||||
if (this.accessTypes != null) query.accessTypes(this.accessTypes);
|
if (this.accessTypes != null) query.accessTypes(this.accessTypes);
|
||||||
|
|
|
@ -8,10 +8,10 @@ import { PlanDescriptionTemplateLookup } from './plan-description-template.looku
|
||||||
import { PlanUserLookup } from './plan-user.lookup';
|
import { PlanUserLookup } from './plan-user.lookup';
|
||||||
import { PlanBlueprintLookup } from './plan-blueprint.lookup';
|
import { PlanBlueprintLookup } from './plan-blueprint.lookup';
|
||||||
import { PlanReferenceLookup } from './reference.lookup';
|
import { PlanReferenceLookup } from './reference.lookup';
|
||||||
|
import { TenantLookup } from './tenant.lookup';
|
||||||
|
|
||||||
export class PlanLookup extends Lookup implements PlanFilter {
|
export class PlanLookup extends Lookup implements PlanFilter {
|
||||||
ids: Guid[];
|
ids: Guid[];
|
||||||
tenantIds: Guid[];
|
|
||||||
excludedIds: Guid[];
|
excludedIds: Guid[];
|
||||||
like: string;
|
like: string;
|
||||||
isActive: IsActive[];
|
isActive: IsActive[];
|
||||||
|
@ -21,6 +21,7 @@ export class PlanLookup extends Lookup implements PlanFilter {
|
||||||
versions: Number[];
|
versions: Number[];
|
||||||
groupIds: Guid[];
|
groupIds: Guid[];
|
||||||
|
|
||||||
|
tenantSubQuery: TenantLookup;
|
||||||
planUserSubQuery: PlanUserLookup;
|
planUserSubQuery: PlanUserLookup;
|
||||||
planBlueprintSubQuery: PlanBlueprintLookup;
|
planBlueprintSubQuery: PlanBlueprintLookup;
|
||||||
planDescriptionTemplateSubQuery: PlanDescriptionTemplateLookup;
|
planDescriptionTemplateSubQuery: PlanDescriptionTemplateLookup;
|
||||||
|
|
|
@ -2,10 +2,12 @@ import { Injectable } from "@angular/core";
|
||||||
import { PlanBlueprint } from "@app/core/model/plan-blueprint/plan-blueprint";
|
import { PlanBlueprint } from "@app/core/model/plan-blueprint/plan-blueprint";
|
||||||
import { Plan, PlanDescriptionTemplate, PlanUser } from "@app/core/model/plan/plan";
|
import { Plan, PlanDescriptionTemplate, PlanUser } from "@app/core/model/plan/plan";
|
||||||
import { Reference } from "@app/core/model/reference/reference";
|
import { Reference } from "@app/core/model/reference/reference";
|
||||||
|
import { Tenant } from "@app/core/model/tenant/tenant";
|
||||||
import { PlanBlueprintLookup } from "@app/core/query/plan-blueprint.lookup";
|
import { PlanBlueprintLookup } from "@app/core/query/plan-blueprint.lookup";
|
||||||
import { PlanDescriptionTemplateLookup } from "@app/core/query/plan-description-template.lookup";
|
import { PlanDescriptionTemplateLookup } from "@app/core/query/plan-description-template.lookup";
|
||||||
import { PlanUserLookup } from "@app/core/query/plan-user.lookup";
|
import { PlanUserLookup } from "@app/core/query/plan-user.lookup";
|
||||||
import { PlanReferenceLookup } from "@app/core/query/reference.lookup";
|
import { PlanReferenceLookup } from "@app/core/query/reference.lookup";
|
||||||
|
import { TenantLookup } from "@app/core/query/tenant.lookup";
|
||||||
import { IsActive } from "@notification-service/core/enum/is-active.enum";
|
import { IsActive } from "@notification-service/core/enum/is-active.enum";
|
||||||
import { nameof } from "ts-simple-nameof";
|
import { nameof } from "ts-simple-nameof";
|
||||||
|
|
||||||
|
@ -65,4 +67,17 @@ export class PlanFilterService {
|
||||||
|
|
||||||
return lookup;
|
return lookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static initializeTenantLookup(): TenantLookup {
|
||||||
|
const lookup = new TenantLookup();
|
||||||
|
lookup.metadata = { countAll: true };
|
||||||
|
lookup.isActive = [IsActive.Active];
|
||||||
|
lookup.project = {
|
||||||
|
fields: [
|
||||||
|
nameof<Tenant>(x => x.code),
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
return lookup;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -94,7 +94,8 @@ export class PlanListingComponent extends BaseListingComponent<BasePlan, PlanLoo
|
||||||
get hasFilters(): boolean {
|
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.statuses != null ||
|
||||||
this.lookup.planReferenceSubQuery != null || this.lookup.planDescriptionTemplateSubQuery != null ||
|
this.lookup.planReferenceSubQuery != null || this.lookup.planDescriptionTemplateSubQuery != null ||
|
||||||
this.lookup.planBlueprintSubQuery != null || this.lookup.planUserSubQuery != null;
|
this.lookup.planBlueprintSubQuery != null || this.lookup.planUserSubQuery != null ||
|
||||||
|
this.lookup.tenantSubQuery != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -359,6 +360,17 @@ export class PlanListingComponent extends BaseListingComponent<BasePlan, PlanLoo
|
||||||
lookup.page = { size: querySize, offset: queryOffset };
|
lookup.page = { size: querySize, offset: queryOffset };
|
||||||
lookup.project = { fields: this._lookupFields };
|
lookup.project = { fields: this._lookupFields };
|
||||||
lookup.metadata = { countAll: true };
|
lookup.metadata = { countAll: true };
|
||||||
|
|
||||||
|
if (lookup.tenantSubQuery && lookup.tenantSubQuery?.codes && lookup.tenantSubQuery?.codes?.length > 0) {
|
||||||
|
const tenantFilter = lookup.tenantSubQuery?.codes[0];
|
||||||
|
|
||||||
|
if (tenantFilter != this.authService.selectedTenant()) {
|
||||||
|
lookup.tenantSubQuery = null;
|
||||||
|
this.filterChanged(lookup);
|
||||||
|
return lookup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return lookup;
|
return lookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,9 +392,12 @@ export class PlanListingComponent extends BaseListingComponent<BasePlan, PlanLoo
|
||||||
let viewOnlyTenant = formGroup.get("viewOnlyTenant")?.value ?? false;
|
let viewOnlyTenant = formGroup.get("viewOnlyTenant")?.value ?? false;
|
||||||
if (viewOnlyTenant) {
|
if (viewOnlyTenant) {
|
||||||
let tenant = this.tenants?.find(t => t.code && t.code?.toString() == this.authService.selectedTenant());
|
let tenant = this.tenants?.find(t => t.code && t.code?.toString() == this.authService.selectedTenant());
|
||||||
if (tenant && tenant?.id) lookup.tenantIds = [tenant.id]
|
if (tenant && tenant?.code) {
|
||||||
else lookup.tenantIds = null;
|
lookup.tenantSubQuery = PlanFilterService.initializeTenantLookup();
|
||||||
} else lookup.tenantIds = null;
|
lookup.tenantSubQuery.codes = [tenant.code]
|
||||||
|
}
|
||||||
|
else lookup.tenantSubQuery = null;
|
||||||
|
} else lookup.tenantSubQuery = null;
|
||||||
|
|
||||||
// Description Templates
|
// Description Templates
|
||||||
let descriptionTemplates = formGroup.get("descriptionTemplates")?.value ?? null;
|
let descriptionTemplates = formGroup.get("descriptionTemplates")?.value ?? null;
|
||||||
|
@ -426,7 +441,7 @@ export class PlanListingComponent extends BaseListingComponent<BasePlan, PlanLoo
|
||||||
private _buildFormFromLookup(lookup: PlanLookup): UntypedFormGroup {
|
private _buildFormFromLookup(lookup: PlanLookup): UntypedFormGroup {
|
||||||
return (new UntypedFormBuilder()).group({
|
return (new UntypedFormBuilder()).group({
|
||||||
status: [lookup.statuses?.length > 0 ? lookup.statuses[0] : null],
|
status: [lookup.statuses?.length > 0 ? lookup.statuses[0] : null],
|
||||||
viewOnlyTenant: [lookup.tenantIds?.length > 0 ? true : false],
|
viewOnlyTenant: [lookup.tenantSubQuery?.codes?.length > 0 ? true : false],
|
||||||
descriptionTemplates: lookup.planDescriptionTemplateSubQuery?.descriptionTemplateGroupIds ? [lookup.planDescriptionTemplateSubQuery?.descriptionTemplateGroupIds] : [],
|
descriptionTemplates: lookup.planDescriptionTemplateSubQuery?.descriptionTemplateGroupIds ? [lookup.planDescriptionTemplateSubQuery?.descriptionTemplateGroupIds] : [],
|
||||||
planBlueprints: lookup.planBlueprintSubQuery?.ids ? [lookup.planBlueprintSubQuery?.ids]: [],
|
planBlueprints: lookup.planBlueprintSubQuery?.ids ? [lookup.planBlueprintSubQuery?.ids]: [],
|
||||||
role: lookup.planUserSubQuery?.userRoles ? lookup.planUserSubQuery?.userRoles[0] : null,
|
role: lookup.planUserSubQuery?.userRoles ? lookup.planUserSubQuery?.userRoles[0] : null,
|
||||||
|
@ -437,6 +452,7 @@ export class PlanListingComponent extends BaseListingComponent<BasePlan, PlanLoo
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
if (lookup.statuses) count += lookup.statuses.length;
|
if (lookup.statuses) count += lookup.statuses.length;
|
||||||
|
if (lookup.tenantSubQuery) count += 1;
|
||||||
if (lookup.planDescriptionTemplateSubQuery) count += lookup.planDescriptionTemplateSubQuery.descriptionTemplateGroupIds?.length;
|
if (lookup.planDescriptionTemplateSubQuery) count += lookup.planDescriptionTemplateSubQuery.descriptionTemplateGroupIds?.length;
|
||||||
if (lookup.planBlueprintSubQuery) count += lookup.planBlueprintSubQuery.ids?.length;
|
if (lookup.planBlueprintSubQuery) count += lookup.planBlueprintSubQuery.ids?.length;
|
||||||
if (lookup.planUserSubQuery) count += lookup.planUserSubQuery.userRoles?.length;
|
if (lookup.planUserSubQuery) count += lookup.planUserSubQuery.userRoles?.length;
|
||||||
|
|
Loading…
Reference in New Issue