Search in sources :

Example 41 with ResponseEntity

use of org.springframework.http.ResponseEntity in project OpenClinica by OpenClinica.

the class IdtViewController method postSDVedItemDataAndEventCrfWorkflow.

@RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseEntity postSDVedItemDataAndEventCrfWorkflow(@RequestBody ArrayList<HashMap<String, String>> maps) throws Exception {
    int tagId = 1;
    UserAccount userAccount = null;
    HashSet<String> listOfEventCrfPaths = new HashSet();
    for (HashMap map : maps) {
        String eventCrfPath = map.get("ssOid") + "." + map.get("sedOid") + "." + map.get("eventOrdinal") + "." + map.get("crfOid");
        String itemDataPath = eventCrfPath + "." + map.get("groupOid") + "." + map.get("groupOrdinal") + "." + map.get("itemOid");
        String workflowStatus = (String) map.get("itemDataWorkflowStatus");
        listOfEventCrfPaths.add(eventCrfPath);
        saveOrUpdateItemDataFlag(tagId, itemDataPath, workflowStatus);
    }
    for (String eventCrfPath : listOfEventCrfPaths) {
        saveOrUpdateEventCrfFlag(tagId, eventCrfPath, userAccount);
    }
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) UserAccount(org.akaza.openclinica.domain.user.UserAccount) HashSet(java.util.HashSet)

Example 42 with ResponseEntity

use of org.springframework.http.ResponseEntity in project OpenClinica by OpenClinica.

the class EditFormController method getEditUrl.

/**
     * @api {get} /pages/api/v1/editform/:studyOid/url Get Form Edit URL
     * @apiName getEditUrl
     * @apiPermission admin
     * @apiVersion 3.8.0
     * @apiParam {String} studyOid Study Oid.
     * @apiParam {String} ecid Key that will be used by enketo to cache form information.
     * @apiGroup Form
     * @apiDescription This API is used to retrieve a URL for a form with data pre-loaded into it
     * @apiParamExample {json} Request-Example:
     *                  {
     *                  "studyOid": "S_BL101",
     *                  "ecid":"a9f8f3aadea4b67e1f214140ccfdf70bad0b9e9b622a9776a3c85bbf6bb532cd"
     *                  }
     * @apiSuccessExample Success-Response:
     *                    HTTP/1.1 200 OK
     *                    {
     *                    http://ocform.oc.com:8005/edit/::YYYM?instance_id=
     *                    d16bba9200177fad34594e75d8b9565ff92b0bce4297e3b6c27275e531044a59
     *                    &returnUrl=http%3A%2F%2Fstudy1.mystudy.me%3A8080%2F%23%2Fevent%2FSS_SUB001%2Fdashboard&ecid=
     *                    d16bba9200177fad34594e75d8b9565ff92b0bce4297e3b6c27275e531044a59
     *                    }
     */
