Improve Xml export styling and ignore null DMP's on Dataset model mapping

This commit is contained in:
George Kalampokis 2020-03-03 11:19:08 +02:00
parent e243126bf9
commit 8a4afade34
2 changed files with 7 additions and 4 deletions

View File

@ -12,6 +12,7 @@ import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
@ -47,6 +48,8 @@ public class XmlBuilder {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
DOMSource source = new DOMSource(doc);
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
trans.transform(source, result);
return writer.toString();
} catch (TransformerException e) {

View File

@ -158,18 +158,18 @@ public class DatasetListingModel implements DataModel<Dataset, DatasetListingMod
@Override
public DatasetListingModel fromDataModel(Dataset entity) {
this.id = entity.getId().toString();
this.id = entity.getId() != null ? entity.getId().toString() : "";
this.label = entity.getLabel();
this.created = entity.getCreated();
this.modified = entity.getModified();
this.grant = entity.getDmp().getGrant().getLabel();
this.grant = entity.getDmp() != null ? entity.getDmp().getGrant().getLabel() : "";
this.dmp = entity.getDmp() != null ? entity.getDmp().getLabel() : "";
this.dmpId = entity.getDmp() != null ? entity.getDmp().getId().toString() : "";
this.profile = entity.getProfile() != null ? entity.getProfile().getLabel() : "";
this.description = entity.getDescription();
this.status = entity.getStatus();
this.grantAbbreviation = entity.getDmp().getGrant().getAbbreviation();
this.grantId = entity.getDmp().getGrant().getId().toString();
this.grantAbbreviation = entity.getDmp() != null ? entity.getDmp().getGrant().getAbbreviation() : "";
this.grantId = entity.getDmp() != null ? entity.getDmp().getGrant().getId().toString() : "";
this.registries = LabelBuilder.getLabel(entity.getRegistries().stream().map(item -> new eu.eudat.models.data.dataset.Registry().fromDataModel(item)).collect(Collectors.toList()));
this.dataRepositories = LabelBuilder.getLabel(entity.getDatasetDataRepositories().stream().map(item -> new DataRepository().fromDataModel(item.getDataRepository())).collect(Collectors.toList()));
this.services = LabelBuilder.getLabel(entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()));