Program: 115027
Project: 115027
Buggy source:
/** 
 * @api {post} /pages/auth/api/v1/studies/ Create a study
 * @apiName createNewStudy
 * @apiPermission Authenticate using api-key. admin
 * @apiVersion 3.8.0
 * @apiParam {String} uniqueProtococlId Study unique study ID.
 * @apiParam {String} briefTitle Brief Title .
 * @apiParam {String} principalInvestigator Principal Investigator Name.
 * @apiParam {Integer} expectedTotalEnrollment Expected Total Enrollment number
 * @apiParam {String} sponsor Sponsor name.
 * @apiParam {String} studyType 'Interventional' or ' Observational'
 * @apiParam {String} status 'Available' or 'Design'
 * @apiParam {String} briefSummary Study Summary
 * @apiParam {Date} startDate Start date
 * @apiParam {Array} assignUserRoles Assign Users to Roles for this Study.
 * @apiGroup Study
 * @apiHeader {String} api_key Users unique access-key.
 * @apiDescription This API is to create a New Study in OC.All the fields are required fields and can't be left blank. You need to provide your Api-key to be connected.
 * @apiParamExample {json} Request-Example:{ "briefTitle": "Study Study ID Name", "principalInvestigator": "Principal Investigator Name", "expectedTotalEnrollment": "10", "sponsor": "Sponsor Name", "studyType": "Interventional", "status": "available", "assignUserRoles": [ { "username": "usera", "role": "Data Manager" }, { "username": "userb", "role": "Study Director" }, { "username": "userc", "role": "Data Specialist" }, { "username": "userd", "role": "Monitor" }, { "username": "usere", "role": "Data Entry Person" } ], "uniqueStudyID": "Study Study ID", "briefSummary": "Study Summary", "startDate": "2011-11-11" }
 * @apiErrorExample {json} Error-Response:HTTP/1.1 400 Bad Request { "message": "VALIDATION FAILED", "status": "available", "principalInvestigator": "Principal Investigator Name", "expectedTotalEnrollment": "10", "sponsor": "Sponsor Name", "studyType": "Interventional", "errors": [ {"field": "UniqueStudyId","resource": "Study Object","code": "Unique Study Id exist in the System"} ], "startDate": "2011-11-11", "assignUserRoles": [ {"username": "usera","role": "Data Manager"}, {"username": "userb","role": "Study Director"}, {"username": "userc","role": "Data Specialist"} ], "uniqueStudyID": "Study Study ID", "briefTitle": "Study Study ID", "briefSummary": "Study Summary", "studyOid": null }
 * @apiSuccessExample {json} Success-Response:HTTP/1.1 200 OK { "message": "SUCCESS", "uniqueStudyID": "Study Study ID", "studyOid": "S_STUDYPRO", }
 */
