package eu.eudat.managers; import java.util.Date; import java.util.List; import org.w3c.dom.Document; import org.w3c.dom.Element; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import eu.eudat.entities.DatasetProfileViewstyle; import eu.eudat.entities.xmlmodels.modeldefinition.FieldGroup; import eu.eudat.entities.xmlmodels.viewstyledefinition.Section; import eu.eudat.entities.xmlmodels.viewstyledefinition.ViewStyleModel; import eu.eudat.models.admin.components.datasetprofile.FieldSet; import eu.eudat.models.admin.composite.DatasetProfile; import eu.eudat.utilities.builders.ModelBuilder; import eu.eudat.utilities.builders.XmlBuilder; import eu.eudat.utilities.helpers.ModelBuilderCollector; public class AdminManager { public static eu.eudat.entities.DatasetProfile generateModelDefinition(DatasetProfile profile){ ObjectMapper xmlMapper = new XmlMapper(); List
fieldSets = ModelBuilderCollector.collectCompositeFields(profile.getSections()); FieldGroup fieldGroup = new FieldGroup(); List fieldset = new ModelBuilder().toModelDefinition(fieldSets, eu.eudat.entities.xmlmodels.modeldefinition.FieldSet.class); fieldGroup.setFieldSets(fieldset); Document modelDoc = XmlBuilder.getDocument(); fieldGroup.toXml(modelDoc); String xml = XmlBuilder.generateXml(modelDoc); eu.eudat.entities.DatasetProfile datasetProfile = new eu.eudat.entities.DatasetProfile(); datasetProfile.setDefinition(xml); datasetProfile.setStatus((short)1); datasetProfile.setLabel(profile.getLabel()); datasetProfile.setCreated(new Date()); return datasetProfile; } public static DatasetProfileViewstyle generateViewStyleDefinition(DatasetProfile profile){ ViewStyleModel viewStyleModel = new ViewStyleModel(); viewStyleModel.setSections(new ModelBuilder().toViewStyleDefinition(profile.getSections(), eu.eudat.entities.xmlmodels.viewstyledefinition.Section.class)); Document viewStyleDoc = XmlBuilder.getDocument(); Element elementViewStyle = viewStyleModel.toXml(viewStyleDoc); viewStyleDoc.appendChild(elementViewStyle); String xml = XmlBuilder.generateXml(viewStyleDoc); DatasetProfileViewstyle datasetProfileViewstyle = new DatasetProfileViewstyle(); datasetProfileViewstyle.setDefinition(xml); datasetProfileViewstyle.setLabel(profile.getLabel()); return datasetProfileViewstyle; } public static eu.eudat.models.admin.composite.DatasetProfile generateDatasetProfileModel(eu.eudat.entities.DatasetProfile profile){ Document viewStyleDoc = XmlBuilder.fromXml(profile.getViewstyle().getDefinition()); Element root = (Element)viewStyleDoc.getDocumentElement(); eu.eudat.entities.xmlmodels.viewstyledefinition.ViewStyleModel viewstyle= new eu.eudat.entities.xmlmodels.viewstyledefinition.ViewStyleModel().fromXml(root); Document profileDoc = XmlBuilder.fromXml(profile.getDefinition()); root = (Element)profileDoc.getDocumentElement(); eu.eudat.entities.xmlmodels.modeldefinition.FieldGroup fieldGroup = new eu.eudat.entities.xmlmodels.modeldefinition.FieldGroup().fromXml(root); eu.eudat.models.admin.composite.DatasetProfile datasetprofile = new eu.eudat.models.admin.composite.DatasetProfile(); datasetprofile.buildProfile(fieldGroup, viewstyle); return datasetprofile; } }