Search in sources :

Example 1 with DataGridTemplate

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;
}
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 DataGridTemplate

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();
}
Also used : Query(org.hibernate.Query) DataGridTemplate(com.emc.metalnx.core.domain.entity.DataGridTemplate)

Example 3 with DataGridTemplate

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";
}
Also used : TemplateFieldForm(com.emc.metalnx.modelattribute.template.field.TemplateFieldForm) MetadataTemplateForm(com.emc.metalnx.modelattribute.metadatatemplate.MetadataTemplateForm) DataGridTemplate(com.emc.metalnx.core.domain.entity.DataGridTemplate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with DataGridTemplate

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);
    }
}
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 5 with DataGridTemplate

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";
}
Also used : TemplateFieldForm(com.emc.metalnx.modelattribute.template.field.TemplateFieldForm) DataGridTemplate(com.emc.metalnx.core.domain.entity.DataGridTemplate) DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataGridTemplate (com.emc.metalnx.core.domain.entity.DataGridTemplate)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 DataGridTemplateField (com.emc.metalnx.core.domain.entity.DataGridTemplateField)4 TemplateFieldForm (com.emc.metalnx.modelattribute.template.field.TemplateFieldForm)4 IOException (java.io.IOException)3 JAXBException (javax.xml.bind.JAXBException)3 MlxMetadataTemplate (com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplate)2 MlxMetadataTemplates (com.emc.com.emc.metalnx.core.xml.MlxMetadataTemplates)2 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)2 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)2 DataGridTemplateAttrException (com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException)2 DataGridTemplateUnitException (com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException)2 DataGridTemplateValueException (com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException)2 DataGridTooLongTemplateNameException (com.emc.metalnx.core.domain.exceptions.DataGridTooLongTemplateNameException)2 JAXBContext (javax.xml.bind.JAXBContext)2 Query (org.hibernate.Query)2 MlxMetadataAVU (com.emc.com.emc.metalnx.core.xml.MlxMetadataAVU)1 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)1 MetadataTemplateForm (com.emc.metalnx.modelattribute.metadatatemplate.MetadataTemplateForm)1 Marshaller (javax.xml.bind.Marshaller)1