update pom and common model builders fixes

This commit is contained in:
CITE\amentis 2024-09-24 16:00:25 +03:00
parent 8732479769
commit a563c50cab
7 changed files with 170 additions and 22 deletions

View File

@ -51,12 +51,12 @@
<dependency>
<groupId>org.opencdmp</groupId>
<artifactId>repositorydepositbase</artifactId>
<version>2.0.16</version>
<version>2.0.17</version>
</dependency>
<dependency>
<groupId>org.opencdmp</groupId>
<artifactId>common-models</artifactId>
<version>0.0.19</version>
<version>0.0.20</version>
</dependency>
<dependency>
<groupId>gr.cite</groupId>
@ -66,7 +66,7 @@
<dependency>
<groupId>org.opencdmp</groupId>
<artifactId>file-transformer-base</artifactId>
<version>0.0.24</version>
<version>0.0.25</version>
</dependency>
<dependency>
<groupId>gr.cite</groupId>

View File

@ -78,7 +78,7 @@ public class PlanUserCommonModelBuilder extends BaseCommonModelBuilder<PlanUserM
this.logger.debug("checking related - {}", UserModel.class.getSimpleName());
Map<UUID, UserModel> itemMap;
UserQuery q = this.queryFactory.query(UserQuery.class).disableTracking().isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(PlanUserEntity::getUserId).distinct().collect(Collectors.toList()));
UserQuery q = this.queryFactory.query(UserQuery.class).disableTracking().isActive(IsActive.Active).ids(data.stream().map(PlanUserEntity::getUserId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, UserEntity::getId);
return itemMap;
}

View File

@ -8,6 +8,7 @@ import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.enums.DescriptionStatus;
import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.description.DescriptionStatusModel;
import org.opencdmp.commonmodels.models.descriptiotemplate.DescriptionTemplateModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.commons.JsonHandlingService;
@ -25,10 +26,7 @@ import org.opencdmp.model.builder.commonmodels.CommonModelBuilderItemResponse;
import org.opencdmp.model.builder.commonmodels.descriptiontemplate.DescriptionTemplateCommonModelBuilder;
import org.opencdmp.model.builder.commonmodels.plan.PlanCommonModelBuilder;
import org.opencdmp.model.descriptiontemplate.DescriptionTemplate;
import org.opencdmp.query.DescriptionTemplateQuery;
import org.opencdmp.query.PlanDescriptionTemplateQuery;
import org.opencdmp.query.PlanQuery;
import org.opencdmp.query.PlanStatusQuery;
import org.opencdmp.query.*;
import org.opencdmp.service.visibility.VisibilityService;
import org.opencdmp.service.visibility.VisibilityServiceImpl;
import org.slf4j.LoggerFactory;
@ -104,18 +102,15 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder<Descri
Map<UUID, DefinitionEntity> definitionEntityMap = this.collectDescriptionTemplateDefinitions(data);
Map<UUID, UUID> planDescriptionTemplateSections = this.collectPlanDescriptionTemplateSections(data);
Map<UUID, DescriptionStatusModel> descriptionStatuses = this.collectDescriptionStatuses(data);
List<CommonModelBuilderItemResponse<DescriptionModel, DescriptionEntity>> models = new ArrayList<>();
for (DescriptionEntity d : data) {
DescriptionModel m = new DescriptionModel();
m.setId(d.getId());
m.setLabel(d.getLabel());
m.setDescription(d.getDescription());
switch (d.getStatus()){
case Finalized -> m.setStatus(DescriptionStatus.Finalized);
case Draft -> m.setStatus(DescriptionStatus.Draft);
case Canceled -> m.setStatus(DescriptionStatus.Canceled);
default -> throw new MyApplicationException("unrecognized type " + d.getStatus());
}
if (descriptionStatuses != null && d.getStatusId() != null && descriptionStatuses.containsKey(d.getStatusId())) m.setStatus(descriptionStatuses.get(d.getStatusId()));
m.setCreatedAt(d.getCreatedAt());
m.setDescription(d.getDescription());
if (plans != null && d.getPlanId() != null && plans.containsKey(d.getPlanId())) m.setPlan(plans.get(d.getPlanId()));
@ -233,4 +228,16 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder<Descri
return itemMap;
}
private Map<UUID, DescriptionStatusModel> collectDescriptionStatuses(List<DescriptionEntity> data) throws MyApplicationException {
if (data.isEmpty())
return null;
this.logger.debug("checking related - {}", DescriptionStatusModel.class.getSimpleName());
Map<UUID, DescriptionStatusModel> itemMap;
DescriptionStatusQuery q = this.queryFactory.query(DescriptionStatusQuery.class).disableTracking().authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getStatusId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DescriptionStatusCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, DescriptionStatusEntity::getId);
return itemMap;
}
}

