public String updateTemplate(HttpHeaders hh, String payload) throws HelperException { logger.debug("StartOf updateTemplate payload:" + payload); try { JAXBContext context = JAXBContext.newInstance(Template.class); Unmarshaller unMarshaller = context.createUnmarshaller(); eu.atos.sla.parser.data.wsag.Template templateXML = (eu.atos.sla.parser.data.wsag.Template) unMarshaller.unmarshal(new StringReader(payload)); Template template = getTemplateForDB(templateXML, payload); boolean templateStored = this.templateDAO.update(template.getUuid(), template); ITemplate templateFromDatabase = new Template(); String str = null; if (templateStored) { templateFromDatabase = this.templateDAO.getByUuid(template.getUuid()); str = printTemplateToXML(templateFromDatabase); } logger.debug("EndOf updateTemplate"); return str; } catch (JAXBException e) { logger.error("Error in updateTemplate ", e); throw new HelperException( Code.PARSER, "Error when updating template parsing file:" + e.getMessage()); } catch (Throwable e) { logger.error("Error in updateTemplate ", e); throw new HelperException(Code.INTERNAL, "Error when updating template:" + e.getMessage()); } }
private Template getTemplateForDB( eu.atos.sla.parser.data.wsag.Template templateXML, String payload) { Template templateDB = new Template(); if (templateXML.getTemplateId() != null) { templateDB.setUuid(templateXML.getTemplateId()); logger.debug("templateId:" + templateDB.getUuid()); } if (payload != null) { templateDB.setText(payload); } return templateDB; }