Search in sources :

Example 1 with DataGridTemplateField

use of com.emc.metalnx.core.domain.entity.DataGridTemplateField 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 DataGridTemplateField

use of com.emc.metalnx.core.domain.entity.DataGridTemplateField in project metalnx-web by irods-contrib.

the class TemplateFieldsDaoImpl method findById.

@Override
public DataGridTemplateField findById(long id) {
    Query q = sessionFactory.getCurrentSession().createQuery("from DataGridTemplateField where template_field_id=(:id)");
    q.setParameter("id", id);
    return (DataGridTemplateField) q.uniqueResult();
}
Also used : Query(org.hibernate.Query) DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField)

Example 3 with DataGridTemplateField

use of com.emc.metalnx.core.domain.entity.DataGridTemplateField in project metalnx-web by irods-contrib.

the class TemplateFieldsDaoImpl method modifyById.

@Override
public boolean modifyById(long id, String attribute, String value, String unit) throws DataGridTemplateAttrException, DataGridTemplateValueException, DataGridTemplateUnitException {
    DataGridTemplateField templateField = findById(id);
    if (templateField == null) {
        return false;
    }
    templateField.setAttribute(attribute);
    templateField.setValue(value);
    templateField.setUnit(unit);
    merge(templateField);
    return true;
}
Also used : DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField)

Example 4 with DataGridTemplateField

use of com.emc.metalnx.core.domain.entity.DataGridTemplateField 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)

Example 5 with DataGridTemplateField

use of com.emc.metalnx.core.domain.entity.DataGridTemplateField in project metalnx-web by irods-contrib.

the class TemplateController method mapTempFieldFormToDataGridTemp.

/**
 * Map a Template Field form object into a DataGridTemplateField object
 *
 * @param tempFieldForm
 *            template field form object to be mapped
 * @return DataGridTemplateField object
 * @throws DataGridTemplateAttrException
 * @throws DataGridTemplateValueException
 * @throws DataGridTemplateUnitException
 */
private DataGridTemplateField mapTempFieldFormToDataGridTemp(final TemplateFieldForm tempFieldForm) throws DataGridTemplateAttrException, DataGridTemplateValueException, DataGridTemplateUnitException {
    if (tempFieldForm == null) {
        return null;
    }
    DataGridTemplateField templateField = new DataGridTemplateField();
    templateField.setAttribute(tempFieldForm.getAttribute());
    templateField.setValue(tempFieldForm.getValue());
    templateField.setUnit(tempFieldForm.getUnit());
    templateField.setStartRange(tempFieldForm.getStartRange());
    templateField.setEndRange(tempFieldForm.getEndRange());
    templateField.setOrder(tempFieldForm.getOrder());
    if (tempFieldForm.getId() != null) {
        templateField.setId(tempFieldForm.getId());
    }
    return templateField;
}
Also used : DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField)

Aggregations

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