Search in sources :

Example 1 with MlxMetadataTemplate

use of com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplate in project metalnx-web by irods-contrib.

the class TemplateServiceImpl method importXmlMetadataTemplate.

@Override
public boolean importXmlMetadataTemplate(InputStream inStream, String owner, String prefix, String suffix) throws JAXBException, DataGridTooLongTemplateNameException, DataGridTemplateAttrException, DataGridTemplateValueException, DataGridTemplateUnitException {
    JAXBContext jaxbContext = JAXBContext.newInstance(MlxMetadataTemplates.class);
    Unmarshaller un = jaxbContext.createUnmarshaller();
    MlxMetadataTemplates ts = (MlxMetadataTemplates) un.unmarshal(inStream);
    boolean result = true;
    for (MlxMetadataTemplate t : ts.getTemplates()) {
        String newTemplateName = String.format("%s%s%s", prefix, t.getName(), suffix);
        if (findByName(newTemplateName) != null) {
            logger.info("Template with name {} already exists on the database", newTemplateName);
            result = false;
            continue;
        }
        DataGridTemplate nt = new DataGridTemplate();
        nt.setTemplateName(newTemplateName);
        nt.setDescription(t.getDescription());
        nt.setUsageInformation(t.getUsageInfo());
        nt.setAccessType(t.getAccessType());
        nt.setOwner(owner);
        nt.setFields(new HashSet<DataGridTemplateField>());
        long tid = createTemplate(nt);
        nt.setId(tid);
        for (MlxMetadataAVU a : t.getMetadatas()) {
            DataGridTemplateField na = new DataGridTemplateField();
            na.setAttribute(a.getAttribute());
            na.setValue(a.getValue());
            na.setUnit(a.getUnit());
            na.setTemplate(nt);
            templateFieldDao.save(na);
        }
    }
    return result;
}
Also used : MlxMetadataTemplate(com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplate) MlxMetadataAVU(com.emc.com.emc.metalnx.core.xml.MlxMetadataAVU) DataGridTemplate(com.emc.metalnx.core.domain.entity.DataGridTemplate) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) MlxMetadataTemplates(com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplates) DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField)

Example 2 with MlxMetadataTemplate

use of com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplate in project metalnx-web by irods-contrib.

the class TemplateController method exportTemplateListToXMLFile.

@RequestMapping(value = "/exportTemplatesToXMLFile/")
public void exportTemplateListToXMLFile(final HttpServletResponse response) {
    try {
        setReponseHeaderForXmlExport(response);
        // Creating marshaller mechanism
        JAXBContext jaxbContext = JAXBContext.newInstance(MlxMetadataTemplates.class);
        Marshaller m = jaxbContext.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        // Creating XML data structure for exporting
        MlxMetadataTemplates ts = new MlxMetadataTemplates();
        for (Long templateId : selectedTemplates) {
            // Getting template data
            DataGridTemplate template = templateService.findById(Long.valueOf(templateId));
            // Mapping DB entity to XML entity
            MlxMetadataTemplate t = templateService.mapDataGridTemplateToXml(template);
            ts.getTemplates().add(t);
        }
        // Marshalling and flushing stream
        m.marshal(ts, response.getOutputStream());
        response.getOutputStream().flush();
        selectedTemplates.clear();
    } catch (JAXBException | IOException e) {
        logger.error("Could not export templates using metadata", e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) MlxMetadataTemplate(com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplate) JAXBException(javax.xml.bind.JAXBException) DataGridTemplate(com.emc.metalnx.core.domain.entity.DataGridTemplate) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) MlxMetadataTemplates(com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplates) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with MlxMetadataTemplate

use of com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplate in project metalnx-web by irods-contrib.

the class TemplateServiceImpl method mapDataGridTemplateToXml.

@Override
public MlxMetadataTemplate mapDataGridTemplateToXml(DataGridTemplate template) {
    // Mapping DB entity to XML entity
    MlxMetadataTemplate t = new MlxMetadataTemplate();
    t.setName(template.getTemplateName());
    t.setDescription(template.getDescription());
    t.setUsageInfo(template.getUsageInformation());
    t.setAccessType(template.getAccessType());
    for (DataGridTemplateField field : template.getFields()) {
        MlxMetadataAVU avu = new MlxMetadataAVU();
        avu.setAttribute(field.getAttribute());
        avu.setValue(field.getValue());
        avu.setUnit(field.getUnit());
        t.getMetadatas().add(avu);
    }
    return t;
}
Also used : MlxMetadataTemplate(com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplate) MlxMetadataAVU(com.emc.com.emc.metalnx.core.xml.MlxMetadataAVU) DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField)

Aggregations

MlxMetadataTemplate (com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplate)3 MlxMetadataAVU (com.emc.com.emc.metalnx.core.xml.MlxMetadataAVU)2 MlxMetadataTemplates (com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplates)2 DataGridTemplate (com.emc.metalnx.core.domain.entity.DataGridTemplate)2 DataGridTemplateField (com.emc.metalnx.core.domain.entity.DataGridTemplateField)2 JAXBContext (javax.xml.bind.JAXBContext)2 IOException (java.io.IOException)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1