Search in sources :

Example 1 with MlxMetadataAVU

use of com.emc.com.emc.metalnx.core.xml.MlxMetadataAVU 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 MlxMetadataAVU

use of com.emc.com.emc.metalnx.core.xml.MlxMetadataAVU 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

MlxMetadataAVU (com.emc.com.emc.metalnx.core.xml.MlxMetadataAVU)2 MlxMetadataTemplate (com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplate)2 DataGridTemplateField (com.emc.metalnx.core.domain.entity.DataGridTemplateField)2 MlxMetadataTemplates (com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplates)1 DataGridTemplate (com.emc.metalnx.core.domain.entity.DataGridTemplate)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1