Search in sources :

Example 1 with UserDTO

use of org.akaza.openclinica.bean.login.UserDTO in project OpenClinica by OpenClinica.

the class AccountController method getAccount3.

/**
 * @api {get} /pages/accounts/study/:studyOid/studysubject/:studySubjectId Retrieve a user account - participant
 * @apiName getAccount3
 * @apiPermission Module participate - enabled & admin
 * @apiVersion 3.8.0
 * @apiParam {String} studyOid Study Oid.
 * @apiParam {String} studySubjectId Study Subject Id .
 * @apiGroup User Account
 * @apiDescription Retrieves the participant user account with the given studySubjectId and studyOid
 * @apiParamExample {json} Request-Example:
 *                  {
 *                  "studyOid": " S_BL101",
 *                  "studySubjectId": "Sub100"
 *                  }
 * @apiSuccessExample {json} Success-Response:
 *                    HTTP/1.1 200 OK
 *                    {
 *                    "lName": "",
 *                    "mobile": "JTaa7WGRdH5dGs42XyTrgA==",
 *                    "accessCode": "5s02UFpiMBijWuzaxSOojg==",
 *                    "password": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
 *                    "email": "XzJadh3l3V7uUoPCggbSoIfoNW8IQU3qsvrtHfJH7J0=",
 *                    "userName": "S_BL101.SS_SUB100",
 *                    "studySubjectId": null,
 *                    "fName": "pdyGCN1CdAKIGOUEERz/yQ=="
 *                    }
 */
@RequestMapping(value = "/study/{studyOid}/studysubject/{studySubjectId}", method = RequestMethod.GET)
public ResponseEntity<UserDTO> getAccount3(@PathVariable("studyOid") String studyOid, @PathVariable("studySubjectId") String studySubjectId) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    uDTO = null;
    StudyBean parentStudy = getParentStudy(studyOid);
    String oid = parentStudy.getOid();
    StudySubjectBean studySubjectBean = getStudySubject(studySubjectId, parentStudy);
    if (isStudyASiteLevelStudy(studyOid))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (!mayProceed(oid, studySubjectBean))
        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 (isStudySubjectDoesNotExist(studySubjectBean))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    // build UserName
    HashMap<String, String> mapValues = buildParticipantUserName(studySubjectBean);
    // Participant User Name
    String pUserName = mapValues.get("pUserName");
    UserAccountDAO udao = new UserAccountDAO(dataSource);
    UserAccountBean userAccountBean = (UserAccountBean) udao.findByUserName(pUserName);
    if (!userAccountBean.isActive()) {
        uDTO = new UserDTO();
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.OK);
    } else {
        buildUserDTO(userAccountBean);
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.OK);
    }
}
Also used : Locale(java.util.Locale) ResponseEntity(org.springframework.http.ResponseEntity) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserDTO(org.akaza.openclinica.bean.login.UserDTO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UserDTO

use of org.akaza.openclinica.bean.login.UserDTO in project OpenClinica by OpenClinica.

the class AccountController method buildUserDTO.

private UserDTO buildUserDTO(UserAccountBean userAccountBean) {
    uDTO = new UserDTO();
    uDTO.setfName(userAccountBean.getFirstName());
    uDTO.setlName(userAccountBean.getLastName());
    uDTO.setMobile(userAccountBean.getPhone());
    uDTO.setUserName(userAccountBean.getName());
    uDTO.setAccessCode(userAccountBean.getAccessCode());
    uDTO.setPassword(userAccountBean.getPasswd());
    uDTO.setEmail(userAccountBean.getEmail());
    return uDTO;
}
Also used : UserDTO(org.akaza.openclinica.bean.login.UserDTO)

Example 3 with UserDTO

use of org.akaza.openclinica.bean.login.UserDTO in project OpenClinica by OpenClinica.

the class AccountController method getAccount1.

/**
 * @api {get} /pages/accounts/study/:studyOid/crc/:crcUserName Retrieve a user account - crc
 * @apiName getAccount1
 * @apiPermission Module participate - enabled & admin
 * @apiVersion 3.8.0
 * @apiParam {String} studyOid Study Oid.
 * @apiParam {String} crcUserName CRC Username .
 * @apiGroup User Account
 * @apiDescription Retrieves the crc user account with the given crcUserName and studyOid
 * @apiParamExample {json} Request-Example:
 *                  {
 *                  "studyOid": " S_BL101",
 *                  "crcUserName": "crc_user"
 *                  }
 * @apiSuccessExample {json} Success-Response:
 *                    HTTP/1.1 200 OK
 *                    {
 *                    "lName": "Jackson",
 *                    "mobile": "",
 *                    "accessCode": "",
 *                    "apiKey": "6e8b69f6fb774e899f9a6c349c5adace",
 *                    "password": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
 *                    "email": "abc@yahoo.com",
 *                    "userName": "crc_user",
 *                    "studySubjectId": null,
 *                    "fName": "joe"
 *                    }
 */
@RequestMapping(value = "/study/{studyOid}/crc/{crcUserName}", method = RequestMethod.GET)
public ResponseEntity<UserDTO> getAccount1(@PathVariable("studyOid") String studyOid, @PathVariable("crcUserName") String crcUserName) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    UserAccountDAO udao = new UserAccountDAO(dataSource);
    uDTO = null;
    StudyBean parentStudy = getParentStudy(studyOid);
    Integer pStudyId = parentStudy.getId();
    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 (isCRCUserAccountDoesNotExist(crcUserName))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (doesCRCNotHaveStudyAccessRole(crcUserName, pStudyId))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    UserAccountBean userAccountBean = (UserAccountBean) udao.findByUserName(crcUserName);
    buildUserDTO(userAccountBean);
    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) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with UserDTO

