migration fixes
This commit is contained in:
parent
bff183753b
commit
152320dbd0
|
@ -102,7 +102,7 @@ public class DescriptionTemplateXmlMigrationService {
|
|||
logger.error("Migrate DescriptionTemplate " + item.getId() + " failed read xml");
|
||||
throw new MyApplicationException("Migrate DescriptionTemplate " + item.getId() + " failed read xml");
|
||||
}
|
||||
item.setDefinition(this.xmlHandlingService.toXml(this.buildDefinitionEntity(viewStyleModel, referenceTypeEntityMap, knownReferenceEntities)));
|
||||
item.setDefinition(this.xmlHandlingService.toXml(this.buildDefinitionEntity(viewStyleModel, referenceTypeEntityMap, knownReferenceEntities, item.getId())));
|
||||
this.entityManager.merge(item);
|
||||
}
|
||||
|
||||
|
@ -118,22 +118,22 @@ public class DescriptionTemplateXmlMigrationService {
|
|||
this.entityManager.flush();
|
||||
}
|
||||
|
||||
private @NotNull DefinitionEntity buildDefinitionEntity(ViewStyleModel persist, Map<String, ReferenceTypeEntity> referenceTypeEntityMap, Map<UUID, ReferenceTypeEntity> knownReferenceEntities) throws URISyntaxException {
|
||||
private @NotNull DefinitionEntity buildDefinitionEntity(ViewStyleModel persist, Map<String, ReferenceTypeEntity> referenceTypeEntityMap, Map<UUID, ReferenceTypeEntity> knownReferenceEntities, UUID descriptionTemplateId) throws URISyntaxException {
|
||||
DefinitionEntity data = new DefinitionEntity();
|
||||
if (persist == null)
|
||||
return data;
|
||||
if (!this.conventionService.isListNullOrEmpty(persist.getPages())) {
|
||||
Map<String, List<Section>> sectionPerPage = mapSectionsToPage(persist);
|
||||
Map<String, List<Section>> sectionPerPage = mapSectionsToPage(persist, descriptionTemplateId);
|
||||
data.setPages(new ArrayList<>());
|
||||
for (Page pagePersist : persist.getPages()) {
|
||||
data.getPages().add(this.buildPageEntity(pagePersist, sectionPerPage.get(pagePersist.getId().trim()), referenceTypeEntityMap, knownReferenceEntities));
|
||||
data.getPages().add(this.buildPageEntity(pagePersist, sectionPerPage.get(pagePersist.getId().trim()), referenceTypeEntityMap, knownReferenceEntities, descriptionTemplateId));
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private @NotNull SectionEntity buildSectionEntity(Section persist, Map<String, ReferenceTypeEntity> referenceTypeEntityMap, Map<UUID, ReferenceTypeEntity> knownReferenceEntities) throws URISyntaxException {
|
||||
private @NotNull SectionEntity buildSectionEntity(Section persist, Map<String, ReferenceTypeEntity> referenceTypeEntityMap, Map<UUID, ReferenceTypeEntity> knownReferenceEntities, UUID descriptionTemplateId) throws URISyntaxException {
|
||||
SectionEntity data = new SectionEntity();
|
||||
if (persist == null)
|
||||
return data;
|
||||
|
@ -147,21 +147,21 @@ public class DescriptionTemplateXmlMigrationService {
|
|||
if (!this.conventionService.isListNullOrEmpty(persist.getSections())) {
|
||||
data.setSections(new ArrayList<>());
|
||||
for (Section sectionPersist : persist.getSections()) {
|
||||
data.getSections().add(this.buildSectionEntity(sectionPersist, referenceTypeEntityMap, knownReferenceEntities));
|
||||
data.getSections().add(this.buildSectionEntity(sectionPersist, referenceTypeEntityMap, knownReferenceEntities, descriptionTemplateId));
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.conventionService.isListNullOrEmpty(persist.getFieldSets())) {
|
||||
data.setFieldSets(new ArrayList<>());
|
||||
for (FieldSet fieldSetPersist : persist.getFieldSets()) {
|
||||
data.getFieldSets().add(this.buildFieldSetEntity(fieldSetPersist, referenceTypeEntityMap, knownReferenceEntities));
|
||||
data.getFieldSets().add(this.buildFieldSetEntity(fieldSetPersist, referenceTypeEntityMap, knownReferenceEntities, descriptionTemplateId));
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private @NotNull FieldSetEntity buildFieldSetEntity(FieldSet persist, Map<String, ReferenceTypeEntity> referenceTypeEntityMap, Map<UUID, ReferenceTypeEntity> knownReferenceEntities) throws URISyntaxException {
|
||||
private @NotNull FieldSetEntity buildFieldSetEntity(FieldSet persist, Map<String, ReferenceTypeEntity> referenceTypeEntityMap, Map<UUID, ReferenceTypeEntity> knownReferenceEntities, UUID descriptionTemplateId) throws URISyntaxException {
|
||||
FieldSetEntity data = new FieldSetEntity();
|
||||
if (persist == null)
|
||||
return data;
|
||||
|
@ -180,13 +180,13 @@ public class DescriptionTemplateXmlMigrationService {
|
|||
if (!this.conventionService.isListNullOrEmpty(persist.getFields())) {
|
||||
data.setFields(new ArrayList<>());
|
||||
for (Field fieldPersist : persist.getFields()) {
|
||||
data.getFields().add(this.buildFieldEntity(fieldPersist, referenceTypeEntityMap, knownReferenceEntities));
|
||||
data.getFields().add(this.buildFieldEntity(fieldPersist, referenceTypeEntityMap, knownReferenceEntities, descriptionTemplateId));
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private @NotNull FieldEntity buildFieldEntity(Field persist, Map<String, ReferenceTypeEntity> referenceTypeEntityMap, Map<UUID, ReferenceTypeEntity> knownReferenceEntities) throws URISyntaxException {
|
||||
private @NotNull FieldEntity buildFieldEntity(Field persist, Map<String, ReferenceTypeEntity> referenceTypeEntityMap, Map<UUID, ReferenceTypeEntity> knownReferenceEntities, UUID descriptionTemplateId) throws URISyntaxException {
|
||||
FieldEntity data = new FieldEntity();
|
||||
if (persist == null)
|
||||
return data;
|
||||
|
@ -230,7 +230,7 @@ public class DescriptionTemplateXmlMigrationService {
|
|||
}
|
||||
}
|
||||
|
||||
if (persist.getDefaultValue() != null) data.setDefaultValue(this.buildDefaultValueEntity(persist.getDefaultValue(), data.getData().getFieldType()));
|
||||
if (persist.getDefaultValue() != null) data.setDefaultValue(this.buildDefaultValueEntity(persist.getDefaultValue(), data.getData().getFieldType(), descriptionTemplateId));
|
||||
if (persist.getVisible() != null && !this.conventionService.isListNullOrEmpty(persist.getVisible().getRules())) {
|
||||
data.setVisibilityRules(new ArrayList<>());
|
||||
for (Rule fieldPersist : persist.getVisible().getRules()) {
|
||||
|
@ -402,7 +402,7 @@ public class DescriptionTemplateXmlMigrationService {
|
|||
return data;
|
||||
}
|
||||
|
||||
private @NotNull DefaultValueEntity buildDefaultValueEntity(DefaultValue persist, FieldType fieldType) {
|
||||
private @NotNull DefaultValueEntity buildDefaultValueEntity(DefaultValue persist, FieldType fieldType, UUID descriptionTemplateId) {
|
||||
DefaultValueEntity data = new DefaultValueEntity();
|
||||
if (persist == null)
|
||||
return data;
|
||||
|
@ -439,9 +439,9 @@ 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_DESCRIPTIONS -> throw new NotSupportedException("INTERNAL_ENTRIES_DESCRIPTIONS validator not supported");
|
||||
case REFERENCE_TYPES -> throw new NotSupportedException("REFERENCE_TYPES validator not supported");
|
||||
case INTERNAL_ENTRIES_DMPS -> throw new NotSupportedException("INTERNAL_ENTRIES_DMPS 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);
|
||||
}
|
||||
return data;
|
||||
|
@ -514,7 +514,7 @@ public class DescriptionTemplateXmlMigrationService {
|
|||
|
||||
|
||||
|
||||
private @NotNull PageEntity buildPageEntity(Page persist, List<Section> sections, Map<String, ReferenceTypeEntity> referenceTypeEntityMap, Map<UUID, ReferenceTypeEntity> knownReferenceEntities) throws URISyntaxException {
|
||||
private @NotNull PageEntity buildPageEntity(Page persist, List<Section> sections, Map<String, ReferenceTypeEntity> referenceTypeEntityMap, Map<UUID, ReferenceTypeEntity> knownReferenceEntities, UUID descriptionTemplateId) throws URISyntaxException {
|
||||
PageEntity data = new PageEntity();
|
||||
if (persist == null)
|
||||
return data;
|
||||
|
@ -526,14 +526,14 @@ public class DescriptionTemplateXmlMigrationService {
|
|||
if (!this.conventionService.isListNullOrEmpty(sections)) {
|
||||
data.setSections(new ArrayList<>());
|
||||
for (Section sectionPersist : sections) {
|
||||
data.getSections().add(this.buildSectionEntity(sectionPersist, referenceTypeEntityMap, knownReferenceEntities));
|
||||
data.getSections().add(this.buildSectionEntity(sectionPersist, referenceTypeEntityMap, knownReferenceEntities, descriptionTemplateId));
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
private Map<String, List<Section>> mapSectionsToPage(ViewStyleModel persist){
|
||||
private Map<String, List<Section>> mapSectionsToPage(ViewStyleModel persist, UUID descriptionTemplateId){
|
||||
List<String> mappedSectionsIds = new ArrayList<>();
|
||||
Map<String, List<Section>> sectionPerPage = new HashMap<>();
|
||||
if (persist == null || persist.getPages() == null || persist.getSections() == null) return sectionPerPage;
|
||||
|
@ -550,7 +550,7 @@ public class DescriptionTemplateXmlMigrationService {
|
|||
}
|
||||
|
||||
for (Section section : persist.getSections()){
|
||||
if (!mappedSectionsIds.contains(section.getId().trim())) throw new MyApplicationException("Orphan section found " + section.getId().trim());
|
||||
if (!mappedSectionsIds.contains(section.getId().trim())) throw new MyApplicationException("Orphan section found " + section.getId().trim() + " for description template " + descriptionTemplateId);
|
||||
}
|
||||
|
||||
return sectionPerPage;
|
||||
|
|
|
@ -39,6 +39,9 @@ import org.xml.sax.SAXException;
|
|||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -105,7 +108,7 @@ public class DmpMigrationService {
|
|||
|
||||
for (DMP item : items) {
|
||||
//entityManager.detach(item);
|
||||
org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definitionEntity = blueprintDefinitionMap.get(item.getId());
|
||||
org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definitionEntity = blueprintDefinitionMap.get(item.getProfile().getId());
|
||||
DataManagementPlan model = new DataManagementPlan();
|
||||
model.fromDataModel(item);
|
||||
List<DMP> itemGroupDmps = groupDmpMap.get(item.getGroupId());
|
||||
|
@ -180,10 +183,16 @@ public class DmpMigrationService {
|
|||
DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity();
|
||||
valueEntity.setFieldId(UUID.fromString(key));
|
||||
org.opencdmp.commons.types.dmpblueprint.FieldEntity fieldEntity = this.getFieldOfId(definitionEntity, valueEntity.getFieldId());
|
||||
if (fieldEntity != null && fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)){
|
||||
if (fieldEntity != null && val != null && fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)){
|
||||
ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity;
|
||||
switch (extraFieldEntity.getType()){
|
||||
case Date -> valueEntity.setDateValue(Instant.parse((String) val));
|
||||
case Date -> {
|
||||
try {
|
||||
valueEntity.setDateValue(Instant.parse((String) val));
|
||||
} catch (DateTimeParseException ex) {
|
||||
valueEntity.setDateValue(LocalDate.parse((String) val).atStartOfDay().toInstant(ZoneOffset.UTC));
|
||||
}
|
||||
}
|
||||
case RichTex, Text -> valueEntity.setValue((String) val);
|
||||
case Number -> valueEntity.setNumberValue(Double.parseDouble((String) val));
|
||||
default -> throw new MyApplicationException("unrecognized type " + extraFieldEntity.getType().getValue());
|
||||
|
|
Loading…
Reference in New Issue