use of com.emc.metalnx.core.domain.entity.DataGridTemplate 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.metalnx.core.domain.entity.DataGridTemplate in project metalnx-web by irods-contrib.
the class TemplateDaoImpl method findById.
@Override
public DataGridTemplate findById(long id) {
Query q = this.sessionFactory.getCurrentSession().createQuery("from DataGridTemplate where template_id=(:id)");
q.setParameter("id", id);
return (DataGridTemplate) q.uniqueResult();
}
use of com.emc.metalnx.core.domain.entity.DataGridTemplate in project metalnx-web by irods-contrib.
the class TemplateController method showModifyTemplate.
@RequestMapping(value = "modify/")
public String showModifyTemplate(final Model model, final HttpServletRequest request) {
// DataGridTemplate template =
// templateService.findById(selectedTemplates.iterator().next());
DataGridTemplate template = templateService.findById(Long.parseLong(request.getParameter("templateId")));
if (template == null) {
return "redirect:/templates/";
}
MetadataTemplateForm templateForm = new MetadataTemplateForm();
templateForm.setId(template.getId());
templateForm.setTemplateName(template.getTemplateName());
templateForm.setDescription(template.getDescription());
templateForm.setUsageInformation(template.getUsageInformation());
templateForm.setOwner(template.getOwner());
templateForm.setAccessType(template.getAccessType());
templateForm.setVersion(template.getVersion());
TemplateFieldForm templateFieldForm = new TemplateFieldForm();
model.addAttribute("uiMode", request.getSession().getAttribute("uiMode"));
model.addAttribute("accessTypes", MetadataTemplateAccessType.values());
model.addAttribute("metadataTemplateForm", templateForm);
model.addAttribute("templateFieldForm", templateFieldForm);
model.addAttribute("requestMapping", "/templates/modify/action/");
return "template/templateForm";
}
use of com.emc.metalnx.core.domain.entity.DataGridTemplate 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);
}
}
use of com.emc.metalnx.core.domain.entity.DataGridTemplate in project metalnx-web by irods-contrib.
the class TemplateController method listTemplateFields.
@RequestMapping(value = "/listTemplateFields", method = RequestMethod.POST)
public String listTemplateFields(final Model model, @RequestParam("template") final String template) {
updateAddTemplateFieldsList();
List<DataGridTemplateField> dataGridTemplateFields = templateService.listTemplateFields(template);
List<TemplateFieldForm> templateFields = this.mapDataGridTempToFieldForm(dataGridTemplateFields);
DataGridTemplate metadataTemplate = templateService.findByName(template);
if (addTemplateFields != null) {
templateFields.addAll(addTemplateFields);
}
if (removeTemplateFields != null) {
templateFields.removeAll(removeTemplateFields);
}
model.addAttribute("metadataTemplate", metadataTemplate);
model.addAttribute("templateFields", templateFields);
model.addAttribute("resultSize", templateFields.size());
model.addAttribute("foundTemplateFields", templateFields.size() > 0);
return "template/templateFieldList";
}
Aggregations