refactor description template xml
This commit is contained in:
parent
7e63abca50
commit
bcd42d66b7
|
@ -34,6 +34,8 @@ import javax.xml.transform.TransformerException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class DescriptionTemplateXmlMigrationService {
|
public class DescriptionTemplateXmlMigrationService {
|
||||||
|
@ -77,13 +79,14 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
logger.error("Migrate DescriptionTemplate " + item.getId() + " failed read xml");
|
logger.error("Migrate DescriptionTemplate " + item.getId() + " failed read xml");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
ViewStyleModel viewStyleModel = null;
|
||||||
try {
|
try {
|
||||||
ViewStyleModel viewStyleModel = new ViewStyleModel().fromXml(document.getDocumentElement());
|
viewStyleModel = new ViewStyleModel().fromXml(document.getDocumentElement());
|
||||||
item.setDefinition(this.xmlHandlingService.toXml(this.buildDefinitionEntity(viewStyleModel)));
|
|
||||||
} catch (Exception ex){
|
} catch (Exception ex){
|
||||||
logger.error("Migrate DescriptionTemplate " + item.getId() + " failed read xml");
|
logger.error("Migrate DescriptionTemplate " + item.getId() + " failed read xml");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
item.setDefinition(this.xmlHandlingService.toXml(this.buildDefinitionEntity(viewStyleModel)));
|
||||||
this.entityManager.merge(item);
|
this.entityManager.merge(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,16 +100,10 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
DefinitionEntity data = new DefinitionEntity();
|
DefinitionEntity data = new DefinitionEntity();
|
||||||
if (persist == null)
|
if (persist == null)
|
||||||
return data;
|
return data;
|
||||||
if (!this.conventionService.isListNullOrEmpty(persist.getSections())) {
|
|
||||||
data.setSections(new ArrayList<>());
|
|
||||||
for (Section sectionPersist : persist.getSections()) {
|
|
||||||
data.getSections().add(this.buildSectionEntity(sectionPersist));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.conventionService.isListNullOrEmpty(persist.getPages())) {
|
if (!this.conventionService.isListNullOrEmpty(persist.getPages())) {
|
||||||
data.setPages(new ArrayList<>());
|
data.setPages(new ArrayList<>());
|
||||||
for (Page pagePersist : persist.getPages()) {
|
for (Page pagePersist : persist.getPages()) {
|
||||||
data.getPages().add(this.buildPageEntity(pagePersist));
|
data.getPages().add(this.buildPageEntity(pagePersist, persist.getSections()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +122,6 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
data.setOrdinal(persist.getOrdinal());
|
data.setOrdinal(persist.getOrdinal());
|
||||||
data.setDefaultVisibility(persist.isDefaultVisibility());
|
data.setDefaultVisibility(persist.isDefaultVisibility());
|
||||||
data.setMultiplicity(persist.getMultiplicity());
|
data.setMultiplicity(persist.getMultiplicity());
|
||||||
data.setPage(persist.getPage());
|
|
||||||
data.setTitle(persist.getTitle());
|
data.setTitle(persist.getTitle());
|
||||||
|
|
||||||
if (!this.conventionService.isListNullOrEmpty(persist.getSections())) {
|
if (!this.conventionService.isListNullOrEmpty(persist.getSections())) {
|
||||||
|
@ -206,7 +202,7 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BaseFieldDataEntity<?> buildFieldDataEntity(FieldData persist, String renderStyle) {
|
private BaseFieldDataEntity buildFieldDataEntity(FieldData persist, String renderStyle) {
|
||||||
if (renderStyle.equals("checkBox")){
|
if (renderStyle.equals("checkBox")){
|
||||||
return this.buildLabelDataEntity(persist.getLabel(), FieldType.CHECK_BOX);
|
return this.buildLabelDataEntity(persist.getLabel(), FieldType.CHECK_BOX);
|
||||||
}
|
}
|
||||||
|
@ -281,7 +277,7 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
if (renderStyle.equals("externalDatasets")){
|
if (renderStyle.equals("externalDatasets")){
|
||||||
ExternalDatasetDataEntity data = new ExternalDatasetDataEntity();
|
ExternalDatasetDataEntity data = new ExternalDatasetDataEntity();
|
||||||
data.setLabel(persist.getLabel());
|
data.setLabel(persist.getLabel());
|
||||||
data.setMultiAutoComplete(((ExternalDatasetsData)persist).getMultiAutoComplete());
|
data.setMultipleSelect(((ExternalDatasetsData)persist).getMultiAutoComplete());
|
||||||
data.setType(FieldDataExternalDatasetType.of(((ExternalDatasetsData)persist).getType()));
|
data.setType(FieldDataExternalDatasetType.of(((ExternalDatasetsData)persist).getType()));
|
||||||
data.setFieldType(FieldType.EXTERNAL_DATASETS);
|
data.setFieldType(FieldType.EXTERNAL_DATASETS);
|
||||||
return data;
|
return data;
|
||||||
|
@ -325,37 +321,35 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
if (renderStyle.equals("combobox")){
|
if (renderStyle.equals("combobox")){
|
||||||
switch (((ComboBoxData<?>)persist).getType()){
|
switch (((ComboBoxData<?>)persist).getType()){
|
||||||
case "wordlist":{
|
case "wordlist":{
|
||||||
WordListDataEntity data = new WordListDataEntity();
|
SelectDataEntity data = new SelectDataEntity();
|
||||||
data.setLabel(persist.getLabel());
|
data.setLabel(persist.getLabel());
|
||||||
data.setOptions(new ArrayList<>());
|
data.setOptions(new ArrayList<>());
|
||||||
data.setMultiList(((WordListData)persist).getMultiList());
|
data.setMultipleSelect(((WordListData)persist).getMultiList());
|
||||||
if (((WordListData)persist).getOptions() != null){
|
if (((WordListData)persist).getOptions() != null){
|
||||||
for (ComboBoxData.Option option : ((WordListData)persist).getOptions()){
|
for (ComboBoxData.Option option : ((WordListData)persist).getOptions()){
|
||||||
ComboBoxDataEntity.Option optionEntity = new ComboBoxDataEntity.Option();
|
SelectDataEntity.OptionEntity optionEntity = new SelectDataEntity.OptionEntity();
|
||||||
optionEntity.setValue(option.getValue());
|
optionEntity.setValue(option.getValue());
|
||||||
optionEntity.setLabel(option.getLabel());
|
optionEntity.setLabel(option.getLabel());
|
||||||
optionEntity.setSource(option.getSource());
|
|
||||||
optionEntity.setUri(option.getUri());
|
|
||||||
data.getOptions().add(optionEntity);
|
data.getOptions().add(optionEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.setFieldType(FieldType.WORD_LIST);
|
data.setFieldType(FieldType.SELECT);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
case "autocomplete":{
|
case "autocomplete":{
|
||||||
AutoCompleteDataEntity data = new AutoCompleteDataEntity();
|
ExternalSelectDataEntity data = new ExternalSelectDataEntity();
|
||||||
data.setLabel(persist.getLabel());
|
data.setLabel(persist.getLabel());
|
||||||
data.setAutoCompleteSingleDataList(new ArrayList<>());
|
data.setSources(new ArrayList<>());
|
||||||
data.setMultiAutoComplete(((AutoCompleteData)persist).getMultiAutoComplete());
|
data.setMultipleSelect(((AutoCompleteData)persist).getMultiAutoComplete());
|
||||||
if (((AutoCompleteData)persist).getAutoCompleteSingleDataList() != null){
|
if (((AutoCompleteData)persist).getAutoCompleteSingleDataList() != null){
|
||||||
for (AutoCompleteData.AutoCompleteSingleData autoCompleteSingleData : ((AutoCompleteData)persist).getAutoCompleteSingleDataList()){
|
for (AutoCompleteData.AutoCompleteSingleData autoCompleteSingleData : ((AutoCompleteData)persist).getAutoCompleteSingleDataList()){
|
||||||
AutoCompleteDataEntity.AutoCompleteSingleData autoCompleteSingleDataEntity = new AutoCompleteDataEntity.AutoCompleteSingleData();
|
ExternalSelectDataEntity.ExternalSelectSourceEntity autoCompleteSingleDataEntity = new ExternalSelectDataEntity.ExternalSelectSourceEntity();
|
||||||
autoCompleteSingleDataEntity.setOptionsRoot(autoCompleteSingleData.getOptionsRoot());
|
autoCompleteSingleDataEntity.setOptionsRoot(autoCompleteSingleData.getOptionsRoot());
|
||||||
autoCompleteSingleDataEntity.setUrl(autoCompleteSingleData.getUrl());
|
autoCompleteSingleDataEntity.setUrl(autoCompleteSingleData.getUrl());
|
||||||
autoCompleteSingleDataEntity.setMethod(autoCompleteSingleData.getMethod());
|
autoCompleteSingleDataEntity.setMethod(autoCompleteSingleData.getMethod());
|
||||||
autoCompleteSingleDataEntity.setHasAuth(autoCompleteSingleData.getHasAuth());
|
autoCompleteSingleDataEntity.setHasAuth(autoCompleteSingleData.getHasAuth());
|
||||||
if (autoCompleteSingleData.getHasAuth() && autoCompleteSingleData.getAuth()!= null) {
|
if (autoCompleteSingleData.getHasAuth() && autoCompleteSingleData.getAuth()!= null) {
|
||||||
AutoCompleteDataEntity.AuthAutoCompleteData optionEntity = new AutoCompleteDataEntity.AuthAutoCompleteData();
|
ExternalSelectDataEntity.ExternalSelectAuthDataEntity optionEntity = new ExternalSelectDataEntity.ExternalSelectAuthDataEntity();
|
||||||
optionEntity.setBody(autoCompleteSingleData.getAuth().getBody());
|
optionEntity.setBody(autoCompleteSingleData.getAuth().getBody());
|
||||||
optionEntity.setMethod(autoCompleteSingleData.getAuth().getMethod());
|
optionEntity.setMethod(autoCompleteSingleData.getAuth().getMethod());
|
||||||
optionEntity.setUrl(autoCompleteSingleData.getAuth().getUrl());
|
optionEntity.setUrl(autoCompleteSingleData.getAuth().getUrl());
|
||||||
|
@ -363,19 +357,17 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
optionEntity.setBody(autoCompleteSingleData.getAuth().getBody());
|
optionEntity.setBody(autoCompleteSingleData.getAuth().getBody());
|
||||||
autoCompleteSingleDataEntity.setAuth(optionEntity);
|
autoCompleteSingleDataEntity.setAuth(optionEntity);
|
||||||
}
|
}
|
||||||
autoCompleteSingleDataEntity.setAutocompleteType(AutoCompleteDataEntity.AutocompleteType.of(autoCompleteSingleData.getAutocompleteType()));
|
|
||||||
if (autoCompleteSingleData.getAutoCompleteOptions() != null) {
|
if (autoCompleteSingleData.getAutoCompleteOptions() != null) {
|
||||||
ComboBoxDataEntity.Option optionEntity = new ComboBoxDataEntity.Option();
|
ExternalSelectDataEntity.ExternalSelectSourceBindingEntity optionEntity = new ExternalSelectDataEntity.ExternalSelectSourceBindingEntity();
|
||||||
optionEntity.setValue(autoCompleteSingleData.getAutoCompleteOptions().getValue());
|
optionEntity.setValue(autoCompleteSingleData.getAutoCompleteOptions().getValue());
|
||||||
optionEntity.setLabel(autoCompleteSingleData.getAutoCompleteOptions().getLabel());
|
optionEntity.setLabel(autoCompleteSingleData.getAutoCompleteOptions().getLabel());
|
||||||
optionEntity.setSource(autoCompleteSingleData.getAutoCompleteOptions().getSource());
|
optionEntity.setSource(autoCompleteSingleData.getAutoCompleteOptions().getSource());
|
||||||
optionEntity.setUri(autoCompleteSingleData.getAutoCompleteOptions().getUri());
|
autoCompleteSingleDataEntity.setSourceBinding(optionEntity);
|
||||||
autoCompleteSingleDataEntity.setAutoCompleteOptions(optionEntity);
|
|
||||||
}
|
}
|
||||||
data.getAutoCompleteSingleDataList().add(autoCompleteSingleDataEntity);
|
data.getSources().add(autoCompleteSingleDataEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.setFieldType(FieldType.AUTO_COMPLETE);
|
data.setFieldType(FieldType.EXTERNAL_SELECT);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -383,18 +375,18 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
throw new MyApplicationException("Can transform field data" + renderStyle);
|
throw new MyApplicationException("Can transform field data" + renderStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BaseFieldDataEntity<?> buildLabelDataEntity(String label, FieldType fieldType) {
|
private BaseFieldDataEntity buildLabelDataEntity(String label, FieldType fieldType) {
|
||||||
LabelDataEntity data = new LabelDataEntity();
|
LabelDataEntity data = new LabelDataEntity();
|
||||||
data.setLabel(label);
|
data.setLabel(label);
|
||||||
data.setFieldType(fieldType);
|
data.setFieldType(fieldType);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BaseFieldDataEntity<?> buildLabelAndMultiplicityDataEntity(String label, Boolean multiAutoComplete, FieldType fieldType) {
|
private BaseFieldDataEntity buildLabelAndMultiplicityDataEntity(String label, Boolean multiAutoComplete, FieldType fieldType) {
|
||||||
LabelAndMultiplicityDataEntity data = new LabelAndMultiplicityDataEntity();
|
LabelAndMultiplicityDataEntity data = new LabelAndMultiplicityDataEntity();
|
||||||
data.setLabel(label);
|
data.setLabel(label);
|
||||||
data.setFieldType(fieldType);
|
data.setFieldType(fieldType);
|
||||||
data.setMultiAutoComplete(multiAutoComplete);
|
data.setMultipleSelect(multiAutoComplete);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +413,7 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private @NotNull PageEntity buildPageEntity(Page persist) {
|
private @NotNull PageEntity buildPageEntity(Page persist, List<Section> allSections) {
|
||||||
PageEntity data = new PageEntity();
|
PageEntity data = new PageEntity();
|
||||||
if (persist == null)
|
if (persist == null)
|
||||||
return data;
|
return data;
|
||||||
|
@ -429,6 +421,26 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
data.setId(persist.getId());
|
data.setId(persist.getId());
|
||||||
data.setOrdinal(persist.getOrdinal());
|
data.setOrdinal(persist.getOrdinal());
|
||||||
data.setTitle(persist.getTitle());
|
data.setTitle(persist.getTitle());
|
||||||
|
|
||||||
|
List<Section> sections = allSections.stream().filter(x-> this.isInPage(x, persist)).toList();
|
||||||
|
if (!this.conventionService.isListNullOrEmpty(sections)) {
|
||||||
|
data.setSections(new ArrayList<>());
|
||||||
|
for (Section sectionPersist : sections) {
|
||||||
|
data.getSections().add(this.buildSectionEntity(sectionPersist));
|
||||||
|
}
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isInPage(Section section, Page page){
|
||||||
|
try {
|
||||||
|
return UUID.fromString(section.getPage()).equals(UUID.fromString(page.getId()));
|
||||||
|
} catch (Exception e){
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(section.getPage().replace("page_", "")) == page.getOrdinal();
|
||||||
|
} catch (Exception e1){
|
||||||
|
return section.getPage().toLowerCase(Locale.ROOT).equals(page.getId().toLowerCase(Locale.ROOT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue