diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateFacadeImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateFacadeImpl.java index 03a366f2..7c45cbd1 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateFacadeImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateFacadeImpl.java @@ -27,6 +27,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import odml.core.Property; @@ -47,6 +49,10 @@ public class TemplateFacadeImpl implements TemplateFacade { + private static final String XML_FILE_SUFFIX = ".xml"; + private static final String ODML_TEMPLATE_PREFIX = "ODML-"; + private static final String EEG_TEMPLATE_PREFIX = "EEG-"; + protected Log log = LogFactory.getLog(getClass()); private TemplateService service; @@ -160,7 +166,7 @@ public List
getListOfAvailableODMLSections() { try { paths = new ClassPathResource(odmlSectionsPath).getFile().listFiles(); for (File path : paths) { - if (path.getName().endsWith(".xml")) { + if (path.getName().endsWith(XML_FILE_SUFFIX)) { filteredFiles.add(path); } } @@ -179,6 +185,20 @@ public List
getListOfAvailableODMLSections() { log.error(e.getMessage(), e); } } + + for(Section section : sections) { + if(!section.getName().startsWith(EEG_TEMPLATE_PREFIX)) { + section.setName(ODML_TEMPLATE_PREFIX + section.getName()); + } + } + + Collections.sort(sections, new Comparator
() { + + @Override + public int compare(Section o1, Section o2) { + return o1.getName().compareTo(o2.getName()); + } + }); try { Section empty = new Section(ResourceUtils.getString("text.template.empty.section"), "new"); @@ -223,9 +243,14 @@ public boolean migrateSQLToES() { @Override public boolean createSystemTemplate(Section section) { try { - - Writer writer = new Writer(section, true, true); - FileOutputStream fostream = new FileOutputStream(new File(new ClassPathResource(odmlSectionsPath).getFile(), section.getName() + ".xml")); + + Section root = new Section(); + root.add(section); + section.setName(EEG_TEMPLATE_PREFIX + section.getName()); + section.setType(section.getName().toLowerCase()); + + Writer writer = new Writer(root, true, true); + FileOutputStream fostream = new FileOutputStream(new File(new ClassPathResource(odmlSectionsPath).getFile(), section.getName() + XML_FILE_SUFFIX)); writer.write(fostream); fostream.close();