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