Search in sources :

Example 1 with FormVersion

use of org.akaza.openclinica.service.dto.FormVersion in project OpenClinica by OpenClinica.

the class XformMetaDataService method executeIndividualCrf.

public void executeIndividualCrf(ExecuteIndividualCrfObject eicObject) {
    for (OCodmComplexTypeDefinitionFormLayoutDef formLayoutDef : eicObject.formLayoutDefs) {
        List<String> fileLinks = null;
        String vForm = "";
        RestTemplate rest = new RestTemplate();
        if (eicObject.form != null) {
            List<FormVersion> versions = eicObject.form.getVersions();
            for (FormVersion version : versions) {
                if (version.getName().equals(formLayoutDef.getOID())) {
                    fileLinks = version.getFileLinks();
                    for (String fileLink : fileLinks) {
                        if (fileLink.endsWith(VERSION)) {
                            vForm = rest.getForObject(fileLink, String.class);
                            break;
                        }
                    }
                    if (!eicObject.errors.hasErrors()) {
                        ObjectMapper mapper = new ObjectMapper();
                        TypeReference<List<XformGroup>> mapType = new TypeReference<List<XformGroup>>() {
                        };
                        List<XformGroup> jsonList = null;
                        try {
                            jsonList = mapper.readValue(vForm, mapType);
                        } catch (JsonParseException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (JsonMappingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        XformContainer xformContainer = new XformContainer();
                        xformContainer.setGroups(jsonList);
                        eicObject.setContainer(xformContainer);
                        if (eicObject.errors.hasErrors()) {
                            return;
                        }
                        // Save meta-data in database
                        saveFormMetadata(eicObject, version, eicObject.container, formLayoutDef, fileLinks);
                    }
                }
            }
        }
    }
}
Also used : OCodmComplexTypeDefinitionFormLayoutDef(org.openclinica.ns.odm_ext_v130.v31.OCodmComplexTypeDefinitionFormLayoutDef) XformGroup(org.akaza.openclinica.domain.xform.XformGroup) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) XformContainer(org.akaza.openclinica.domain.xform.XformContainer) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) RestTemplate(org.springframework.web.client.RestTemplate) List(java.util.List) ArrayList(java.util.ArrayList) TypeReference(com.fasterxml.jackson.core.type.TypeReference) FormVersion(org.akaza.openclinica.service.dto.FormVersion) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 XformContainer (org.akaza.openclinica.domain.xform.XformContainer)1 XformGroup (org.akaza.openclinica.domain.xform.XformGroup)1 FormVersion (org.akaza.openclinica.service.dto.FormVersion)1 OCodmComplexTypeDefinitionFormLayoutDef (org.openclinica.ns.odm_ext_v130.v31.OCodmComplexTypeDefinitionFormLayoutDef)1 RestTemplate (org.springframework.web.client.RestTemplate)1