85 lines
2.8 KiB
Java
85 lines
2.8 KiB
Java
package eu.eudat.file.transformer.entities.descriptiontemplate;
|
|
|
|
import eu.eudat.file.transformer.entities.definition.DefinitionSerializable;
|
|
import eu.eudat.file.transformer.entities.xml.XmlBuilder;
|
|
import eu.eudat.file.transformer.entities.xml.XmlSerializable;
|
|
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.Definition;
|
|
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.Page;
|
|
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.Section;
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
import org.w3c.dom.Node;
|
|
import org.w3c.dom.NodeList;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
public class DefinitionEntity implements DefinitionSerializable<DefinitionEntity, Definition> {
|
|
private List<SectionEntity> sections;
|
|
private List<PageEntity> pages;
|
|
|
|
public List<SectionEntity> getSections() {
|
|
return sections;
|
|
}
|
|
|
|
public void setSections(List<SectionEntity> sections) {
|
|
this.sections = sections;
|
|
}
|
|
|
|
public List<PageEntity> getPages() {
|
|
return pages;
|
|
}
|
|
|
|
public void setPages(List<PageEntity> pageEntities) {
|
|
this.pages = pageEntities;
|
|
}
|
|
|
|
/*@Override
|
|
public Element toXml(Document doc) {
|
|
Element root = doc.createElement("root");
|
|
Element sections = doc.createElement("sections");
|
|
Element pages = doc.createElement("pages");
|
|
for (SectionEntity sectionEntity : this.sections) {
|
|
sectionEntity.setNumbering("" + (this.sections.indexOf(sectionEntity) + 1));
|
|
sections.appendChild(sectionEntity.toXml(doc));
|
|
}
|
|
|
|
for (PageEntity pageEntity : this.pages) {
|
|
pages.appendChild(pageEntity.toXml(doc));
|
|
}
|
|
|
|
root.appendChild(pages);
|
|
root.appendChild(sections);
|
|
return root;
|
|
}*/
|
|
public List<FieldEntity> getFieldById(String id){
|
|
List<FieldEntity> fieldEntities = new ArrayList<>();
|
|
if (id == null || id.isBlank()) return fieldEntities;
|
|
if (this.getSections() != null){
|
|
for (SectionEntity sectionEntity: this.getSections()) {
|
|
fieldEntities.addAll(sectionEntity.getFieldById(id));
|
|
}
|
|
}
|
|
return fieldEntities;
|
|
}
|
|
|
|
@Override
|
|
public DefinitionEntity fromDefinition(Definition object) {
|
|
this.sections = new LinkedList();
|
|
if (object.getSections() != null) {
|
|
for (Section section : object.getSections()) {
|
|
this.sections.add(new SectionEntity().fromDefinition(section));
|
|
}
|
|
}
|
|
if (object.getPages() != null) {
|
|
this.pages = new LinkedList<>();
|
|
for (Page page: object.getPages()) {
|
|
this.pages.add(new PageEntity().fromDefinition(page));
|
|
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
}
|