migration fixes
This commit is contained in:
parent
e7bbb148d9
commit
1e2d29c25e
|
@ -1,12 +1,15 @@
|
|||
package eu.old.eudat.migration;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
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;
|
||||
|
@ -14,6 +17,7 @@ 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 eu.old.eudat.data.dao.entities.DMPDao;
|
||||
|
@ -84,9 +88,11 @@ public class DmpMigrationService {
|
|||
|
||||
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());
|
||||
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)
|
||||
.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))
|
||||
|
@ -96,7 +102,7 @@ public class DmpMigrationService {
|
|||
|
||||
for (DMP item : items) {
|
||||
//entityManager.detach(item);
|
||||
|
||||
org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definitionEntity = blueprintDefinitionMap.get(item.getId());
|
||||
DataManagementPlan model = new DataManagementPlan();
|
||||
model.fromDataModel(item);
|
||||
List<DMP> itemGroupDmps = groupDmpMap.get(item.getGroupId());
|
||||
|
@ -156,7 +162,17 @@ public class DmpMigrationService {
|
|||
model.getProperties().forEach((key,val) -> {
|
||||
DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity();
|
||||
valueEntity.setFieldId(UUID.fromString(key));
|
||||
valueEntity.setValue((String) val);
|
||||
org.opencdmp.commons.types.dmpblueprint.FieldEntity fieldEntity = this.getFieldOfId(definitionEntity, valueEntity.getFieldId());
|
||||
if (fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)){
|
||||
ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity;
|
||||
switch (extraFieldEntity.getType()){
|
||||
case Date -> valueEntity.setDateValue(Instant.parse((String) val));
|
||||
case RichTex, Text, Number -> valueEntity.setValue((String) val);
|
||||
default -> throw new MyApplicationException("unrecognized type " + extraFieldEntity.getType().getValue());
|
||||
}
|
||||
} else {
|
||||
valueEntity.setValue((String) val);
|
||||
}
|
||||
dmpProperties.getDmpBlueprintValues().add(valueEntity);
|
||||
});
|
||||
}
|
||||
|
@ -210,6 +226,17 @@ 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){
|
||||
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);
|
||||
if (fieldModel != null) return fieldModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void migrateOrganizations(DMP item, List<ReferenceTypeFieldEntity> referenceTypeFieldEntities){
|
||||
Set<Organisation> organisations = item.getOrganisations();
|
||||
if (organisations == null || organisations.isEmpty()) return;
|
||||
|
|
Loading…
Reference in New Issue