Search in sources :

Example 6 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;
    System.out.println("I'm in createOrUpdateAccount");
    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"));
    System.out.println("******************     You are in the Rest Service   *****************");
    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***");
        System.out.println("***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 ***");
        System.out.println("***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)

Aggregations

UserDTO (org.akaza.openclinica.bean.login.UserDTO)6 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 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)2 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)2 ArrayList (java.util.ArrayList)1