fallback to default tenant config workflows if specific tenant workflows not set

This commit is contained in:
CITE\amentis 2024-10-01 17:07:31 +03:00
parent 0ae9ad4ed1
commit 567f4c0b76
7 changed files with 46 additions and 18 deletions

View File

@ -7,7 +7,6 @@ import org.opencdmp.commons.types.planstatus.PlanStatusDefinitionEntity;
import org.opencdmp.event.DescriptionStatusTouchedEvent;
import org.opencdmp.event.PlanStatusTouchedEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@ -57,13 +56,11 @@ public class CustomPolicyCacheService extends CacheService<CustomPolicyCacheServ
}
}
@EventListener
public void handlePlanTouchedEvent(PlanStatusTouchedEvent event) {
public void clearCache(PlanStatusTouchedEvent event) {
this.evict(this.buildKey(event.getTenantCode()));
}
@EventListener
public void handleDescriptionStatusTouchedEvent(DescriptionStatusTouchedEvent event) {
public void clearCache(DescriptionStatusTouchedEvent event) {
this.evict(this.buildKey(event.getTenantCode()));
}

View File

@ -146,12 +146,27 @@ public class DescriptionWorkflowServiceImpl implements DescriptionWorkflowServic
public DescriptionWorkflowDefinitionEntity getWorkFlowDefinition() throws InvalidApplicationException {
DescriptionWorkflowQuery query = this.queryFactory.query(DescriptionWorkflowQuery.class).authorize(AuthorizationFlags.AllExceptPublic).isActives(IsActive.Active);
if (this.tenantScope.isDefaultTenant())
query = query.defaultTenant(true);
else
query = query.tenantIds(this.tenantScope.getTenant());
if (this.tenantScope.isDefaultTenant()) query = query.defaultTenant(true);
List<DescriptionWorkflowEntity> descriptionWorkflowEntities = query.collect();
if (this.conventionService.isListNullOrEmpty(descriptionWorkflowEntities)) throw new MyApplicationException("Description workflows not found!");
DescriptionWorkflowEntity entity = null;
if (!this.tenantScope.isDefaultTenant()) {
entity = descriptionWorkflowEntities.stream().filter(x -> {
try {
return (this.tenantScope.getTenant().equals(x.getTenantId()));
} catch (InvalidApplicationException e) {
throw new RuntimeException(e);
}
}).findFirst().orElse(null);
}
// fallback to default tenant
if (entity == null) {
entity = descriptionWorkflowEntities.stream().filter(x -> x.getTenantId() == null).findFirst().orElse(null);
}
DescriptionWorkflowEntity entity = query.first();
if (entity == null) throw new MyApplicationException("Description workflow not found!");
DescriptionWorkflowDefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DescriptionWorkflowDefinitionEntity.class, entity.getDefinition());

View File

@ -150,12 +150,26 @@ public class PlanWorkflowServiceImpl implements PlanWorkflowService {
public PlanWorkflowDefinitionEntity getWorkFlowDefinition() throws InvalidApplicationException {
PlanWorkflowQuery query = this.queryFactory.query(PlanWorkflowQuery.class).authorize(AuthorizationFlags.AllExceptPublic).isActives(IsActive.Active);
if (this.tenantScope.isDefaultTenant())
query = query.defaultTenant(true);
else
query = query.tenantIds(this.tenantScope.getTenant());
if (this.tenantScope.isDefaultTenant()) query = query.defaultTenant(true);
List<PlanWorkflowEntity> planWorkflowEntities = query.collect();
if (this.conventionService.isListNullOrEmpty(planWorkflowEntities)) throw new MyApplicationException("Plan workflows not found!");
PlanWorkflowEntity entity = null;
if (!this.tenantScope.isDefaultTenant()) {
entity = planWorkflowEntities.stream().filter(x -> {
try {
return (this.tenantScope.getTenant().equals(x.getTenantId()));
} catch (InvalidApplicationException e) {
throw new RuntimeException(e);
}
}).findFirst().orElse(null);
}
// fallback to default tenant
if (entity == null) {
entity = planWorkflowEntities.stream().filter(x -> x.getTenantId() == null).findFirst().orElse(null);
}
PlanWorkflowEntity entity = query.first();
if (entity == null) throw new MyApplicationException("Plan workflow not found!");
PlanWorkflowDefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(PlanWorkflowDefinitionEntity.class, entity.getDefinition());

View File

@ -50,11 +50,13 @@ public class OpencdmpPermissionPolicyContextImpl extends PermissionPolicyContext
@EventListener
public void handlePlanTouchedEvent(PlanStatusTouchedEvent event) {
this.customPolicyCacheService.clearCache(event);
this.refresh(true);
}
@EventListener
public void handleDescriptionStatusTouchedEvent(DescriptionStatusTouchedEvent event) {
this.customPolicyCacheService.clearCache(event);
this.refresh(true);
}

View File

@ -67,7 +67,7 @@
<button [disabled]="saving" mat-menu-item (click)="saveAndClose()" type="button">{{ 'DESCRIPTION-EDITOR.ACTIONS.SAVE-AND-CLOSE' | translate }}</button>
<button [disabled]="saving" mat-menu-item (click)="saveAndContinue()" type="button">{{ 'DESCRIPTION-EDITOR.ACTIONS.SAVE-AND-CONTINUE' | translate }}</button>
</mat-menu>
<ng-container *ngIf="canEditStatus && !isNew && item.availableStatuses && item.availableStatuses.length > 0 && !isLocked && item.id && isNotFinalizedPlan()">
<ng-container *ngIf="canEditStatus && !isNew && item.availableStatuses && item.availableStatuses.length > 0 && !isLocked && item.id && isNotFinalizedPlan() && item.belongsToCurrentTenant != false">
<button *ngFor='let status of item.availableStatuses' [disabled]="saving" mat-button class="rounded-btn neutral mr-2" type="button" (click)="persistStatus(status)">{{ status.action?.length > 0 ? status.action : status.name }}</button>
</ng-container>
<button [disabled]="saving" *ngIf="isLocked" mat-button disabled class="rounded-btn neutral cursor-default" type="button">{{ 'PLAN-OVERVIEW.LOCKED' | translate}}</button>

View File

@ -134,7 +134,7 @@
<div class="row">
<div class="col-12">
<div class="frame mb-3 pt-4 pl-4 pr-5 pb-3">
<ng-container *ngIf="canEditStatus && description.availableStatuses && description.availableStatuses.length > 0 && !isLocked && isNotFinalizedPlan(description)">
<ng-container *ngIf="canEditStatus && description.availableStatuses && description.availableStatuses.length > 0 && !isLocked && isNotFinalizedPlan(description) && description.belongsToCurrentTenant != false">
<div *ngFor='let status of description.availableStatuses'>
<div class="row align-items-center" (click)="persistStatus(status, description)">
<div class="col-auto pr-0">

View File

@ -52,7 +52,7 @@
<button [disabled]="saving" mat-menu-item (click)="formSubmit()" type="button">{{ 'PLAN-EDITOR.ACTIONS.SAVE-AND-CONTINUE' | translate }}</button>
</mat-menu>
</div>
<div *ngIf="canEditStatus && !isNew && item.availableStatuses && item.availableStatuses.length > 0 && item.versionStatus != planVersionStatusEnum.Previous &&!isLocked && !isNew && hasNotDoi()" class="col-auto d-flex align-items-center" [matTooltipDisabled]="formGroup.pristine" matTooltip="{{'PLAN-EDITOR.ACTIONS.FINALIZE.CAN-NOT-FINALIZE' | translate}}">
<div *ngIf="canEditStatus && !isNew && item.availableStatuses && item.availableStatuses.length > 0 && item.versionStatus != planVersionStatusEnum.Previous && !isLocked && hasNotDoi() && item.belongsToCurrentTenant != false" class="col-auto d-flex align-items-center" [matTooltipDisabled]="formGroup.pristine" matTooltip="{{'PLAN-EDITOR.ACTIONS.FINALIZE.CAN-NOT-FINALIZE' | translate}}">
<button *ngFor='let status of item.availableStatuses' [disabled]="saving || !formGroup.pristine" mat-button class="rounded-btn primary-inverted mr-2" type="button" (click)="persistStatus(status)">{{ status.action?.length > 0 ? status.action : status.name }}</button>
</div>
<div *ngIf="isLocked" class="col-auto d-flex align-items-center">