use of org.akaza.openclinica.bean.login.UserDTO 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;
    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) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with UserDTO

use of org.akaza.openclinica.bean.login.UserDTO in project OpenClinica by OpenClinica.

the class AccountController method createOrUpdateAccount.

/**
 * @api {post} /pages/accounts/ Create a user account - participant
 * @apiName createParticipantUserAccount
 * @apiPermission Module participate - enabled & admin
 * @apiVersion 3.8.0
 * @apiParam {String} studyOid Study Oid.
 * @apiParam {String} studySubjectId Study Subject Id .
 * @apiParam {String} fName First Name
 * @apiParam {String} lName Last Name
 * @apiParam {String} mobile Mobile Phone
 * @apiParam {String} accessCode Access Code
 * @apiParam {String} crcUserName CRC UserName
 * @apiParam {String} email Email Address
 *
 * @apiGroup User Account
 * @apiDescription Creates a participant user account
 * @apiParamExample {json} Request-Example:
 *                  {
 *                  "studyOid": "S_BL101",
 *                  "studySubjectId": "Sub100",
 *                  "fName": "Dany",
 *                  "lName": "Keegan",
 *                  "mobile": "617 865 4567",
 *                  "accessCode": "5s02UFpiMBijWuzaxSOojg==",
 *                  "crcUserName": "crc_user",
 *                  "email": "abc@yahoo.com"
 *                  }
 * @apiSuccessExample {json} Success-Response:
 *                    HTTP/1.1 200 OK
 *                    {
 *                    "studySubjectId": null,
 *                    "email": "abc@yahoo.com",
 *                    "accessCode": "5s02UFpiMBijWuzaxSOojg==",
 *                    "password": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
 *                    "userName": "S_BL101.SS_SUB100",
 *                    "fName": "Dany",
 *                    "lName": "Keegan",
 *                    "mobile": "617 865 4567"
 *                    }
 */