@RequestMapping(value="String_Node_Str",method=RequestMethod.POST) public ResponseEntity<Object> createNewStudy(HttpServletRequest request,@RequestBody HashMap<String,Object> map) throws Exception {
  ArrayList<ErrorObject> errorObjects=new ArrayList();
  StudyDTO studyDTO=new StudyDTO();
  logger.info("String_Node_Str");
  ResponseEntity<Object> response=null;
  String validation_failed_message="String_Node_Str";
  String validation_passed_message="String_Node_Str";
  String uniqueStudyID=(String)map.get("String_Node_Str");
  String name=(String)map.get("String_Node_Str");
  String studyOid=(String)map.get("String_Node_Str");
  String studyEnvUuid=(String)map.get("String_Node_Str");
  String uuid=(String)map.get("String_Node_Str");
  Matcher m=Pattern.compile("String_Node_Str").matcher(studyOid);
  String envType="String_Node_Str";
  if (m.find()) {
    if (m.groupCount() != 2) {
      ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
      errorObjects.add(errorOBject);
    }
 else {
      envType=m.group(2);
    }
  }
  AsyncStudyHelper asyncStudyHelper=new AsyncStudyHelper("String_Node_Str","String_Node_Str",LocalTime.now());
  AsyncStudyHelper.put(uniqueStudyID,asyncStudyHelper);
  if (StringUtils.isEmpty(uniqueStudyID)) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
 else {
    uniqueStudyID=uniqueStudyID.trim();
  }
  if (StringUtils.isEmpty(name)) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
 else {
    name=name.trim();
  }
  if (StringUtils.isEmpty(studyOid)) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
 else {
    studyOid=studyOid.trim();
  }
  if (StringUtils.isEmpty(uuid)) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
 else {
    uuid=uuid.trim();
  }
  if (StringUtils.isEmpty(studyEnvUuid)) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
 else {
    studyEnvUuid=studyEnvUuid.trim();
  }
  Locale locale=new Locale("String_Node_Str");
  request.getSession().setAttribute(LocaleResolver.getLocaleSessionAttributeName(),locale);
  ResourceBundleProvider.updateLocale(locale);
  request.setAttribute("String_Node_Str",uniqueStudyID);
  request.setAttribute("String_Node_Str",name);
  request.setAttribute("String_Node_Str",studyOid);
  request.setAttribute("String_Node_Str",uuid);
  request.setAttribute("String_Node_Str",envType);
  request.setAttribute("String_Node_Str",studyEnvUuid);
  ResponseEntity<HashMap> responseEntity=processSSOUserContext(request,studyEnvUuid);
  UserAccountBean ownerUserAccount=getStudyOwnerAccountWithCreatedUser(request,responseEntity);
  if (ownerUserAccount == null) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
  Validator v0=new Validator(request);
  v0.addValidation("String_Node_Str",Validator.NO_BLANKS);
  HashMap vError0=v0.validate();
  if (!vError0.isEmpty()) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
  Validator v1=new Validator(request);
  v1.addValidation("String_Node_Str",Validator.NO_BLANKS);
  HashMap vError1=v1.validate();
  if (!vError1.isEmpty()) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
  Validator v2=new Validator(request);
  v2.addValidation("String_Node_Str",Validator.NO_BLANKS);
  HashMap vError2=v2.validate();
  if (!vError2.isEmpty()) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
  Validator v3=new Validator(request);
  v3.addValidation("String_Node_Str",Validator.NO_BLANKS);
  HashMap vError3=v3.validate();
  if (!vError3.isEmpty()) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
  Validator v4=new Validator(request);
  v4.addValidation("String_Node_Str",Validator.NO_LEADING_OR_TRAILING_SPACES);
  HashMap vError4=v4.validate();
  if (!vError4.isEmpty()) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
  if (errorObjects != null && errorObjects.size() != 0) {
    studyDTO.setMessage(validation_failed_message);
    response=new ResponseEntity(studyDTO,org.springframework.http.HttpStatus.BAD_REQUEST);
    return response;
  }
  studyDTO.setErrors(errorObjects);
  Study study=new Study();
  study.setUniqueIdentifier(uniqueStudyID);
  study.setName(name);
  study.setOc_oid(studyOid);
  study.setEnvType(StudyEnvEnum.valueOf(envType));
  study.setStudyEnvUuid(studyEnvUuid);
  study.setUuid(uuid);
  Study byOidEnvType=studyDao.findByOidEnvType(studyOid,StudyEnvEnum.valueOf(envType));
  if (byOidEnvType != null && byOidEnvType.getOc_oid() != null) {
    return getResponseSuccess(byOidEnvType);
  }
  StudyInfoObject studyInfoObject=null;
  Study schemaStudy=null;
  try {
    studyInfoObject=studyBuildService.process(request,study,ownerUserAccount);
    liquibaseOnDemandService.createForeignTables(studyInfoObject);
    schemaStudy=liquibaseOnDemandService.process(studyInfoObject,ownerUserAccount);
  }
 catch (  Exception e) {
    try {
      schemaCleanupService.dropSchema(studyInfoObject);
    }
 catch (    Exception schemaEx) {
      throw new Exception("String_Node_Str");
    }
    throw e;
  }
  logger.debug("String_Node_Str" + schemaStudy.getStudyId());
  if (errorObjects != null && errorObjects.size() != 0) {
    studyDTO.setMessage(validation_failed_message);
    response=new ResponseEntity(studyDTO,org.springframework.http.HttpStatus.BAD_REQUEST);
  }
 else {
    studyDTO.setStudyOid(schemaStudy.getOc_oid());
    studyDTO.setMessage(validation_passed_message);
    studyDTO.setUniqueProtocolID(schemaStudy.getUniqueIdentifier());
    logger.debug("String_Node_Str" + schemaStudy.getOc_oid());
    ResponseSuccessStudyDTO responseSuccess=new ResponseSuccessStudyDTO();
    responseSuccess.setMessage(studyDTO.getMessage());
    responseSuccess.setStudyOid(studyDTO.getStudyOid());
    responseSuccess.setUniqueStudyID(studyDTO.getUniqueProtocolID());
    responseSuccess.setSchemaName(studyInfoObject.getSchema());
    response=new ResponseEntity(responseSuccess,org.springframework.http.HttpStatus.OK);
  }
  request.getSession().setAttribute("String_Node_Str",null);
  AsyncStudyHelper asyncStudyDone=new AsyncStudyHelper("String_Node_Str","String_Node_Str");
  AsyncStudyHelper.put(uniqueStudyID,asyncStudyDone);
  return response;
}

