Search in sources :

Example 1 with Html

use of org.akaza.openclinica.web.pform.dto.Html in project OpenClinica by OpenClinica.

the class OpenRosaXmlGenerator method buildForm.

/**
     * @param formId
     * @return
     * @throws Exception
     */
public String buildForm(String formId) throws Exception {
    try {
        CRFVersionDAO versionDAO = new CRFVersionDAO(dataSource);
        FormLayoutDAO fldao = new FormLayoutDAO<>(dataSource);
        FormLayoutBean formLayout = fldao.findByOid(formId);
        CRFDAO crfDAO = new CRFDAO(dataSource);
        CRFBean crf = (CRFBean) crfDAO.findByPK(formLayout.getCrfId());
        CRFVersionMetadataUtil metadataUtil = new CRFVersionMetadataUtil(dataSource);
        ArrayList<SectionBean> crfSections = metadataUtil.retrieveFormMetadata(formLayout);
        ArrayList<CRFVersionBean> crfVersions = versionDAO.findAllByCRFId(crf.getId());
        CRFVersionBean crfVersion = crfVersions.get(0);
        StringWriter writer = new StringWriter();
        IOUtils.copy(getClass().getResourceAsStream("/properties/xform_template.xml"), writer, "UTF-8");
        String xform = writer.toString();
        Html html = buildJavaXForm(xform);
        int sectionCount = mapBeansToDTO(html, crf, crfVersion, crfSections);
        if (sectionCount > 1)
            setFormPaging(html);
        String xformMinusInstance = buildStringXForm(html);
        String preInstance = xformMinusInstance.substring(0, xformMinusInstance.indexOf("<instance>"));
        String instance = buildInstance(html.getHead().getModel(), formLayout, crfVersion, crfSections);
        String nodeset = xformMinusInstance.substring(xformMinusInstance.indexOf("</instance>") + "</instance>".length());
        // add nodeset for instanceId
        String postInstance = "<bind calculate=\"concat('uuid:', uuid())\" nodeset=\"/" + formLayout.getOid() + "/meta/instanceID\" readonly=\"true()\" type=\"string\"/>" + nodeset;
        logger.debug(preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance);
        System.out.println(preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance);
        return preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance;
    } catch (Exception e) {
        log.error(e.getMessage());
        log.error(ExceptionUtils.getStackTrace(e));
        throw new Exception(e);
    }
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) Html(org.akaza.openclinica.web.pform.dto.Html) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) StringWriter(java.io.StringWriter) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) CRFVersionMetadataUtil(org.akaza.openclinica.control.managestudy.CRFVersionMetadataUtil)

Example 2 with Html

use of org.akaza.openclinica.web.pform.dto.Html in project OpenClinica by OpenClinica.

the class OpenRosaXmlGenerator method buildJavaXForm.

private Html buildJavaXForm(String content) throws Exception {
    // XML to Object
    Reader reader = new StringReader(content);
    Unmarshaller unmarshaller = xmlContext.createUnmarshaller();
    unmarshaller.setClass(Html.class);
    unmarshaller.setWhitespacePreserve(false);
    Html html = (Html) unmarshaller.unmarshal(reader);
    reader.close();
    return html;
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) Html(org.akaza.openclinica.web.pform.dto.Html) Unmarshaller(org.exolab.castor.xml.Unmarshaller)

Aggregations

Html (org.akaza.openclinica.web.pform.dto.Html)2 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)1 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)1 FormLayoutBean (org.akaza.openclinica.bean.submit.FormLayoutBean)1 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)1 CRFVersionMetadataUtil (org.akaza.openclinica.control.managestudy.CRFVersionMetadataUtil)1 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)1 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)1 FormLayoutDAO (org.akaza.openclinica.dao.submit.FormLayoutDAO)1 OpenClinicaException (org.akaza.openclinica.exception.OpenClinicaException)1 Unmarshaller (org.exolab.castor.xml.Unmarshaller)1