use of com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplates 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;
}
use of com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplates 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);
}
}
Aggregations