Fixed version (ground truth):
/** 
 * @api {post} /pages/auth/api/v1/studies/ Create a study
 * @apiName createNewStudy
 * @apiPermission Authenticate using api-key. admin
 * @apiVersion 3.8.0
 * @apiParam {String} uniqueProtococlId Study unique study ID.
 * @apiParam {String} briefTitle Brief Title .
 * @apiParam {String} principalInvestigator Principal Investigator Name.
 * @apiParam {Integer} expectedTotalEnrollment Expected Total Enrollment number
 * @apiParam {String} sponsor Sponsor name.
 * @apiParam {String} studyType 'Interventional' or ' Observational'
 * @apiParam {String} status 'Available' or 'Design'
 * @apiParam {String} briefSummary Study Summary
 * @apiParam {Date} startDate Start date
 * @apiParam {Array} assignUserRoles Assign Users to Roles for this Study.
 * @apiGroup Study
 * @apiHeader {String} api_key Users unique access-key.
 * @apiDescription This API is to create a New Study in OC.All the fields are required fields and can't be left blank. You need to provide your Api-key to be connected.
 * @apiParamExample {json} Request-Example:{ "briefTitle": "Study Study ID Name", "principalInvestigator": "Principal Investigator Name", "expectedTotalEnrollment": "10", "sponsor": "Sponsor Name", "studyType": "Interventional", "status": "available", "assignUserRoles": [ { "username": "usera", "role": "Data Manager" }, { "username": "userb", "role": "Study Director" }, { "username": "userc", "role": "Data Specialist" }, { "username": "userd", "role": "Monitor" }, { "username": "usere", "role": "Data Entry Person" } ], "uniqueStudyID": "Study Study ID", "briefSummary": "Study Summary", "startDate": "2011-11-11" }
 * @apiErrorExample {json} Error-Response:HTTP/1.1 400 Bad Request { "message": "VALIDATION FAILED", "status": "available", "principalInvestigator": "Principal Investigator Name", "expectedTotalEnrollment": "10", "sponsor": "Sponsor Name", "studyType": "Interventional", "errors": [ {"field": "UniqueStudyId","resource": "Study Object","code": "Unique Study Id exist in the System"} ], "startDate": "2011-11-11", "assignUserRoles": [ {"username": "usera","role": "Data Manager"}, {"username": "userb","role": "Study Director"}, {"username": "userc","role": "Data Specialist"} ], "uniqueStudyID": "Study Study ID", "briefTitle": "Study Study ID", "briefSummary": "Study Summary", "studyOid": null }
 * @apiSuccessExample {json} Success-Response:HTTP/1.1 200 OK { "message": "SUCCESS", "uniqueStudyID": "Study Study ID", "studyOid": "S_STUDYPRO", }
 */