/**
 * @api {post} /pages/accounts/ Update a user account - participant
 * @apiName updateParticipantUserAccount
 * @apiPermission Module participate - enabled & admin
 * @apiVersion 3.8.0
 * @apiParam {String} studyOid Study Oid.
 * @apiParam {String} studySubjectId Study Subject Id .
 * @apiParam {String} fName First Name
 * @apiParam {String} lName Last Name
 * @apiParam {String} mobile Mobile Phone
 * @apiParam {String} accessCode Access Code
 * @apiParam {String} crcUserName CRC UserName
 * @apiParam {String} email Email Address
 *
 * @apiGroup User Account
 * @apiDescription Updates a participant user account
 * @apiParamExample {json} Request-Example:
 *                  {
 *                  "studyOid": "S_BL101",
 *                  "studySubjectId": "Sub100",
 *                  "fName": "Dany",
 *                  "lName": "Keegan",
 *                  "mobile": "617 865 4567",
 *                  "accessCode": "5s02UFpiMBijWuzaxSOojg==",
 *                  "crcUserName": "crc_user",
 *                  "email": "abc@yahoo.com"
 *                  }
 * @apiSuccessExample {json} Success-Response:
 *                    HTTP/1.1 200 OK
 *                    {
 *                    "studySubjectId": null,
 *                    "email": "abc@yahoo.com",
 *                    "accessCode": "5s02UFpiMBijWuzaxSOojg==",
 *                    "password": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
 *                    "userName": "S_BL101.SS_SUB100",
 *                    "fName": "Dany",
 *                    "lName": "Keegan",
 *                    "mobile": "617 865 4567"
 *                    }
 */
@RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseEntity<UserDTO> createOrUpdateAccount(@RequestBody HashMap<String, String> map) throws Exception {
    uDTO = null;
    StudyBean parentStudy = getParentStudy(map.get("studyOid"));
    String oid = parentStudy.getOid();
    String studySubjectId = map.get("studySubjectId");
    String fName = map.get("fName");
    String lName = map.get("lName");
    String mobile = map.get("mobile");
    String accessCode = map.get("accessCode");
    String crcUserName = map.get("crcUserName");
    String email = map.get("email");
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    UserAccountBean uBean = null;
    StudySubjectBean studySubjectBean = getStudySubject(studySubjectId, parentStudy);
    UserAccountBean ownerUserAccount = getUserAccount(crcUserName);
    if (!mayProceed(oid, studySubjectBean))
        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 (isStudySubjectDoesNotExist(studySubjectBean))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (isFistNameInValid(fName))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (isPhoneFieldIsNull(mobile) && isEmailIsNull(email))
        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);
    if (isAccessCodeExistInSystem(accessCode))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    // build UserName
    HashMap<String, String> mapValues = buildParticipantUserName(studySubjectBean);
    // Participant User Name
    String pUserName = mapValues.get("pUserName");
    String studySubjectOid = mapValues.get("studySubjectOid");
    Integer pStudyId = Integer.valueOf(mapValues.get("pStudyId"));
    if (isCRCUserAccountDoesNotExist(crcUserName))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    // This also verifies that fact that the CRC and the Participant both have access to same study/site
    if (doesCRCNotHaveStudyAccessRole(crcUserName, pStudyId))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    // Participant user account create (if does not exist in user table) or Update(if exist in user table)
    uBean = buildUserAccount(oid, studySubjectOid, fName, lName, mobile, accessCode, ownerUserAccount, pUserName, email);
    UserAccountBean participantUserAccountBean = getUserAccount(pUserName);
    if (!participantUserAccountBean.isActive()) {
        createUserAccount(uBean);
        uBean.setUpdater(uBean.getOwner());
        updateUserAccount(uBean);
        disableUserAccount(uBean);
        logger.info("***New User Account is created***");
        uDTO = buildUserDTO(uBean);
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.OK);
    } else {
        uBean.setId(getUserAccount(uBean.getName()).getId());
        uBean.setUpdater(uBean.getOwner());
        updateUserAccount(uBean);
        logger.info("***User Account already exist in the system and data is been Updated ***");
        uDTO = buildUserDTO(uBean);
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.OK);
    }
}
Also used : Locale(java.util.Locale) ResponseEntity(org.springframework.http.ResponseEntity) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserDTO(org.akaza.openclinica.bean.login.UserDTO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UserDTO (org.akaza.openclinica.bean.login.UserDTO)7 Locale (java.util.Locale)5 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)5 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)5 ResponseEntity (org.springframework.http.ResponseEntity)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)3 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)2 ArrayList (java.util.ArrayList)1 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)1