@RequestMapping(value = "/{studyOid}/url", method = RequestMethod.GET)
public ResponseEntity<String> getEditUrl(@RequestParam(FORM_CONTEXT) String formContext, @PathVariable("studyOid") String studyOID) throws Exception {
    String editURL = null;
    if (!mayProceed(studyOID))
        return new ResponseEntity<String>(editURL, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    // Load context
    PFormCache cache = PFormCache.getInstance(context);
    HashMap<String, String> subjectContextMap = cache.getSubjectContext(formContext);
    PFormCacheSubjectContextEntry subjectContext = new PFormCacheSubjectContextEntry();
    subjectContext.setStudyEventDefinitionId(Integer.valueOf(subjectContextMap.get("studyEventDefinitionID")));
    subjectContext.setFormLayoutOid(subjectContextMap.get("formLayoutOID"));
    subjectContext.setStudySubjectOid(subjectContextMap.get("studySubjectOID"));
    subjectContext.setOrdinal(Integer.valueOf(subjectContextMap.get("studyEventOrdinal")));
    editURL = urlService.getEditUrl(formContext, subjectContext, studyOID, null, null, NO_FLAVOR);
    logger.debug("Generating Enketo edit url for form: " + editURL);
    return new ResponseEntity<String>(editURL, org.springframework.http.HttpStatus.ACCEPTED);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PFormCache(org.akaza.openclinica.web.pform.PFormCache) PFormCacheSubjectContextEntry(org.akaza.openclinica.service.crfdata.xform.PFormCacheSubjectContextEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 43 with ResponseEntity

use of org.springframework.http.ResponseEntity in project OpenClinica by OpenClinica.

the class AnonymousFormControllerV2 method getEnketoForm.

/**
     * @api {post} /pages/api/v2/anonymousform/form Retrieve anonymous form URL
     * @apiName getEnketoForm
     * @apiPermission Module participate - enabled
     * @apiVersion 3.8.0
     * @apiParam {String} studyOid Study Oid
     * @apiParam {String} submissionUri Submission Url
     * @apiGroup Form
     * @apiDescription Retrieve anonymous form url.
     * @apiParamExample {json} Request-Example:
     *                  {
     *                  "studyOid": "S_BL101",
     *                  "submissionUri": "abcde"
     *                  }
     * @apiSuccessExample {json} Success-Response:
     *                    HTTP/1.1 200 OK
     *                    {
     *                    "url":
     *                    "http://localhost:8006/::YYYi?iframe=true&ecid=abb764d026830e98b895ece6d9dcaf3c5e817983cc00a4ebfaabcb6c3700b4d5",
     *                    "offline": "false"
     *                    }
     */
@RequestMapping(value = "/form", method = RequestMethod.POST)
public ResponseEntity<AnonymousUrlResponse> getEnketoForm(@RequestBody HashMap<String, String> map) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    EventDefinitionCrfTagService tagService = (EventDefinitionCrfTagService) SpringServletAccess.getApplicationContext(context).getBean("eventDefinitionCrfTagService");
    String formUrl = null;
    String studyOid = map.get("studyOid");
    if (!mayProceed(studyOid))
        return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    String submissionUri = map.get("submissionUri");
    if (submissionUri != "" && submissionUri != null) {
        StudyBean study = getStudy(studyOid);
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(dataSource);
        ArrayList<EventDefinitionCRFBean> edcBeans = edcdao.findAllSubmissionUriAndStudyId(submissionUri, study.getId());
        if (edcBeans.size() != 0) {
            EventDefinitionCRFBean edcBean = edcBeans.get(0);
            CRFDAO crfdao = new CRFDAO(dataSource);
            FormLayoutDAO fldao = new FormLayoutDAO(dataSource);
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(dataSource);
            FormLayoutBean formLayout = (FormLayoutBean) fldao.findByPK(edcBean.getDefaultVersionId());
            CRFBean crf = (CRFBean) crfdao.findByPK(formLayout.getCrfId());
            StudyBean sBean = (StudyBean) sdao.findByPK(edcBean.getStudyId());
            StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) seddao.findByPK(edcBean.getStudyEventDefinitionId());
            String tagPath = sedBean.getOid() + "." + crf.getOid();
            boolean isOffline = tagService.getEventDefnCrfOfflineStatus(2, tagPath, true);
            String offline = null;
            if (isOffline)
                offline = "true";
            else
                offline = "false";
            formUrl = createAnonymousEnketoUrl(sBean.getOid(), formLayout, edcBean, isOffline);
            AnonymousUrlResponse anonResponse = new AnonymousUrlResponse(formUrl, offline, crf.getName(), formLayout.getDescription());
            return new ResponseEntity<AnonymousUrlResponse>(anonResponse, org.springframework.http.HttpStatus.OK);
        } else {
            return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
        }
    } else {
        return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    }
}
Also used : Locale(java.util.Locale) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventDefinitionCrfTagService(org.akaza.openclinica.service.managestudy.EventDefinitionCrfTagService) ResponseEntity(org.springframework.http.ResponseEntity) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 44 with ResponseEntity

use of org.springframework.http.ResponseEntity in project OpenClinica by OpenClinica.

the class BatchCRFMigrationController method runAuthPreview.

/**
     * @api {post} /pages/auth/api/v1/forms/migrate/preview Batch CRF Version Migration Preview
     * @apiName runAuthPreview
     * @apiPermission Authenticate using api-key. admin
     * @apiVersion 3.8.0
     * @apiParam {String} studyOID is the Target Study OID.
     * @apiParam {String} sourceFormVersion Form Version OID From.
     * @apiParam {String} targetFormVersion Form Version OID To.
     * @apiParam {String} studyEventDefs List Of Event Definitions , when left blank, implies all events within
     *           target study.
     * @apiParam {String} sites List Of Sites , when left blank, implies all sites including target study
     * @apiGroup Form
     * @apiDescription This api is a summary report for crf version migration and returns json object of report log.
     * @apiParamExample {json} Request-Example:
     *                  {
     *                  "studyOID" : "S_BL101" ,
     *                  "sourceFormVersion" : "F_GROUPS_ADVER_V221" ,
     *                  "targetFormVersion" : "F_GROUPS_ADVER_V22" ,
     *                  "studyEventDefs" : [] ,
     *                  "sites" : []
     *                  }
     * 
     * @apiErrorExample {json} Error-Response:
     *                  HTTP/1.1 406 NOT ACCEPTABLE
     *                  {
     *                  "errors": ["The OID of the Target Study that you provided is invalid."],
     *                  "reportPreview": null,
     *                  "subjectCount": 0,
     *                  "eventCrfCount": 0,
     *                  "canNotMigrate": [],
     *                  "logs": []
     *                  }
     * 
     * @apiSuccessExample {json} Success-Response:
     *                    HTTP/1.1 200 OK
     *                    {
     *                    "errors": [],
     *                    "reportPreview": null,
     *                    "subjectCount": 8,
     *                    "eventCrfCount": 12,
     *                    "canNotMigrate": [],
     *                    "logs": []
     *                    }
     */
@Produces(MediaType.APPLICATION_JSON)
@RequestMapping(value = "/auth/api/v1/forms/migrate/preview", method = RequestMethod.POST)
public ResponseEntity<ReportLog> runAuthPreview(@RequestBody TransferObject transferObject, HttpServletRequest request) throws Exception {
    ResponseEntity<HelperObject> res = runPreviewTest(transferObject, request);
    HelperObject helperObject = res.getBody();
    return new ResponseEntity<ReportLog>(helperObject.getReportLog(), org.springframework.http.HttpStatus.OK);
}
Also used : HelperObject(org.akaza.openclinica.controller.helper.HelperObject) ResponseEntity(org.springframework.http.ResponseEntity) Produces(javax.ws.rs.Produces) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with ResponseEntity

use of org.springframework.http.ResponseEntity in project OpenClinica by OpenClinica.

the class AccountController method getAccount2.

/**
	 * @api {get} /pages/accounts/study/:studyOid/accesscode/:accessCode Retrieve a user account - participant
	 * @apiName getAccount2
	 * @apiPermission Module participate - enabled & admin
	 * @apiVersion 3.8.0
	 * @apiParam {String} studyOid Study Oid.
	 * @apiParam {String} accessCode Participant Access code .
	 * @apiGroup User Account
	 * @apiDescription Retrieves the participant user account with the given accessCode and studyOid
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "studyOid": " S_BL101",
	 *                  "accessCode": "yfzqpvDpiJftIZgNDphvxg=="
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    HTTP/1.1 200 OK
	 *                    {
	 *                    "lName": "",
	 *                    "mobile": "jLGQwxkuVpPBLJCtnLdrAw==",
	 *                    "accessCode": "yfzqpvDpiJftIZgNDphvxg==",
	 *                    "password": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
	 *                    "email": "XzJadh3l3V7uUoPCggbSoIfoNW8IQU3qsvrtHfJH7J0=",
	 *                    "userName": "S_BL101.SS_SUBA101",
	 *                    "studySubjectId": null,
	 *                    "fName": "07hQGfwT6LRXk0rLLYwkviwNdOEycnj4lOjrNMBdesk="
	 *                    }
	 */
@RequestMapping(value = "/study/{studyOid}/accesscode/{accessCode}", method = RequestMethod.GET)
public ResponseEntity<UserDTO> getAccount2(@PathVariable("studyOid") String studyOid, @PathVariable("accessCode") String accessCode) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    uDTO = null;
    System.out.println("I'm in getAccount2");
    accessCode = URLDecoder.decode(accessCode, "UTF-8");
    StudyBean parentStudy = getParentStudy(studyOid);
    String oid = parentStudy.getOid();
    if (isStudyASiteLevelStudy(studyOid))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (!mayProceed(oid))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (isStudyDoesNotExist(oid))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (isAccessCodeIsNull(accessCode))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    UserAccountBean accessCodeAccountBean = getAccessCodeAccount(accessCode);
    if (!accessCodeAccountBean.isActive())
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    // This code should've been in liquibase migration for better readability.
    if (accessCodeAccountBean.getApiKey() == null || accessCodeAccountBean.getApiKey().isEmpty()) {
        String apiKey = null;
        do {
            apiKey = getRandom32ChApiKey();
        } while (isApiKeyExist(apiKey));
        accessCodeAccountBean.setEnableApiKey(true);
        accessCodeAccountBean.setApiKey(apiKey);
        updateUserAccount(accessCodeAccountBean);
    }
    buildUserDTO(accessCodeAccountBean);
    // Client want to trade access_code for api_key, for later usage of our api.
    if (accessCodeAccountBean.isEnableApiKey()) {
        uDTO.setApiKey(accessCodeAccountBean.getApiKey());
    }
    return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.OK);
}
Also used : Locale(java.util.Locale) ResponseEntity(org.springframework.http.ResponseEntity) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserDTO(org.akaza.openclinica.bean.login.UserDTO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean)

Aggregations

ResponseEntity (org.springframework.http.ResponseEntity)279 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)91 HttpHeaders (org.springframework.http.HttpHeaders)89 ApiOperation (io.swagger.annotations.ApiOperation)44 Test (org.junit.Test)39 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)39 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)38 ArrayList (java.util.ArrayList)34 Locale (java.util.Locale)32 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)32 HashMap (java.util.HashMap)30 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)24 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)22 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)16 ApiResponses (io.swagger.annotations.ApiResponses)16 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)16 List (java.util.List)15 InputStream (java.io.InputStream)14 MediaType (org.springframework.http.MediaType)14 IOException (java.io.IOException)13