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");
|
logger.error("Migrate DescriptionTemplate " + item.getId() + " failed read xml");
|
||||||
throw new MyApplicationException("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);
|
this.entityManager.merge(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,22 +118,22 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
this.entityManager.flush();
|
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();
|
DefinitionEntity data = new DefinitionEntity();
|
||||||
if (persist == null)
|
if (persist == null)
|
||||||
return data;
|
return data;
|
||||||
if (!this.conventionService.isListNullOrEmpty(persist.getPages())) {
|
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<>());
|
data.setPages(new ArrayList<>());
|
||||||
for (Page pagePersist : persist.getPages()) {
|
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;
|
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();
|
SectionEntity data = new SectionEntity();
|
||||||
if (persist == null)
|
if (persist == null)
|
||||||
return data;
|
return data;
|
||||||
|
@ -147,21 +147,21 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
if (!this.conventionService.isListNullOrEmpty(persist.getSections())) {
|
if (!this.conventionService.isListNullOrEmpty(persist.getSections())) {
|
||||||
data.setSections(new ArrayList<>());
|
data.setSections(new ArrayList<>());
|
||||||
for (Section sectionPersist : persist.getSections()) {
|
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())) {
|
if (!this.conventionService.isListNullOrEmpty(persist.getFieldSets())) {
|
||||||
data.setFieldSets(new ArrayList<>());
|
data.setFieldSets(new ArrayList<>());
|
||||||
for (FieldSet fieldSetPersist : persist.getFieldSets()) {
|
for (FieldSet fieldSetPersist : persist.getFieldSets()) {
|
||||||
data.getFieldSets().add(this.buildFieldSetEntity(fieldSetPersist, referenceTypeEntityMap, knownReferenceEntities));
|
data.getFieldSets().add(this.buildFieldSetEntity(fieldSetPersist, referenceTypeEntityMap, knownReferenceEntities, descriptionTemplateId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
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();
|
FieldSetEntity data = new FieldSetEntity();
|
||||||
if (persist == null)
|
if (persist == null)
|
||||||
return data;
|
return data;
|
||||||
|
@ -180,13 +180,13 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
if (!this.conventionService.isListNullOrEmpty(persist.getFields())) {
|
if (!this.conventionService.isListNullOrEmpty(persist.getFields())) {
|
||||||
data.setFields(new ArrayList<>());
|
data.setFields(new ArrayList<>());
|
||||||
for (Field fieldPersist : persist.getFields()) {
|
for (Field fieldPersist : persist.getFields()) {
|
||||||
data.getFields().add(this.buildFieldEntity(fieldPersist, referenceTypeEntityMap, knownReferenceEntities));
|
data.getFields().add(this.buildFieldEntity(fieldPersist, referenceTypeEntityMap, knownReferenceEntities, descriptionTemplateId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data;
|
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();
|
FieldEntity data = new FieldEntity();
|
||||||
if (persist == null)
|
if (persist == null)
|
||||||
return data;
|
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())) {
|
if (persist.getVisible() != null && !this.conventionService.isListNullOrEmpty(persist.getVisible().getRules())) {
|
||||||
data.setVisibilityRules(new ArrayList<>());
|
data.setVisibilityRules(new ArrayList<>());
|
||||||
for (Rule fieldPersist : persist.getVisible().getRules()) {
|
for (Rule fieldPersist : persist.getVisible().getRules()) {
|
||||||
|
@ -402,7 +402,7 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private @NotNull DefaultValueEntity buildDefaultValueEntity(DefaultValue persist, FieldType fieldType) {
|
private @NotNull DefaultValueEntity buildDefaultValueEntity(DefaultValue persist, FieldType fieldType, UUID descriptionTemplateId) {
|
||||||
DefaultValueEntity data = new DefaultValueEntity();
|
DefaultValueEntity data = new DefaultValueEntity();
|
||||||
if (persist == null)
|
if (persist == null)
|
||||||
return data;
|
return data;
|
||||||
|
@ -439,9 +439,9 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
case UPLOAD -> throw new NotSupportedException("Upload validator not supported");
|
case UPLOAD -> throw new NotSupportedException("Upload validator not supported");
|
||||||
case TAGS -> throw new NotSupportedException("Tags 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_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");
|
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");
|
case REFERENCE_TYPES -> throw new NotSupportedException("REFERENCE_TYPES validator not supported for description template " + descriptionTemplateId);
|
||||||
default -> throw new MyApplicationException("unrecognized type " + fieldType);
|
default -> throw new MyApplicationException("unrecognized type " + fieldType);
|
||||||
}
|
}
|
||||||
return data;
|
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();
|
PageEntity data = new PageEntity();
|
||||||
if (persist == null)
|
if (persist == null)
|
||||||
return data;
|
return data;
|
||||||
|
@ -526,14 +526,14 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
if (!this.conventionService.isListNullOrEmpty(sections)) {
|
if (!this.conventionService.isListNullOrEmpty(sections)) {
|
||||||
data.setSections(new ArrayList<>());
|
data.setSections(new ArrayList<>());
|
||||||
for (Section sectionPersist : sections) {
|
for (Section sectionPersist : sections) {
|
||||||
data.getSections().add(this.buildSectionEntity(sectionPersist, referenceTypeEntityMap, knownReferenceEntities));
|
data.getSections().add(this.buildSectionEntity(sectionPersist, referenceTypeEntityMap, knownReferenceEntities, descriptionTemplateId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data;
|
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<>();
|
List<String> mappedSectionsIds = new ArrayList<>();
|
||||||
Map<String, List<Section>> sectionPerPage = new HashMap<>();
|
Map<String, List<Section>> sectionPerPage = new HashMap<>();
|
||||||
if (persist == null || persist.getPages() == null || persist.getSections() == null) return sectionPerPage;
|
if (persist == null || persist.getPages() == null || persist.getSections() == null) return sectionPerPage;
|
||||||
|
@ -550,7 +550,7 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Section section : persist.getSections()){
|
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;
|
return sectionPerPage;
|
||||||
|
|
|
@ -39,6 +39,9 @@ import org.xml.sax.SAXException;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.time.format.DateTimeParseException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -105,7 +108,7 @@ public class DmpMigrationService {
|
||||||
|
|
||||||
for (DMP item : items) {
|
for (DMP item : items) {
|
||||||
//entityManager.detach(item);
|
//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();
|
DataManagementPlan model = new DataManagementPlan();
|
||||||
model.fromDataModel(item);
|
model.fromDataModel(item);
|
||||||
List<DMP> itemGroupDmps = groupDmpMap.get(item.getGroupId());
|
List<DMP> itemGroupDmps = groupDmpMap.get(item.getGroupId());
|
||||||
|
@ -180,10 +183,16 @@ public class DmpMigrationService {
|
||||||
DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity();
|
DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity();
|
||||||
valueEntity.setFieldId(UUID.fromString(key));
|
valueEntity.setFieldId(UUID.fromString(key));
|
||||||
org.opencdmp.commons.types.dmpblueprint.FieldEntity fieldEntity = this.getFieldOfId(definitionEntity, valueEntity.getFieldId());
|
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;
|
ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity;
|
||||||
switch (extraFieldEntity.getType()){
|
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 RichTex, Text -> valueEntity.setValue((String) val);
|
||||||
case Number -> valueEntity.setNumberValue(Double.parseDouble((String) val));
|
case Number -> valueEntity.setNumberValue(Double.parseDouble((String) val));
|
||||||
default -> throw new MyApplicationException("unrecognized type " + extraFieldEntity.getType().getValue());
|
default -> throw new MyApplicationException("unrecognized type " + extraFieldEntity.getType().getValue());
|
||||||
|
|
Loading…
Reference in New Issue