Search in sources :

Example 6 with DataGridTemplateField

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

the class TemplateController method mapDataGridTempToFieldForm.

/**
 * Maps a list of DataGridTemplateField objects into a list of TemplateFieldForm
 * objects
 *
 * @param tempFields
 *            list of data grid template objects
 * @return list of TemplateFieldForm objects
 */
private List<TemplateFieldForm> mapDataGridTempToFieldForm(final List<DataGridTemplateField> tempFields) {
    List<TemplateFieldForm> tempFieldFormList = new ArrayList<TemplateFieldForm>();
    if (tempFields == null || tempFields.isEmpty()) {
        return tempFieldFormList;
    }
    TemplateFieldForm tempField = null;
    int position = 0;
    for (DataGridTemplateField dataGridTemplateField : tempFields) {
        tempField = this.mapDataGridTempToFieldForm(dataGridTemplateField, position);
        tempFieldFormList.add(tempField);
    }
    return tempFieldFormList;
}
Also used : TemplateFieldForm(com.emc.metalnx.modelattribute.template.field.TemplateFieldForm) ArrayList(java.util.ArrayList) DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField)

Example 7 with DataGridTemplateField

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

the class TemplateController method modifyTemplate.

@RequestMapping(value = "modify/action/")
public String modifyTemplate(final Model model, @ModelAttribute final MetadataTemplateForm templateForm, final RedirectAttributes redirectAttributes) {
    DataGridTemplate template = null;
    try {
        template = templateService.findById(templateForm.getId());
        if (template == null) {
            throw new Exception("Cannot modify a non-existent template");
        }
        DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
        if (!template.getOwner().equalsIgnoreCase(loggedUser.getUsername())) {
            throw new Exception("Cannot modify a template beloging to another user");
        }
        template.setTemplateName(templateForm.getTemplateName());
        template.setDescription(templateForm.getDescription());
        template.setUsageInformation(templateForm.getUsageInformation());
        template.setAccessType(templateForm.getAccessType().toString());
        List<String> positions = templateForm.getAvuPositions();
        List<String> attributes = templateForm.getAvuAttributes();
        List<String> values = templateForm.getAvuValues();
        List<String> units = templateForm.getAvuUnits();
        if (attributes != null) {
            for (int i = 0; i < attributes.size(); i++) {
                for (int j = i + 1; j < attributes.size(); j++) {
                    if (attributes.get(i).equals(attributes.get(j)) && !values.get(i).isEmpty() && values.get(i).equals(values.get(j)) && units.get(i).equals(units.get(j))) {
                        redirectAttributes.addFlashAttribute("repeatedAVU", true);
                        return "redirect:/templates/modify/";
                    }
                }
            }
        }
        if (positions != null) {
            for (int i = 0; i < positions.size(); i++) {
                String position = positions.get(i);
                if (position.contains("mod_pos_")) {
                    addTemplateFields.get(Integer.parseInt(position.replace("mod_pos_", ""))).setAttribute(attributes.get(i));
                    addTemplateFields.get(Integer.parseInt(position.replace("mod_pos_", ""))).setValue(values.get(i));
                    addTemplateFields.get(Integer.parseInt(position.replace("mod_pos_", ""))).setUnit(units.get(i));
                } else if (position.contains("mod_id_")) {
                    templateFieldService.modifyTemplateField(Long.parseLong(position.replace("mod_id_", "")), attributes.get(i), values.get(i), units.isEmpty() ? "" : units.get(i));
                    template.setModified(true);
                }
            }
        }
        // adding all fields to the template
        for (TemplateFieldForm tempFieldForm : addTemplateFields) {
            DataGridTemplateField dataGridTempField = mapTempFieldFormToDataGridTemp(tempFieldForm);
            dataGridTempField.setTemplate(template);
            templateFieldService.createTemplateField(dataGridTempField);
            template.setModified(true);
        }
        Set<DataGridTemplateField> currentTempFields = template.getFields();
        // removing fields from the template
        for (TemplateFieldForm tempFieldForm : removeTemplateFields) {
            DataGridTemplateField dataGridTempField = mapTempFieldFormToDataGridTemp(tempFieldForm);
            dataGridTempField.setTemplate(template);
            template.setModified(true);
            // removing template fields from template
            if (currentTempFields.remove(dataGridTempField)) {
                templateFieldService.deleteTemplateField(dataGridTempField);
                logger.debug("Template removed from memory and database");
            } else // template field wasn't removed
            {
                throw new Exception("Could not removed template field from memory.");
            }
        }
        template.setFields(currentTempFields);
        templateService.modifyTemplate(template);
        // reseting the temporary fields to be added and removed from a template
        addTemplateFields = new ArrayList<TemplateFieldForm>();
        removeTemplateFields = new ArrayList<TemplateFieldForm>();
        redirectAttributes.addFlashAttribute("templateModifiedSuccessfully", template.getTemplateName());
        selectedTemplates.clear();
    } catch (Exception e) {
        logger.error("Could not modify template {}.", templateForm.getTemplateName());
        redirectAttributes.addFlashAttribute("templateNotModifiedSuccessfully", templateForm.getTemplateName());
    }
    return "redirect:/templates/";
}
Also used : TemplateFieldForm(com.emc.metalnx.modelattribute.template.field.TemplateFieldForm) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) DataGridTemplate(com.emc.metalnx.core.domain.entity.DataGridTemplate) DataGridTemplateUnitException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JAXBException(javax.xml.bind.JAXBException) DataGridTemplateValueException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridTooLongTemplateNameException(com.emc.metalnx.core.domain.exceptions.DataGridTooLongTemplateNameException) IOException(java.io.IOException) DataGridTemplateAttrException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException) DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with DataGridTemplateField

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

