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;
}
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();
}
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;
}
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";
}
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;
}
Aggregations