@RequestMapping(value="String_Node_Str",method=RequestMethod.POST) public ResponseEntity<Object> createNewStudy(HttpServletRequest request,@RequestBody HashMap<String,Object> map) throws Exception {
  ArrayList<ErrorObject> errorObjects=new ArrayList();
  StudyDTO studyDTO=new StudyDTO();
  logger.info("String_Node_Str");
  ResponseEntity<Object> response=null;
  String validation_failed_message="String_Node_Str";
  String validation_passed_message="String_Node_Str";
  String uniqueStudyID=(String)map.get("String_Node_Str");
  String name=(String)map.get("String_Node_Str");
  String studyOid=(String)map.get("String_Node_Str");
  String studyEnvUuid=(String)map.get("String_Node_Str");
  String uuid=(String)map.get("String_Node_Str");
  Matcher m=Pattern.compile("String_Node_Str").matcher(studyOid);
  String envType="String_Node_Str";
  if (m.find()) {
    if (m.groupCount() != 2) {
      ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
      errorObjects.add(errorOBject);
    }
 else {
      envType=m.group(2);
    }
  }
  AsyncStudyHelper asyncStudyHelper=new AsyncStudyHelper("String_Node_Str","String_Node_Str",LocalTime.now());
  AsyncStudyHelper.put(uniqueStudyID,asyncStudyHelper);
  if (StringUtils.isEmpty(uniqueStudyID)) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
 else {
    uniqueStudyID=uniqueStudyID.trim();
  }
  if (StringUtils.isEmpty(name)) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
 else {
    name=name.trim();
  }
  if (StringUtils.isEmpty(studyOid)) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
 else {
    studyOid=studyOid.trim();
  }
  if (StringUtils.isEmpty(uuid)) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
 else {
    uuid=uuid.trim();
  }
  if (StringUtils.isEmpty(studyEnvUuid)) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
 else {
    studyEnvUuid=studyEnvUuid.trim();
  }
  Locale locale=new Locale("String_Node_Str");
  request.getSession().setAttribute(LocaleResolver.getLocaleSessionAttributeName(),locale);
  ResourceBundleProvider.updateLocale(locale);
  request.setAttribute("String_Node_Str",uniqueStudyID);
  request.setAttribute("String_Node_Str",name);
  request.setAttribute("String_Node_Str",studyOid);
  request.setAttribute("String_Node_Str",uuid);
  request.setAttribute("String_Node_Str",envType);
  request.setAttribute("String_Node_Str",studyEnvUuid);
  ResponseEntity<HashMap> responseEntity=processSSOUserContext(request,studyEnvUuid);
  UserAccountBean ownerUserAccount=getStudyOwnerAccountWithCreatedUser(request,responseEntity);
  if (ownerUserAccount == null) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
  Validator v0=new Validator(request);
  v0.addValidation("String_Node_Str",Validator.NO_BLANKS);
  HashMap vError0=v0.validate();
  if (!vError0.isEmpty()) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
  Validator v1=new Validator(request);
  v1.addValidation("String_Node_Str",Validator.NO_BLANKS);
  HashMap vError1=v1.validate();
  if (!vError1.isEmpty()) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
  Validator v2=new Validator(request);
  v2.addValidation("String_Node_Str",Validator.NO_BLANKS);
  HashMap vError2=v2.validate();
  if (!vError2.isEmpty()) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
  Validator v3=new Validator(request);
  v3.addValidation("String_Node_Str",Validator.NO_BLANKS);
  HashMap vError3=v3.validate();
  if (!vError3.isEmpty()) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
  Validator v4=new Validator(request);
  v4.addValidation("String_Node_Str",Validator.NO_LEADING_OR_TRAILING_SPACES);
  HashMap vError4=v4.validate();
  if (!vError4.isEmpty()) {
    ErrorObject errorOBject=createErrorObject("String_Node_Str","String_Node_Str","String_Node_Str");
    errorObjects.add(errorOBject);
  }
  if (errorObjects != null && errorObjects.size() != 0) {
    studyDTO.setMessage(validation_failed_message);
    response=new ResponseEntity(studyDTO,org.springframework.http.HttpStatus.BAD_REQUEST);
    return response;
  }
  studyDTO.setErrors(errorObjects);
  Study study=new Study();
  study.setUniqueIdentifier(uniqueStudyID);
  study.setName(name);
  study.setOc_oid(studyOid);
  study.setEnvType(StudyEnvEnum.valueOf(envType));
  study.setStudyEnvUuid(studyEnvUuid);
  study.setUuid(uuid);
  Study byOidEnvType=studyDao.findByOidEnvType(studyOid,StudyEnvEnum.valueOf(envType));
  if (byOidEnvType != null && byOidEnvType.getOc_oid() != null) {
    return getResponseSuccess(byOidEnvType);
  }
  StudyInfoObject studyInfoObject=null;
  Study schemaStudy=null;
  try {
    studyInfoObject=studyBuildService.process(request,study,ownerUserAccount);
    liquibaseOnDemandService.createForeignTables(studyInfoObject);
    schemaStudy=liquibaseOnDemandService.process(studyInfoObject,studyInfoObject.getUb());
  }
 catch (  Exception e) {
    try {
      schemaCleanupService.dropSchema(studyInfoObject);
    }
 catch (    Exception schemaEx) {
      throw new Exception("String_Node_Str");
    }
    throw e;
  }
  logger.debug("String_Node_Str" + schemaStudy.getStudyId());
  if (errorObjects != null && errorObjects.size() != 0) {
    studyDTO.setMessage(validation_failed_message);
    response=new ResponseEntity(studyDTO,org.springframework.http.HttpStatus.BAD_REQUEST);
  }
 else {
    studyDTO.setStudyOid(schemaStudy.getOc_oid());
    studyDTO.setMessage(validation_passed_message);
    studyDTO.setUniqueProtocolID(schemaStudy.getUniqueIdentifier());
    logger.debug("String_Node_Str" + schemaStudy.getOc_oid());
    ResponseSuccessStudyDTO responseSuccess=new ResponseSuccessStudyDTO();
    responseSuccess.setMessage(studyDTO.getMessage());
    responseSuccess.setStudyOid(studyDTO.getStudyOid());
    responseSuccess.setUniqueStudyID(studyDTO.getUniqueProtocolID());
    responseSuccess.setSchemaName(studyInfoObject.getSchema());
    response=new ResponseEntity(responseSuccess,org.springframework.http.HttpStatus.OK);
  }
  request.getSession().setAttribute("String_Node_Str",null);
  AsyncStudyHelper asyncStudyDone=new AsyncStudyHelper("String_Node_Str","String_Node_Str");
  AsyncStudyHelper.put(uniqueStudyID,asyncStudyDone);
  return response;
}