Skip to content

Commit

Permalink
#117 improved system template for ODML and EEG groups and sort them.
Browse files Browse the repository at this point in the history
  • Loading branch information
rinkesj committed Jul 2, 2015
1 parent ab5ca95 commit d1f8106
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -160,7 +166,7 @@ public List<Section> 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);
}
}
Expand All @@ -179,6 +185,20 @@ public List<Section> 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<Section>() {

@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");
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit d1f8106

Please sign in to comment.