View File

@ -0,0 +1,67 @@
package org.opencdmp.model.builder.commonmodels.description;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.description.DescriptionStatusModel;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.DescriptionStatusEntity;
import org.opencdmp.model.builder.commonmodels.BaseCommonModelBuilder;
import org.opencdmp.model.builder.commonmodels.CommonModelBuilderItemResponse;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionStatusCommonModelBuilder extends BaseCommonModelBuilder<DescriptionStatusModel, DescriptionStatusEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DescriptionStatusCommonModelBuilder(
ConventionService conventionService
) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionStatusCommonModelBuilder.class)));
}
public DescriptionStatusCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
protected List<CommonModelBuilderItemResponse<DescriptionStatusModel, DescriptionStatusEntity>> buildInternal(List<DescriptionStatusEntity> data) throws MyApplicationException {
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty()) return new ArrayList<>();
List<CommonModelBuilderItemResponse<DescriptionStatusModel, DescriptionStatusEntity>> models = new ArrayList<>();
for (DescriptionStatusEntity d : data) {
DescriptionStatusModel m = new DescriptionStatusModel();
m.setId(d.getId());
m.setName(d.getName());
if (d.getInternalStatus() != null) {
switch (d.getInternalStatus()){
case Finalized -> m.setInternalStatus(org.opencdmp.commonmodels.enums.DescriptionStatus.Finalized);
case Draft -> m.setInternalStatus(org.opencdmp.commonmodels.enums.DescriptionStatus.Draft);
case Canceled -> m.setInternalStatus(org.opencdmp.commonmodels.enums.DescriptionStatus.Canceled);
default -> throw new MyApplicationException("unrecognized type " + d.getInternalStatus());
}
}
models.add(new CommonModelBuilderItemResponse<>(m, d));
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -15,6 +15,7 @@ import org.opencdmp.commonmodels.models.FileEnvelopeModel;
import org.opencdmp.commonmodels.models.UserModel;
import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.commonmodels.models.plan.PlanStatusModel;
import org.opencdmp.commonmodels.models.planblueprint.PlanBlueprintModel;
import org.opencdmp.commonmodels.models.planreference.PlanReferenceModel;
import org.opencdmp.commons.JsonHandlingService;
@ -127,6 +128,7 @@ public class PlanCommonModelBuilder extends BaseCommonModelBuilder<PlanModel, Pl
Map<UUID, UserModel> creators = this.collectCreators(data);
Map<UUID, PlanBlueprintModel> planBlueprints = this.collectPlanBlueprints(data);
Map<UUID, DefinitionEntity> definitionEntityMap = this.collectPlanBlueprintDefinitions(data);
Map<UUID, PlanStatusModel> planStatuses = this.collectPlanStatuses(data);
for (PlanEntity d : data) {
PlanModel m = new PlanModel();
@ -137,11 +139,7 @@ public class PlanCommonModelBuilder extends BaseCommonModelBuilder<PlanModel, Pl
m.setFinalizedAt(d.getFinalizedAt());
m.setCreatedAt(d.getCreatedAt());
m.setLanguage(d.getLanguage());
switch (d.getStatus()){
case Finalized -> m.setStatus(PlanStatus.Finalized);
case Draft -> m.setStatus(PlanStatus.Draft);
default -> throw new MyApplicationException("unrecognized type " + d.getStatus());
}
if (planStatuses != null && !planStatuses.isEmpty() && d.getStatusId() != null && planStatuses.containsKey(d.getStatusId())) m.setStatus(planStatuses.get(d.getStatusId()));
if (entityDois != null && !entityDois.isEmpty() && entityDois.containsKey(d.getId())) m.setEntityDois(entityDois.get(d.getId()));
if (creators != null && !creators.isEmpty() && d.getCreatorId() != null && creators.containsKey(d.getCreatorId())) m.setCreator(creators.get(d.getCreatorId()));
if (planBlueprints != null && !planBlueprints.isEmpty() && d.getBlueprintId() != null && planBlueprints.containsKey(d.getBlueprintId())) m.setPlanBlueprint(planBlueprints.get(d.getBlueprintId()));
@ -194,8 +192,8 @@ public class PlanCommonModelBuilder extends BaseCommonModelBuilder<PlanModel, Pl
this.logger.debug("checking related - {}", PlanUser.class.getSimpleName());
Map<UUID, List<PlanUserModel>> itemMap;
PlanUserQuery query = this.queryFactory.query(PlanUserQuery.class).disableTracking().isActives(IsActive.Active).authorize(this.authorize).planIds(data.stream().map(PlanEntity::getId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(PlanUserCommonModelBuilder.class).authorize(this.authorize).asMasterKey(query, PlanUserEntity::getPlanId);
PlanUserQuery query = this.queryFactory.query(PlanUserQuery.class).disableTracking().isActives(IsActive.Active).planIds(data.stream().map(PlanEntity::getId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(PlanUserCommonModelBuilder.class).asMasterKey(query, PlanUserEntity::getPlanId);
return itemMap;
}
@ -291,4 +289,15 @@ public class PlanCommonModelBuilder extends BaseCommonModelBuilder<PlanModel, Pl
return itemMap;
}
private Map<UUID, PlanStatusModel> collectPlanStatuses(List<PlanEntity> data) throws MyApplicationException {
if (data.isEmpty())
return null;
this.logger.debug("checking related - {}", PlanStatusModel.class.getSimpleName());
Map<UUID, PlanStatusModel> itemMap;
PlanStatusQuery q = this.queryFactory.query(PlanStatusQuery.class).isActives(IsActive.Active).authorize(this.authorize).ids(data.stream().filter(x-> x.getStatusId() != null).map(PlanEntity::getStatusId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(PlanStatusCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, PlanStatusEntity::getId);
return itemMap;
}
}

View File

@ -0,0 +1,64 @@
package org.opencdmp.model.builder.commonmodels.plan;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.plan.PlanStatusModel;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.PlanStatusEntity;
import org.opencdmp.model.builder.commonmodels.BaseCommonModelBuilder;
import org.opencdmp.model.builder.commonmodels.CommonModelBuilderItemResponse;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PlanStatusCommonModelBuilder extends BaseCommonModelBuilder<PlanStatusModel, PlanStatusEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public PlanStatusCommonModelBuilder(
ConventionService conventionService
) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(PlanStatusCommonModelBuilder.class)));
}
public PlanStatusCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
protected List<CommonModelBuilderItemResponse<PlanStatusModel, PlanStatusEntity>> buildInternal(List<PlanStatusEntity> data) throws MyApplicationException {
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty()) return new ArrayList<>();
List<CommonModelBuilderItemResponse<PlanStatusModel, PlanStatusEntity>> models = new ArrayList<>();
for (PlanStatusEntity d : data) {
PlanStatusModel m = new PlanStatusModel();
m.setId(d.getId());
m.setName(d.getName());
if (d.getInternalStatus() != null) {
switch (d.getInternalStatus()){
case Finalized -> m.setInternalStatus(org.opencdmp.commonmodels.enums.PlanStatus.Finalized);
case Draft -> m.setInternalStatus(org.opencdmp.commonmodels.enums.PlanStatus.Draft);
default -> throw new MyApplicationException("unrecognized type " + d.getInternalStatus());
}
}
models.add(new CommonModelBuilderItemResponse<>(m, d));
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -24,6 +24,7 @@ import org.opencdmp.commonmodels.models.reference.ReferenceModel;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.*;
import org.opencdmp.commons.enums.DescriptionStatus;
import org.opencdmp.commons.notification.NotificationProperties;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope;
@ -269,7 +270,7 @@ public class DescriptionServiceImpl implements DescriptionService {
PlanStatusEntity planStatusEntity = this.entityManager.find(PlanStatusEntity.class, plan.getStatusId(), true);
if (planStatusEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{plan.getStatusId(), PlanStatusEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (planStatusEntity.getInternalStatus() != null && planStatusEntity.getInternalStatus().equals(PlanStatus.Finalized) && isUpdate) throw new MyValidationException(this.errors.getPlanIsFinalized().getCode(), this.errors.getPlanIsFinalized().getMessage());
if (planStatusEntity.getInternalStatus() != null && planStatusEntity.getInternalStatus().equals(PlanStatus.Finalized)) throw new MyValidationException(this.errors.getPlanIsFinalized().getCode(), this.errors.getPlanIsFinalized().getMessage());
data.setLabel(model.getLabel());
data.setDescription(model.getDescription());