fix blueprint update version status on delete
This commit is contained in:
parent
5e6c42ffdf
commit
37a0fb18a6
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.deleter.DeleterFactory;
|
||||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.exception.MyForbiddenException;
|
||||
|
@ -23,12 +24,10 @@ import org.opencdmp.commons.XmlHandlingService;
|
|||
import org.opencdmp.commons.enums.*;
|
||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||
import org.opencdmp.commons.types.planblueprint.*;
|
||||
import org.opencdmp.commons.types.planblueprint.DescriptionTemplateEntity;
|
||||
import org.opencdmp.commons.types.planblueprint.importexport.*;
|
||||
import org.opencdmp.convention.ConventionService;
|
||||
import org.opencdmp.data.PlanBlueprintEntity;
|
||||
import org.opencdmp.data.PrefillingSourceEntity;
|
||||
import org.opencdmp.data.ReferenceTypeEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.data.*;
|
||||
import org.opencdmp.errorcode.ErrorThesaurusProperties;
|
||||
import org.opencdmp.model.builder.planblueprint.PlanBlueprintBuilder;
|
||||
import org.opencdmp.model.deleter.PlanBlueprintDeleter;
|
||||
|
@ -42,10 +41,7 @@ import org.opencdmp.model.planblueprint.PlanBlueprint;
|
|||
import org.opencdmp.model.planblueprint.Section;
|
||||
import org.opencdmp.model.prefillingsource.PrefillingSource;
|
||||
import org.opencdmp.model.referencetype.ReferenceType;
|
||||
import org.opencdmp.query.DescriptionTemplateQuery;
|
||||
import org.opencdmp.query.PlanBlueprintQuery;
|
||||
import org.opencdmp.query.PrefillingSourceQuery;
|
||||
import org.opencdmp.query.ReferenceTypeQuery;
|
||||
import org.opencdmp.query.*;
|
||||
import org.opencdmp.service.accounting.AccountingService;
|
||||
import org.opencdmp.service.responseutils.ResponseUtilsService;
|
||||
import org.opencdmp.service.usagelimit.UsageLimitService;
|
||||
|
@ -318,6 +314,27 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
|
|||
|
||||
this.authorizationService.authorizeForce(Permission.DeletePlanBlueprint);
|
||||
|
||||
PlanBlueprintEntity data = this.entityManager.find(PlanBlueprintEntity.class, id);
|
||||
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, PlanBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
|
||||
if (!data.getVersionStatus().equals(PlanBlueprintVersionStatus.Previous)){
|
||||
PlanBlueprintQuery planBlueprintQuery = this.queryFactory.query(PlanBlueprintQuery.class)
|
||||
.excludedIds(data.getId())
|
||||
.isActive(IsActive.Active)
|
||||
.groupIds(data.getGroupId());
|
||||
|
||||
planBlueprintQuery.setOrder(new Ordering().addDescending(PlanBlueprint._version));
|
||||
PlanBlueprintEntity previousPlanBlueprint = planBlueprintQuery.count() > 0 ? planBlueprintQuery.collect().getFirst() : null;
|
||||
if (previousPlanBlueprint != null){
|
||||
if (previousPlanBlueprint.getStatus().equals(PlanBlueprintStatus.Finalized)) previousPlanBlueprint.setVersionStatus(PlanBlueprintVersionStatus.Current);
|
||||
else previousPlanBlueprint.setVersionStatus(PlanBlueprintVersionStatus.NotFinalized);
|
||||
this.entityManager.merge(previousPlanBlueprint);
|
||||
data.setVersionStatus(PlanBlueprintVersionStatus.NotFinalized);
|
||||
}
|
||||
this.entityManager.merge(data);
|
||||
this.entityManager.flush();
|
||||
}
|
||||
|
||||
this.deleterFactory.deleter(PlanBlueprintDeleter.class).deleteAndSaveByIds(List.of(id));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue