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;
}
Aggregations