Search in sources :

Example 16 with FormLayout

use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.

the class OpenRosaServices method getFormXml.

/**
     * @api {get} /rest2/openrosa/:studyOID/formXml Get Form XML
     * @apiName getFormXml
     * @apiPermission admin
     * @apiVersion 3.8.0
     * @apiParam {String} studyOID Study Oid.
     * @apiGroup Form
     * @apiDescription Downloads the contents of a form
     */
@GET
@Path("/{studyOID}/formXml")
@Produces(MediaType.APPLICATION_XML)
public String getFormXml(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("formId") String uniqueId, @RequestHeader("Authorization") String authorization) throws Exception {
    if (!mayProceedPreview(studyOID))
        return null;
    String xform = null;
    // get parameters
    String formId = request.getParameter("formId");
    if (formId == null) {
        return "<error>formID is null :(</error>";
    }
    String flavor = getQuerySet(uniqueId);
    String formLayoutOid = getFormLayoutOid(uniqueId);
    FormLayout formLayout = formLayoutDao.findByOcOID(formLayoutOid);
    CrfBean crf = formLayout.getCrf();
    String xformOutput = "";
    String directoryPath = Utils.getCrfMediaFilePath(crf.getOcOid(), formLayout.getOcOid());
    File dir = new File(directoryPath);
    File[] directoryListing = dir.listFiles();
    if (directoryListing != null) {
        for (File child : directoryListing) {
            if (flavor.equals(QUERY_FLAVOR) && child.getName().endsWith(QUERY_SUFFIX) || flavor.equals(NO_FLAVOR) && child.getName().endsWith(NO_SUFFIX)) {
                xformOutput = new String(Files.readAllBytes(Paths.get(child.getPath())));
                break;
            }
        }
    }
    try {
        if (StringUtils.isNotEmpty(xformOutput)) {
            xform = xformOutput;
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
        LOGGER.error(ExceptionUtils.getStackTrace(e));
        return "<error>" + e.getMessage() + "</error>";
    }
    response.setHeader("Content-Type", "text/xml; charset=UTF-8");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + formId + ".xml" + "\";");
    response.setContentType("text/xml; charset=utf-8");
    return xform;
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) CrfBean(org.akaza.openclinica.domain.datamap.CrfBean) MediaFile(org.akaza.openclinica.web.pform.manifest.MediaFile) File(java.io.File) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)16 Date (java.util.Date)6 IOException (java.io.IOException)5 CrfBean (org.akaza.openclinica.domain.datamap.CrfBean)5 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)4 FormLayoutMedia (org.akaza.openclinica.domain.datamap.FormLayoutMedia)4 Study (org.akaza.openclinica.domain.datamap.Study)4 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)4 File (java.io.File)3 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)3 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)3 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)3 StringWriter (java.io.StringWriter)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)2