revert previous commit

This commit is contained in:
CITE\amentis 2024-08-01 12:32:54 +03:00
parent 70486ae3f2
commit a0f7621f60
1 changed files with 4 additions and 71 deletions

View File

@ -508,9 +508,9 @@ public class PlanServiceImpl implements PlanService {
newTemplate.setIsActive(IsActive.Active); newTemplate.setIsActive(IsActive.Active);
this.entityManager.persist(newTemplate); this.entityManager.persist(newTemplate);
this.entityManager.flush(); this.entityManager.flush();
this.cloneDescription(newPlan.getId(), null, newVersionPlanDescriptionPersist.getDescriptionId(), newTemplate.getId(), false); this.cloneDescription(newPlan.getId(), null, newVersionPlanDescriptionPersist.getDescriptionId(), newTemplate.getId());
} else{ } else{
this.cloneDescription(newPlan.getId(), null, newVersionPlanDescriptionPersist.getDescriptionId(), existingPlanDescriptionTemplateEntity.getId(), false); this.cloneDescription(newPlan.getId(), null, newVersionPlanDescriptionPersist.getDescriptionId(), existingPlanDescriptionTemplateEntity.getId());
} }
} }
} }
@ -599,7 +599,7 @@ public class PlanServiceImpl implements PlanService {
return this.builderFactory.builder(PlanBuilder.class).build(BaseFieldSet.build(fields, Plan._id), newPlan); return this.builderFactory.builder(PlanBuilder.class).build(BaseFieldSet.build(fields, Plan._id), newPlan);
} }
public void cloneDescription(UUID planId, Map<UUID, UUID> planDescriptionTemplateRemap, UUID descriptionId, UUID newPlanDescriptionTemplateId, Boolean isPublicClone) throws InvalidApplicationException, IOException { public void cloneDescription(UUID planId, Map<UUID, UUID> planDescriptionTemplateRemap, UUID descriptionId, UUID newPlanDescriptionTemplateId) throws InvalidApplicationException, IOException {
logger.debug("cloning description: {} with description: {}", descriptionId, planId); logger.debug("cloning description: {} with description: {}", descriptionId, planId);
this.usageLimitService.checkIncrease(UsageLimitTargetMetric.DESCRIPTION_COUNT); this.usageLimitService.checkIncrease(UsageLimitTargetMetric.DESCRIPTION_COUNT);
@ -612,17 +612,6 @@ public class PlanServiceImpl implements PlanService {
DescriptionEntity existing = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(descriptionId).isActive(IsActive.Active).first(); DescriptionEntity existing = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(descriptionId).isActive(IsActive.Active).first();
if (existing == null && isPublicClone) {
// query for public description
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();
this.entityManager.reloadTenantFilters();
} finally {
this.entityManager.reloadTenantFilters();
}
}
if (existing == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionId, Description.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (existing == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionId, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DescriptionEntity newDescription = new DescriptionEntity(); DescriptionEntity newDescription = new DescriptionEntity();
@ -652,27 +641,6 @@ public class PlanServiceImpl implements PlanService {
.isActive(IsActive.Active) .isActive(IsActive.Active)
.collect(); .collect();
if (isPublicClone) {
try {
this.entityManager.disableTenantFilters();
if (this.conventionService.isListNullOrEmpty(descriptionReferences)) {
descriptionReferences = this.queryFactory.query(DescriptionReferenceQuery.class).disableTracking()
.descriptionIds(existing.getId())
.isActive(IsActive.Active)
.collect();
}
if (this.conventionService.isListNullOrEmpty(descriptionTags)) {
descriptionTags = this.queryFactory.query(DescriptionTagQuery.class).disableTracking()
.descriptionIds(existing.getId())
.isActive(IsActive.Active)
.collect();
}
this.entityManager.reloadTenantFilters();
} finally {
this.entityManager.reloadTenantFilters();
}
}
for (DescriptionReferenceEntity descriptionReference : descriptionReferences) { for (DescriptionReferenceEntity descriptionReference : descriptionReferences) {
DescriptionReferenceEntity newReference = new DescriptionReferenceEntity(); DescriptionReferenceEntity newReference = new DescriptionReferenceEntity();
newReference.setId(UUID.randomUUID()); newReference.setId(UUID.randomUUID());
@ -752,20 +720,8 @@ public class PlanServiceImpl implements PlanService {
this.usageLimitService.checkIncrease(UsageLimitTargetMetric.PLAN_COUNT); this.usageLimitService.checkIncrease(UsageLimitTargetMetric.PLAN_COUNT);
boolean isPublic = false;
PlanEntity existingPlanEntity = this.queryFactory.query(PlanQuery.class).disableTracking().ids(model.getId()).firstAs(fields); PlanEntity existingPlanEntity = this.queryFactory.query(PlanQuery.class).disableTracking().ids(model.getId()).firstAs(fields);
if (existingPlanEntity == null) {
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);
if (existingPlanEntity != null) isPublic = true;
this.entityManager.reloadTenantFilters();
} finally {
this.entityManager.reloadTenantFilters();
}
}
if (existingPlanEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Plan.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (existingPlanEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Plan.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (existingPlanEntity.getAccessType() != null && !existingPlanEntity.getAccessType().equals(PlanAccessType.Public)) this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.planAffiliation( model.getId())), Permission.ClonePlan); if (existingPlanEntity.getAccessType() != null && !existingPlanEntity.getAccessType().equals(PlanAccessType.Public)) this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.planAffiliation( model.getId())), Permission.ClonePlan);
@ -803,29 +759,6 @@ public class PlanServiceImpl implements PlanService {
.isActive(IsActive.Active) .isActive(IsActive.Active)
.collect(); .collect();
// public plan
if (isPublic) {
try {
this.entityManager.disableTenantFilters();
// query for public plan
if (this.conventionService.isListNullOrEmpty(planDescriptionTemplates)){
planDescriptionTemplates = this.queryFactory.query(PlanDescriptionTemplateQuery.class).disableTracking()
.planIds(model.getId())
.isActive(IsActive.Active)
.collect();
}
if (this.conventionService.isListNullOrEmpty(planReferences)) {
planReferences = this.queryFactory.query(PlanReferenceQuery.class).disableTracking()
.planIds(model.getId())
.isActives(IsActive.Active)
.collect();
}
this.entityManager.reloadTenantFilters();
} finally {
this.entityManager.reloadTenantFilters();
}
}
UUID currentUserId = this.userScope.getUserId(); UUID currentUserId = this.userScope.getUserId();
boolean isCurrentUserInPlan = planUsers.stream().anyMatch(u -> u.getUserId().equals(currentUserId)); boolean isCurrentUserInPlan = planUsers.stream().anyMatch(u -> u.getUserId().equals(currentUserId));
@ -894,7 +827,7 @@ public class PlanServiceImpl implements PlanService {
PlanEntity resultingPlanEntity = this.queryFactory.query(PlanQuery.class).disableTracking().ids(newPlan.getId()).firstAs(fields); PlanEntity resultingPlanEntity = this.queryFactory.query(PlanQuery.class).disableTracking().ids(newPlan.getId()).firstAs(fields);
if (!this.conventionService.isListNullOrEmpty(model.getDescriptions())){ if (!this.conventionService.isListNullOrEmpty(model.getDescriptions())){
for (UUID description: model.getDescriptions()) { for (UUID description: model.getDescriptions()) {
this.cloneDescription(newPlan.getId(), planDescriptionTemplateRemap, description, null, isPublic); this.cloneDescription(newPlan.getId(), planDescriptionTemplateRemap, description, null);
} }
} }
return this.builderFactory.builder(PlanBuilder.class).build(fields, resultingPlanEntity); return this.builderFactory.builder(PlanBuilder.class).build(fields, resultingPlanEntity);