Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Sofia Papacharalampous 2024-07-05 16:30:49 +03:00
commit a3c7fc13a8
38 changed files with 433 additions and 443 deletions

View File

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

View File

@ -5,8 +5,8 @@ import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.enums.DmpUserRole;
import org.opencdmp.commonmodels.models.DmpUserModel;
import org.opencdmp.commonmodels.enums.PlanUserRole;
import org.opencdmp.commonmodels.models.PlanUserModel;
import org.opencdmp.commonmodels.models.UserModel;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.convention.ConventionService;
@ -24,7 +24,7 @@ import java.util.stream.Collectors;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PlanUserCommonModelBuilder extends BaseCommonModelBuilder<DmpUserModel, PlanUserEntity> {
public class PlanUserCommonModelBuilder extends BaseCommonModelBuilder<PlanUserModel, PlanUserEntity> {
private final BuilderFactory builderFactory;
@ -47,7 +47,7 @@ public class PlanUserCommonModelBuilder extends BaseCommonModelBuilder<DmpUserMo
}
@Override
protected List<CommonModelBuilderItemResponse<DmpUserModel, PlanUserEntity>> buildInternal(List<PlanUserEntity> data) throws MyApplicationException {
protected List<CommonModelBuilderItemResponse<PlanUserModel, PlanUserEntity>> buildInternal(List<PlanUserEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items ", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null)
return new ArrayList<>();
@ -55,14 +55,14 @@ public class PlanUserCommonModelBuilder extends BaseCommonModelBuilder<DmpUserMo
Map<UUID, UserModel> userItemsMap = this.collectUsers(data);
List<CommonModelBuilderItemResponse<DmpUserModel, PlanUserEntity>> models = new ArrayList<>();
List<CommonModelBuilderItemResponse<PlanUserModel, PlanUserEntity>> models = new ArrayList<>();
for (PlanUserEntity d : data) {
DmpUserModel m = new DmpUserModel();
PlanUserModel m = new PlanUserModel();
switch (d.getRole()){
case Viewer -> m.setRole(DmpUserRole.Viewer);
case Owner -> m.setRole(DmpUserRole.Owner);
case DescriptionContributor -> m.setRole(DmpUserRole.DescriptionContributor);
case Reviewer -> m.setRole(DmpUserRole.Reviewer);
case Viewer -> m.setRole(PlanUserRole.Viewer);
case Owner -> m.setRole(PlanUserRole.Owner);
case DescriptionContributor -> m.setRole(PlanUserRole.DescriptionContributor);
case Reviewer -> m.setRole(PlanUserRole.Reviewer);
default -> throw new MyApplicationException("unrecognized type " + d.getRole().getValue());
}
if (userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));

View File

@ -9,7 +9,7 @@ import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.enums.DescriptionStatus;
import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.descriptiotemplate.DescriptionTemplateModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.types.description.PropertyDefinitionEntity;
@ -87,7 +87,7 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder<Descri
if (data == null || data.isEmpty()) return new ArrayList<>();
Map<UUID, DescriptionTemplateModel> descriptionTemplates = this.collectDescriptionTemplates(data);
Map<UUID, DmpModel> plans = this.collectPlans(data);
Map<UUID, PlanModel> plans = this.collectPlans(data);
Map<UUID, DefinitionEntity> definitionEntityMap = this.collectDescriptionTemplateDefinitions(data);
Map<UUID, UUID> planDescriptionTemplateSections = this.collectPlanDescriptionTemplateSections(data);
@ -106,7 +106,7 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder<Descri
}
m.setCreatedAt(d.getCreatedAt());
m.setDescription(d.getDescription());
if (plans != null && d.getPlanId() != null && plans.containsKey(d.getPlanId())) m.setDmp(plans.get(d.getPlanId()));
if (plans != null && d.getPlanId() != null && plans.containsKey(d.getPlanId())) m.setPlan(plans.get(d.getPlanId()));
if (planDescriptionTemplateSections != null && d.getPlanDescriptionTemplateId() != null && planDescriptionTemplateSections.containsKey(d.getPlanDescriptionTemplateId())) m.setSectionId(planDescriptionTemplateSections.get(d.getPlanDescriptionTemplateId()));
if (descriptionTemplates != null && d.getDescriptionTemplateId() != null && descriptionTemplates.containsKey(d.getDescriptionTemplateId())) m.setDescriptionTemplate(descriptionTemplates.get(d.getDescriptionTemplateId()));
if (d.getProperties() != null){
@ -155,12 +155,12 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder<Descri
return itemMap;
}
private Map<UUID, DmpModel> collectPlans(List<DescriptionEntity> data) throws MyApplicationException {
private Map<UUID, PlanModel> collectPlans(List<DescriptionEntity> data) throws MyApplicationException {
if (data.isEmpty())
return null;
this.logger.debug("checking related - {}", DmpModel.class.getSimpleName());
this.logger.debug("checking related - {}", PlanModel.class.getSimpleName());
Map<UUID, DmpModel> itemMap;
Map<UUID, PlanModel> itemMap;
PlanQuery q = this.queryFactory.query(PlanQuery.class).authorize(this.authorize).disableTracking().ids(data.stream().map(DescriptionEntity::getPlanId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(PlanCommonModelBuilder.class).setRepositoryId(this.repositoryId).useSharedStorage(this.useSharedStorage).setDisableDescriptions(true).authorize(this.authorize).asForeignKey(q, PlanEntity::getId);

View File

@ -53,7 +53,7 @@ public abstract class BaseFieldDataCommonModelBuilder<Model extends BaseFieldDat
case SELECT -> m.setFieldType(FieldType.SELECT);
case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION);
case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX);
case INTERNAL_ENTRIES_PLANS -> m.setFieldType(FieldType.INTERNAL_ENTRIES_DMPS);
case INTERNAL_ENTRIES_PLANS -> m.setFieldType(FieldType.INTERNAL_ENTRIES_PlANS);
case INTERNAL_ENTRIES_DESCRIPTIONS -> m.setFieldType(FieldType.INTERNAL_ENTRIES_DESCRIPTIONS);
case CHECK_BOX -> m.setFieldType(FieldType.CHECK_BOX);
case FREE_TEXT -> m.setFieldType(FieldType.FREE_TEXT);

View File

@ -1,7 +1,7 @@
package org.opencdmp.model.builder.commonmodels.plan;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.dmp.DmpBlueprintValueModel;
import org.opencdmp.commonmodels.models.plan.PlanBlueprintValueModel;
import org.opencdmp.commons.enums.PlanBlueprintExtraFieldDataType;
import org.opencdmp.commons.enums.PlanBlueprintFieldCategory;
import org.opencdmp.commons.types.plan.PlanBlueprintValueEntity;
@ -26,7 +26,7 @@ import java.util.Optional;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PlanBlueprintValueCommonModelBuilder extends BaseCommonModelBuilder<DmpBlueprintValueModel, PlanBlueprintValueEntity> {
public class PlanBlueprintValueCommonModelBuilder extends BaseCommonModelBuilder<PlanBlueprintValueModel, PlanBlueprintValueEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private DefinitionEntity definition;
@ -48,17 +48,17 @@ public class PlanBlueprintValueCommonModelBuilder extends BaseCommonModelBuilder
}
@Override
protected List<CommonModelBuilderItemResponse<DmpBlueprintValueModel, PlanBlueprintValueEntity>> buildInternal(List<PlanBlueprintValueEntity> data) throws MyApplicationException {
protected List<CommonModelBuilderItemResponse<PlanBlueprintValueModel, PlanBlueprintValueEntity>> buildInternal(List<PlanBlueprintValueEntity> 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<DmpBlueprintValueModel, PlanBlueprintValueEntity>> models = new ArrayList<>();
List<CommonModelBuilderItemResponse<PlanBlueprintValueModel, PlanBlueprintValueEntity>> models = new ArrayList<>();
for (PlanBlueprintValueEntity d : data) {
FieldEntity fieldEntity = this.definition != null ? this.definition.getFieldById(d.getFieldId()).stream().findFirst().orElse(null) : null;
if (fieldEntity != null && fieldEntity.getCategory().equals(PlanBlueprintFieldCategory.Extra)) {
ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity;
DmpBlueprintValueModel m = new DmpBlueprintValueModel();
PlanBlueprintValueModel m = new PlanBlueprintValueModel();
m.setFieldId(d.getFieldId());
if (extraFieldEntity != null && PlanBlueprintExtraFieldDataType.isDateType(extraFieldEntity.getType())){
m.setDateValue(d.getDateValue());

View File

@ -7,16 +7,16 @@ import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.enums.DmpAccessType;
import org.opencdmp.commonmodels.enums.DmpStatus;
import org.opencdmp.commonmodels.models.DmpUserModel;
import org.opencdmp.commonmodels.enums.PlanAccessType;
import org.opencdmp.commonmodels.enums.PlanStatus;
import org.opencdmp.commonmodels.models.PlanUserModel;
import org.opencdmp.commonmodels.models.EntityDoiModel;
import org.opencdmp.commonmodels.models.FileEnvelopeModel;
import org.opencdmp.commonmodels.models.UserModel;
import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.dmpblueprint.DmpBlueprintModel;
import org.opencdmp.commonmodels.models.dmpreference.DmpReferenceModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.commonmodels.models.planblueprint.PlanBlueprintModel;
import org.opencdmp.commonmodels.models.planreference.PlanReferenceModel;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.IsActive;
@ -46,7 +46,7 @@ import java.util.stream.Collectors;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PlanCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, PlanEntity> {
public class PlanCommonModelBuilder extends BaseCommonModelBuilder<PlanModel, PlanEntity> {
private final QueryFactory queryFactory;
@ -103,22 +103,22 @@ public class PlanCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, Pla
}
@Override
protected List<CommonModelBuilderItemResponse<DmpModel, PlanEntity>> buildInternal(List<PlanEntity> data) throws MyApplicationException {
protected List<CommonModelBuilderItemResponse<PlanModel, PlanEntity>> buildInternal(List<PlanEntity> 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<DmpModel, PlanEntity>> models = new ArrayList<>();
List<CommonModelBuilderItemResponse<PlanModel, PlanEntity>> models = new ArrayList<>();
Map<UUID, List<DmpReferenceModel>> planReferencesMap = this.collectPlanReferences(data);
Map<UUID, List<DmpUserModel>> planUsersMap = this.collectPlanUsers(data);
Map<UUID, List<PlanReferenceModel>> planReferencesMap = this.collectPlanReferences(data);
Map<UUID, List<PlanUserModel>> planUsersMap = this.collectPlanUsers(data);
Map<UUID, List<DescriptionModel>> descriptionsMap = this.disableDescriptions ? null : this.collectPlanDescriptions(data);
Map<UUID, List<EntityDoiModel>> entityDois = this.collectPlanEntityDois(data);
Map<UUID, UserModel> creators = this.collectCreators(data);
Map<UUID, DmpBlueprintModel> planBlueprints = this.collectPlanBlueprints(data);
Map<UUID, PlanBlueprintModel> planBlueprints = this.collectPlanBlueprints(data);
Map<UUID, DefinitionEntity> definitionEntityMap = this.collectPlanBlueprintDefinitions(data);
for (PlanEntity d : data) {
DmpModel m = new DmpModel();
PlanModel m = new PlanModel();
m.setId(d.getId());
m.setLabel(d.getLabel());
m.setVersion(d.getVersion());
@ -127,13 +127,13 @@ public class PlanCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, Pla
m.setCreatedAt(d.getCreatedAt());
m.setLanguage(d.getLanguage());
switch (d.getStatus()){
case Finalized -> m.setStatus(DmpStatus.Finalized);
case Draft -> m.setStatus(DmpStatus.Draft);
case Finalized -> m.setStatus(PlanStatus.Finalized);
case Draft -> m.setStatus(PlanStatus.Draft);
default -> throw new MyApplicationException("unrecognized type " + d.getStatus());
}
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.setDmpBlueprint(planBlueprints.get(d.getBlueprintId()));
if (planBlueprints != null && !planBlueprints.isEmpty() && d.getBlueprintId() != null && planBlueprints.containsKey(d.getBlueprintId())) m.setPlanBlueprint(planBlueprints.get(d.getBlueprintId()));
if (d.getProperties() != null){
//TODO Update with the new logic of property definition
PlanPropertiesEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PlanPropertiesEntity.class, d.getProperties());
@ -145,8 +145,8 @@ public class PlanCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, Pla
m.setRdaJsonFile(this.rdaJsonFile);
if (d.getVersion() > (short)1) m.setPreviousDOI(this.getPreviousDOI(d.getGroupId(), d.getId()));
switch (d.getAccessType()){
case Public -> m.setAccessType(DmpAccessType.Public);
case Restricted -> m.setAccessType(DmpAccessType.Restricted);
case Public -> m.setAccessType(PlanAccessType.Public);
case Restricted -> m.setAccessType(PlanAccessType.Restricted);
case null -> m.setAccessType(null);
default -> throw new MyApplicationException("unrecognized type " + d.getAccessType());
}
@ -179,20 +179,20 @@ public class PlanCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, Pla
return null;
}
private Map<UUID, List<DmpUserModel>> collectPlanUsers(List<PlanEntity> data) throws MyApplicationException {
private Map<UUID, List<PlanUserModel>> collectPlanUsers(List<PlanEntity> data) throws MyApplicationException {
this.logger.debug("checking related - {}", PlanUser.class.getSimpleName());
Map<UUID, List<DmpUserModel>> itemMap;
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);
return itemMap;
}
private Map<UUID, List<DmpReferenceModel>> collectPlanReferences(List<PlanEntity> data) throws MyApplicationException {
private Map<UUID, List<PlanReferenceModel>> collectPlanReferences(List<PlanEntity> data) throws MyApplicationException {
this.logger.debug("checking related - {}", PlanReference.class.getSimpleName());
Map<UUID, List<DmpReferenceModel>> itemMap;
Map<UUID, List<PlanReferenceModel>> itemMap;
PlanReferenceQuery query = this.queryFactory.query(PlanReferenceQuery.class).disableTracking().isActives(IsActive.Active).authorize(this.authorize).planIds(data.stream().map(PlanEntity::getId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(PlanReferenceCommonModelBuilder.class).authorize(this.authorize).asMasterKey(query, PlanReferenceEntity::getPlanId);
@ -232,12 +232,12 @@ public class PlanCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, Pla
return itemMap;
}
private Map<UUID, DmpBlueprintModel> collectPlanBlueprints(List<PlanEntity> data) throws MyApplicationException {
private Map<UUID, PlanBlueprintModel> collectPlanBlueprints(List<PlanEntity> data) throws MyApplicationException {
if (data.isEmpty())
return null;
this.logger.debug("checking related - {}", DmpBlueprintModel.class.getSimpleName());
this.logger.debug("checking related - {}", PlanBlueprintModel.class.getSimpleName());
Map<UUID, DmpBlueprintModel> itemMap;
Map<UUID, PlanBlueprintModel> itemMap;
PlanBlueprintQuery q = this.queryFactory.query(PlanBlueprintQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().filter(x-> x.getBlueprintId() != null).map(PlanEntity::getBlueprintId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(PlanBlueprintCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, PlanBlueprintEntity::getId);
return itemMap;

View File

@ -5,7 +5,7 @@ import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.dmp.DmpContactModel;
import org.opencdmp.commonmodels.models.plan.PlanContactModel;
import org.opencdmp.commons.types.plan.PlanContactEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.commonmodels.BaseCommonModelBuilder;
@ -20,7 +20,7 @@ import java.util.*;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PlanContactCommonModelBuilder extends BaseCommonModelBuilder<DmpContactModel, PlanContactEntity> {
public class PlanContactCommonModelBuilder extends BaseCommonModelBuilder<PlanContactModel, PlanContactEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final BuilderFactory builderFactory;
@ -41,13 +41,13 @@ public class PlanContactCommonModelBuilder extends BaseCommonModelBuilder<DmpCon
}
@Override
protected List<CommonModelBuilderItemResponse<DmpContactModel, PlanContactEntity>> buildInternal(List<PlanContactEntity> data) throws MyApplicationException {
protected List<CommonModelBuilderItemResponse<PlanContactModel, PlanContactEntity>> buildInternal(List<PlanContactEntity> 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<DmpContactModel, PlanContactEntity>> models = new ArrayList<>();
List<CommonModelBuilderItemResponse<PlanContactModel, PlanContactEntity>> models = new ArrayList<>();
for (PlanContactEntity d : data) {
DmpContactModel m = new DmpContactModel();
PlanContactModel m = new PlanContactModel();
m.setEmail(d.getEmail());
m.setFirstName(d.getFirstName());
m.setLastName(d.getLastName());

View File

@ -1,7 +1,7 @@
package org.opencdmp.model.builder.commonmodels.plan;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.dmp.DmpPropertiesModel;
import org.opencdmp.commonmodels.models.plan.PlanPropertiesModel;
import org.opencdmp.commons.types.plan.PlanPropertiesEntity;
import org.opencdmp.commons.types.planblueprint.DefinitionEntity;
import org.opencdmp.convention.ConventionService;
@ -23,7 +23,7 @@ import java.util.Optional;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PlanPropertiesCommonModelBuilder extends BaseCommonModelBuilder<DmpPropertiesModel, PlanPropertiesEntity> {
public class PlanPropertiesCommonModelBuilder extends BaseCommonModelBuilder<PlanPropertiesModel, PlanPropertiesEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private DefinitionEntity definition;
@ -46,14 +46,14 @@ public class PlanPropertiesCommonModelBuilder extends BaseCommonModelBuilder<Dmp
}
@Override
protected List<CommonModelBuilderItemResponse<DmpPropertiesModel, PlanPropertiesEntity>> buildInternal(List<PlanPropertiesEntity> data) throws MyApplicationException {
protected List<CommonModelBuilderItemResponse<PlanPropertiesModel, PlanPropertiesEntity>> buildInternal(List<PlanPropertiesEntity> 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<DmpPropertiesModel, PlanPropertiesEntity>> models = new ArrayList<>();
List<CommonModelBuilderItemResponse<PlanPropertiesModel, PlanPropertiesEntity>> models = new ArrayList<>();
for (PlanPropertiesEntity d : data) {
DmpPropertiesModel m = new DmpPropertiesModel();
if (d.getPlanBlueprintValues() != null) m.setDmpBlueprintValues(this.builderFactory.builder(PlanBlueprintValueCommonModelBuilder.class).withDefinition(definition).authorize(this.authorize).build(d.getPlanBlueprintValues()));
PlanPropertiesModel m = new PlanPropertiesModel();
if (d.getPlanBlueprintValues() != null) m.setPlanBlueprintValues(this.builderFactory.builder(PlanBlueprintValueCommonModelBuilder.class).withDefinition(definition).authorize(this.authorize).build(d.getPlanBlueprintValues()));
if (d.getContacts() != null) m.setContacts(this.builderFactory.builder(PlanContactCommonModelBuilder.class).authorize(this.authorize).build(d.getContacts()));
models.add(new CommonModelBuilderItemResponse<>(m, d));

View File

@ -1,7 +1,7 @@
package org.opencdmp.model.builder.commonmodels.planblueprint;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.dmpblueprint.DefinitionModel;
import org.opencdmp.commonmodels.models.planblueprint.DefinitionModel;
import org.opencdmp.commons.types.planblueprint.DefinitionEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.commonmodels.BaseCommonModelBuilder;

View File

@ -1,7 +1,7 @@
package org.opencdmp.model.builder.commonmodels.planblueprint;
import org.opencdmp.commonmodels.enums.DmpBlueprintExtraFieldDataType;
import org.opencdmp.commonmodels.models.dmpblueprint.ExtraFieldModel;
import org.opencdmp.commonmodels.enums.PlanBlueprintExtraFieldDataType;
import org.opencdmp.commonmodels.models.planblueprint.ExtraFieldModel;
import org.opencdmp.commons.types.planblueprint.ExtraFieldEntity;
import org.opencdmp.convention.ConventionService;
import gr.cite.tools.exception.MyApplicationException;
@ -26,10 +26,10 @@ public class ExtraFieldCommonModelBuilder extends FieldCommonModelBuilder<ExtraF
protected ExtraFieldModel buildChild(ExtraFieldEntity data, ExtraFieldModel model) {
switch (data.getType()){
case Date -> model.setDataType(DmpBlueprintExtraFieldDataType.Date);
case Number -> model.setDataType(DmpBlueprintExtraFieldDataType.Number);
case RichTex -> model.setDataType(DmpBlueprintExtraFieldDataType.RichTex);
case Text -> model.setDataType(DmpBlueprintExtraFieldDataType.Text);
case Date -> model.setDataType(PlanBlueprintExtraFieldDataType.Date);
case Number -> model.setDataType(PlanBlueprintExtraFieldDataType.Number);
case RichTex -> model.setDataType(PlanBlueprintExtraFieldDataType.RichTex);
case Text -> model.setDataType(PlanBlueprintExtraFieldDataType.Text);
default -> throw new MyApplicationException("unrecognized type " + data.getType());
}
return model;

View File

@ -1,8 +1,8 @@
package org.opencdmp.model.builder.commonmodels.planblueprint;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory;
import org.opencdmp.commonmodels.models.dmpblueprint.FieldModel;
import org.opencdmp.commonmodels.enums.PlanBlueprintFieldCategory;
import org.opencdmp.commonmodels.models.planblueprint.FieldModel;
import org.opencdmp.commons.types.planblueprint.FieldEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.commonmodels.BaseCommonModelBuilder;
@ -51,9 +51,9 @@ public abstract class FieldCommonModelBuilder<Model extends FieldModel, Entity e
m.setId(d.getId());
m.setDescription(d.getDescription());
switch (d.getCategory()){
case System -> m.setCategory(DmpBlueprintFieldCategory.System);
case Extra -> m.setCategory(DmpBlueprintFieldCategory.Extra);
case ReferenceType -> m.setCategory(DmpBlueprintFieldCategory.ReferenceType);
case System -> m.setCategory(PlanBlueprintFieldCategory.System);
case Extra -> m.setCategory(PlanBlueprintFieldCategory.Extra);
case ReferenceType -> m.setCategory(PlanBlueprintFieldCategory.ReferenceType);
default -> throw new MyApplicationException("unrecognized type " + d.getCategory());
}
m.setPlaceholder(d.getPlaceholder());

View File

@ -1,8 +1,8 @@
package org.opencdmp.model.builder.commonmodels.planblueprint;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.enums.DmpBlueprintStatus;
import org.opencdmp.commonmodels.models.dmpblueprint.DmpBlueprintModel;
import org.opencdmp.commonmodels.enums.PlanBlueprintStatus;
import org.opencdmp.commonmodels.models.planblueprint.PlanBlueprintModel;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.types.planblueprint.DefinitionEntity;
import org.opencdmp.convention.ConventionService;
@ -25,7 +25,7 @@ import java.util.Optional;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PlanBlueprintCommonModelBuilder extends BaseCommonModelBuilder<DmpBlueprintModel, PlanBlueprintEntity> {
public class PlanBlueprintCommonModelBuilder extends BaseCommonModelBuilder<PlanBlueprintModel, PlanBlueprintEntity> {
private final BuilderFactory builderFactory;
private final XmlHandlingService xmlHandlingService;
@ -44,21 +44,21 @@ public class PlanBlueprintCommonModelBuilder extends BaseCommonModelBuilder<DmpB
return this;
}
@Override
protected List<CommonModelBuilderItemResponse<DmpBlueprintModel, PlanBlueprintEntity>> buildInternal(List<PlanBlueprintEntity> data) throws MyApplicationException {
protected List<CommonModelBuilderItemResponse<PlanBlueprintModel, PlanBlueprintEntity>> buildInternal(List<PlanBlueprintEntity> 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<DmpBlueprintModel, PlanBlueprintEntity>> models = new ArrayList<>();
List<CommonModelBuilderItemResponse<PlanBlueprintModel, PlanBlueprintEntity>> models = new ArrayList<>();
for (PlanBlueprintEntity d : data) {
DmpBlueprintModel m = new DmpBlueprintModel();
PlanBlueprintModel m = new PlanBlueprintModel();
m.setId(d.getId());
m.setLabel(d.getLabel());
m.setGroupId(d.getGroupId());
switch (d.getStatus()){
case Finalized -> m.setStatus(DmpBlueprintStatus.Finalized);
case Draft -> m.setStatus(DmpBlueprintStatus.Draft);
case Finalized -> m.setStatus(PlanBlueprintStatus.Finalized);
case Draft -> m.setStatus(PlanBlueprintStatus.Draft);
default -> throw new MyApplicationException("unrecognized type " + d.getStatus());
}
if (d.getDefinition() != null){

View File

@ -2,7 +2,7 @@ package org.opencdmp.model.builder.commonmodels.planblueprint;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import org.opencdmp.commonmodels.models.dmpblueprint.ReferenceTypeFieldModel;
import org.opencdmp.commonmodels.models.planblueprint.ReferenceTypeFieldModel;
import org.opencdmp.commons.types.planblueprint.ReferenceTypeFieldEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.commonmodels.ReferenceTypeCommonModelBuilder;

View File

@ -1,7 +1,7 @@
package org.opencdmp.model.builder.commonmodels.planblueprint;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.dmpblueprint.SectionModel;
import org.opencdmp.commonmodels.models.planblueprint.SectionModel;
import org.opencdmp.commons.enums.PlanBlueprintFieldCategory;
import org.opencdmp.commons.types.planblueprint.ExtraFieldEntity;
import org.opencdmp.commons.types.planblueprint.ReferenceTypeFieldEntity;

View File

@ -1,7 +1,7 @@
package org.opencdmp.model.builder.commonmodels.planblueprint;
import org.opencdmp.commonmodels.enums.DmpBlueprintSystemFieldType;
import org.opencdmp.commonmodels.models.dmpblueprint.SystemFieldModel;
import org.opencdmp.commonmodels.enums.PlanBlueprintSystemFieldType;
import org.opencdmp.commonmodels.models.planblueprint.SystemFieldModel;
import org.opencdmp.commons.types.planblueprint.SystemFieldEntity;
import org.opencdmp.convention.ConventionService;
import gr.cite.tools.exception.MyApplicationException;
@ -26,12 +26,12 @@ public class SystemFieldCommonModelBuilder extends FieldCommonModelBuilder<Syste
protected SystemFieldModel buildChild(SystemFieldEntity data, SystemFieldModel model) {
switch (data.getType()){
case AccessRights -> model.setSystemFieldType(DmpBlueprintSystemFieldType.AccessRights);
case Contact -> model.setSystemFieldType(DmpBlueprintSystemFieldType.Contact);
case Description -> model.setSystemFieldType(DmpBlueprintSystemFieldType.Description);
case Language -> model.setSystemFieldType(DmpBlueprintSystemFieldType.Language);
case Title -> model.setSystemFieldType(DmpBlueprintSystemFieldType.Title);
case User -> model.setSystemFieldType(DmpBlueprintSystemFieldType.User);
case AccessRights -> model.setSystemFieldType(PlanBlueprintSystemFieldType.AccessRights);
case Contact -> model.setSystemFieldType(PlanBlueprintSystemFieldType.Contact);
case Description -> model.setSystemFieldType(PlanBlueprintSystemFieldType.Description);
case Language -> model.setSystemFieldType(PlanBlueprintSystemFieldType.Language);
case Title -> model.setSystemFieldType(PlanBlueprintSystemFieldType.Title);
case User -> model.setSystemFieldType(PlanBlueprintSystemFieldType.User);
default -> throw new MyApplicationException("unrecognized type " + data.getType());
}
return model;

View File

@ -5,7 +5,7 @@ import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.dmpreference.DmpReferenceModel;
import org.opencdmp.commonmodels.models.planreference.PlanReferenceModel;
import org.opencdmp.commonmodels.models.reference.ReferenceModel;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.types.planreference.PlanReferenceDataEntity;
@ -27,7 +27,7 @@ import java.util.stream.Collectors;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PlanReferenceCommonModelBuilder extends BaseCommonModelBuilder<DmpReferenceModel, PlanReferenceEntity> {
public class PlanReferenceCommonModelBuilder extends BaseCommonModelBuilder<PlanReferenceModel, PlanReferenceEntity> {
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
@ -50,14 +50,14 @@ public class PlanReferenceCommonModelBuilder extends BaseCommonModelBuilder<DmpR
}
@Override
protected List<CommonModelBuilderItemResponse<DmpReferenceModel, PlanReferenceEntity>> buildInternal(List<PlanReferenceEntity> data) throws MyApplicationException {
protected List<CommonModelBuilderItemResponse<PlanReferenceModel, PlanReferenceEntity>> buildInternal(List<PlanReferenceEntity> data) throws MyApplicationException {
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty()) return new ArrayList<>();
Map<UUID, ReferenceModel> referenceModelMap = this.collectReferences(data);
List<CommonModelBuilderItemResponse<DmpReferenceModel, PlanReferenceEntity>> models = new ArrayList<>();
List<CommonModelBuilderItemResponse<PlanReferenceModel, PlanReferenceEntity>> models = new ArrayList<>();
for (PlanReferenceEntity d : data) {
DmpReferenceModel m = new DmpReferenceModel();
PlanReferenceModel m = new PlanReferenceModel();
m.setId(d.getId());
if (d.getData() != null){
PlanReferenceDataEntity definition = this.jsonHandlingService.fromJsonSafe(PlanReferenceDataEntity.class, d.getData());

View File

@ -1,7 +1,7 @@
package org.opencdmp.model.builder.commonmodels.planreference;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.dmpreference.DmpReferenceDataModel;
import org.opencdmp.commonmodels.models.planreference.PlanReferenceDataModel;
import org.opencdmp.commons.types.planreference.PlanReferenceDataEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.commonmodels.BaseCommonModelBuilder;
@ -22,7 +22,7 @@ import java.util.Optional;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PlanReferenceDataCommonModelBuilder extends BaseCommonModelBuilder<DmpReferenceDataModel, PlanReferenceDataEntity> {
public class PlanReferenceDataCommonModelBuilder extends BaseCommonModelBuilder<PlanReferenceDataModel, PlanReferenceDataEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@ -40,13 +40,13 @@ public class PlanReferenceDataCommonModelBuilder extends BaseCommonModelBuilder<
}
@Override
protected List<CommonModelBuilderItemResponse<DmpReferenceDataModel, PlanReferenceDataEntity>> buildInternal(List<PlanReferenceDataEntity> data) throws MyApplicationException {
protected List<CommonModelBuilderItemResponse<PlanReferenceDataModel, PlanReferenceDataEntity>> buildInternal(List<PlanReferenceDataEntity> 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<DmpReferenceDataModel, PlanReferenceDataEntity>> models = new ArrayList<>();
List<CommonModelBuilderItemResponse<PlanReferenceDataModel, PlanReferenceDataEntity>> models = new ArrayList<>();
for (PlanReferenceDataEntity d : data) {
DmpReferenceDataModel m = new DmpReferenceDataModel();
PlanReferenceDataModel m = new PlanReferenceDataModel();
m.setBlueprintFieldId(d.getBlueprintFieldId());
models.add(new CommonModelBuilderItemResponse<>(m, d));
}

View File

@ -2,7 +2,7 @@ package org.opencdmp.service.deposit;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.depositbase.repository.DepositClient;
import org.opencdmp.depositbase.repository.DepositConfiguration;
import org.slf4j.LoggerFactory;
@ -21,9 +21,9 @@ public class DepositClientImpl implements DepositClient {
@Override
public String deposit(DmpModel dmpDepositModel, String repositoryAccessToken) throws Exception {
logger.debug(new MapLogEntry("deposit").And("dmpDepositModel", dmpDepositModel));
return this.depositClient.post().uri("", uriBuilder -> uriBuilder.queryParam("authToken", repositoryAccessToken).build()).bodyValue(dmpDepositModel).exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(String.class)).block();
public String deposit(PlanModel planDepositModel, String repositoryAccessToken) throws Exception {
logger.debug(new MapLogEntry("deposit").And("planDepositModel", planDepositModel));
return this.depositClient.post().uri("", uriBuilder -> uriBuilder.queryParam("authToken", repositoryAccessToken).build()).bodyValue(planDepositModel).exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(String.class)).block();
}
@Override

View File

@ -17,7 +17,7 @@ import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission;
import org.opencdmp.authorization.authorizationcontentresolver.AuthorizationContentResolver;
import org.opencdmp.commonmodels.models.FileEnvelopeModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.StorageType;
@ -311,7 +311,7 @@ public class DepositServiceImpl implements DepositService {
}
//GK: Fifth Transform them to the DepositModel
DmpModel depositModel = this.builderFactory.builder(PlanCommonModelBuilder.class).useSharedStorage(depositClient.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.AllExceptPublic)
PlanModel depositModel = this.builderFactory.builder(PlanCommonModelBuilder.class).useSharedStorage(depositClient.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.AllExceptPublic)
.setRepositoryId(planDepositModel.getRepositoryId()).setPdfFile(pdfEnvelope).setRdaJsonFile(jsonEnvelope).build(planEntity);

View File

@ -1187,7 +1187,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
case SELECT -> fieldType = FieldType.SELECT;
case BOOLEAN_DECISION -> fieldType = FieldType.BOOLEAN_DECISION;
case RADIO_BOX -> fieldType = FieldType.RADIO_BOX;
case INTERNAL_ENTRIES_DMPS -> fieldType = FieldType.INTERNAL_ENTRIES_PLANS;
case INTERNAL_ENTRIES_PlANS -> fieldType = FieldType.INTERNAL_ENTRIES_PLANS;
case INTERNAL_ENTRIES_DESCRIPTIONS -> fieldType = FieldType.INTERNAL_ENTRIES_DESCRIPTIONS;
case CHECK_BOX -> fieldType = FieldType.CHECK_BOX;
case FREE_TEXT -> fieldType = FieldType.FREE_TEXT;

View File

@ -4,13 +4,13 @@ import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.commonmodels.models.FileEnvelopeModel;
import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerClient;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerConfiguration;
import org.opencdmp.filetransformerbase.models.misc.DescriptionImportModel;
import org.opencdmp.filetransformerbase.models.misc.DmpImportModel;
import org.opencdmp.filetransformerbase.models.misc.PlanImportModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingDescriptionModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingDmpModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingPlanModel;
import org.slf4j.LoggerFactory;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.web.reactive.function.client.WebClient;
@ -27,17 +27,17 @@ public class FileTransformerRepository implements FileTransformerClient {
}
@Override
public FileEnvelopeModel exportDmp(DmpModel dmpModel, String format) {
logger.debug(new MapLogEntry("exportDmp").And("format", format).And("dmpModel", dmpModel));
return this.transformerClient.post().uri("/export/dmp", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(dmpModel)
public FileEnvelopeModel exportPlan(PlanModel planModel, String format) {
logger.debug(new MapLogEntry("exportPlan").And("format", format).And("planModel", planModel));
return this.transformerClient.post().uri("/export/plan", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(planModel)
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(FileEnvelopeModel.class)).block();
}
@Override
public DmpModel importDmp(DmpImportModel dmpImportModel) {
logger.debug(new MapLogEntry("importDmp").And("fileEnvelope", dmpImportModel.getFile()));
return this.transformerClient.post().uri("/import/dmp").bodyValue(dmpImportModel)
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(DmpModel.class)).block();
public PlanModel importPlan(PlanImportModel planImportModel) {
logger.debug(new MapLogEntry("importPlan").And("fileEnvelope", planImportModel.getFile()));
return this.transformerClient.post().uri("/import/plan").bodyValue(planImportModel)
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(PlanModel.class)).block();
}
@Override
@ -62,10 +62,10 @@ public class FileTransformerRepository implements FileTransformerClient {
}
@Override
public PreprocessingDmpModel preprocessingDmp(FileEnvelopeModel fileEnvelopeModel) {
logger.debug(new MapLogEntry("preprocessingDmp").And("fileEnvelope", fileEnvelopeModel));
return this.transformerClient.post().uri("/preprocessing/dmp").bodyValue(fileEnvelopeModel)
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(PreprocessingDmpModel.class)).block();
public PreprocessingPlanModel preprocessingPlan(FileEnvelopeModel fileEnvelopeModel) {
logger.debug(new MapLogEntry("preprocessingPlan").And("fileEnvelope", fileEnvelopeModel));
return this.transformerClient.post().uri("/preprocessing/plan").bodyValue(fileEnvelopeModel)
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(PreprocessingPlanModel.class)).block();
}
@Override

View File

@ -1,8 +1,8 @@
package org.opencdmp.service.filetransformer;
import jakarta.xml.bind.JAXBException;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingDmpModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingPlanModel;
import org.opencdmp.model.file.RepositoryFileFormat;
import org.opencdmp.model.persist.PlanCommonModelConfig;
@ -24,7 +24,7 @@ public interface FileTransformerService {
org.opencdmp.model.file.FileEnvelope exportDescription(UUID descriptionId, String repositoryId, String format) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException;
DmpModel importPlan(PlanCommonModelConfig planCommonModelConfig) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, IOException, JAXBException;
PlanModel importPlan(PlanCommonModelConfig planCommonModelConfig) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, IOException, JAXBException;
PreprocessingDmpModel preprocessingPlan(UUID fileId, String repositoryId) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, IOException;
PreprocessingPlanModel preprocessingPlan(UUID fileId, String repositoryId) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, IOException;
}

View File

@ -19,8 +19,8 @@ import org.opencdmp.authorization.Permission;
import org.opencdmp.commonmodels.models.FileEnvelopeModel;
import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.descriptiotemplate.DescriptionTemplateModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.dmpblueprint.DmpBlueprintModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.commonmodels.models.planblueprint.PlanBlueprintModel;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.StorageType;
@ -36,8 +36,8 @@ import org.opencdmp.data.TenantConfigurationEntity;
import org.opencdmp.event.TenantConfigurationTouchedEvent;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerConfiguration;
import org.opencdmp.filetransformerbase.models.misc.DescriptionImportModel;
import org.opencdmp.filetransformerbase.models.misc.DmpImportModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingDmpModel;
import org.opencdmp.filetransformerbase.models.misc.PlanImportModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingPlanModel;
import org.opencdmp.model.StorageFile;
import org.opencdmp.model.builder.commonmodels.description.DescriptionCommonModelBuilder;
import org.opencdmp.model.builder.commonmodels.descriptiontemplate.DescriptionTemplateCommonModelBuilder;
@ -259,10 +259,10 @@ public class FileTransformerServiceImpl implements FileTransformerService {
if (repository == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{format, FileTransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale()));
//GK: Second get the Target Data Management Plan
PlanQuery query = this.queryFactory.query(PlanQuery.class).disableTracking().authorize(AuthorizationFlags.All).ids(planId);
DmpModel dmpFileTransformerModel = this.builderFactory.builder(PlanCommonModelBuilder.class).useSharedStorage(repository.getConfiguration().isUseSharedStorage()).setRepositoryId(repository.getConfiguration().getFileTransformerId()).authorize(AuthorizationFlags.AllExceptPublic).build(query.first());
if (dmpFileTransformerModel == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{planId, Plan.class.getSimpleName()}, LocaleContextHolder.getLocale()));
PlanModel planFileTransformerModel = this.builderFactory.builder(PlanCommonModelBuilder.class).useSharedStorage(repository.getConfiguration().isUseSharedStorage()).setRepositoryId(repository.getConfiguration().getFileTransformerId()).authorize(AuthorizationFlags.AllExceptPublic).build(query.first());
if (planFileTransformerModel == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{planId, Plan.class.getSimpleName()}, LocaleContextHolder.getLocale()));
FileEnvelopeModel fileEnvelope = repository.exportDmp(dmpFileTransformerModel, format);
FileEnvelopeModel fileEnvelope = repository.exportPlan(planFileTransformerModel, format);
org.opencdmp.model.file.FileEnvelope result = new org.opencdmp.model.file.FileEnvelope();
byte[] data = repository.getConfiguration().isUseSharedStorage() ? this.storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFileRef(), StorageType.Transformer) : fileEnvelope.getFile();
@ -313,7 +313,7 @@ public class FileTransformerServiceImpl implements FileTransformerService {
}
@Override
public DmpModel importPlan(PlanCommonModelConfig planCommonModelConfig) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, IOException, JAXBException {
public PlanModel importPlan(PlanCommonModelConfig planCommonModelConfig) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, IOException, JAXBException {
this.authorizationService.authorizeForce(Permission.NewPlan);
StorageFileEntity tempFile = this.queryFactory.query(StorageFileQuery.class).disableTracking().authorize(AuthorizationFlags.AllExceptPublic).ids(planCommonModelConfig.getFileId()).first();
@ -325,11 +325,11 @@ public class FileTransformerServiceImpl implements FileTransformerService {
if (repository == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{planCommonModelConfig.getRepositoryId(), FileTransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale()));
PlanBlueprintQuery planBlueprintQuery = this.queryFactory.query(PlanBlueprintQuery.class).disableTracking().authorize(AuthorizationFlags.AllExceptPublic).ids(planCommonModelConfig.getBlueprintId());
DmpBlueprintModel dmpBlueprintModel = this.builderFactory.builder(PlanBlueprintCommonModelBuilder.class).authorize(AuthorizationFlags.AllExceptPublic).build(planBlueprintQuery.first());
if (dmpBlueprintModel == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{planCommonModelConfig.getBlueprintId(), PlanBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
PlanBlueprintModel planBlueprintModel = this.builderFactory.builder(PlanBlueprintCommonModelBuilder.class).authorize(AuthorizationFlags.AllExceptPublic).build(planBlueprintQuery.first());
if (planBlueprintModel == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{planCommonModelConfig.getBlueprintId(), PlanBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DmpImportModel dmpImportModel = new DmpImportModel();
dmpImportModel.setBlueprintModel(dmpBlueprintModel);
PlanImportModel planImportModel = new PlanImportModel();
planImportModel.setBlueprintModel(planBlueprintModel);
if (!this.conventionService.isListNullOrEmpty(planCommonModelConfig.getDescriptions())){
List<DescriptionTemplateEntity> descriptionTemplateEntities = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().authorize(AuthorizationFlags.AllExceptPublic).ids(planCommonModelConfig.getDescriptions().stream().map(x -> x.getTemplateId()).distinct().collect(Collectors.toList())).collect();
@ -351,7 +351,7 @@ public class FileTransformerServiceImpl implements FileTransformerService {
}
}
dmpImportModel.setDescriptions(descriptionImportModels);
planImportModel.setDescriptions(descriptionImportModels);
}
String originalFileName = tempFile.getName() + (tempFile.getExtension().startsWith(".") ? "" : ".") + tempFile.getExtension();
@ -374,13 +374,13 @@ public class FileTransformerServiceImpl implements FileTransformerService {
fileEnvelope.setFileRef(storageFile.getFileRef());
}
dmpImportModel.setFile(fileEnvelope);
planImportModel.setFile(fileEnvelope);
return repository.importDmp(dmpImportModel);
return repository.importPlan(planImportModel);
}
@Override
public PreprocessingDmpModel preprocessingPlan(UUID fileId, String repositoryId) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, IOException {
public PreprocessingPlanModel preprocessingPlan(UUID fileId, String repositoryId) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, IOException {
this.authorizationService.authorizeForce(Permission.NewPlan);
StorageFileEntity tempFile = this.queryFactory.query(StorageFileQuery.class).disableTracking().authorize(AuthorizationFlags.AllExceptPublic).ids(fileId).first();
@ -411,7 +411,7 @@ public class FileTransformerServiceImpl implements FileTransformerService {
fileEnvelope.setFileRef(storageFile.getFileRef());
}
return repository.preprocessingDmp(fileEnvelope);
return repository.preprocessingPlan(fileEnvelope);
}
}

View File

@ -7,7 +7,7 @@ import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.FieldSet;
import jakarta.xml.bind.JAXBException;
import org.opencdmp.commons.types.plan.importexport.PlanImportExport;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingDmpModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingPlanModel;
import org.opencdmp.model.PlanUser;
import org.opencdmp.model.PlanValidationResult;
import org.opencdmp.model.plan.Plan;
@ -61,5 +61,5 @@ public interface PlanService {
Plan importJson(PlanCommonModelConfig planCommonModelConfig, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, InvalidApplicationException, IOException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, ParserConfigurationException, TransformerException, InstantiationException, IllegalAccessException, SAXException;
PreprocessingDmpModel preprocessingPlan(UUID fileId, String repositoryId) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, IOException;
PreprocessingPlanModel preprocessingPlan(UUID fileId, String repositoryId) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, IOException;
}

View File

@ -21,19 +21,19 @@ import org.jetbrains.annotations.NotNull;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission;
import org.opencdmp.authorization.authorizationcontentresolver.AuthorizationContentResolver;
import org.opencdmp.commonmodels.models.DmpUserModel;
import org.opencdmp.commonmodels.models.PlanUserModel;
import org.opencdmp.commonmodels.models.UserModel;
import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.dmp.DmpBlueprintValueModel;
import org.opencdmp.commonmodels.models.dmp.DmpContactModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.dmp.DmpPropertiesModel;
import org.opencdmp.commonmodels.models.dmpblueprint.ExtraFieldModel;
import org.opencdmp.commonmodels.models.dmpblueprint.FieldModel;
import org.opencdmp.commonmodels.models.dmpblueprint.ReferenceTypeFieldModel;
import org.opencdmp.commonmodels.models.dmpblueprint.SectionModel;
import org.opencdmp.commonmodels.models.dmpdescriptiontemplate.DmpDescriptionTemplateModel;
import org.opencdmp.commonmodels.models.dmpreference.DmpReferenceModel;
import org.opencdmp.commonmodels.models.plan.PlanBlueprintValueModel;
import org.opencdmp.commonmodels.models.plan.PlanContactModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.commonmodels.models.plan.PlanPropertiesModel;
import org.opencdmp.commonmodels.models.planblueprint.ExtraFieldModel;
import org.opencdmp.commonmodels.models.planblueprint.FieldModel;
import org.opencdmp.commonmodels.models.planblueprint.ReferenceTypeFieldModel;
import org.opencdmp.commonmodels.models.planblueprint.SectionModel;
import org.opencdmp.commonmodels.models.plandescriptiontemplate.PlanDescriptionTemplateModel;
import org.opencdmp.commonmodels.models.planreference.PlanReferenceModel;
import org.opencdmp.commonmodels.models.reference.ReferenceModel;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.XmlHandlingService;
@ -64,7 +64,7 @@ import org.opencdmp.data.*;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.opencdmp.event.PlanTouchedEvent;
import org.opencdmp.event.EventBroker;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingDmpModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingPlanModel;
import org.opencdmp.integrationevent.outbox.annotationentityremoval.AnnotationEntityRemovalIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.annotationentitytouch.AnnotationEntityTouchedIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent;
@ -931,7 +931,7 @@ public class PlanServiceImpl implements PlanService {
if (persist.getPlanBlueprintValues() != null && !persist.getPlanBlueprintValues().isEmpty()){
data.setPlanBlueprintValues(new ArrayList<>());
for (PlanBlueprintValuePersist fieldValuePersist: persist.getPlanBlueprintValues().values()) {
if (!this.conventionService.isNullOrEmpty(fieldValuePersist.getFieldValue()) || fieldValuePersist.getDateValue() != null || fieldValuePersist.getNumberValue() != null) data.getPlanBlueprintValues().add(this.buildDmpBlueprintValueEntity(fieldValuePersist, definition));
if (!this.conventionService.isNullOrEmpty(fieldValuePersist.getFieldValue()) || fieldValuePersist.getDateValue() != null || fieldValuePersist.getNumberValue() != null) data.getPlanBlueprintValues().add(this.buildPlanBlueprintValueEntity(fieldValuePersist, definition));
}
}
return data;
@ -947,7 +947,7 @@ public class PlanServiceImpl implements PlanService {
return data;
}
private @NotNull PlanBlueprintValueEntity buildDmpBlueprintValueEntity(PlanBlueprintValuePersist persist, org.opencdmp.commons.types.planblueprint.DefinitionEntity definition){
private @NotNull PlanBlueprintValueEntity buildPlanBlueprintValueEntity(PlanBlueprintValuePersist persist, org.opencdmp.commons.types.planblueprint.DefinitionEntity definition){
PlanBlueprintValueEntity data = new PlanBlueprintValueEntity();
if (persist == null || definition == null) return data;
@ -1266,11 +1266,11 @@ public class PlanServiceImpl implements PlanService {
persist.setAccessType(data.getAccessType());
persist.setLanguage(data.getLanguage());
List<PlanUserEntity> dmpUserEntities = this.queryFactory.query(PlanUserQuery.class).disableTracking().authorize(AuthorizationFlags.AllExceptPublic).planIds(data.getId()).isActives(IsActive.Active).collect();
List<PlanUserEntity> planUserEntities = this.queryFactory.query(PlanUserQuery.class).disableTracking().authorize(AuthorizationFlags.AllExceptPublic).planIds(data.getId()).isActives(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(dmpUserEntities)){
if (!this.conventionService.isListNullOrEmpty(planUserEntities)){
persist.setUsers(new ArrayList<>());
for (PlanUserEntity user: dmpUserEntities) {
for (PlanUserEntity user: planUserEntities) {
persist.getUsers().add(this.buildPlanUserPersist(user));
}
}
@ -1279,10 +1279,10 @@ public class PlanServiceImpl implements PlanService {
org.opencdmp.commons.types.planblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.planblueprint.DefinitionEntity.class, planBlueprintEntity.getDefinition());
List<PlanDescriptionTemplateEntity> dmpDescriptionTemplateEntities = this.queryFactory.query(PlanDescriptionTemplateQuery.class).disableTracking().authorize(AuthorizationFlags.AllExceptPublic).planIds(data.getId()).isActive(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(dmpDescriptionTemplateEntities)){
List<PlanDescriptionTemplateEntity> planDescriptionTemplateEntities = this.queryFactory.query(PlanDescriptionTemplateQuery.class).disableTracking().authorize(AuthorizationFlags.AllExceptPublic).planIds(data.getId()).isActive(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(planDescriptionTemplateEntities)){
persist.setDescriptionTemplates(new ArrayList<>());
for (PlanDescriptionTemplateEntity descriptionTemplateEntity: dmpDescriptionTemplateEntities) {
for (PlanDescriptionTemplateEntity descriptionTemplateEntity: planDescriptionTemplateEntities) {
persist.getDescriptionTemplates().add(this.buildPlanDescriptionTemplatePersists(descriptionTemplateEntity));
}
}
@ -2053,14 +2053,14 @@ public class PlanServiceImpl implements PlanService {
//region Import RDA JSON
public PreprocessingDmpModel preprocessingPlan(UUID fileId, String repositoryId) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, IOException {
public PreprocessingPlanModel preprocessingPlan(UUID fileId, String repositoryId) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, IOException {
return this.fileTransformerService.preprocessingPlan(fileId, repositoryId);
}
public Plan importJson(PlanCommonModelConfig planCommonModelConfig, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, InvalidApplicationException, IOException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, ParserConfigurationException, TransformerException, InstantiationException, IllegalAccessException, SAXException {
logger.debug(new MapLogEntry("import data").And("file id", planCommonModelConfig.getFileId()).And("label", planCommonModelConfig.getLabel()).And("fields", fields));
DmpModel model = this.fileTransformerService.importPlan(planCommonModelConfig);
PlanModel model = this.fileTransformerService.importPlan(planCommonModelConfig);
if (model == null) throw new MyNotFoundException("Plan Import Error");
PlanPersist persist = new PlanPersist();
@ -2093,10 +2093,10 @@ public class PlanServiceImpl implements PlanService {
return plan;
}
private List<PlanDescriptionTemplatePersist> commonModelPlanDescriptionTemplatesToPersist(DmpModel commonModel){
private List<PlanDescriptionTemplatePersist> commonModelPlanDescriptionTemplatesToPersist(PlanModel commonModel){
if (!this.conventionService.isListNullOrEmpty(commonModel.getDescriptionTemplates())) {
List<PlanDescriptionTemplatePersist> descriptionTemplates = new ArrayList<>();
for (DmpDescriptionTemplateModel descriptionTemplate : commonModel.getDescriptionTemplates()) {
for (PlanDescriptionTemplateModel descriptionTemplate : commonModel.getDescriptionTemplates()) {
descriptionTemplates.add(this.commonModelPlanDescriptionTemplateToPersist(descriptionTemplate));
}
return descriptionTemplates.stream().filter(Objects::nonNull).toList();
@ -2104,7 +2104,7 @@ public class PlanServiceImpl implements PlanService {
return null;
}
private PlanDescriptionTemplatePersist commonModelPlanDescriptionTemplateToPersist(DmpDescriptionTemplateModel commonModel) {
private PlanDescriptionTemplatePersist commonModelPlanDescriptionTemplateToPersist(PlanDescriptionTemplateModel commonModel) {
if (commonModel == null)
return null;
@ -2116,21 +2116,21 @@ public class PlanServiceImpl implements PlanService {
return persist;
}
private UUID commonModelPlanBlueprintToPersist(DmpModel planXml) throws JAXBException, InvalidApplicationException, ParserConfigurationException, IOException, TransformerException, InstantiationException, IllegalAccessException, SAXException {
if (planXml.getDmpBlueprint() != null){
PlanBlueprintEntity planBlueprintEntity = this.queryFactory.query(PlanBlueprintQuery.class).disableTracking().ids(planXml.getDmpBlueprint().getId()).first();
if (planBlueprintEntity == null) planBlueprintEntity = this.queryFactory.query(PlanBlueprintQuery.class).disableTracking().groupIds(planXml.getDmpBlueprint().getGroupId()).versionStatuses(PlanBlueprintVersionStatus.Current).isActive(IsActive.Active).statuses(PlanBlueprintStatus.Finalized).first();
private UUID commonModelPlanBlueprintToPersist(PlanModel planXml) throws JAXBException, InvalidApplicationException, ParserConfigurationException, IOException, TransformerException, InstantiationException, IllegalAccessException, SAXException {
if (planXml.getPlanBlueprint() != null){
PlanBlueprintEntity planBlueprintEntity = this.queryFactory.query(PlanBlueprintQuery.class).disableTracking().ids(planXml.getPlanBlueprint().getId()).first();
if (planBlueprintEntity == null) planBlueprintEntity = this.queryFactory.query(PlanBlueprintQuery.class).disableTracking().groupIds(planXml.getPlanBlueprint().getGroupId()).versionStatuses(PlanBlueprintVersionStatus.Current).isActive(IsActive.Active).statuses(PlanBlueprintStatus.Finalized).first();
if (planBlueprintEntity != null){
return planBlueprintEntity.getId();
} else {
PlanBlueprint persisted = this.planBlueprintService.importCommonModel(planXml.getDmpBlueprint(), new BaseFieldSet().ensure(PlanBlueprint._label).ensure(PlanBlueprint._hash));
PlanBlueprint persisted = this.planBlueprintService.importCommonModel(planXml.getPlanBlueprint(), new BaseFieldSet().ensure(PlanBlueprint._label).ensure(PlanBlueprint._hash));
return persisted.getId();
}
}
return null;
}
private PlanPropertiesPersist commonModelPlanPropertiesToPersist(DmpModel commonModel) {
private PlanPropertiesPersist commonModelPlanPropertiesToPersist(PlanModel commonModel) {
if (commonModel == null || commonModel.getProperties() == null) return null;
PlanPropertiesPersist persist = new PlanPropertiesPersist();
@ -2140,10 +2140,10 @@ public class PlanServiceImpl implements PlanService {
return persist;
}
private List<PlanContactPersist> commonModelToPlanContactPersist(DmpPropertiesModel commonModel){
private List<PlanContactPersist> commonModelToPlanContactPersist(PlanPropertiesModel commonModel){
if (!this.conventionService.isListNullOrEmpty(commonModel.getContacts())) {
List<PlanContactPersist> contacts = new ArrayList<>();
for (DmpContactModel contact : commonModel.getContacts()) {
for (PlanContactModel contact : commonModel.getContacts()) {
contacts.add(this.commonModelPlanContactToPersist(contact));
}
return contacts;
@ -2151,27 +2151,27 @@ public class PlanServiceImpl implements PlanService {
return null;
}
private Map<UUID, PlanBlueprintValuePersist> commonModelToPlanBlueprintValuePersist(DmpModel commonModel){
if (commonModel.getDmpBlueprint() != null && commonModel.getDmpBlueprint().getDefinition() != null && !this.conventionService.isListNullOrEmpty(commonModel.getDmpBlueprint().getDefinition().getSections())) {
private Map<UUID, PlanBlueprintValuePersist> commonModelToPlanBlueprintValuePersist(PlanModel commonModel){
if (commonModel.getPlanBlueprint() != null && commonModel.getPlanBlueprint().getDefinition() != null && !this.conventionService.isListNullOrEmpty(commonModel.getPlanBlueprint().getDefinition().getSections())) {
Map<UUID, PlanBlueprintValuePersist> planBlueprintValues = new HashMap<>();
List<SectionModel> sections = commonModel.getDmpBlueprint().getDefinition().getSections();
List<SectionModel> sections = commonModel.getPlanBlueprint().getDefinition().getSections();
if (!this.conventionService.isListNullOrEmpty(sections)){
for (SectionModel section : sections) {
if (!this.conventionService.isListNullOrEmpty(section.getFields())){
for (FieldModel field : section.getFields()) {
// reference
if (field.getCategory().equals(org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.ReferenceType)){
if (field.getCategory().equals(org.opencdmp.commonmodels.enums.PlanBlueprintFieldCategory.ReferenceType)){
ReferenceTypeFieldModel referenceField = (ReferenceTypeFieldModel) field;
List<DmpReferenceModel> dmpReferencesByField = commonModel.getReferences().stream().filter(x -> x.getData() != null && x.getData().getBlueprintFieldId().equals(referenceField.getId())).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(dmpReferencesByField)){
planBlueprintValues.put(referenceField.getId(), this.commonModelPlanReferenceFieldToPlanBlueprintValuePersist(referenceField, dmpReferencesByField));
List<PlanReferenceModel> planReferencesByField = commonModel.getReferences().stream().filter(x -> x.getData() != null && x.getData().getBlueprintFieldId().equals(referenceField.getId())).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(planReferencesByField)){
planBlueprintValues.put(referenceField.getId(), this.commonModelPlanReferenceFieldToPlanBlueprintValuePersist(referenceField, planReferencesByField));
}
} else {
// custom fields
if (field.getCategory().equals(org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.Extra) && commonModel.getProperties() != null && !this.conventionService.isListNullOrEmpty(commonModel.getProperties().getDmpBlueprintValues())){
DmpBlueprintValueModel dmpBlueprintValueModel = commonModel.getProperties().getDmpBlueprintValues().stream().filter(x -> x.getFieldId().equals(field.getId())).findFirst().orElse(null);
if (field.getCategory().equals(org.opencdmp.commonmodels.enums.PlanBlueprintFieldCategory.Extra) && commonModel.getProperties() != null && !this.conventionService.isListNullOrEmpty(commonModel.getProperties().getPlanBlueprintValues())){
PlanBlueprintValueModel planBlueprintValueModel = commonModel.getProperties().getPlanBlueprintValues().stream().filter(x -> x.getFieldId().equals(field.getId())).findFirst().orElse(null);
ExtraFieldModel extraFieldModel = (ExtraFieldModel) field;
if (dmpBlueprintValueModel != null) planBlueprintValues.put(dmpBlueprintValueModel.getFieldId(), this.commonModelPlanBlueprintValueToPersist(dmpBlueprintValueModel, extraFieldModel));
if (planBlueprintValueModel != null) planBlueprintValues.put(planBlueprintValueModel.getFieldId(), this.commonModelPlanBlueprintValueToPersist(planBlueprintValueModel, extraFieldModel));
}
}
}
@ -2183,7 +2183,7 @@ public class PlanServiceImpl implements PlanService {
return null;
}
private PlanBlueprintValuePersist commonModelPlanReferenceFieldToPlanBlueprintValuePersist(ReferenceTypeFieldModel model, List<DmpReferenceModel> planReferences) {
private PlanBlueprintValuePersist commonModelPlanReferenceFieldToPlanBlueprintValuePersist(ReferenceTypeFieldModel model, List<PlanReferenceModel> planReferences) {
if (model == null || this.conventionService.isListNullOrEmpty(planReferences) || model.getReferenceType() == null)
return null;
@ -2196,7 +2196,7 @@ public class PlanServiceImpl implements PlanService {
persist.setFieldId(model.getId());
if (model.getMultipleSelect()){
List<ReferencePersist> references = new ArrayList<>();
for (DmpReferenceModel planReference : planReferences) {
for (PlanReferenceModel planReference : planReferences) {
references.add(this.commonPlanReferenceToReferencePersist(planReference.getReference(), referenceTypeEntity));
}
persist.setReferences(references);
@ -2239,7 +2239,7 @@ public class PlanServiceImpl implements PlanService {
return persist;
}
private PlanBlueprintValuePersist commonModelPlanBlueprintValueToPersist(DmpBlueprintValueModel commonModel, ExtraFieldModel extraFieldModel) {
private PlanBlueprintValuePersist commonModelPlanBlueprintValueToPersist(PlanBlueprintValueModel commonModel, ExtraFieldModel extraFieldModel) {
if (commonModel == null || extraFieldModel == null)
return null;
PlanBlueprintValuePersist persist = new PlanBlueprintValuePersist();
@ -2255,22 +2255,22 @@ public class PlanServiceImpl implements PlanService {
return persist;
}
private List<PlanUserPersist> commonModelToPlanUsersPersist(DmpModel commonModel){
private List<PlanUserPersist> commonModelToPlanUsersPersist(PlanModel commonModel){
if (!this.conventionService.isListNullOrEmpty(commonModel.getUsers())) {
List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().ids(commonModel.getUsers().stream().map(DmpUserModel::getUser).filter(Objects::nonNull).map(UserModel::getId).filter(Objects::nonNull).distinct().toList()).isActive(IsActive.Active).collect();
List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().ids(commonModel.getUsers().stream().map(PlanUserModel::getUser).filter(Objects::nonNull).map(UserModel::getId).filter(Objects::nonNull).distinct().toList()).isActive(IsActive.Active).collect();
List<UUID> userIds = users == null ? new ArrayList<>() : users.stream().map(UserEntity::getId).collect(Collectors.toList());
List<PlanUserPersist> dmpUsers = new ArrayList<>();
for (DmpUserModel user : commonModel.getUsers()) {
dmpUsers.add(this.commonModelPlanUserToPersist(user, userIds));
List<PlanUserPersist> planUsers = new ArrayList<>();
for (PlanUserModel user : commonModel.getUsers()) {
planUsers.add(this.commonModelPlanUserToPersist(user, userIds));
}
return dmpUsers;
return planUsers;
}
return null;
}
private PlanUserPersist commonModelPlanUserToPersist(DmpUserModel commonModel, List<UUID> userIds) {
private PlanUserPersist commonModelPlanUserToPersist(PlanUserModel commonModel, List<UUID> userIds) {
if (commonModel == null)
return null;
@ -2293,7 +2293,7 @@ public class PlanServiceImpl implements PlanService {
return null;
}
private PlanContactPersist commonModelPlanContactToPersist(DmpContactModel commonModel) {
private PlanContactPersist commonModelPlanContactToPersist(PlanContactModel commonModel) {
if (commonModel == null)
return null;

View File

@ -7,7 +7,7 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.FieldSet;
import jakarta.xml.bind.JAXBException;
import org.opencdmp.commonmodels.models.dmpblueprint.DmpBlueprintModel;
import org.opencdmp.commonmodels.models.planblueprint.PlanBlueprintModel;
import org.opencdmp.commons.enums.PlanBlueprintSystemFieldType;
import org.opencdmp.commons.types.planblueprint.importexport.BlueprintImportExport;
import org.opencdmp.data.PlanBlueprintEntity;
@ -43,5 +43,5 @@ public interface PlanBlueprintService {
PlanBlueprint importXml(BlueprintImportExport planBlueprintDefinition, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
PlanBlueprint importXml(byte[] bytes, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
PlanBlueprint importCommonModel(DmpBlueprintModel planBlueprintModel, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
PlanBlueprint importCommonModel(PlanBlueprintModel planBlueprintModel, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
}

View File

@ -18,7 +18,7 @@ import jakarta.xml.bind.JAXBException;
import org.jetbrains.annotations.NotNull;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commonmodels.models.dmpblueprint.*;
import org.opencdmp.commonmodels.models.planblueprint.*;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.*;
import org.opencdmp.commons.scope.tenant.TenantScope;
@ -809,7 +809,7 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
//region Import Common Model
@Override
public PlanBlueprint importCommonModel(DmpBlueprintModel planBlueprintModel, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException {
public PlanBlueprint importCommonModel(PlanBlueprintModel planBlueprintModel, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException {
logger.debug(new MapLogEntry("import data").And("planBlueprintModel", planBlueprintModel).And("fields", fields));
this.authorizationService.authorizeForce(Permission.ImportPlanBlueprint);
@ -872,13 +872,13 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
persist.setHasTemplates(commonModel.getHasTemplates());
List<FieldPersist> planBlueprintFieldModels = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(commonModel.getFields())) {
for (SystemFieldModel systemField : commonModel.getFields().stream().filter(x-> org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.System.equals(x.getCategory())).map(x-> (SystemFieldModel)x).toList()) {
for (SystemFieldModel systemField : commonModel.getFields().stream().filter(x-> org.opencdmp.commonmodels.enums.PlanBlueprintFieldCategory.System.equals(x.getCategory())).map(x-> (SystemFieldModel)x).toList()) {
planBlueprintFieldModels.add(this.commonModelSystemFieldToPersist(systemField));
}
for (ReferenceTypeFieldModel referenceField : commonModel.getFields().stream().filter(x-> org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.ReferenceType.equals(x.getCategory())).map(x-> (ReferenceTypeFieldModel)x).toList()) {
for (ReferenceTypeFieldModel referenceField : commonModel.getFields().stream().filter(x-> org.opencdmp.commonmodels.enums.PlanBlueprintFieldCategory.ReferenceType.equals(x.getCategory())).map(x-> (ReferenceTypeFieldModel)x).toList()) {
planBlueprintFieldModels.add(this.commonModelReferenceFieldToPersist(referenceField));
}
for (ExtraFieldModel extraField : commonModel.getFields().stream().filter(x-> org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.Extra.equals(x.getCategory())).map(x-> (ExtraFieldModel)x).toList()) {
for (ExtraFieldModel extraField : commonModel.getFields().stream().filter(x-> org.opencdmp.commonmodels.enums.PlanBlueprintFieldCategory.Extra.equals(x.getCategory())).map(x-> (ExtraFieldModel)x).toList()) {
planBlueprintFieldModels.add(this.commonExtraFieldToPersist(extraField));
}
}

View File

@ -30,7 +30,7 @@ import org.opencdmp.controllers.swagger.annotation.OperationWithTenantHeader;
import org.opencdmp.controllers.swagger.annotation.Swagger400;
import org.opencdmp.controllers.swagger.annotation.Swagger404;
import org.opencdmp.controllers.swagger.annotation.SwaggerCommonErrorResponses;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingDmpModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingPlanModel;
import org.opencdmp.model.DescriptionsToBeFinalized;
import org.opencdmp.model.PlanUser;
import org.opencdmp.model.PlanValidationResult;
@ -499,17 +499,17 @@ public class PlanController {
@OperationWithTenantHeader(summary = "Preprocess a plan from a json file", description = "",
responses = @ApiResponse(description = "OK", responseCode = "200", content = @Content(
schema = @Schema(
implementation = PreprocessingDmpModel.class
implementation = PreprocessingPlanModel.class
))
))
@Transactional
public PreprocessingDmpModel preprocessing(
public PreprocessingPlanModel preprocessing(
@RequestParam("fileId") UUID fileId,
@RequestParam("repositoryId") String repositoryId
) throws InvalidAlgorithmParameterException, JAXBException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, IOException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
logger.debug(new MapLogEntry("preprocessing plan" + Plan.class.getSimpleName()).And("transformerId", repositoryId).And("fileId", fileId));
PreprocessingDmpModel model = this.planService.preprocessingPlan(fileId, repositoryId);
PreprocessingPlanModel model = this.planService.preprocessingPlan(fileId, repositoryId);
this.auditService.track(AuditableAction.Plan_Import, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("transformerId", repositoryId),

View File

@ -14,7 +14,7 @@ import java.util.UUID;
@Entity
@Table(name = "\"DmpBlueprint\"")
@Table(name = "\"PlanBlueprint\"")
public class DMPProfile implements DataEntity<DMPProfile, UUID> {
public enum Status {

View File

@ -1,7 +1,6 @@
package eu.old.eudat.migration;
import eu.old.eudat.data.entities.DMP;
import eu.old.eudat.elastic.entities.Tag;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.*;
@ -9,12 +8,12 @@ import org.opencdmp.commons.types.description.*;
import org.opencdmp.commons.types.descriptionreference.DescriptionReferenceDataEntity;
import org.opencdmp.commons.types.descriptiontemplate.FieldSetEntity;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity;
import org.opencdmp.commons.types.dmpblueprint.DefinitionEntity;
import org.opencdmp.commons.types.planblueprint.DefinitionEntity;
import org.opencdmp.commons.types.externalfetcher.ExternalFetcherApiSourceConfigurationEntity;
import org.opencdmp.commons.types.referencetype.ReferenceTypeDefinitionEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.*;
import org.opencdmp.model.dmp.Dmp;
import org.opencdmp.model.plan.Plan;
import org.opencdmp.model.reference.Reference;
import org.opencdmp.model.referencetype.ReferenceType;
import org.opencdmp.query.*;
@ -48,7 +47,7 @@ import java.util.stream.Stream;
@Service
public class DatasetMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpDatasetProfileMigrationService.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DatasetMigrationService.class));
private final DatabaseRepository databaseRepository;
private final JsonHandlingService jsonHandlingService;
private final QueryFactory queryFactory;
@ -96,11 +95,11 @@ public class DatasetMigrationService {
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Dataset " + page * PageSize + " of " + total);
List<DmpBlueprintEntity> dmpBlueprints = this.queryFactory.query(DmpBlueprintQuery.class).ids(items.stream().map(x-> x.getDmp().getProfile().getId()).distinct().toList()).collect();
Map<UUID, DefinitionEntity> dmpBlueprintsMap = new HashMap<>();
for (DmpBlueprintEntity dmpBlueprint : dmpBlueprints) {
DefinitionEntity definitionEntity = this.xmlHandlingService.fromXml(DefinitionEntity.class, dmpBlueprint.getDefinition());
dmpBlueprintsMap.put(dmpBlueprint.getId(), definitionEntity);
List<PlanBlueprintEntity> planBlueprints = this.queryFactory.query(PlanBlueprintQuery.class).ids(items.stream().map(x-> x.getDmp().getProfile().getId()).distinct().toList()).collect();
Map<UUID, DefinitionEntity> planBlueprintsMap = new HashMap<>();
for (PlanBlueprintEntity planBlueprint : planBlueprints) {
DefinitionEntity definitionEntity = this.xmlHandlingService.fromXml(DefinitionEntity.class, planBlueprint.getDefinition());
planBlueprintsMap.put(planBlueprint.getId(), definitionEntity);
}
List<UUID> changeTemplateToH2020 = Stream.of("0c82f2ce-5ff7-4ca9-a500-9f3062adf550",
"7acd3b36-e598-459c-8170-87c51ac80efb",
@ -118,8 +117,8 @@ public class DatasetMigrationService {
UUID horizon2020UUID = UUID.fromString("6ddde24b-e7a0-477f-a2cd-0a8fad915dc8");
UUID horizonGroupId = UUID.fromString("3689bcce-405a-4d55-9854-669597b79c0a");
List<DmpDescriptionTemplateEntity> dmpDescriptionTemplateEntities = this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(items.stream().map(x-> x.getDmp().getId()).distinct().toList()).collect();
Map<UUID, UUID> creatorsByDmp = this.queryFactory.query(DmpQuery.class).ids(items.stream().map(x-> x.getDmp().getId()).distinct().toList()).collectAs(new BaseFieldSet().ensure(Dmp._id).ensure(Dmp._creator)).stream().collect(Collectors.toMap(DmpEntity::getId, DmpEntity::getCreatorId));
List<PlanDescriptionTemplateEntity> planDescriptionTemplateEntities = this.queryFactory.query(PlanDescriptionTemplateQuery.class).planIds(items.stream().map(x-> x.getDmp().getId()).distinct().toList()).collect();
Map<UUID, UUID> creatorsByPlan = this.queryFactory.query(PlanQuery.class).ids(items.stream().map(x-> x.getDmp().getId()).distinct().toList()).collectAs(new BaseFieldSet().ensure(Plan._id).ensure(Plan._creator)).stream().collect(Collectors.toMap(PlanEntity::getId, PlanEntity::getCreatorId));
List<UUID> profileIds = new ArrayList<>(items.stream().map(x -> x.getProfile().getId()).distinct().toList());
profileIds.add(horizon2020UUID);
@ -137,7 +136,7 @@ public class DatasetMigrationService {
profileGroupId = horizonGroupId;
}
DefinitionEntity definition = dmpBlueprintsMap.getOrDefault(item.getDmp().getProfile().getId(), null);
DefinitionEntity definition = planBlueprintsMap.getOrDefault(item.getDmp().getProfile().getId(), null);
if (definition == null || definition.getSections() == null || definition.getSections().size() <= item.getDmpSectionIndex()) {
throw new MyApplicationException("Migrate Dataset " + item.getId() + " cannot found section id for section " + item.getDmpSectionIndex());
@ -147,10 +146,10 @@ public class DatasetMigrationService {
throw new MyApplicationException("Migrate Dataset " + item.getId() + " cannot found section id for section " + item.getDmpSectionIndex());
}
List<DmpDescriptionTemplateEntity> itemDescriptionTemplates = this.getOrCreateDmpDescriptionTemplateEntity(item, sectionId, profileGroupId, dmpDescriptionTemplateEntities);
List<PlanDescriptionTemplateEntity> itemDescriptionTemplates = this.getOrCreatePlanDescriptionTemplateEntity(item, sectionId, profileGroupId, planDescriptionTemplateEntities);
if (itemDescriptionTemplates.size() > 1) {
throw new MyApplicationException("Migrate Dataset " + item.getId() + " multiple DmpDescriptionTemplateEntity for section " + item.getDmpSectionIndex());
throw new MyApplicationException("Migrate Dataset " + item.getId() + " multiple PlanDescriptionTemplateEntity for section " + item.getDmpSectionIndex());
}
DescriptionEntity data = new DescriptionEntity();
@ -159,11 +158,11 @@ public class DatasetMigrationService {
if (item.getCreator() != null) {
data.setCreatedById(item.getCreator().getId());
} else {
data.setCreatedById(creatorsByDmp.getOrDefault(item.getDmp().getId(), null));
data.setCreatedById(creatorsByPlan.getOrDefault(item.getDmp().getId(), null));
}
data.setDmpId(item.getDmp().getId());
data.setPlanId(item.getDmp().getId());
data.setLabel(item.getLabel());
data.setDmpDescriptionTemplateId(itemDescriptionTemplates.getFirst().getId());
data.setPlanDescriptionTemplateId(itemDescriptionTemplates.getFirst().getId());
data.setDescriptionTemplateId(profileId);
data.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now());
@ -196,16 +195,16 @@ public class DatasetMigrationService {
} while (items != null && !items.isEmpty() && !TestMode);
}
private List<DmpDescriptionTemplateEntity> getOrCreateDmpDescriptionTemplateEntity(Dataset item, UUID sectionId, UUID groupId, List<DmpDescriptionTemplateEntity> dmpDescriptionTemplateEntities){
List<DmpDescriptionTemplateEntity> itemDescriptionTemplates = dmpDescriptionTemplateEntities.stream().filter(x-> x.getDescriptionTemplateGroupId().equals(groupId) && x.getDmpId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId)).toList();
private List<PlanDescriptionTemplateEntity> getOrCreatePlanDescriptionTemplateEntity(Dataset item, UUID sectionId, UUID groupId, List<PlanDescriptionTemplateEntity> dmpDescriptionTemplateEntities){
List<PlanDescriptionTemplateEntity> itemDescriptionTemplates = dmpDescriptionTemplateEntities.stream().filter(x-> x.getDescriptionTemplateGroupId().equals(groupId) && x.getPlanId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId)).toList();
if (itemDescriptionTemplates.isEmpty()) {
boolean isDeleted = item.getStatus().equals(Dataset.Status.CANCELED.getValue()) ||item.getStatus().equals(Dataset.Status.DELETED.getValue()) || item.getDmp().getStatus().equals(DMP.DMPStatus.DELETED.getValue());
if (!isDeleted) logger.warn("Migrate Dataset " + item.getId() + " cannot found DmpDescriptionTemplateEntity for section " + item.getDmpSectionIndex());
if (dmpDescriptionTemplateEntities.stream().anyMatch(x -> x.getDmpId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId))) {
DmpDescriptionTemplateEntity dmpDescriptionTemplateEntity = new DmpDescriptionTemplateEntity();
if (!isDeleted) logger.warn("Migrate Dataset " + item.getId() + " cannot found PlanDescriptionTemplateEntity for section " + item.getDmpSectionIndex());
if (dmpDescriptionTemplateEntities.stream().anyMatch(x -> x.getPlanId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId))) {
PlanDescriptionTemplateEntity dmpDescriptionTemplateEntity = new PlanDescriptionTemplateEntity();
dmpDescriptionTemplateEntity.setId(UUID.randomUUID());
dmpDescriptionTemplateEntity.setDescriptionTemplateGroupId(groupId);
dmpDescriptionTemplateEntity.setDmpId(item.getDmp().getId());
dmpDescriptionTemplateEntity.setPlanId(item.getDmp().getId());
dmpDescriptionTemplateEntity.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now());
dmpDescriptionTemplateEntity.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now());
dmpDescriptionTemplateEntity.setSectionId(sectionId);
@ -214,7 +213,7 @@ public class DatasetMigrationService {
this.entityManager.flush();
itemDescriptionTemplates = List.of(dmpDescriptionTemplateEntity);
} else {
throw new MyApplicationException("Migrate Dataset " + item.getId() + " " + item.getLabel() + " cannot found DmpDescriptionTemplateEntity for section " + item.getDmpSectionIndex());
throw new MyApplicationException("Migrate Dataset " + item.getId() + " " + item.getLabel() + " cannot found PlanDescriptionTemplateEntity for section " + item.getDmpSectionIndex());
}
}
return itemDescriptionTemplates;
@ -327,10 +326,10 @@ public class DatasetMigrationService {
keyParts = newKey.split("_");
}
}
String fieldSetId = "";
String groupId = "";
String fieldSetId;
String groupId;
int ordinal = Integer.MIN_VALUE;
String fieldId = "";
String fieldId;
if (keyParts.length == 4) {
fieldSetId = keyParts[0].trim();
@ -405,7 +404,7 @@ public class DatasetMigrationService {
propertyDefinitionEntity.getFieldSets().put(currentFieldSet.getId().trim(), propertyDefinitionFieldSetEntity);
}
PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity = null;
PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity;
if (this.conventionService.isListNullOrEmpty(propertyDefinitionFieldSetEntity.getItems())){
propertyDefinitionFieldSetItemEntity = new PropertyDefinitionFieldSetItemEntity();
propertyDefinitionFieldSetItemEntity.setFields(new HashMap<>());
@ -427,7 +426,7 @@ public class DatasetMigrationService {
propertyDefinitionEntity.getFieldSets().put(currentFieldSet.getId().trim(), propertyDefinitionFieldSetEntity);
}
PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity = null;
PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity;
if (this.conventionService.isListNullOrEmpty(propertyDefinitionFieldSetEntity.getItems())){
propertyDefinitionFieldSetItemEntity = new PropertyDefinitionFieldSetItemEntity();
propertyDefinitionFieldSetItemEntity.setFields(new HashMap<>());
@ -509,7 +508,7 @@ public class DatasetMigrationService {
}
}
case INTERNAL_ENTRIES_DMPS -> throw new MyApplicationException("Found INTERNAL_ENTRIES_DMPS into description");
case INTERNAL_ENTRIES_PLANS -> throw new MyApplicationException("Found INTERNAL_ENTRIES_DMPS into description");
case INTERNAL_ENTRIES_DESCRIPTIONS -> throw new MyApplicationException("Found INTERNAL_ENTRIES_DMPS into description");
case VALIDATION -> throw new MyApplicationException("Found VALIDATION into description");
case REFERENCE_TYPES -> {
@ -603,7 +602,7 @@ public class DatasetMigrationService {
if (this.conventionService.isListNullOrEmpty(referenceTypeDefinition.getSources())) throw new MyApplicationException("Could not find reference source for reference : " + this.jsonHandlingService.toJsonSafe(textValue));
//if (referenceTypeDefinition.getSources().size() > 1) throw new MyApplicationException("Multiple reference source for reference : " + this.jsonHandlingService.toJsonSafe(textValue));
String source = referenceTypeDefinition.getSources().getFirst().getKey();
String[] parts = null;
String[] parts;
if (textValue.startsWith("[\"")){
parts = migrationTools.tryParseJsonAsObjectString(String[].class, textValue);
} else{
@ -623,7 +622,7 @@ public class DatasetMigrationService {
items.add(ref);
}
if (items.isEmpty()) break;
references = items.toArray(new Map[items.size()]);
references = items.toArray(new Map[0]);
}
}
}
@ -686,7 +685,7 @@ public class DatasetMigrationService {
items.add(ref);
}
if (items.isEmpty()) break;
references = items.toArray(new Map[items.size()]);
references = items.toArray(new Map[0]);
}
}
if (references == null && (ReferenceTypeIds.Datasets.equals(referenceTypeDataEntity.getReferenceTypeId())
@ -697,7 +696,7 @@ public class DatasetMigrationService {
if (textValue.equals("[\".\"]")){
break;
} else if (!textValue.contains("{")) {
String[] parts = null;
String[] parts;
if (textValue.startsWith("[\"")){
parts = migrationTools.tryParseJsonAsObjectString(String[].class, textValue);
} else{
@ -719,7 +718,7 @@ public class DatasetMigrationService {
items.add(ref);
}
if (items.isEmpty()) break;
references = items.toArray(new Map[items.size()]);
references = items.toArray(new Map[0]);
}
}
}

View File

@ -17,7 +17,7 @@ import java.util.UUID;
@Service
public class DatasetReferenceMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpDatasetProfileMigrationService.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DatasetReferenceMigrationService.class));
private final DatabaseRepository databaseRepository;
private static final int PageSize = 500;
private final EntityManager entityManager;

View File

@ -304,7 +304,7 @@ public class DescriptionTemplateXmlMigrationService {
if (renderStyle.equals("internalDmpEntities")){
switch (((InternalDmpEntitiesData<?>)persist).getType()){
case "dmps":
return this.buildLabelAndMultiplicityDataEntity(persist.getLabel(), ((DMPsAutoCompleteData)persist).getMultiAutoComplete(),FieldType.INTERNAL_ENTRIES_DMPS);
return this.buildLabelAndMultiplicityDataEntity(persist.getLabel(), ((DMPsAutoCompleteData)persist).getMultiAutoComplete(),FieldType.INTERNAL_ENTRIES_PLANS);
case "datasets":
return this.buildLabelAndMultiplicityDataEntity(persist.getLabel(), ((DatasetsAutoCompleteData)persist).getMultiAutoComplete(),FieldType.INTERNAL_ENTRIES_DESCRIPTIONS);
case "researchers":
@ -439,7 +439,7 @@ public class DescriptionTemplateXmlMigrationService {
case UPLOAD -> throw new NotSupportedException("Upload validator not supported");
case TAGS -> throw new NotSupportedException("Tags validator not supported");
case INTERNAL_ENTRIES_DMPS -> throw new NotSupportedException("INTERNAL_ENTRIES_DMPS validator not supported for description template " + descriptionTemplateId);
case INTERNAL_ENTRIES_PLANS -> throw new NotSupportedException("INTERNAL_ENTRIES_PLANS validator not supported for description template " + descriptionTemplateId);
case INTERNAL_ENTRIES_DESCRIPTIONS -> throw new NotSupportedException("INTERNAL_ENTRIES_DESCRIPTIONS validator not supported for description template " + descriptionTemplateId);
case REFERENCE_TYPES -> throw new NotSupportedException("REFERENCE_TYPES validator not supported for description template " + descriptionTemplateId);
default -> throw new MyApplicationException("unrecognized type " + fieldType);
@ -493,7 +493,7 @@ public class DescriptionTemplateXmlMigrationService {
case UPLOAD -> throw new NotSupportedException("Upload validator not supported");
case TAGS -> throw new NotSupportedException("Tags validator not supported");
case INTERNAL_ENTRIES_DMPS -> throw new NotSupportedException("INTERNAL_ENTRIES_DMPS validator not supported");
case INTERNAL_ENTRIES_PLANS -> throw new NotSupportedException("INTERNAL_ENTRIES_PLANS validator not supported");
case INTERNAL_ENTRIES_DESCRIPTIONS -> throw new NotSupportedException("INTERNAL_ENTRIES_DESCRIPTIONS validator not supported");
case REFERENCE_TYPES -> throw new NotSupportedException("REFERENCE_TYPES validator not supported");
default -> throw new MyApplicationException("unrecognized type " + fieldType);

View File

@ -1,10 +1,7 @@
package eu.old.eudat.migration;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.ReferenceFieldDataType;
import org.opencdmp.commons.enums.ReferenceSourceType;
import org.opencdmp.commons.types.reference.DefinitionEntity;
import org.opencdmp.commons.types.reference.FieldEntity;
import org.opencdmp.data.ReferenceEntity;
import eu.old.eudat.data.dao.entities.FunderDao;
import eu.old.eudat.data.entities.Funder;
@ -14,7 +11,6 @@ import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

View File

@ -1,16 +1,16 @@
package eu.old.eudat.migration;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.DmpBlueprintExtraFieldDataType;
import org.opencdmp.commons.enums.DmpBlueprintFieldCategory;
import org.opencdmp.commons.enums.DmpBlueprintSystemFieldType;
import org.opencdmp.commons.types.dmpblueprint.*;
import org.opencdmp.commons.enums.PlanBlueprintExtraFieldDataType;
import org.opencdmp.commons.enums.PlanBlueprintFieldCategory;
import org.opencdmp.commons.enums.PlanBlueprintSystemFieldType;
import org.opencdmp.commons.types.planblueprint.*;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.DescriptionTemplateEntity;
import org.opencdmp.data.DmpBlueprintEntity;
import org.opencdmp.model.dmpblueprint.DmpBlueprint;
import org.opencdmp.data.PlanBlueprintEntity;
import org.opencdmp.model.planblueprint.PlanBlueprint;
import org.opencdmp.query.DescriptionTemplateQuery;
import org.opencdmp.query.DmpBlueprintQuery;
import org.opencdmp.query.PlanBlueprintQuery;
import eu.old.eudat.logic.utilities.builders.XmlBuilder;
import eu.old.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.*;
import eu.old.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.FieldCategory;
@ -36,9 +36,9 @@ import java.io.IOException;
import java.util.*;
@Service
public class DmpBlueprintXmlMigrationService {
public class PlanBlueprintXmlMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpBlueprintXmlMigrationService.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PlanBlueprintXmlMigrationService.class));
private final EntityManager entityManager;
private final ConventionService conventionService;
private final XmlHandlingService xmlHandlingService;
@ -47,7 +47,7 @@ public class DmpBlueprintXmlMigrationService {
private static final int PageSize = 500;
private static final boolean TestMode = false;
public DmpBlueprintXmlMigrationService(EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService, QueryFactory queryFactory) {
public PlanBlueprintXmlMigrationService(EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService, QueryFactory queryFactory) {
this.entityManager = entityManager;
this.conventionService = conventionService;
this.xmlHandlingService = xmlHandlingService;
@ -55,31 +55,31 @@ public class DmpBlueprintXmlMigrationService {
}
public void migrate() throws IOException, NoSuchFieldException, IllegalAccessException, JAXBException, ParserConfigurationException, InstantiationException, SAXException, InvalidApplicationException, TransformerException {
long total = this.queryFactory.query(DmpBlueprintQuery.class).count();
logger.debug("Migrate DmpBlueprint Total : " + total);
long total = this.queryFactory.query(PlanBlueprintQuery.class).count();
logger.debug("Migrate PlanBlueprint Total : " + total);
int page = 0;
List<DmpBlueprintEntity> items;
List<PlanBlueprintEntity> items;
List<DescriptionTemplateEntity> descriptionTemplateEntities = this.queryFactory.query(DescriptionTemplateQuery.class).collectAs(new BaseFieldSet().ensure(org.opencdmp.model.descriptiontemplate.DescriptionTemplate._id).ensure(org.opencdmp.model.descriptiontemplate.DescriptionTemplate._groupId));
Map<UUID, UUID> descriptionTemplateGroupMap = new HashMap<>();
for (DescriptionTemplateEntity descriptionTemplateEntity: descriptionTemplateEntities) {
descriptionTemplateGroupMap.put(descriptionTemplateEntity.getId(), descriptionTemplateEntity.getGroupId());
}
do {
DmpBlueprintQuery query = this.queryFactory.query(DmpBlueprintQuery.class);
query.setOrder(new Ordering().addDescending(DmpBlueprint._createdAt));
PlanBlueprintQuery query = this.queryFactory.query(PlanBlueprintQuery.class);
query.setOrder(new Ordering().addDescending(PlanBlueprint._createdAt));
query.setPage(new Paging(page * PageSize, PageSize));
items = query.collect();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate DmpBlueprint " + page * PageSize + " of " + total);
logger.debug("Migrate PlanBlueprint " + page * PageSize + " of " + total);
for (DmpBlueprintEntity item : items) {
for (PlanBlueprintEntity item : items) {
if (this.conventionService.isNullOrEmpty(item.getDefinition())) continue;
Document document = XmlBuilder.fromXml(item.getDefinition());
if (document == null){
logger.error("Migrate DmpBlueprint " + item.getId() + " failed read xml");
logger.error("Migrate PlanBlueprint " + item.getId() + " failed read xml");
continue;
}
@ -94,8 +94,8 @@ public class DmpBlueprintXmlMigrationService {
} while (items != null && !items.isEmpty() && !TestMode);
}
private @NotNull org.opencdmp.commons.types.dmpblueprint.DefinitionEntity buildDefinitionEntity(DataManagementPlanBlueprint dataManagementPlanBlueprint, Map<UUID, UUID> descriptionTemplateGroupMap ) {
org.opencdmp.commons.types.dmpblueprint.DefinitionEntity data = new DefinitionEntity();
private @NotNull org.opencdmp.commons.types.planblueprint.DefinitionEntity buildDefinitionEntity(DataManagementPlanBlueprint dataManagementPlanBlueprint, Map<UUID, UUID> descriptionTemplateGroupMap ) {
org.opencdmp.commons.types.planblueprint.DefinitionEntity data = new DefinitionEntity();
if (dataManagementPlanBlueprint == null)
return data;
if (!this.conventionService.isListNullOrEmpty(dataManagementPlanBlueprint.getSections())) {
@ -135,13 +135,13 @@ public class DmpBlueprintXmlMigrationService {
return data;
}
private @NotNull org.opencdmp.commons.types.dmpblueprint.DescriptionTemplateEntity buildDescriptionTemplateEntity(DescriptionTemplate itm, Map<UUID, UUID> descriptionTemplateGroupMap ) {
org.opencdmp.commons.types.dmpblueprint.DescriptionTemplateEntity data = new org.opencdmp.commons.types.dmpblueprint.DescriptionTemplateEntity();
private @NotNull org.opencdmp.commons.types.planblueprint.DescriptionTemplateEntity buildDescriptionTemplateEntity(DescriptionTemplate itm, Map<UUID, UUID> descriptionTemplateGroupMap ) {
org.opencdmp.commons.types.planblueprint.DescriptionTemplateEntity data = new org.opencdmp.commons.types.planblueprint.DescriptionTemplateEntity();
if (itm == null)
return data;
UUID groupId = descriptionTemplateGroupMap.getOrDefault(itm.getDescriptionTemplateId(), null);
if (groupId == null){
logger.error("Migrate DmpBlueprint, DescriptionTemplate " + itm.getDescriptionTemplateId() + " group not found");
logger.error("Migrate PlanBlueprint, DescriptionTemplate " + itm.getDescriptionTemplateId() + " group not found");
data.setDescriptionTemplateGroupId(itm.getDescriptionTemplateId());
} else {
data.setDescriptionTemplateGroupId(groupId);
@ -154,7 +154,7 @@ public class DmpBlueprintXmlMigrationService {
}
private @NotNull org.opencdmp.commons.types.dmpblueprint.FieldEntity buildFieldEntity(FieldModel itm) {
private @NotNull org.opencdmp.commons.types.planblueprint.FieldEntity buildFieldEntity(FieldModel itm) {
if (itm == null)
return new ExtraFieldEntity();
FieldEntity data;
@ -163,26 +163,26 @@ public class DmpBlueprintXmlMigrationService {
ExtraField extraField = itm.toExtraField();
switch (extraField.getType()){
case TEXT -> dataTyped.setType(DmpBlueprintExtraFieldDataType.Text);
case DATE -> dataTyped.setType(DmpBlueprintExtraFieldDataType.Date);
case NUMBER -> dataTyped.setType(DmpBlueprintExtraFieldDataType.Number);
case RICH_TEXT -> dataTyped.setType(DmpBlueprintExtraFieldDataType.RichTex);
case TEXT -> dataTyped.setType(PlanBlueprintExtraFieldDataType.Text);
case DATE -> dataTyped.setType(PlanBlueprintExtraFieldDataType.Date);
case NUMBER -> dataTyped.setType(PlanBlueprintExtraFieldDataType.Number);
case RICH_TEXT -> dataTyped.setType(PlanBlueprintExtraFieldDataType.RichTex);
default -> throw new MyApplicationException("Type not found " + extraField.getType());
}
dataTyped.setRequired(extraField.getRequired());
data = dataTyped;
data.setCategory(DmpBlueprintFieldCategory.Extra);
data.setCategory(PlanBlueprintFieldCategory.Extra);
} else {
SystemFieldEntity dataTyped = new SystemFieldEntity();
ReferenceTypeFieldEntity referenceTypeFieldEntity = new ReferenceTypeFieldEntity();
SystemField systemField = itm.toSystemField();
switch (systemField.getType()){
case TEXT -> dataTyped.setType(DmpBlueprintSystemFieldType.Title);
case HTML_TEXT -> dataTyped.setType(DmpBlueprintSystemFieldType.Description);
case ACCESS_RIGHTS -> dataTyped.setType(DmpBlueprintSystemFieldType.AccessRights);
case CONTACT -> dataTyped.setType(DmpBlueprintSystemFieldType.Contact);
case LANGUAGE -> dataTyped.setType(DmpBlueprintSystemFieldType.Language);
case TEXT -> dataTyped.setType(PlanBlueprintSystemFieldType.Title);
case HTML_TEXT -> dataTyped.setType(PlanBlueprintSystemFieldType.Description);
case ACCESS_RIGHTS -> dataTyped.setType(PlanBlueprintSystemFieldType.AccessRights);
case CONTACT -> dataTyped.setType(PlanBlueprintSystemFieldType.Contact);
case LANGUAGE -> dataTyped.setType(PlanBlueprintSystemFieldType.Language);
case FUNDER -> {
referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.Funder);
referenceTypeFieldEntity.setMultipleSelect(false);
@ -219,11 +219,11 @@ public class DmpBlueprintXmlMigrationService {
if (referenceTypeFieldEntity.getReferenceTypeId() == null){
data = dataTyped;
data.setCategory(DmpBlueprintFieldCategory.System);
data.setCategory(PlanBlueprintFieldCategory.System);
}
else{
data = referenceTypeFieldEntity;
data.setCategory(DmpBlueprintFieldCategory.ReferenceType);
data.setCategory(PlanBlueprintFieldCategory.ReferenceType);
}
}
data.setId(itm.getId());

View File

@ -5,10 +5,10 @@ import eu.old.eudat.data.entities.DMP;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.data.DmpBlueprintEntity;
import org.opencdmp.data.DmpDescriptionTemplateEntity;
import org.opencdmp.query.DmpBlueprintQuery;
import org.opencdmp.query.DmpDescriptionTemplateQuery;
import org.opencdmp.data.PlanBlueprintEntity;
import org.opencdmp.data.PlanDescriptionTemplateEntity;
import org.opencdmp.query.PlanBlueprintQuery;
import org.opencdmp.query.PlanDescriptionTemplateQuery;
import eu.old.eudat.data.dao.entities.DmpDatasetProfileDao;
import eu.old.eudat.data.entities.DMPDatasetProfile;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
@ -25,18 +25,17 @@ import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.xml.sax.SAXException;
import org.opencdmp.commons.types.dmpblueprint.DefinitionEntity;
import org.opencdmp.commons.types.planblueprint.DefinitionEntity;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.security.SecureRandom;
import java.time.Instant;
import java.util.*;
@Service
public class DmpDatasetProfileMigrationService {
public class PlanDatasetProfileMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpDatasetProfileMigrationService.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PlanDatasetProfileMigrationService.class));
private final DatabaseRepository databaseRepository;
private final JsonHandlingService jsonHandlingService;
@ -46,7 +45,7 @@ public class DmpDatasetProfileMigrationService {
private static final boolean TestMode = false;
private final EntityManager entityManager;
public DmpDatasetProfileMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, QueryFactory queryFactory, XmlHandlingService xmlHandlingService, EntityManager entityManager) {
public PlanDatasetProfileMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, QueryFactory queryFactory, XmlHandlingService xmlHandlingService, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.jsonHandlingService = jsonHandlingService;
this.queryFactory = queryFactory;
@ -57,18 +56,18 @@ public class DmpDatasetProfileMigrationService {
public void migrate() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException {
DmpDatasetProfileDao dmpDatasetProfileDao = databaseRepository.getDmpDatasetProfileDao();
long total = dmpDatasetProfileDao.asQueryable().count();
logger.debug("Migrate DmpDatasetProfile Total : " + total);
logger.debug("Migrate PlanDatasetProfile Total : " + total);
int page = 0;
List<DMPDatasetProfile> items;
do {
items = dmpDatasetProfileDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate DmpDatasetProfile " + page * PageSize + " of " + total);
logger.debug("Migrate PlanDatasetProfile " + page * PageSize + " of " + total);
List<DmpBlueprintEntity> dmpBlueprints = this.queryFactory.query(DmpBlueprintQuery.class).ids(items.stream().map(x-> x.getDmp().getProfile().getId()).distinct().toList()).collect();
List<PlanBlueprintEntity> dmpBlueprints = this.queryFactory.query(PlanBlueprintQuery.class).ids(items.stream().map(x-> x.getDmp().getProfile().getId()).distinct().toList()).collect();
Map<UUID, DefinitionEntity> dmpBlueprintsMap = new HashMap<>();
for (DmpBlueprintEntity dmpBlueprint : dmpBlueprints) {
for (PlanBlueprintEntity dmpBlueprint : dmpBlueprints) {
DefinitionEntity definitionEntity = this.xmlHandlingService.fromXml(DefinitionEntity.class, dmpBlueprint.getDefinition());
dmpBlueprintsMap.put(dmpBlueprint.getId(), definitionEntity);
}
@ -76,35 +75,35 @@ public class DmpDatasetProfileMigrationService {
for (DMPDatasetProfile item : items) {
entityManager.detach(item);
DmpDatasetProfileData profileData = jsonHandlingService.fromJson(DmpDatasetProfileData.class, item.getData());
PlanDatasetProfileData profileData = jsonHandlingService.fromJson(PlanDatasetProfileData.class, item.getData());
if (profileData == null || profileData.dmpSectionIndex == null || profileData.dmpSectionIndex.isEmpty()){
if (profileData != null && item.getDmp() != null && item.getDmp().getProfile() != null && item.getDmp().getProfile().getId() != null && item.getDmp().getProfile().getId().equals(UUID.fromString("86635178-36a6-484f-9057-a934e4eeecd5"))){
profileData.dmpSectionIndex = new ArrayList<>();
profileData.dmpSectionIndex.add(3);
logger.warn("Migrate DmpDatasetProfile " + item.getId() + " failed no section info set to 3");
logger.warn("Migrate PlanDatasetProfile " + item.getId() + " failed no section info set to 3");
} else {
throw new MyApplicationException("Migrate DmpDatasetProfile " + item.getId() + " failed no section info ");
throw new MyApplicationException("Migrate PlanDatasetProfile " + item.getId() + " failed no section info ");
}
}
DefinitionEntity definition = dmpBlueprintsMap.getOrDefault(item.getDmp().getProfile().getId(), null);
if (definition == null){
throw new MyApplicationException("Migrate DmpDatasetProfile " + item.getId() + " failed blueprint definition not found for blueprint " + item.getDmp().getProfile().getId());
throw new MyApplicationException("Migrate PlanDatasetProfile " + item.getId() + " failed blueprint definition not found for blueprint " + item.getDmp().getProfile().getId());
}
for (int sectionIndex: profileData.dmpSectionIndex) {
if (definition.getSections() == null || definition.getSections().size() <= sectionIndex) {
throw new MyApplicationException("Migrate DmpDatasetProfile " + item.getId() + " cannot found section id for section " + sectionIndex);
throw new MyApplicationException("Migrate PlanDatasetProfile " + item.getId() + " cannot found section id for section " + sectionIndex);
}
UUID sectionId = definition.getSections().get(sectionIndex).getId();
if (sectionId == null) {
throw new MyApplicationException("Migrate DmpDatasetProfile " + item.getId() + " cannot found section id for section " + sectionIndex);
throw new MyApplicationException("Migrate PlanDatasetProfile " + item.getId() + " cannot found section id for section " + sectionIndex);
}
DmpDescriptionTemplateEntity data = new DmpDescriptionTemplateEntity();
PlanDescriptionTemplateEntity data = new PlanDescriptionTemplateEntity();
data.setId(UUID.randomUUID());
data.setDescriptionTemplateGroupId(item.getDatasetprofile().getGroupId());
data.setDmpId(getDmp(item).getId());
data.setPlanId(getPlan(item).getId());
data.setCreatedAt(item.getDmp().getCreated() != null ? item.getDmp().getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getDmp().getModified() != null ? item.getDmp().getModified().toInstant() : Instant.now());
data.setSectionId(sectionId);
@ -121,37 +120,37 @@ public class DmpDatasetProfileMigrationService {
removeDuplicates();
}
private DMP getDmp(DMPDatasetProfile item) {
private DMP getPlan(DMPDatasetProfile item) {
return item.getDmp();
}
private void removeDuplicates() {
logger.debug("Checking for duplicates on DmpDescriptionTemplate table after migration");
logger.debug("Checking for duplicates on PlanDescriptionTemplate table after migration");
DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class);
PlanDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(PlanDescriptionTemplateQuery.class);
long total = dmpDescriptionTemplateQuery.count();
logger.debug("Record count to check: {}", total);
CriteriaBuilder b = this.entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> criteria = b.createQuery(Tuple.class);
Root<DmpDescriptionTemplateEntity> root = criteria.from(DmpDescriptionTemplateEntity.class);
criteria.groupBy(Arrays.asList(root.get(DmpDescriptionTemplateEntity._dmpId), root.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId), root.get(DmpDescriptionTemplateEntity._sectionId)));
criteria.multiselect(root.get(DmpDescriptionTemplateEntity._dmpId), root.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId), root.get(DmpDescriptionTemplateEntity._sectionId), b.count(root));
Root<PlanDescriptionTemplateEntity> root = criteria.from(PlanDescriptionTemplateEntity.class);
criteria.groupBy(Arrays.asList(root.get(PlanDescriptionTemplateEntity._planId), root.get(PlanDescriptionTemplateEntity._descriptionTemplateGroupId), root.get(PlanDescriptionTemplateEntity._sectionId)));
criteria.multiselect(root.get(PlanDescriptionTemplateEntity._planId), root.get(PlanDescriptionTemplateEntity._descriptionTemplateGroupId), root.get(PlanDescriptionTemplateEntity._sectionId), b.count(root));
List<Tuple> resultList = this.entityManager.createQuery(criteria).getResultList();
List<Tuple> duplicatesList = resultList.stream().filter(x -> (long) x.get(3) > 1).toList();
CriteriaDelete<DmpDescriptionTemplateEntity> delete = b.createCriteriaDelete(DmpDescriptionTemplateEntity.class);
Root<DmpDescriptionTemplateEntity> root1 = delete.from(DmpDescriptionTemplateEntity.class);
CriteriaDelete<PlanDescriptionTemplateEntity> delete = b.createCriteriaDelete(PlanDescriptionTemplateEntity.class);
Root<PlanDescriptionTemplateEntity> root1 = delete.from(PlanDescriptionTemplateEntity.class);
for (Tuple duplicate : duplicatesList) {
List<DmpDescriptionTemplateEntity> duplicateEntities = dmpDescriptionTemplateQuery
.dmpIds((UUID) duplicate.get(0))
List<PlanDescriptionTemplateEntity> duplicateEntities = dmpDescriptionTemplateQuery
.planIds((UUID) duplicate.get(0))
.descriptionTemplateGroupIds((UUID) duplicate.get(1))
.sectionIds((UUID) duplicate.get(2))
.collect();
List<UUID> toDelete = new ArrayList<>(duplicateEntities.stream().map(DmpDescriptionTemplateEntity::getId).toList());
toDelete.remove(0);
delete.where(root1.get(DmpDescriptionTemplateEntity._id).in(toDelete));
List<UUID> toDelete = new ArrayList<>(duplicateEntities.stream().map(PlanDescriptionTemplateEntity::getId).toList());
toDelete.removeFirst();
delete.where(root1.get(PlanDescriptionTemplateEntity._id).in(toDelete));
this.entityManager.createQuery(delete).executeUpdate();
}
@ -159,7 +158,7 @@ public class DmpDatasetProfileMigrationService {
}
@JsonIgnoreProperties({"validationErrorModel"})
public static class DmpDatasetProfileData {
public static class PlanDatasetProfileData {
private List<Integer> dmpSectionIndex;
@ -170,7 +169,6 @@ public class DmpDatasetProfileMigrationService {
public void setDmpSectionIndex(List<Integer> dmpSectionIndex) {
this.dmpSectionIndex = dmpSectionIndex;
}
}
}

View File

@ -2,25 +2,22 @@ package eu.old.eudat.migration;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.old.eudat.data.dao.entities.UserInfoDao;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.dmpblueprint.SectionModel;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.*;
import org.opencdmp.commons.types.dmp.DmpBlueprintValueEntity;
import org.opencdmp.commons.types.dmp.DmpContactEntity;
import org.opencdmp.commons.types.dmp.DmpPropertiesEntity;
import org.opencdmp.commons.types.dmpblueprint.ExtraFieldEntity;
import org.opencdmp.commons.types.dmpblueprint.ReferenceTypeFieldEntity;
import org.opencdmp.commons.types.dmpblueprint.SectionEntity;
import org.opencdmp.commons.types.dmpreference.DmpReferenceDataEntity;
import org.opencdmp.commons.types.plan.PlanBlueprintValueEntity;
import org.opencdmp.commons.types.plan.PlanContactEntity;
import org.opencdmp.commons.types.plan.PlanPropertiesEntity;
import org.opencdmp.commons.types.planblueprint.ExtraFieldEntity;
import org.opencdmp.commons.types.planblueprint.ReferenceTypeFieldEntity;
import org.opencdmp.commons.types.planblueprint.SectionEntity;
import org.opencdmp.commons.types.planreference.PlanReferenceDataEntity;
import org.opencdmp.commons.types.reference.DefinitionEntity;
import org.opencdmp.commons.types.reference.FieldEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.*;
import org.opencdmp.model.dmp.DmpBlueprintValue;
import org.opencdmp.model.dmpblueprint.DmpBlueprint;
import org.opencdmp.query.DmpBlueprintQuery;
import org.opencdmp.model.planblueprint.PlanBlueprint;
import org.opencdmp.query.PlanBlueprintQuery;
import eu.old.eudat.data.dao.entities.DMPDao;
import eu.old.eudat.data.entities.*;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
@ -46,9 +43,9 @@ import java.util.*;
import java.util.stream.Collectors;
@Service
public class DmpMigrationService {
public class PlanMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpMigrationService.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PlanMigrationService.class));
private final DatabaseRepository databaseRepository;
private final JsonHandlingService jsonHandlingService;
private final EntityManager entityManager;
@ -60,7 +57,7 @@ public class DmpMigrationService {
private static final int PageSize = 500;
private static final boolean TestMode = false;
public DmpMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService, Environment environment, QueryFactory queryFactory) {
public PlanMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService, Environment environment, QueryFactory queryFactory) {
this.databaseRepository = databaseRepository;
this.jsonHandlingService = jsonHandlingService;
this.entityManager = entityManager;
@ -74,7 +71,7 @@ public class DmpMigrationService {
UserInfoDao userInfoDao = databaseRepository.getUserInfoDao();
DMPDao dmpDao = databaseRepository.getDmpDao();
long total = dmpDao.asQueryable().count();
logger.debug("Migrate Dmp Total : " + total);
logger.debug("Migrate Plan Total : " + total);
int page = 0;
Map<String, UUID> licenseIdByName = new HashMap<>();
@ -82,54 +79,54 @@ public class DmpMigrationService {
do {
items = dmpDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
List<DMP> finalItems = items;
List<DMP> groupDmps = dmpDao.asQueryable().where((builder, root) -> root.get("groupId").in(finalItems.stream().map(DMP::getGroupId).distinct().collect(Collectors.toList()))).toList();
Map<UUID, List<DMP>> groupDmpMap = new HashMap<>();
for (DMP dmp: groupDmps) {
if (!groupDmpMap.containsKey(dmp.getGroupId())) groupDmpMap.put(dmp.getGroupId(), new ArrayList<>());
groupDmpMap.get(dmp.getGroupId()).add(dmp);
List<DMP> groupPlans = dmpDao.asQueryable().where((builder, root) -> root.get("groupId").in(finalItems.stream().map(DMP::getGroupId).distinct().collect(Collectors.toList()))).toList();
Map<UUID, List<DMP>> groupPlanMap = new HashMap<>();
for (DMP dmp: groupPlans) {
if (!groupPlanMap.containsKey(dmp.getGroupId())) groupPlanMap.put(dmp.getGroupId(), new ArrayList<>());
groupPlanMap.get(dmp.getGroupId()).add(dmp);
}
Map<UUID, UserInfo> oldUsers = userInfoDao.asQueryable().toList().stream().collect(Collectors.toMap(UserInfo::getId, x-> x));
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Dmp " + page * PageSize + " of " + total);
List<DmpBlueprintEntity> dmpBlueprintEntities = this.queryFactory.query(DmpBlueprintQuery.class).ids(items.stream().filter(x-> x.getProfile() != null).map(x-> x.getProfile().getId()).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DmpBlueprint._definition).ensure(DmpBlueprint._id));
Map<UUID, org.opencdmp.commons.types.dmpblueprint.DefinitionEntity> blueprintDefinitionMap = new HashMap<>();
Map<UUID, List<ReferenceTypeFieldEntity>> referenceTypeFieldsByDmpBlueprintId = new HashMap<>();
for (DmpBlueprintEntity dmpBlueprintEntity : dmpBlueprintEntities) {
org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXml(org.opencdmp.commons.types.dmpblueprint.DefinitionEntity.class, dmpBlueprintEntity.getDefinition());
logger.debug("Migrate Plan " + page * PageSize + " of " + total);
List<PlanBlueprintEntity> dmpBlueprintEntities = this.queryFactory.query(PlanBlueprintQuery.class).ids(items.stream().filter(x-> x.getProfile() != null).map(x-> x.getProfile().getId()).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(PlanBlueprint._definition).ensure(PlanBlueprint._id));
Map<UUID, org.opencdmp.commons.types.planblueprint.DefinitionEntity> blueprintDefinitionMap = new HashMap<>();
Map<UUID, List<ReferenceTypeFieldEntity>> referenceTypeFieldsByPlanBlueprintId = new HashMap<>();
for (PlanBlueprintEntity dmpBlueprintEntity : dmpBlueprintEntities) {
org.opencdmp.commons.types.planblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXml(org.opencdmp.commons.types.planblueprint.DefinitionEntity.class, dmpBlueprintEntity.getDefinition());
blueprintDefinitionMap.put(dmpBlueprintEntity.getId(), definition);
List<ReferenceTypeFieldEntity> referenceTypeFieldEntities = definition.getSections().stream().filter(x-> x.getFields() != null).map(SectionEntity::getFields).flatMap(List::stream).filter(x-> x.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType)).map(x-> (ReferenceTypeFieldEntity)x)
List<ReferenceTypeFieldEntity> referenceTypeFieldEntities = definition.getSections().stream().filter(x-> x.getFields() != null).map(SectionEntity::getFields).flatMap(List::stream).filter(x-> x.getCategory().equals(PlanBlueprintFieldCategory.ReferenceType)).map(x-> (ReferenceTypeFieldEntity)x)
.filter(x-> x.getReferenceTypeId().equals(ReferenceTypeIds.License) || x.getReferenceTypeId().equals(ReferenceTypeIds.Project) || x.getReferenceTypeId().equals(ReferenceTypeIds.Researcher)
|| x.getReferenceTypeId().equals(ReferenceTypeIds.Grants) || x.getReferenceTypeId().equals(ReferenceTypeIds.Organizations) || x.getReferenceTypeId().equals(ReferenceTypeIds.Funder))
.collect(Collectors.toList());
referenceTypeFieldsByDmpBlueprintId.put(dmpBlueprintEntity.getId() , referenceTypeFieldEntities);
referenceTypeFieldsByPlanBlueprintId.put(dmpBlueprintEntity.getId() , referenceTypeFieldEntities);
}
for (DMP item : items) {
//entityManager.detach(item);
org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definitionEntity = blueprintDefinitionMap.get(item.getProfile().getId());
org.opencdmp.commons.types.planblueprint.DefinitionEntity definitionEntity = blueprintDefinitionMap.get(item.getProfile().getId());
DataManagementPlan model = new DataManagementPlan();
model.fromDataModel(item);
List<DMP> itemGroupDmps = groupDmpMap.get(item.getGroupId());
DMP currentVersionDmp = itemGroupDmps.stream().filter(x-> DmpStatus.Finalized.getValue().equals(x.getStatus())).max(Comparator.comparing(DMP::getVersion)).orElse(null);
List<DMP> itemGroupPlans = groupPlanMap.get(item.getGroupId());
DMP currentVersionPlan = itemGroupPlans.stream().filter(x-> PlanStatus.Finalized.getValue().equals(x.getStatus())).max(Comparator.comparing(DMP::getVersion)).orElse(null);
DmpPropertiesEntity dmpProperties = new DmpPropertiesEntity();
dmpProperties.setDmpBlueprintValues(new ArrayList<>());
PlanPropertiesEntity dmpProperties = new PlanPropertiesEntity();
dmpProperties.setPlanBlueprintValues(new ArrayList<>());
dmpProperties.setContacts(new ArrayList<>());
DmpEntity data = new DmpEntity();
PlanEntity data = new PlanEntity();
data.setId(model.getId());
data.setLabel(model.getLabel());
data.setDescription(model.getDescription());
if (model.getCreator() != null && model.getCreator().getId() != null) {
data.setCreatorId(model.getCreator().getId());
} else {
for (DMP groupDmp: itemGroupDmps) {
DataManagementPlan groupDmpModel = new DataManagementPlan();
groupDmpModel.fromDataModel(groupDmp);
if (groupDmpModel.getCreator() != null) {
data.setCreatorId(groupDmpModel.getCreator().getId());
for (DMP groupPlan: itemGroupPlans) {
DataManagementPlan groupPlanModel = new DataManagementPlan();
groupPlanModel.fromDataModel(groupPlan);
if (groupPlanModel.getCreator() != null) {
data.setCreatorId(groupPlanModel.getCreator().getId());
break;
}
}
@ -139,14 +136,14 @@ public class DmpMigrationService {
}
data.setGroupId(model.getGroupId());
data.setVersion((short) model.getVersion());
if (currentVersionDmp != null && currentVersionDmp.getId().equals(item.getId())){
data.setVersionStatus(DmpVersionStatus.Current);
if (currentVersionPlan != null && currentVersionPlan.getId().equals(item.getId())){
data.setVersionStatus(PlanVersionStatus.Current);
} else {
if (DmpStatus.Finalized.getValue().equals(item.getStatus())){
if (currentVersionDmp == null) throw new MyApplicationException("Found Finalized Dmp out of the group ");
data.setVersionStatus(DmpVersionStatus.Previous);
if (PlanStatus.Finalized.getValue().equals(item.getStatus())){
if (currentVersionPlan == null) throw new MyApplicationException("Found Finalized Plan out of the group ");
data.setVersionStatus(PlanVersionStatus.Previous);
} else {
data.setVersionStatus(DmpVersionStatus.NotFinalized);
data.setVersionStatus(PlanVersionStatus.NotFinalized);
}
}
if (model.getCreated() != null)
@ -160,16 +157,16 @@ public class DmpMigrationService {
if (model.getExtraProperties().containsKey("language") && model.getExtraProperties().get("language") != null)
data.setLanguage((String) model.getExtraProperties().get("language"));
if (model.getExtraProperties().containsKey("visible") && model.getExtraProperties().get("visible") != null)
data.setAccessType((boolean) model.getExtraProperties().get("visible") ? DmpAccessType.Public : DmpAccessType.Restricted);
data.setAccessType((boolean) model.getExtraProperties().get("visible") ? PlanAccessType.Public : PlanAccessType.Restricted);
if (model.getExtraProperties().containsKey("contact") && model.getExtraProperties().get("contact") != null) {
UserInfo userInfo = oldUsers.getOrDefault(UUID.fromString((String)model.getExtraProperties().get("contact")), null);
if (userInfo != null) {
DmpContactEntity contactEntity = new DmpContactEntity();
PlanContactEntity contactEntity = new PlanContactEntity();
contactEntity.setEmail(userInfo.getEmail());
contactEntity.setFirstName(userInfo.getName());
dmpProperties.getContacts().add(contactEntity);
} else {
throw new MyApplicationException("Contact not found " + UUID.fromString((String)model.getExtraProperties().get("contact")) + " Dmp " + item.getId());
throw new MyApplicationException("Contact not found " + UUID.fromString((String)model.getExtraProperties().get("contact")) + " Plan " + item.getId());
}
}
@ -183,10 +180,10 @@ public class DmpMigrationService {
}
if (model.getProperties() != null) {
model.getProperties().forEach((key,val) -> {
DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity();
PlanBlueprintValueEntity valueEntity = new PlanBlueprintValueEntity();
valueEntity.setFieldId(UUID.fromString(key));
org.opencdmp.commons.types.dmpblueprint.FieldEntity fieldEntity = this.getFieldOfId(definitionEntity, valueEntity.getFieldId());
if (fieldEntity != null && val != null && fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)){
org.opencdmp.commons.types.planblueprint.FieldEntity fieldEntity = this.getFieldOfId(definitionEntity, valueEntity.getFieldId());
if (fieldEntity != null && val != null && fieldEntity.getCategory().equals(PlanBlueprintFieldCategory.Extra)){
ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity;
switch (extraFieldEntity.getType()){
case Date -> {
@ -204,23 +201,23 @@ public class DmpMigrationService {
} else {
valueEntity.setValue((String) val);
}
dmpProperties.getDmpBlueprintValues().add(valueEntity);
dmpProperties.getPlanBlueprintValues().add(valueEntity);
});
}
if (model.getStatus() == 99) {
data.setIsActive(IsActive.Inactive);
data.setStatus(DmpStatus.Draft);
data.setStatus(PlanStatus.Draft);
} else {
data.setIsActive(IsActive.Active);
data.setStatus(DmpStatus.of((short) model.getStatus()));
data.setStatus(PlanStatus.of((short) model.getStatus()));
}
data.setProperties(jsonHandlingService.toJson(dmpProperties));
if (data.getAccessType() == null && item.getStatus().equals(DmpStatus.Finalized.getValue())) {
if (data.getAccessType() == null && item.getStatus().equals(PlanStatus.Finalized.getValue())) {
logger.warn("AccessType not found set to default for dmp " + item.getId());
data.setAccessType(item.isPublic() ? DmpAccessType.Public : DmpAccessType.Restricted);
data.setAccessType(item.isPublic() ? PlanAccessType.Public : PlanAccessType.Restricted);
}
if ((data.getLanguage() == null || data.getLanguage().isBlank()) && item.getStatus().equals(DmpStatus.Finalized.getValue())) {
if ((data.getLanguage() == null || data.getLanguage().isBlank()) && item.getStatus().equals(PlanStatus.Finalized.getValue())) {
logger.warn("Language not found set to default for dmp " + item.getId());
data.setLanguage("en");
}
@ -231,13 +228,13 @@ public class DmpMigrationService {
this.entityManager.persist(data);
this.entityManager.flush();
boolean shouldCreateOwner = item.getUsers() == null || item.getUsers().stream().noneMatch(x-> x.getUser() != null && data.getCreatorId().equals(x.getUser().getId()) && DmpUserRole.Owner.getValue().equals(x.getRole().shortValue()));
boolean shouldCreateOwner = item.getUsers() == null || item.getUsers().stream().noneMatch(x-> x.getUser() != null && data.getCreatorId().equals(x.getUser().getId()) && PlanUserRole.Owner.getValue().equals(x.getRole().shortValue()));
if (shouldCreateOwner) {
DmpUserEntity dmpUserEntity = new DmpUserEntity();
PlanUserEntity dmpUserEntity = new PlanUserEntity();
dmpUserEntity.setId(UUID.randomUUID());
dmpUserEntity.setDmpId(data.getId());
dmpUserEntity.setPlanId(data.getId());
dmpUserEntity.setUserId(data.getCreatorId());
dmpUserEntity.setRole(DmpUserRole.Owner);
dmpUserEntity.setRole(PlanUserRole.Owner);
dmpUserEntity.setCreatedAt(data.getCreatedAt());
dmpUserEntity.setUpdatedAt(data.getCreatedAt());
dmpUserEntity.setIsActive(IsActive.Active);
@ -245,11 +242,11 @@ public class DmpMigrationService {
this.entityManager.flush();
}
licenseIdByName = this.migrateLicense(item, model, licenseIdByName, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null));
this.migrateOrganizations(item, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null));
this.migrateResearchers(item, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null));
this.migrateProjects(item, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null));
this.migrateGrantAndFunder(item, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null));
licenseIdByName = this.migrateLicense(item, model, licenseIdByName, referenceTypeFieldsByPlanBlueprintId.getOrDefault(data.getBlueprintId(), null));
this.migrateOrganizations(item, referenceTypeFieldsByPlanBlueprintId.getOrDefault(data.getBlueprintId(), null));
this.migrateResearchers(item, referenceTypeFieldsByPlanBlueprintId.getOrDefault(data.getBlueprintId(), null));
this.migrateProjects(item, referenceTypeFieldsByPlanBlueprintId.getOrDefault(data.getBlueprintId(), null));
this.migrateGrantAndFunder(item, referenceTypeFieldsByPlanBlueprintId.getOrDefault(data.getBlueprintId(), null));
}
page++;
@ -257,11 +254,11 @@ public class DmpMigrationService {
} while (items != null && !items.isEmpty() && !TestMode);
}
private org.opencdmp.commons.types.dmpblueprint.FieldEntity getFieldOfId(org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition, UUID fieldId){
private org.opencdmp.commons.types.planblueprint.FieldEntity getFieldOfId(org.opencdmp.commons.types.planblueprint.DefinitionEntity definition, UUID fieldId){
if (definition == null || definition.getSections() == null) return null;
for (SectionEntity sectionModel : definition.getSections()){
if (sectionModel.getFields() != null){
org.opencdmp.commons.types.dmpblueprint.FieldEntity fieldModel = sectionModel.getFields().stream().filter(x-> x.getId().equals(fieldId)).findFirst().orElse(null);
org.opencdmp.commons.types.planblueprint.FieldEntity fieldModel = sectionModel.getFields().stream().filter(x-> x.getId().equals(fieldId)).findFirst().orElse(null);
if (fieldModel != null) return fieldModel;
}
}
@ -281,13 +278,13 @@ public class DmpMigrationService {
}
for (Organisation organisation : organisations) {
DmpReferenceEntity data = new DmpReferenceEntity();
PlanReferenceEntity data = new PlanReferenceEntity();
data.setId(UUID.randomUUID());
data.setDmpId(item.getId());
data.setPlanId(item.getId());
data.setReferenceId(organisation.getId());
data.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now());
data.setData(this.jsonHandlingService.toJsonSafe(this.buildDmpReferenceDataEntity(referenceTypeFieldEntity)));
data.setData(this.jsonHandlingService.toJsonSafe(this.buildPlanReferenceDataEntity(referenceTypeFieldEntity)));
data.setIsActive(IsActive.Active);
this.entityManager.persist(data);
}
@ -304,14 +301,14 @@ public class DmpMigrationService {
throw new MyApplicationException("Migration failed Project field not found " + item.getId());
}
DmpReferenceEntity data = new DmpReferenceEntity();
PlanReferenceEntity data = new PlanReferenceEntity();
data.setId(UUID.randomUUID());
data.setDmpId(item.getId());
data.setPlanId(item.getId());
data.setReferenceId(project.getId());
data.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now());
data.setIsActive(IsActive.Active);
data.setData(this.jsonHandlingService.toJsonSafe(this.buildDmpReferenceDataEntity(referenceTypeFieldEntity)));
data.setData(this.jsonHandlingService.toJsonSafe(this.buildPlanReferenceDataEntity(referenceTypeFieldEntity)));
this.entityManager.persist(data);
}
@ -327,13 +324,13 @@ public class DmpMigrationService {
}
for (Researcher researcher : researchers) {
DmpReferenceEntity data = new DmpReferenceEntity();
PlanReferenceEntity data = new PlanReferenceEntity();
data.setId(UUID.randomUUID());
data.setDmpId(item.getId());
data.setPlanId(item.getId());
data.setReferenceId(researcher.getId());
data.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now());
data.setData(this.jsonHandlingService.toJsonSafe(this.buildDmpReferenceDataEntity(referenceTypeFieldEntity)));
data.setData(this.jsonHandlingService.toJsonSafe(this.buildPlanReferenceDataEntity(referenceTypeFieldEntity)));
data.setIsActive(IsActive.Active);
this.entityManager.persist(data);
}
@ -351,13 +348,13 @@ public class DmpMigrationService {
throw new MyApplicationException("Migration failed Grant field not found " + item.getId());
}
DmpReferenceEntity data = new DmpReferenceEntity();
PlanReferenceEntity data = new PlanReferenceEntity();
data.setId(UUID.randomUUID());
data.setDmpId(item.getId());
data.setPlanId(item.getId());
data.setReferenceId(grant.getId());
data.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now());
data.setData(this.jsonHandlingService.toJsonSafe(this.buildDmpReferenceDataEntity(referenceTypeFieldEntity)));
data.setData(this.jsonHandlingService.toJsonSafe(this.buildPlanReferenceDataEntity(referenceTypeFieldEntity)));
data.setIsActive(IsActive.Active);
this.entityManager.persist(data);
if (grant.getFunder() != null){
@ -365,13 +362,13 @@ public class DmpMigrationService {
if (funderField == null) {
throw new MyApplicationException("Migration failed Funder field not found " + item.getId());
}
DmpReferenceEntity founder = new DmpReferenceEntity();
PlanReferenceEntity founder = new PlanReferenceEntity();
founder.setId(UUID.randomUUID());
founder.setDmpId(item.getId());
founder.setPlanId(item.getId());
founder.setReferenceId(grant.getFunder().getId());
founder.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now());
founder.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now());
founder.setData(this.jsonHandlingService.toJsonSafe(this.buildDmpReferenceDataEntity(funderField)));
founder.setData(this.jsonHandlingService.toJsonSafe(this.buildPlanReferenceDataEntity(funderField)));
founder.setIsActive(IsActive.Active);
this.entityManager.persist(founder);
}
@ -456,13 +453,13 @@ public class DmpMigrationService {
licenseIdByName.put(licensePid, referenceEntity.getId());
}
DmpReferenceEntity dmpReferenceEntity = new DmpReferenceEntity();
PlanReferenceEntity dmpReferenceEntity = new PlanReferenceEntity();
dmpReferenceEntity.setId(UUID.randomUUID());
dmpReferenceEntity.setDmpId(item.getId());
dmpReferenceEntity.setPlanId(item.getId());
dmpReferenceEntity.setReferenceId(licenseIdByName.get(licensePid));
dmpReferenceEntity.setCreatedAt(Instant.now());
dmpReferenceEntity.setUpdatedAt(Instant.now());
dmpReferenceEntity.setData(this.jsonHandlingService.toJsonSafe(this.buildDmpReferenceDataEntity(referenceTypeFieldEntity)));
dmpReferenceEntity.setData(this.jsonHandlingService.toJsonSafe(this.buildPlanReferenceDataEntity(referenceTypeFieldEntity)));
dmpReferenceEntity.setIsActive(IsActive.Active);
if (!licenseExists) entityManager.persist(referenceEntity);
@ -473,8 +470,8 @@ public class DmpMigrationService {
return licenseIdByName;
}
private DmpReferenceDataEntity buildDmpReferenceDataEntity(ReferenceTypeFieldEntity referenceTypeFieldEntity){
DmpReferenceDataEntity data = new DmpReferenceDataEntity();
private PlanReferenceDataEntity buildPlanReferenceDataEntity(ReferenceTypeFieldEntity referenceTypeFieldEntity){
PlanReferenceDataEntity data = new PlanReferenceDataEntity();
data.setBlueprintFieldId(referenceTypeFieldEntity.getId());
return data;
}

View File

@ -1,8 +1,8 @@
package eu.old.eudat.migration;
import org.opencdmp.commons.enums.DmpUserRole;
import org.opencdmp.commons.enums.PlanUserRole;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.data.DmpUserEntity;
import org.opencdmp.data.PlanUserEntity;
import eu.old.eudat.data.dao.entities.UserDmpDao;
import eu.old.eudat.data.entities.UserDMP;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
@ -15,9 +15,9 @@ import java.time.Instant;
import java.util.List;
@Service
public class DmpUserMigrationService {
public class PlanUserMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpUserMigrationService.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PlanUserMigrationService.class));
private final DatabaseRepository databaseRepository;
@ -27,7 +27,7 @@ public class DmpUserMigrationService {
private static final boolean TestMode = false;
public DmpUserMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
public PlanUserMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.entityManager = entityManager;
}
@ -46,11 +46,11 @@ public class DmpUserMigrationService {
for (UserDMP item : items) {
//entityManager.detach(item);
DmpUserEntity data = new DmpUserEntity();
PlanUserEntity data = new PlanUserEntity();
data.setId(item.getId());
data.setDmpId(item.getDmp().getId());
data.setPlanId(item.getDmp().getId());
data.setUserId(item.getUser().getId());
data.setRole(DmpUserRole.of(item.getRole().shortValue()));
data.setRole(PlanUserRole.of(item.getRole().shortValue()));
data.setCreatedAt(item.getDmp().getCreated() != null ? item.getDmp().getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getDmp().getModified() != null ? item.getDmp().getModified().toInstant() : Instant.now());
data.setIsActive(IsActive.Active);

View File

@ -26,7 +26,7 @@ import java.net.URISyntaxException;
public class MigrationController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(MigrationController.class));
private final DmpMigrationService dmpMigrationService;
private final PlanMigrationService planMigrationService;
private final DataRepositoryMigrationService dataRepositoryMigrationService;
private final ExternalDatasetMigrationService externalDatasetMigrationService;
private final FunderMigrationService funderMigrationService;
@ -37,21 +37,21 @@ public class MigrationController {
private final ServiceMigrationService serviceMigrationService;
private final DatasetMigrationService datasetMigrationService;
private final TagMigrationService tagMigrationService;
private final DmpDatasetProfileMigrationService dmpDatasetProfileMigrationService;
private final PlanDatasetProfileMigrationService planDatasetProfileMigrationService;
private final OrganizationMigrationService organizationMigrationService;
private final DatasetReferenceMigrationService datasetReferenceMigrationService;
private final UserContactInfoMigrationService userContactInfoMigrationService;
private final DmpUserMigrationService dmpUserMigrationService;
private final PlanUserMigrationService planUserMigrationService;
private final UserMigrationService userMigrationService;
private final DmpBlueprintXmlMigrationService dmpBlueprintXmlMigrationService;
private final PlanBlueprintXmlMigrationService planBlueprintXmlMigrationService;
private final DescriptionTemplateXmlMigrationService descriptionTemplateXmlMigrationService;
private final DescriptionTemplateXmlCleanInvalidReferenceTypesService descriptionTemplateXmlCleanInvalidReferenceTypesService;
private final StorageFileMigrationService storageFileMigrationService;
public MigrationController(
DmpMigrationService dmpMigrationService,
PlanMigrationService planMigrationService,
DatasetMigrationService datasetMigrationService,
DmpDatasetProfileMigrationService dmpDatasetProfileMigrationService,
PlanDatasetProfileMigrationService planDatasetProfileMigrationService,
DataRepositoryMigrationService dataRepositoryMigrationService,
ExternalDatasetMigrationService externalDatasetMigrationService,
FunderMigrationService funderMigrationService,
@ -63,13 +63,13 @@ public class MigrationController {
OrganizationMigrationService organizationMigrationService,
DatasetReferenceMigrationService datasetReferenceMigrationService,
UserContactInfoMigrationService userContactInfoMigrationService,
DmpUserMigrationService dmpUserMigrationService,
PlanUserMigrationService planUserMigrationService,
UserMigrationService userMigrationService,
DmpBlueprintXmlMigrationService dmpBlueprintXmlMigrationService,
PlanBlueprintXmlMigrationService planBlueprintXmlMigrationService,
DescriptionTemplateXmlMigrationService descriptionTemplateXmlMigrationService, DescriptionTemplateXmlCleanInvalidReferenceTypesService descriptionTemplateXmlCleanInvalidReferenceTypesService, StorageFileMigrationService storageFileMigrationService) {
this.dmpMigrationService = dmpMigrationService;
this.planMigrationService = planMigrationService;
this.datasetMigrationService = datasetMigrationService;
this.dmpDatasetProfileMigrationService = dmpDatasetProfileMigrationService;
this.planDatasetProfileMigrationService = planDatasetProfileMigrationService;
this.dataRepositoryMigrationService = dataRepositoryMigrationService;
this.externalDatasetMigrationService = externalDatasetMigrationService;
this.funderMigrationService = funderMigrationService;
@ -82,9 +82,9 @@ public class MigrationController {
this.organizationMigrationService = organizationMigrationService;
this.datasetReferenceMigrationService = datasetReferenceMigrationService;
this.userContactInfoMigrationService = userContactInfoMigrationService;
this.dmpUserMigrationService = dmpUserMigrationService;
this.planUserMigrationService = planUserMigrationService;
this.userMigrationService = userMigrationService;
this.dmpBlueprintXmlMigrationService = dmpBlueprintXmlMigrationService;
this.planBlueprintXmlMigrationService = planBlueprintXmlMigrationService;
this.descriptionTemplateXmlMigrationService = descriptionTemplateXmlMigrationService;
this.descriptionTemplateXmlCleanInvalidReferenceTypesService = descriptionTemplateXmlCleanInvalidReferenceTypesService;
this.storageFileMigrationService = storageFileMigrationService;
@ -149,7 +149,7 @@ public class MigrationController {
this.userMigrationService.migrate();
//XML recreate
this.dmpBlueprintXmlMigrationService.migrate();
this.planBlueprintXmlMigrationService.migrate();
this.descriptionTemplateXmlMigrationService.migrate();
logger.info("Completed!!!");
@ -161,9 +161,9 @@ public class MigrationController {
@Transactional
public boolean step2() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException, NoSuchFieldException, InvalidApplicationException, TransformerException, URISyntaxException {
//Dmp
this.dmpMigrationService.migrate();
this.dmpDatasetProfileMigrationService.migrate();
this.dmpUserMigrationService.migrate();
this.planMigrationService.migrate();
this.planDatasetProfileMigrationService.migrate();
this.planUserMigrationService.migrate();
logger.info("Completed!!!");
@ -190,7 +190,7 @@ public class MigrationController {
@GetMapping("dmp-blueprints-xml")
@Transactional
public boolean migrateDmpBlueprint() throws JAXBException, InvalidApplicationException, IOException, ParserConfigurationException, NoSuchFieldException, TransformerException, IllegalAccessException, InstantiationException, SAXException {
this.dmpBlueprintXmlMigrationService.migrate();
this.planBlueprintXmlMigrationService.migrate();
return true;
}
@ -239,7 +239,7 @@ public class MigrationController {
@GetMapping("dmps")
@Transactional
public boolean migrateDmps() throws IOException, NoSuchFieldException, IllegalAccessException, JAXBException, ParserConfigurationException, InstantiationException, SAXException {
this.dmpMigrationService.migrate();
this.planMigrationService.migrate();
return true;
}
@ -260,7 +260,7 @@ public class MigrationController {
@GetMapping("dmp-dataset-profiles")
@Transactional
public boolean migrateDmpDatasetProfiles() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException {
this.dmpDatasetProfileMigrationService.migrate();
this.planDatasetProfileMigrationService.migrate();
return true;
}
@ -282,7 +282,7 @@ public class MigrationController {
@GetMapping("dmp-users")
@Transactional
public boolean migrateDmpUsers() {
this.dmpUserMigrationService.migrate();
this.planUserMigrationService.migrate();
return true;
}