the class TemplateController method addNewTemplate.

@RequestMapping(value = "add/action/")
public String addNewTemplate(final Model model, @ModelAttribute final MetadataTemplateForm templateForm, final RedirectAttributes redirectAttributes) {
    DataGridTemplate newTemplate = null;
    try {
        newTemplate = new DataGridTemplate();
        newTemplate.setTemplateName(templateForm.getTemplateName());
        newTemplate.setDescription(templateForm.getDescription());
        newTemplate.setUsageInformation(templateForm.getUsageInformation());
        newTemplate.setOwner(loggedUserUtils.getLoggedDataGridUser().getUsername());
        newTemplate.setAccessType(templateForm.getAccessType().toString());
        long templateID = templateService.createTemplate(newTemplate);
        if (templateID > 0) {
            redirectAttributes.addFlashAttribute("templateAddedSuccessfully", newTemplate.getTemplateName());
            newTemplate.setId(templateID);
            // adding all fields to the template
            for (TemplateFieldForm tempFieldForm : addTemplateFields) {
                DataGridTemplateField dataGridTempField = mapTempFieldFormToDataGridTemp(tempFieldForm);
                dataGridTempField.setTemplate(newTemplate);
                templateFieldService.createTemplateField(dataGridTempField);
            }
            // reseting the temporary fields to be added and removed from a
            // template
            addTemplateFields = new ArrayList<TemplateFieldForm>();
            removeTemplateFields = new ArrayList<TemplateFieldForm>();
            return "redirect:/templates/";
        }
    } catch (DataGridTooLongTemplateNameException e) {
        redirectAttributes.addFlashAttribute("templateNotAddedSuccessfully", true);
        redirectAttributes.addFlashAttribute("tooLongTemplateName", true);
    } catch (Exception e) {
        redirectAttributes.addFlashAttribute("templateNotAddedSuccessfully", true);
    }
    return "redirect:/templates/add/";
}
Also used : TemplateFieldForm(com.emc.metalnx.modelattribute.template.field.TemplateFieldForm) DataGridTemplate(com.emc.metalnx.core.domain.entity.DataGridTemplate) DataGridTooLongTemplateNameException(com.emc.metalnx.core.domain.exceptions.DataGridTooLongTemplateNameException) DataGridTemplateUnitException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JAXBException(javax.xml.bind.JAXBException) DataGridTemplateValueException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridTooLongTemplateNameException(com.emc.metalnx.core.domain.exceptions.DataGridTooLongTemplateNameException) IOException(java.io.IOException) DataGridTemplateAttrException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException) DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with DataGridTemplateField

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

