Search in sources :

Example 1 with ReportLog

use of org.akaza.openclinica.controller.helper.ReportLog in project OpenClinica by OpenClinica.

the class BatchCRFMigrationController method runAuthMigration.

/**
     * @api {post} /pages/auth/api/v1/forms/migrate/run/ Batch CRF Version Migration Run
     * @apiName runAuthMigration
     * @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 will execute crf version migration and return an email with link of a file that include
     *                 details of the transaction.
     * @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": ["Current CRF version and New CRF version can not be same."],
     *                  "reportPreview": null,
     *                  "subjectCount": 0,
     *                  "eventCrfCount": 0,
     *                  "canNotMigrate": [],
     *                  "logs": []
     *                  }
     * 
     * @apiSuccessExample {json} Success-Response:
     *                    HTTP/1.1 200 OK
     *                    {
     *                    "errors": [],
     *                    "reportPreview":
     *                    "Batch CRF version migration is running. You will receive an email once the process is
     *                    complete"
     *                    ,
     *                    "subjectCount": 8,
     *                    "eventCrfCount": 12,
     *                    "canNotMigrate": [],
     *                    "logs": []
     *                    }
     */
@Produces(MediaType.APPLICATION_JSON)
@RequestMapping(value = "/auth/api/v1/forms/migrate/run", method = RequestMethod.POST)
public ResponseEntity<ReportLog> runAuthMigration(@RequestBody TransferObject transferObject, HttpServletRequest request) throws Exception {
    ResponseEntity<HelperObject> res = runPreviewTest(transferObject, request);
    HelperObject helperObject = res.getBody();
    helperObject.setRequest(request);
    fillHelperObject(helperObject);
    ReportLog reportLog = helperObject.getReportLog();
    String str = "";
    if (reportLog.getSubjectCount() != 0 && reportLog.getEventCrfCount() != 0 && reportLog.getErrors().size() == 0) {
        BatchCRFMigrationController bcmController = new BatchCRFMigrationController(helperObject);
        Thread thread = new Thread(bcmController);
        thread.start();
        str = resterms.getString("Batch_CRF_version_migration_is_running_You_will_receive_an_email_once_the_process_is_complete");
        reportLog.setReportPreview(str);
        return new ResponseEntity<ReportLog>(reportLog, org.springframework.http.HttpStatus.OK);
    } else if (reportLog.getErrors().size() > 0) {
        return new ResponseEntity<ReportLog>(reportLog, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    } else {
        str = resterms.getString("Migration_did_not_run_due_to_no_affected_subject");
        reportLog.setReportPreview(str);
        return new ResponseEntity<ReportLog>(reportLog, org.springframework.http.HttpStatus.OK);
    }
}
Also used : HelperObject(org.akaza.openclinica.controller.helper.HelperObject) ReportLog(org.akaza.openclinica.controller.helper.ReportLog) ResponseEntity(org.springframework.http.ResponseEntity) Produces(javax.ws.rs.Produces) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ReportLog

use of org.akaza.openclinica.controller.helper.ReportLog in project OpenClinica by OpenClinica.

the class BatchCRFMigrationController method runPreviewTest.

@SuppressWarnings("unchecked")
public ResponseEntity<HelperObject> runPreviewTest(TransferObject transferObject, HttpServletRequest request) throws Exception {
    HelperObject helperObject = new HelperObject();
    Locale locale = request.getLocale();
    resterms = ResourceBundleProvider.getTermsBundle(locale);
    UserAccountBean userAccountBean = getCurrentUser(request);
    ReportLog reportLog = new ReportLog();
    String studyOid = transferObject.getStudyOID();
    String sourceCrfVersion = transferObject.getSourceFormVersion();
    String targetCrfVersion = transferObject.getTargetFormVersion();
    ArrayList<String> studyEventDefnlist = transferObject.getStudyEventDefs();
    ArrayList<String> studyEventDefnlistFiltered = new ArrayList<String>();
    ArrayList<String> sitelist = transferObject.getSites();
    ArrayList<String> sitelistFiltered = new ArrayList<String>();
    FormLayoutBean sourceCrfVersionBean = fldao().findByOid(sourceCrfVersion);
    FormLayoutBean targetCrfVersionBean = fldao().findByOid(targetCrfVersion);
    StudyBean stBean = sdao().findByOid(studyOid);
    if (stBean == null || !stBean.getStatus().isAvailable() || stBean.getParentStudyId() != 0) {
        reportLog.getErrors().add(resterms.getString("The_OID_of_the_Target_Study_that_you_provided_is_invalid"));
        helperObject.setReportLog(reportLog);
        return new ResponseEntity<HelperObject>(helperObject, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    }
    StudyUserRoleBean suRole = uadao().findRoleByUserNameAndStudyId(userAccountBean.getName(), stBean.getId());
    Role r = suRole.getRole();
    if (suRole == null || !(r.equals(Role.STUDYDIRECTOR) || r.equals(Role.COORDINATOR))) {
        reportLog.getErrors().add(resterms.getString("You_do_not_have_permission_to_perform_CRF_version_migration_in_this_study"));
        helperObject.setReportLog(reportLog);
        return new ResponseEntity<HelperObject>(helperObject, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    }
    if (sourceCrfVersionBean == null || targetCrfVersionBean == null) {
        if (sourceCrfVersion.equals("-1") || targetCrfVersion.equals("-1")) {
            reportLog.getErrors().add(resterms.getString("Current_CRF_version_and_New_CRF_version_should_be_selected"));
        } else {
            reportLog.getErrors().add(resterms.getString("The_OID_of_the_CRF_Version_that_you_provided_is_invalid"));
        }
        helperObject.setReportLog(reportLog);
        return new ResponseEntity<HelperObject>(helperObject, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    }
    if (sourceCrfVersionBean.getId() == targetCrfVersionBean.getId()) {
        reportLog.getErrors().add(resterms.getString("Current_CRF_version_and_New_CRF_version_can_not_be_same"));
        helperObject.setReportLog(reportLog);
        return new ResponseEntity<HelperObject>(helperObject, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    }
    if (sourceCrfVersionBean.getCrfId() != targetCrfVersionBean.getCrfId() || !sourceCrfVersionBean.getStatus().isAvailable() || !targetCrfVersionBean.getStatus().isAvailable()) {
        reportLog.getErrors().add(resterms.getString("The_OID_of_the_CRF_Version_that_you_provided_is_invalid"));
        helperObject.setReportLog(reportLog);
        return new ResponseEntity<HelperObject>(helperObject, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    }
    CRFBean cBean = (CRFBean) cdao().findByPK(sourceCrfVersionBean.getCrfId());
    if (sitelist.size() == 0) {
        ArrayList<StudyBean> listOfSites = (ArrayList<StudyBean>) sdao().findAllByParent(stBean.getId());
        sitelist.add(stBean.getOid());
        for (StudyBean s : listOfSites) {
            if (s.getStatus().isAvailable()) {
                sitelist.add(s.getOid());
            }
        }
    } else {
        for (String site : sitelist) {
            StudyBean siteBean = sdao().findByOid(site.trim());
            if (siteBean == null || getParentStudy(siteBean).getId() != stBean.getId()) {
                reportLog.getErrors().add(resterms.getString("The_OID_of_the_Site_that_you_provided_is_invalid"));
                helperObject.setReportLog(reportLog);
                return new ResponseEntity<HelperObject>(helperObject, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
            } else if (siteBean.getStatus().isAvailable()) {
                sitelistFiltered.add(site);
            }
        }
        sitelist = sitelistFiltered;
    }
    if (studyEventDefnlist.size() == 0) {
        ArrayList<StudyEventDefinitionBean> listOfDefn = seddao().findAllByStudy(stBean);
        for (StudyEventDefinitionBean d : listOfDefn) {
            if (d.getStatus().isAvailable()) {
                studyEventDefnlist.add(d.getOid());
            }
        }
    } else {
        for (String studyEventDefn : studyEventDefnlist) {
            StudyEventDefinitionBean sedefnBean = seddao().findByOid(studyEventDefn);
            if (sedefnBean == null || sedefnBean.getStudyId() != stBean.getId()) {
                reportLog.getErrors().add(resterms.getString("The_OID_of_the_Event_that_you_provided_is_invalid"));
                helperObject.setReportLog(reportLog);
                return new ResponseEntity<HelperObject>(helperObject, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
            } else if (sedefnBean.getStatus().isAvailable()) {
                studyEventDefnlistFiltered.add(studyEventDefn);
            }
        }
        studyEventDefnlist = studyEventDefnlistFiltered;
    }
    int eventCrfCount = ssdao().getTotalEventCrfCountForCrfMigration(sourceCrfVersionBean, targetCrfVersionBean, studyEventDefnlist, sitelist);
    reportLog.setEventCrfCount(eventCrfCount);
    int subjectCount = ssdao().getTotalCountStudySubjectForCrfMigration(sourceCrfVersionBean, targetCrfVersionBean, studyEventDefnlist, sitelist);
    reportLog.setSubjectCount(subjectCount);
    List<EventDefinitionCRFBean> crfMigrationDoesNotPerformList = edcdao().findAllCrfMigrationDoesNotPerform(sourceCrfVersionBean, targetCrfVersionBean, studyEventDefnlist, sitelist);
    for (EventDefinitionCRFBean crfMigrationDoesNotPerform : crfMigrationDoesNotPerformList) {
        StudyEventDefinitionBean seddBean = (StudyEventDefinitionBean) seddao().findByPK(crfMigrationDoesNotPerform.getStudyEventDefinitionId());
        StudyBean sssBean = (StudyBean) sdao().findByPK(crfMigrationDoesNotPerform.getStudyId());
        reportLog.getCanNotMigrate().add(resterms.getString("CRF_Version_Migration_cannot_be_performed_for") + " " + sssBean.getName() + " " + seddBean.getName() + ". " + resterms.getString("Both_CRF_versions_are_not_available_at_the_Site"));
    }
    List<EventCRFBean> eventCrfListToMigrate = ecdao().findAllCRFMigrationReportList(sourceCrfVersionBean, targetCrfVersionBean, studyEventDefnlist, sitelist);
    helperObject.setReportLog(reportLog);
    helperObject.setStBean(stBean);
    helperObject.setcBean(cBean);
    helperObject.setEventCrfListToMigrate(eventCrfListToMigrate);
    helperObject.setSourceCrfVersionBean(sourceCrfVersionBean);
    helperObject.setTargetCrfVersionBean(targetCrfVersionBean);
    helperObject.setUserAccountBean(userAccountBean);
    return new ResponseEntity<HelperObject>(helperObject, org.springframework.http.HttpStatus.OK);
}
Also used : Locale(java.util.Locale) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) ArrayList(java.util.ArrayList) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) Role(org.akaza.openclinica.bean.core.Role) HelperObject(org.akaza.openclinica.controller.helper.HelperObject) ReportLog(org.akaza.openclinica.controller.helper.ReportLog) ResponseEntity(org.springframework.http.ResponseEntity) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 3 with ReportLog

use of org.akaza.openclinica.controller.helper.ReportLog in project OpenClinica by OpenClinica.

the class BatchCRFMigrationController method runMigration.

@Produces(MediaType.APPLICATION_JSON)
@RequestMapping(value = "/api/v1/forms/migrate/run", method = RequestMethod.POST)
@ResponseBody
public String runMigration(HttpServletRequest request, HttpServletResponse response) throws Exception {
    TransferObject transferObject = getUIComponents(request);
    String crfId = request.getParameter("crfId");
    ResponseEntity<HelperObject> res = runPreviewTest(transferObject, request);
    HelperObject helperObject = res.getBody();
    fillHelperObject(helperObject);
    helperObject.setRequest(request);
    ReportLog reportLog = helperObject.getReportLog();
    String pageMessages = null;
    if (reportLog.getSubjectCount() != 0 && reportLog.getEventCrfCount() != 0 && reportLog.getErrors().size() == 0) {
        BatchCRFMigrationController bcmController = new BatchCRFMigrationController(helperObject);
        Thread thread = new Thread(bcmController);
        thread.start();
        pageMessages = resterms.getString("Batch_CRF_version_migration_is_running_You_will_receive_an_email_once_the_process_is_complete");
        return (String) redirect(request, response, "/ListCRF?module=manage" + "&isFromCRFVersionBatchChange=" + pageMessages);
    } else {
        pageMessages = resterms.getString("Error_in_Running_Migration_Please_try_again");
        return (String) redirect(request, response, "/BatchCRFMigration?module=manage&crfId=" + crfId + "&isFromCRFVersionBatchChange=" + pageMessages);
    }
}
Also used : TransferObject(org.akaza.openclinica.controller.helper.TransferObject) HelperObject(org.akaza.openclinica.controller.helper.HelperObject) ReportLog(org.akaza.openclinica.controller.helper.ReportLog) Produces(javax.ws.rs.Produces) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

HelperObject (org.akaza.openclinica.controller.helper.HelperObject)3 ReportLog (org.akaza.openclinica.controller.helper.ReportLog)3 Produces (javax.ws.rs.Produces)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)1 Role (org.akaza.openclinica.bean.core.Role)1 StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)1 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)1 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)1 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)1 FormLayoutBean (org.akaza.openclinica.bean.submit.FormLayoutBean)1 TransferObject (org.akaza.openclinica.controller.helper.TransferObject)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1