133 lines
4.1 KiB
Java
133 lines
4.1 KiB
Java
package eu.eudat.file.transformer.entities.descriptiontemplate.fielddata;
|
|
|
|
import eu.eudat.file.transformer.entities.definition.DefinitionSerializable;
|
|
import eu.eudat.file.transformer.entities.xml.XmlSerializable;
|
|
import eu.eudat.file.transformer.enums.FieldType;
|
|
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.fielddata.UploadData;
|
|
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.fielddata.UploadOption;
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
import org.w3c.dom.Node;
|
|
import org.w3c.dom.NodeList;
|
|
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
|
|
public class UploadDataEntity extends BaseFieldDataEntity<UploadDataEntity, UploadData> {
|
|
@Override
|
|
public FieldType getFieldType() {
|
|
return FieldType.UPLOAD;
|
|
}
|
|
public static class Option implements DefinitionSerializable<Option, UploadOption> {
|
|
private String label;
|
|
private String value;
|
|
|
|
public String getLabel() {
|
|
return label;
|
|
}
|
|
|
|
public void setLabel(String label) {
|
|
this.label = label;
|
|
}
|
|
|
|
public String getValue() {
|
|
return value;
|
|
}
|
|
|
|
public void setValue(String value) {
|
|
this.value = value;
|
|
}
|
|
|
|
/*@Override
|
|
public Element toXml(Document doc) {
|
|
Element option = doc.createElement("option");
|
|
option.setAttribute("label", this.label);
|
|
option.setAttribute("value", this.value);
|
|
return option;
|
|
}
|
|
|
|
@Override
|
|
public Option fromXml(Element item) {
|
|
this.label = item.getAttribute("label");
|
|
this.value = item.getAttribute("value");
|
|
return this;
|
|
}*/
|
|
|
|
|
|
@Override
|
|
public Option fromDefinition(UploadOption object) {
|
|
this.label = object.getLabel();
|
|
this.value = object.getValue();
|
|
return this;
|
|
}
|
|
}
|
|
|
|
private List<Option> types;
|
|
|
|
public List<Option> getTypes() {
|
|
return types;
|
|
}
|
|
|
|
public void setTypes(List<Option> types) {
|
|
this.types = types;
|
|
}
|
|
|
|
private Integer maxFileSizeInMB;
|
|
|
|
public Integer getMaxFileSizeInMB() {
|
|
return maxFileSizeInMB;
|
|
}
|
|
|
|
public void setMaxFileSizeInMB(Integer maxFileSizeInMB) {
|
|
this.maxFileSizeInMB = maxFileSizeInMB;
|
|
}
|
|
|
|
/*@Override
|
|
public Element toXml(Document doc) {
|
|
Element root = super.toXml(doc);
|
|
Element element = doc.createElement("types");
|
|
for (Option type : this.types) {
|
|
element.appendChild(type.toXml(doc));
|
|
}
|
|
root.setAttribute("maxFileSizeInMB", this.getMaxFileSizeInMB().toString());
|
|
root.appendChild(element);
|
|
return root;
|
|
}
|
|
|
|
@Override
|
|
public UploadDataEntity fromXml(Element item) {
|
|
this.types = new LinkedList<>();
|
|
super.fromXml(item);
|
|
Element optionsElement = (Element) item.getElementsByTagName("types").item(0);
|
|
if(item.getAttribute("maxFileSizeInMB") != null) {
|
|
this.setMaxFileSizeInMB(Integer.parseInt(item.getAttribute("maxFileSizeInMB")));
|
|
}
|
|
if (optionsElement != null) {
|
|
NodeList optionElements = optionsElement.getChildNodes();
|
|
for (int temp = 0; temp < optionElements.getLength(); temp++) {
|
|
Node optionElement = optionElements.item(temp);
|
|
if (optionElement.getNodeType() == Node.ELEMENT_NODE) {
|
|
this.types.add(new Option().fromXml((Element) optionElement));
|
|
}
|
|
}
|
|
}
|
|
return this;
|
|
}*/
|
|
|
|
@Override
|
|
public UploadDataEntity fromDefinition(UploadData object) {
|
|
this.types = new LinkedList<>();
|
|
super.fromDefinition(object);
|
|
if(object.getMaxFileSizeInMB() != null) {
|
|
this.setMaxFileSizeInMB(object.getMaxFileSizeInMB());
|
|
}
|
|
if (!object.getTypes().isEmpty() && object.getTypes().get(0) != null) {
|
|
for (UploadOption option: object.getTypes()) {
|
|
this.types.add(new Option().fromDefinition(option));
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
}
|