Search in sources :

Example 96 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class UserInfoController method isApiKeyExist.

public Boolean isApiKeyExist(String uuid) {
    UserAccountDAO udao = new UserAccountDAO(dataSource);
    UserAccountBean uBean = (UserAccountBean) udao.findByApiKey(uuid);
    if (uBean == null || !uBean.isActive()) {
        return false;
    } else {
        return true;
    }
}
Also used : UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 97 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class StudyModuleController method handleMainPage.

@RequestMapping(method = RequestMethod.GET)
public ModelMap handleMainPage(HttpServletRequest request, HttpServletResponse response) {
    ModelMap map = new ModelMap();
    // Todo need something to reset panel from all the Spring Controllers
    StudyInfoPanel panel = new StudyInfoPanel();
    UserAccountBean userBean = (UserAccountBean) request.getSession().getAttribute("userBean");
    if (!mayProceed(request)) {
        try {
            response.sendRedirect(request.getContextPath() + "/MainMenu?message=authentication_failed");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    panel.reset();
    request.getSession().setAttribute("panel", panel);
    // setUpSidebar(request);
    ResourceBundleProvider.updateLocale(LocaleResolver.getLocale(request));
    StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
    eventDefinitionCRFDao = new EventDefinitionCRFDAO(dataSource);
    studyEventDefinitionDao = new StudyEventDefinitionDAO(dataSource);
    crfDao = new CRFDAO(dataSource);
    studyGroupClassDao = new StudyGroupClassDAO(dataSource);
    studyDao = new StudyDAO(dataSource);
    userDao = new UserAccountDAO(dataSource);
    ruleDao = new RuleDAO(dataSource);
    StudyModuleStatus sms = studyModuleStatusDao.findByStudyId(currentStudy.getId());
    if (sms == null) {
        sms = new StudyModuleStatus();
        sms.setStudyId(currentStudy.getId());
    }
    int crfCount = crfDao.findAllByStudy(currentStudy.getId()).size();
    int crfWithEventDefinition = crfDao.findAllActiveByDefinitions(currentStudy.getId()).size();
    int totalCrf = crfCount + crfWithEventDefinition;
    // int eventDefinitionCount = eventDefinitionCRFDao.findAllActiveByStudy(currentStudy).size();
    int eventDefinitionCount = studyEventDefinitionDao.findAllActiveByStudy(currentStudy).size();
    int subjectGroupCount = studyGroupClassDao.findAllActiveByStudy(currentStudy).size();
    // List<RuleSetBean> ruleSets = ruleSetService.getRuleSetsByStudy(currentStudy);
    // ruleSets = ruleSetService.filterByStatusEqualsAvailableOnlyRuleSetRules(ruleSets);
    int ruleCount = ruleSetService.getCountByStudy(currentStudy);
    int siteCount = studyDao.findOlnySiteIdsByStudy(currentStudy).size();
    int userCount = userDao.findAllUsersByStudy(currentStudy.getId()).size();
    Collection childStudies = studyDao.findAllByParent(currentStudy.getId());
    Map childStudyUserCount = new HashMap();
    for (Object sb : childStudies) {
        StudyBean childStudy = (StudyBean) sb;
        childStudyUserCount.put(childStudy.getName(), userDao.findAllUsersByStudy(childStudy.getId()).size());
    }
    if (sms.getCrf() == 0) {
        sms.setCrf(StudyModuleStatus.NOT_STARTED);
    }
    if (sms.getCrf() != 3 && totalCrf > 0) {
        sms.setCrf(StudyModuleStatus.IN_PROGRESS);
    }
    if (sms.getEventDefinition() == 0) {
        sms.setEventDefinition(StudyModuleStatus.NOT_STARTED);
    }
    if (sms.getEventDefinition() != 3 && eventDefinitionCount > 0) {
        sms.setEventDefinition(StudyModuleStatus.IN_PROGRESS);
    }
    if (sms.getSubjectGroup() == 0) {
        sms.setSubjectGroup(StudyModuleStatus.NOT_STARTED);
    }
    if (sms.getSubjectGroup() != 3 && subjectGroupCount > 0) {
        sms.setSubjectGroup(StudyModuleStatus.IN_PROGRESS);
    }
    if (sms.getRule() == 0) {
        sms.setRule(StudyModuleStatus.NOT_STARTED);
    }
    if (sms.getRule() != 3 && ruleCount > 0) {
        sms.setRule(StudyModuleStatus.IN_PROGRESS);
    }
    if (sms.getSite() == 0) {
        sms.setSite(StudyModuleStatus.NOT_STARTED);
    }
    if (sms.getSite() != 3 && siteCount > 0) {
        sms.setSite(StudyModuleStatus.IN_PROGRESS);
    }
    if (sms.getUsers() == 0) {
        sms.setUsers(StudyModuleStatus.NOT_STARTED);
    }
    if (sms.getUsers() != 3 && userCount > 0) {
        sms.setUsers(StudyModuleStatus.IN_PROGRESS);
    }
    map.addObject(sms);
    map.addAttribute("crfCount", totalCrf);
    map.addAttribute("eventDefinitionCount", eventDefinitionCount);
    map.addAttribute("subjectGroupCount", subjectGroupCount);
    map.addAttribute("ruleCount", ruleCount);
    map.addAttribute("siteCount", siteCount);
    map.addAttribute("userCount", userCount);
    map.addAttribute("childStudyUserCount", childStudyUserCount);
    map.addAttribute("studyId", currentStudy.getId());
    map.addAttribute("currentStudy", currentStudy);
    // Load Participate registration information
    String portalURL = CoreResources.getField("portalURL");
    map.addAttribute("portalURL", portalURL);
    if (portalURL != null && !portalURL.equals("")) {
        String participateOCStatus = currentStudy.getStudyParameterConfig().getParticipantPortal();
        ParticipantPortalRegistrar registrar = new ParticipantPortalRegistrar();
        Authorization pManageAuthorization = registrar.getAuthorization(currentStudy.getOid());
        String participateStatus = "";
        String url = "";
        try {
            URL pManageUrl = new URL(portalURL);
            if (pManageAuthorization != null && pManageAuthorization.getAuthorizationStatus() != null && pManageAuthorization.getAuthorizationStatus().getStatus() != null)
                participateStatus = pManageAuthorization.getAuthorizationStatus().getStatus();
            map.addAttribute("participateURL", pManageUrl);
            map.addAttribute("participateOCStatus", participateOCStatus);
            map.addAttribute("participateStatus", participateStatus);
            if (pManageAuthorization != null && pManageAuthorization.getStudy() != null && pManageAuthorization.getStudy().getHost() != null && !pManageAuthorization.getStudy().getHost().equals("")) {
                url = pManageUrl.getProtocol() + "://" + pManageAuthorization.getStudy().getHost() + "." + pManageUrl.getHost() + ((pManageUrl.getPort() > 0) ? ":" + String.valueOf(pManageUrl.getPort()) : "");
            }
        } catch (MalformedURLException e) {
            logger.error(e.getMessage());
            logger.error(ExceptionUtils.getStackTrace(e));
        }
        map.addAttribute("participateURLDisplay", url);
    }
    // Load Randomization  information
    String moduleManager = CoreResources.getField("moduleManager");
    map.addAttribute("moduleManager", moduleManager);
    if (moduleManager != null && !moduleManager.equals("")) {
        String randomizationOCStatus = currentStudy.getStudyParameterConfig().getRandomization();
        RandomizationRegistrar randomizationRegistrar = new RandomizationRegistrar();
        SeRandomizationDTO randomization = null;
        try {
            randomization = randomizationRegistrar.getCachedRandomizationDTOObject(currentStudy.getOid(), true);
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        String randomizationStatus = "";
        URL randomizeUrl = null;
        if (randomization != null && randomization.getStatus() != null) {
            randomizationStatus = randomization.getStatus();
            if (randomization.getUrl() != null) {
                try {
                    randomizeUrl = new URL(randomization.getUrl());
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        map.addAttribute("randomizeURL", randomizeUrl);
        map.addAttribute("randomizationOCStatus", randomizationOCStatus);
        map.addAttribute("randomizationStatus", randomizationStatus);
    }
    // @pgawade 13-April-2011- #8877: Added the rule designer URL
    if (null != coreResources) {
        map.addAttribute("ruleDesignerURL", coreResources.getField("designer.url"));
        map.addAttribute("contextPath", getContextPath(request));
        logMe("before checking getHostPath url = " + request.getRequestURL());
        // JN: for the eclinicalhosting the https is not showing up in the request path, going for a fix of taking
        // the hostpath from sysurl
        // map.addAttribute("hostPath", getHostPath(request));
        map.addAttribute("hostPath", getHostPathFromSysUrl(coreResources.getField("sysURL.base"), request.getContextPath()));
        map.addAttribute("path", "pages/studymodule");
    }
    // UserAccountBean userBean = (UserAccountBean) request.getSession().getAttribute("userBean");
    request.setAttribute("userBean", userBean);
    ArrayList statusMap = Status.toStudyUpdateMembersList();
    // statusMap.add(Status.PENDING);
    request.setAttribute("statusMap", statusMap);
    if (currentStudy.getParentStudyId() > 0) {
        StudyBean parentStudy = (StudyBean) studyDao.findByPK(currentStudy.getParentStudyId());
        request.setAttribute("parentStudy", parentStudy);
    }
    ArrayList pageMessages = new ArrayList();
    if (request.getSession().getAttribute("pageMessages") != null) {
        pageMessages.addAll((ArrayList) request.getSession().getAttribute("pageMessages"));
        request.setAttribute("pageMessages", pageMessages);
        request.getSession().removeAttribute("pageMessages");
    }
    ArrayList regMessages = new ArrayList();
    if (request.getSession().getAttribute(REG_MESSAGE) != null) {
        regMessages.addAll((ArrayList) request.getSession().getAttribute(REG_MESSAGE));
        request.setAttribute(REG_MESSAGE, regMessages);
        request.getSession().removeAttribute(REG_MESSAGE);
    }
    return map;
}
Also used : MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) ArrayList(java.util.ArrayList) StudyInfoPanel(org.akaza.openclinica.view.StudyInfoPanel) URL(java.net.URL) RuleDAO(org.akaza.openclinica.dao.rule.RuleDAO) Authorization(org.akaza.openclinica.service.pmanage.Authorization) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) SeRandomizationDTO(org.akaza.openclinica.service.pmanage.SeRandomizationDTO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) StudyModuleStatus(org.akaza.openclinica.domain.managestudy.StudyModuleStatus) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) ModelMap(org.springframework.ui.ModelMap) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) HttpSessionRequiredException(org.springframework.web.HttpSessionRequiredException) MalformedURLException(java.net.MalformedURLException) ParticipantPortalRegistrar(org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) Collection(java.util.Collection) RandomizationRegistrar(org.akaza.openclinica.service.pmanage.RandomizationRegistrar) ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) HashMap(java.util.HashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 98 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class StudyController method createRole.

public StudyUserRoleBean createRole(UserAccountBean ownerUserAccount, StudyUserRoleBean sub) {
    udao = new UserAccountDAO(dataSource);
    StudyUserRoleBean studyUserRoleBean = (StudyUserRoleBean) udao.createStudyUserRole(ownerUserAccount, sub);
    return studyUserRoleBean;
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 99 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class StudyController method createUserRole.

public StudyUserRoleBean createUserRole(UserAccountBean ownerUserAccount, StudyBean study) {
    udao = new UserAccountDAO(dataSource);
    StudyUserRoleBean surBean = udao.findRoleByUserNameAndStudyId(ownerUserAccount.getName(), study.getId());
    return surBean;
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 100 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class StudyController method createNewSites.

/**
 * @api {post} /pages/auth/api/v1/studies/:uniqueProtocolId/sites Create a site
 * @apiName createNewSite
 * @apiPermission Authenticate using api-key. admin
 * @apiVersion 3.8.0
 * @apiParam {String} uniqueProtococlId Study unique protocol ID.
 * @apiParam {String} briefTitle Brief Title .
 * @apiParam {String} principalInvestigator Principal Investigator Name.
 * @apiParam {Integer} expectedTotalEnrollment Expected Total Enrollment number
 * @apiParam {String} secondaryProtocolID Site Secondary Protocol Id  (Optional)
 * @apiParam {Date} startDate Start date
 * @apiParam {Date} protocolDateVerification protocol Verification date
 * @apiParam {Array} assignUserRoles Assign Users to Roles for this Study.
 * @apiGroup Site
 * @apiHeader {String} api_key Users unique access-key.
 * @apiDescription Create a Site
 * @apiParamExample {json} Request-Example:
 *                  {
 *                  "briefTitle": "Site Protocol ID Name",
 *                  "principalInvestigator": "Principal Investigator Name",
 *                  "expectedTotalEnrollment": "10",
 *                  "assignUserRoles": [
 *                  { "username" : "userc", "role" : "Investigator"},
 *                  { "username" : "userb", "role" : "Clinical Research Coordinator"},
 *                  { "username" : "dm_normal", "role" : "Monitor"},
 *                  { "username" : "sd_root", "role" : "Data Entry Person"}
 *                  ],
 *                  "uniqueProtocolID": "Site Protocol ID",
 *                  "startDate": "2011-11-11",
 *                  "secondaryProtocolID" : "Secondary Protocol ID 1" ,
 *                  "protocolDateVerification" : "2011-10-14"
 *                  }
 *
 * @apiErrorExample {json} Error-Response:
 *                  HTTP/1.1 400 Bad Request
 *                  {
 *                  "message": "VALIDATION FAILED",
 *                  "protocolDateVerification": "2011-10-14",
 *                  "principalInvestigator": "Principal Investigator Name",
 *                  "expectedTotalEnrollment": "10",
 *                  "errors": [
 *                  { "field": "UniqueProtocolId", "resource": "Site Object","code": "Unique Protocol Id exist in the System" }
 *                  ],
 *                  "secondaryProId": "Secondary Protocol ID 1",
 *                  "siteOid": null,
 *                  "briefTitle": "Site Protocol ID Name",
 *                  "assignUserRoles": [
 *                  { "role": "Investigator", "username": "userc"},
 *                  { "role": "Clinical Research Coordinator", "username": "userb"},
 *                  { "role": "Monitor","username": "dm_normal"},
 *                  { "role": "Data Entry Person","username": "sd_root"}
 *                  ],
 *                  "uniqueSiteProtocolID": "Site Protocol ID",
 *                  "startDate": "2011-11-11"
 *                  }
 * @apiSuccessExample {json} Success-Response:
 *                    HTTP/1.1 200 OK
 *                    {
 *                    "message": "SUCCESS",
 *                    "siteOid": "S_SITEPROT",
 *                    "uniqueSiteProtocolID": "Site Protocol IDqq"
 *                    }
 */
@RequestMapping(value = "/{uniqueProtocolID}/sites", method = RequestMethod.POST)
public ResponseEntity<Object> createNewSites(HttpServletRequest request, @RequestBody HashMap<String, Object> map, @PathVariable("uniqueProtocolID") String uniqueProtocolID) throws Exception {
    System.out.println("I'm in Create Sites ");
    ArrayList<ErrorObject> errorObjects = new ArrayList();
    StudyBean siteBean = null;
    ResponseEntity<Object> response = null;
    String validation_failed_message = "VALIDATION FAILED";
    String validation_passed_message = "SUCCESS";
    String name = (String) map.get("briefTitle");
    String principalInvestigator = (String) map.get("principalInvestigator");
    String uniqueSiteProtocolID = (String) map.get("uniqueProtocolID");
    String expectedTotalEnrollment = (String) map.get("expectedTotalEnrollment");
    String startDate = (String) map.get("startDate");
    String protocolDateVerification = (String) map.get("protocolDateVerification");
    String secondaryProId = (String) map.get("secondaryProtocolID");
    ArrayList<UserRole> assignUserRoles = (ArrayList<UserRole>) map.get("assignUserRoles");
    ArrayList<UserRole> userList = new ArrayList<>();
    if (assignUserRoles != null) {
        for (Object userRole : assignUserRoles) {
            UserRole uRole = new UserRole();
            uRole.setUsername((String) ((HashMap<String, Object>) userRole).get("username"));
            uRole.setRole((String) ((HashMap<String, Object>) userRole).get("role"));
            udao = new UserAccountDAO(dataSource);
            UserAccountBean assignedUserBean = (UserAccountBean) udao.findByUserName(uRole.getUsername());
            if (assignedUserBean == null || !assignedUserBean.isActive()) {
                ErrorObject errorOBject = createErrorObject("Study Object", "The Assigned Username " + uRole.getUsername() + " is not a Valid User", "Assigned User");
                errorObjects.add(errorOBject);
            }
            ResourceBundle resterm = org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
            if (getSiteRole(uRole.getRole(), resterm) == null) {
                ErrorObject errorOBject = createErrorObject("Study Object", "Assigned Role for " + uRole.getUsername() + " is not a Valid Site Role", "Assigned Role");
                errorObjects.add(errorOBject);
            }
            userList.add(uRole);
        }
    }
    SiteDTO siteDTO = buildSiteDTO(uniqueSiteProtocolID, name, principalInvestigator, expectedTotalEnrollment, startDate, protocolDateVerification, secondaryProId, userList);
    if (uniqueSiteProtocolID == null) {
        ErrorObject errorOBject = createErrorObject("Site Object", "Missing Field", "UniqueProtocolID");
        errorObjects.add(errorOBject);
    } else {
        uniqueSiteProtocolID = uniqueSiteProtocolID.trim();
    }
    if (name == null) {
        ErrorObject errorOBject = createErrorObject("Site Object", "Missing Field", "BriefTitle");
        errorObjects.add(errorOBject);
    } else {
        name = name.trim();
    }
    if (principalInvestigator == null) {
        ErrorObject errorOBject = createErrorObject("Site Object", "Missing Field", "PrincipalInvestigator");
        errorObjects.add(errorOBject);
    } else {
        principalInvestigator = principalInvestigator.trim();
    }
    if (startDate == null) {
        ErrorObject errorOBject = createErrorObject("Site Object", "Missing Field", "StartDate");
        errorObjects.add(errorOBject);
    } else {
        startDate = startDate.trim();
    }
    if (protocolDateVerification == null) {
        ErrorObject errorOBject = createErrorObject("Site Object", "Missing Field", "ProtocolDateVerification");
        errorObjects.add(errorOBject);
    } else {
        protocolDateVerification = protocolDateVerification.trim();
    }
    if (expectedTotalEnrollment == null) {
        ErrorObject errorOBject = createErrorObject("Site Object", "Missing Field", "ExpectedTotalEnrollment");
        errorObjects.add(errorOBject);
    } else {
        expectedTotalEnrollment = expectedTotalEnrollment.trim();
    }
    if (secondaryProId != null) {
        secondaryProId = secondaryProId.trim();
    }
    if (assignUserRoles == null) {
        ErrorObject errorOBject = createErrorObject("Study Object", "Missing Field", "AssignUserRoles");
        errorObjects.add(errorOBject);
    }
    request.setAttribute("uniqueProId", uniqueSiteProtocolID);
    request.setAttribute("name", name);
    request.setAttribute("prinInvestigator", principalInvestigator);
    request.setAttribute("expectedTotalEnrollment", expectedTotalEnrollment);
    request.setAttribute("startDate", startDate);
    request.setAttribute("protocolDateVerification", protocolDateVerification);
    request.setAttribute("secondProId", secondaryProId);
    String format = "yyyy-MM-dd";
    SimpleDateFormat formatter = null;
    Date formattedStartDate = null;
    Date formattedProtocolDate = null;
    if (startDate != "" && startDate != null) {
        try {
            formatter = new SimpleDateFormat(format);
            formattedStartDate = formatter.parse(startDate);
        } catch (ParseException e) {
            ErrorObject errorOBject = createErrorObject("Site Object", "The StartDate format is not a valid 'yyyy-MM-dd' format", "StartDate");
            errorObjects.add(errorOBject);
        }
        if (formattedStartDate != null) {
            if (!startDate.equals(formatter.format(formattedStartDate))) {
                ErrorObject errorOBject = createErrorObject("Site Object", "The StartDate format is not a valid 'yyyy-MM-dd' format", "StartDate");
                errorObjects.add(errorOBject);
            }
        }
    }
    if (protocolDateVerification != "" && protocolDateVerification != null) {
        try {
            formatter = new SimpleDateFormat(format);
            formattedProtocolDate = formatter.parse(protocolDateVerification);
        } catch (ParseException e) {
            ErrorObject errorOBject = createErrorObject("Site Object", "The Protocol Verification Date format is not a valid 'yyyy-MM-dd' format", "ProtocolDateVerification");
            errorObjects.add(errorOBject);
        }
        if (formattedProtocolDate != null) {
            if (!protocolDateVerification.equals(formatter.format(formattedProtocolDate))) {
                ErrorObject errorOBject = createErrorObject("Site Object", "The Protocol Verification Date format is not a valid 'yyyy-MM-dd' format", "ProtocolDateVerification");
                errorObjects.add(errorOBject);
            }
        }
    }
    StudyBean parentStudy = getStudyByUniqId(uniqueProtocolID);
    if (parentStudy == null) {
        ErrorObject errorOBject = createErrorObject("Study Object", "The Study Protocol Id provided in the URL is not a valid Protocol Id", "Unique Study Protocol Id");
        errorObjects.add(errorOBject);
    } else if (parentStudy.getParentStudyId() != 0) {
        ErrorObject errorOBject = createErrorObject("Study Object", "The Study Protocol Id provided in the URL is not a valid Study Protocol Id", "Unique Study Protocol Id");
        errorObjects.add(errorOBject);
    }
    UserAccountBean ownerUserAccount = null;
    if (parentStudy != null) {
        ownerUserAccount = getSiteOwnerAccount(request, parentStudy);
        if (ownerUserAccount == null) {
            ErrorObject errorOBject = createErrorObject("Site Object", "The Owner User Account is not Valid Account or Does not have rights to Create Sites", "Owner Account");
            errorObjects.add(errorOBject);
        }
    }
    Validator v1 = new Validator(request);
    v1.addValidation("uniqueProId", Validator.NO_BLANKS);
    HashMap vError1 = v1.validate();
    if (!vError1.isEmpty()) {
        ErrorObject errorOBject = createErrorObject("Site Object", "This field cannot be blank.", "UniqueProtocolId");
        errorObjects.add(errorOBject);
    }
    Validator v2 = new Validator(request);
    v2.addValidation("name", Validator.NO_BLANKS);
    HashMap vError2 = v2.validate();
    if (!vError2.isEmpty()) {
        ErrorObject errorOBject = createErrorObject("Site Object", "This field cannot be blank.", "BriefTitle");
        errorObjects.add(errorOBject);
    }
    Validator v3 = new Validator(request);
    v3.addValidation("prinInvestigator", Validator.NO_BLANKS);
    HashMap vError3 = v3.validate();
    if (!vError3.isEmpty()) {
        ErrorObject errorOBject = createErrorObject("Site Object", "This field cannot be blank.", "PrincipleInvestigator");
        errorObjects.add(errorOBject);
    }
    Validator v6 = new Validator(request);
    HashMap vError6 = v6.validate();
    if (uniqueProtocolID != null)
        validateUniqueProId(request, vError6);
    if (!vError6.isEmpty()) {
        ErrorObject errorOBject = createErrorObject("Site Object", "Unique Protocol Id exist in the System", "UniqueProtocolId");
        errorObjects.add(errorOBject);
    }
    Validator v7 = new Validator(request);
    v7.addValidation("expectedTotalEnrollment", Validator.NO_BLANKS);
    HashMap vError7 = v7.validate();
    if (!vError7.isEmpty()) {
        ErrorObject errorOBject = createErrorObject("Site Object", "This field cannot be blank.", "ExpectedTotalEnrollment");
        errorObjects.add(errorOBject);
    }
    if (request.getAttribute("name") != null && ((String) request.getAttribute("name")).length() > 100) {
        ErrorObject errorOBject = createErrorObject("Site Object", "BriefTitle Length exceeds the max length 100", "BriefTitle");
        errorObjects.add(errorOBject);
    }
    if (request.getAttribute("uniqueProId") != null && ((String) request.getAttribute("uniqueProId")).length() > 30) {
        ErrorObject errorOBject = createErrorObject("Site Object", "UniqueProtocolId Length exceeds the max length 30", "UniqueProtocolId");
        errorObjects.add(errorOBject);
    }
    if (request.getAttribute("prinInvestigator") != null && ((String) request.getAttribute("prinInvestigator")).length() > 255) {
        ErrorObject errorOBject = createErrorObject("Site Object", "PrincipleInvestigator Length exceeds the max length 255", "PrincipleInvestigator");
        errorObjects.add(errorOBject);
    }
    if (request.getAttribute("expectedTotalEnrollment") != null && Integer.valueOf((String) request.getAttribute("expectedTotalEnrollment")) <= 0) {
        ErrorObject errorOBject = createErrorObject("Site Object", "ExpectedTotalEnrollment Length can't be negative", "ExpectedTotalEnrollment");
        errorObjects.add(errorOBject);
    }
    siteDTO.setErrors(errorObjects);
    if (errorObjects != null && errorObjects.size() != 0) {
        siteDTO.setMessage(validation_failed_message);
        response = new ResponseEntity(siteDTO, org.springframework.http.HttpStatus.BAD_REQUEST);
    } else {
        siteBean = buildSiteBean(uniqueSiteProtocolID, name, principalInvestigator, Integer.valueOf(expectedTotalEnrollment), formattedStartDate, formattedProtocolDate, secondaryProId, ownerUserAccount, parentStudy.getId());
        StudyBean sBean = createStudy(siteBean, ownerUserAccount);
        siteDTO.setSiteOid(sBean.getOid());
        siteDTO.setMessage(validation_passed_message);
        ResourceBundle resterm = org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
        StudyUserRoleBean sub = null;
        for (UserRole userRole : userList) {
            sub = new StudyUserRoleBean();
            sub.setRole(getSiteRole(userRole.getRole(), resterm));
            sub.setStudyId(sBean.getId());
            sub.setStatus(Status.AVAILABLE);
            sub.setOwner(ownerUserAccount);
            udao = new UserAccountDAO(dataSource);
            UserAccountBean assignedUserBean = (UserAccountBean) udao.findByUserName(userRole.getUsername());
            StudyUserRoleBean surb = createRole(assignedUserBean, sub);
        }
        ResponseSuccessSiteDTO responseSuccess = new ResponseSuccessSiteDTO();
        responseSuccess.setMessage(siteDTO.getMessage());
        responseSuccess.setSiteOid(siteDTO.getSiteOid());
        responseSuccess.setUniqueSiteProtocolID(siteDTO.getUniqueSiteProtocolID());
        response = new ResponseEntity(responseSuccess, org.springframework.http.HttpStatus.OK);
    }
    return response;
}
Also used : HashMap(java.util.HashMap) ResponseSuccessSiteDTO(org.akaza.openclinica.bean.login.ResponseSuccessSiteDTO) ErrorObject(org.akaza.openclinica.bean.login.ErrorObject) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) ArrayList(java.util.ArrayList) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) Date(java.util.Date) ResponseEntity(org.springframework.http.ResponseEntity) UserRole(org.akaza.openclinica.bean.login.UserRole) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) ErrorObject(org.akaza.openclinica.bean.login.ErrorObject) ResourceBundle(java.util.ResourceBundle) ResponseSuccessSiteDTO(org.akaza.openclinica.bean.login.ResponseSuccessSiteDTO) SiteDTO(org.akaza.openclinica.bean.login.SiteDTO) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Validator(org.akaza.openclinica.control.form.Validator)

Aggregations

UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)101 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)69 ArrayList (java.util.ArrayList)44 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)43 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)42 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)36 StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)24 Date (java.util.Date)23 HashMap (java.util.HashMap)21 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)18 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)16 Locale (java.util.Locale)15 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)14 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)14 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)13 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)12 SubjectDAO (org.akaza.openclinica.dao.submit.SubjectDAO)12 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)11 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)10 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)10