the class TemplateController method addFieldToCurrentTemplate.

@RequestMapping(value = "/addFieldToCurrentTemplate")
public String addFieldToCurrentTemplate(final Model model, @ModelAttribute final TemplateFieldForm templateFieldForm) {
    updateAddTemplateFieldsList();
    boolean isAddFieldsEmpty = false;
    try {
        List<DataGridTemplateField> existingTemplateFields = templateService.listTemplateFields(templateFieldForm.getTemplateName());
        DataGridTemplateField newDataGridField = mapTempFieldFormToDataGridTemp(templateFieldForm);
        List<TemplateFieldForm> templateFields = new ArrayList<TemplateFieldForm>();
        TemplateFieldForm newField = this.mapDataGridTempToFieldForm(newDataGridField, addTemplateFields.size());
        templateFields.add(newField);
        if (addTemplateFields.isEmpty()) {
            isAddFieldsEmpty = true;
        }
        // prevent an AVU from being added twice to a template
        if (!addTemplateFields.contains(newField) || addTemplateFields.contains(newField) && newField.getValue().equals("")) {
            addTemplateFields.add(newField.getFormListPosition(), newField);
        }
        model.addAttribute("templateFields", templateFields);
        model.addAttribute("resultSize", templateFields.size());
        model.addAttribute("foundTemplateFields", templateFields.size() > 0);
        if (isAddFieldsEmpty && existingTemplateFields.isEmpty()) {
            return "template/templateFieldList";
        }
    } catch (DataGridTemplateAttrException e) {
        logger.error(e.getMessage());
    } catch (DataGridTemplateValueException e) {
        logger.error(e.getMessage());
    } catch (DataGridTemplateUnitException e) {
        logger.error(e.getMessage());
    }
    return "template/templateFieldList :: avuRow";
}
Also used : TemplateFieldForm(com.emc.metalnx.modelattribute.template.field.TemplateFieldForm) ArrayList(java.util.ArrayList) DataGridTemplateUnitException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException) DataGridTemplateValueException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException) DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField) DataGridTemplateAttrException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with DataGridTemplateField

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

the class TemplateController method listTemplateFieldsForCollections.

@RequestMapping(value = "/listTemplateFieldsForCollections", method = RequestMethod.POST)
public String listTemplateFieldsForCollections(final Model model, @RequestParam("templateIDsList") final long[] templateIDsList) {
    MetadataTemplateForm templateForm = new MetadataTemplateForm();
    List<TemplateFieldForm> templateFields = new ArrayList<TemplateFieldForm>();
    List<DataGridTemplateField> dataGridTemplateFields = new ArrayList<DataGridTemplateField>();
    if (templateIDsList.length > 0) {
        for (long id : templateIDsList) {
            dataGridTemplateFields.addAll(templateService.listTemplateFields(id));
        }
        templateFields = this.mapDataGridTempToFieldForm(dataGridTemplateFields);
    }
    model.addAttribute("templateForm", templateForm);
    model.addAttribute("requestMapping", "/browse/applyTemplatesToCollections/");
    model.addAttribute("templateFields", templateFields);
    model.addAttribute("resultSize", templateFields.size());
    model.addAttribute("foundTemplateFields", templateFields.size() > 0);
    return "collections/templateFieldListForCollections";
}
Also used : TemplateFieldForm(com.emc.metalnx.modelattribute.template.field.TemplateFieldForm) MetadataTemplateForm(com.emc.metalnx.modelattribute.metadatatemplate.MetadataTemplateForm) ArrayList(java.util.ArrayList) DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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