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);
}
}
Aggregations