use of org.akaza.openclinica.bean.login.ResponseSuccessEventDefDTO in project OpenClinica by OpenClinica.
the class StudyController method createEventDefinition.
/**
* @api {post} /pages/auth/api/v1/studies/:uniqueProtocolId/eventdefinitions Create a study event
* @apiName createEventDefinition
* @apiPermission Authenticate using api-key. admin
* @apiVersion 3.8.0
* @apiParam {String} uniqueProtocolId Study unique protocol ID.
* @apiParam {String} name Event Name.
* @apiParam {String} description Event Description.
* @apiParam {String} category Category Name.
* @apiParam {Boolean} repeating 'True' or 'False'.
* @apiParam {String} type 'Scheduled' , 'UnScheduled' or 'Common'.
* @apiGroup Study Event
* @apiHeader {String} api_key Users unique access-key.
* @apiDescription Creates a study event definition.
* @apiParamExample {json} Request-Example:
* {
* "name": "Event Name",
* "description": "Event Description",
* "category": "Category Name",
* "repeating": "true",
* "type":"Scheduled"
* }
* @apiErrorExample {json} Error-Response:
* HTTP/1.1 400 Bad Request
* {
* "name": "Event Name",
* "message": "VALIDATION FAILED",
* "type": "",
* "errors": [
* {"field": "Type","resource": "Event Definition Object","code": "Type Field should be Either 'Scheduled' , 'UnScheduled' or 'Common'"},
* {"field": "Type","resource": "Event Definition Object","code": "This field cannot be blank."}
* ],
* "category": "Category Name",
* "description": "Event Description",
* "eventDefOid": null,
* "repeating": "true"
* }
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "message": "SUCCESS",
* "name": "Event Name",
* "eventDefOid": "SE_EVENTNAME"
* }
*/
@RequestMapping(value = "/{uniqueProtocolID}/eventdefinitions", method = RequestMethod.POST)
public ResponseEntity<Object> createEventDefinition(HttpServletRequest request, @RequestBody HashMap<String, Object> map, @PathVariable("uniqueProtocolID") String uniqueProtocolID) throws Exception {
System.out.println("I'm in Create Event Definition ");
ArrayList<ErrorObject> errorObjects = new ArrayList();
StudyEventDefinitionBean eventBean = null;
ResponseEntity<Object> response = null;
String validation_failed_message = "VALIDATION FAILED";
String validation_passed_message = "SUCCESS";
String name = (String) map.get("name");
String description = (String) map.get("description");
String category = (String) map.get("category");
String type = (String) map.get("type");
String repeating = (String) map.get("repeating");
EventDefinitionDTO eventDefinitionDTO = buildEventDefnDTO(name, description, category, repeating, type);
if (name == null) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "Missing Field", "Name");
errorObjects.add(errorOBject);
} else {
name = name.trim();
}
if (description == null) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "Missing Field", "Description");
errorObjects.add(errorOBject);
} else {
description = description.trim();
}
if (category == null) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "Missing Field", "Category");
errorObjects.add(errorOBject);
} else {
category = category.trim();
}
if (type == null) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "Missing Field", "Type");
errorObjects.add(errorOBject);
} else {
type = type.trim();
}
if (repeating == null) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "Missing Field", "Repeating");
errorObjects.add(errorOBject);
} else {
repeating = repeating.trim();
}
if (repeating != null) {
if (!repeating.equalsIgnoreCase("true") && !repeating.equalsIgnoreCase("false")) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "Repeating Field should be Either 'True' or 'False'", "Repeating");
errorObjects.add(errorOBject);
}
}
if (type != null) {
if (!type.equalsIgnoreCase("scheduled") && !type.equalsIgnoreCase("unscheduled") && !type.equalsIgnoreCase("common")) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "Type Field should be Either 'Scheduled' , 'UnScheduled' or 'Common'", "Type");
errorObjects.add(errorOBject);
}
}
request.setAttribute("name", name);
request.setAttribute("description", description);
request.setAttribute("category", category);
request.setAttribute("type", type);
request.setAttribute("repeating", repeating);
StudyBean parentStudy = getStudyByUniqId(uniqueProtocolID);
if (parentStudy == null) {
ErrorObject errorOBject = createErrorObject("Event Definition 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("Event Definition 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 = getStudyOwnerAccount(request);
if (ownerUserAccount == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "The Owner User Account is not Valid Account or Does not have Admin user type", "Owner Account");
errorObjects.add(errorOBject);
}
Validator v1 = new Validator(request);
v1.addValidation("name", Validator.NO_BLANKS);
HashMap vError1 = v1.validate();
if (!vError1.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "This field cannot be blank.", "Name");
errorObjects.add(errorOBject);
}
if (name != null) {
Validator v2 = new Validator(request);
v2.addValidation("name", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
HashMap vError2 = v2.validate();
if (!vError2.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "The Length Should not exceed 2000.", "Name");
errorObjects.add(errorOBject);
}
}
if (description != null) {
Validator v3 = new Validator(request);
v3.addValidation("description", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
HashMap vError3 = v3.validate();
if (!vError3.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "The Length Should not exceed 2000.", "Description");
errorObjects.add(errorOBject);
}
}
if (category != null) {
Validator v4 = new Validator(request);
v4.addValidation("category", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
HashMap vError4 = v4.validate();
if (!vError4.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "The Length Should not exceed 2000.", "Category");
errorObjects.add(errorOBject);
}
}
Validator v5 = new Validator(request);
v5.addValidation("repeating", Validator.NO_BLANKS);
HashMap vError5 = v5.validate();
if (!vError5.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "This field cannot be blank.", "Repeating");
errorObjects.add(errorOBject);
}
Validator v6 = new Validator(request);
v6.addValidation("type", Validator.NO_BLANKS);
HashMap vError6 = v6.validate();
if (!vError6.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Event Definition Object", "This field cannot be blank.", "Type");
errorObjects.add(errorOBject);
}
eventDefinitionDTO.setErrors(errorObjects);
if (errorObjects != null && errorObjects.size() != 0) {
eventDefinitionDTO.setMessage(validation_failed_message);
response = new ResponseEntity(eventDefinitionDTO, org.springframework.http.HttpStatus.BAD_REQUEST);
} else {
eventBean = buildEventDefBean(name, description, category, type, repeating, ownerUserAccount, parentStudy);
StudyEventDefinitionBean sedBean = createEventDefn(eventBean, ownerUserAccount);
eventDefinitionDTO.setEventDefOid(sedBean.getOid());
eventDefinitionDTO.setMessage(validation_passed_message);
}
ResponseSuccessEventDefDTO responseSuccess = new ResponseSuccessEventDefDTO();
responseSuccess.setMessage(eventDefinitionDTO.getMessage());
responseSuccess.setEventDefOid(eventDefinitionDTO.getEventDefOid());
responseSuccess.setName(eventDefinitionDTO.getName());
response = new ResponseEntity(responseSuccess, org.springframework.http.HttpStatus.OK);
return response;
}
Aggregations