use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class ChangeStudyServlet method confirmChangeStudy.
private void confirmChangeStudy(ArrayList studies) throws Exception {
Validator v = new Validator(request);
FormProcessor fp = new FormProcessor(request);
v.addValidation("studyId", Validator.IS_AN_INTEGER);
errors = v.validate();
if (!errors.isEmpty()) {
request.setAttribute("studies", studies);
forwardPage(Page.CHANGE_STUDY);
} else {
int studyId = fp.getInt("studyId");
logger.info("new study id:" + studyId);
for (int i = 0; i < studies.size(); i++) {
StudyUserRoleBean studyWithRole = (StudyUserRoleBean) studies.get(i);
if (studyWithRole.getStudyId() == studyId) {
request.setAttribute("studyId", new Integer(studyId));
session.setAttribute("studyWithRole", studyWithRole);
request.setAttribute("currentStudy", currentStudy);
forwardPage(Page.CHANGE_STUDY_CONFIRM);
return;
}
}
addPageMessage(restext.getString("no_study_selected"));
forwardPage(Page.CHANGE_STUDY);
}
}
use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class ChangeStudyServlet method changeStudy.
private void changeStudy() throws Exception {
Validator v = new Validator(request);
FormProcessor fp = new FormProcessor(request);
int studyId = fp.getInt("studyId");
int prevStudyId = currentStudy.getId();
StudyDAO sdao = new StudyDAO(sm.getDataSource());
StudyBean current = (StudyBean) sdao.findByPK(studyId);
// reset study parameters -jxu 02/09/2007
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
ArrayList studyParameters = spvdao.findParamConfigByStudy(current);
current.setStudyParameters(studyParameters);
int parentStudyId = currentStudy.getParentStudyId() > 0 ? currentStudy.getParentStudyId() : currentStudy.getId();
StudyParameterValueBean parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdGeneration");
current.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
String idSetting = current.getStudyParameterConfig().getSubjectIdGeneration();
if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
int nextLabel = this.getStudySubjectDAO().findTheGreatestLabel() + 1;
request.setAttribute("label", new Integer(nextLabel).toString());
}
StudyConfigService scs = new StudyConfigService(sm.getDataSource());
if (current.getParentStudyId() <= 0) {
// top study
scs.setParametersForStudy(current);
} else {
// YW <<
if (current.getParentStudyId() > 0) {
current.setParentStudyName(((StudyBean) sdao.findByPK(current.getParentStudyId())).getName());
}
// YW 06-12-2007>>
scs.setParametersForSite(current);
}
if (current.getStatus().equals(Status.DELETED) || current.getStatus().equals(Status.AUTO_DELETED)) {
session.removeAttribute("studyWithRole");
addPageMessage(restext.getString("study_choosed_removed_restore_first"));
} else {
session.setAttribute("study", current);
currentStudy = current;
// change user's active study id
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ub.setActiveStudyId(current.getId());
ub.setUpdater(ub);
ub.setUpdatedDate(new java.util.Date());
udao.update(ub);
if (current.getParentStudyId() > 0) {
/*
* The Role decription will be set depending on whether the user
* logged in at study lever or site level. issue-2422
*/
List roles = Role.toArrayList();
for (Iterator it = roles.iterator(); it.hasNext(); ) {
Role role = (Role) it.next();
switch(role.getId()) {
case 2:
role.setDescription("site_Study_Coordinator");
break;
case 3:
role.setDescription("site_Study_Director");
break;
case 4:
role.setDescription("site_investigator");
break;
case 5:
role.setDescription("site_Data_Entry_Person");
break;
case 6:
role.setDescription("site_monitor");
break;
case 7:
role.setDescription("site_Data_Entry_Person2");
break;
default:
}
}
} else {
/*
* If the current study is a site, we will change the role
* description. issue-2422
*/
List roles = Role.toArrayList();
for (Iterator it = roles.iterator(); it.hasNext(); ) {
Role role = (Role) it.next();
switch(role.getId()) {
case 2:
role.setDescription("Study_Coordinator");
break;
case 3:
role.setDescription("Study_Director");
break;
case 4:
role.setDescription("investigator");
break;
case 5:
role.setDescription("Data_Entry_Person");
break;
case 6:
role.setDescription("monitor");
break;
default:
}
}
}
currentRole = (StudyUserRoleBean) session.getAttribute("studyWithRole");
session.setAttribute("userRole", currentRole);
session.removeAttribute("studyWithRole");
addPageMessage(restext.getString("current_study_changed_succesfully"));
}
ub.incNumVisitsToMainMenu();
// YW 2-18-2008, if study has been really changed <<
if (prevStudyId != studyId) {
session.removeAttribute("eventsForCreateDataset");
session.setAttribute("tableFacadeRestore", "false");
}
request.setAttribute("studyJustChanged", "yes");
// YW >>
//Integer assignedDiscrepancies = getDiscrepancyNoteDAO().countAllItemDataByStudyAndUser(currentStudy, ub);
Integer assignedDiscrepancies = getDiscrepancyNoteDAO().getViewNotesCountWithFilter(" AND dn.assigned_user_id =" + ub.getId() + " AND (dn.resolution_status_id=1 OR dn.resolution_status_id=2 OR dn.resolution_status_id=3)", currentStudy);
request.setAttribute("assignedDiscrepancies", assignedDiscrepancies == null ? 0 : assignedDiscrepancies);
if (currentRole.isInvestigator() || currentRole.isResearchAssistant() || currentRole.isResearchAssistant2()) {
setupListStudySubjectTable();
}
if (currentRole.isMonitor()) {
setupSubjectSDVTable();
} else if (currentRole.isCoordinator() || currentRole.isDirector()) {
if (currentStudy.getStatus().isPending()) {
response.sendRedirect(request.getContextPath() + Page.MANAGE_STUDY_MODULE.getFileName());
return;
}
setupStudySiteStatisticsTable();
setupSubjectEventStatusStatisticsTable();
setupStudySubjectStatusStatisticsTable();
if (currentStudy.getParentStudyId() == 0) {
setupStudyStatisticsTable();
}
}
forwardPage(Page.MENU);
}
use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class StudyController method createNewSites.
/**
* @api {post} /pages/auth/api/v1/studies/:uniqueProtocolId/sites Create a site
* @apiName createNewSite
* @apiPermission Authenticate using api-key. admin
* @apiVersion 3.8.0
* @apiParam {String} uniqueProtococlId Study unique protocol ID.
* @apiParam {String} briefTitle Brief Title .
* @apiParam {String} principalInvestigator Principal Investigator Name.
* @apiParam {Integer} expectedTotalEnrollment Expected Total Enrollment number
* @apiParam {String} secondaryProtocolID Site Secondary Protocol Id (Optional)
* @apiParam {Date} startDate Start date
* @apiParam {Date} protocolDateVerification protocol Verification date
* @apiParam {Array} assignUserRoles Assign Users to Roles for this Study.
* @apiGroup Site
* @apiHeader {String} api_key Users unique access-key.
* @apiDescription Create a Site
* @apiParamExample {json} Request-Example:
* {
* "briefTitle": "Site Protocol ID Name",
* "principalInvestigator": "Principal Investigator Name",
* "expectedTotalEnrollment": "10",
* "assignUserRoles": [
* { "username" : "userc", "role" : "Investigator"},
* { "username" : "userb", "role" : "Clinical Research Coordinator"},
* { "username" : "dm_normal", "role" : "Monitor"},
* { "username" : "sd_root", "role" : "Data Entry Person"}
* ],
* "uniqueProtocolID": "Site Protocol ID",
* "startDate": "2011-11-11",
* "secondaryProtocolID" : "Secondary Protocol ID 1" ,
* "protocolDateVerification" : "2011-10-14"
* }
*
* @apiErrorExample {json} Error-Response:
* HTTP/1.1 400 Bad Request
* {
* "message": "VALIDATION FAILED",
* "protocolDateVerification": "2011-10-14",
* "principalInvestigator": "Principal Investigator Name",
* "expectedTotalEnrollment": "10",
* "errors": [
* { "field": "UniqueProtocolId", "resource": "Site Object","code": "Unique Protocol Id exist in the System" }
* ],
* "secondaryProId": "Secondary Protocol ID 1",
* "siteOid": null,
* "briefTitle": "Site Protocol ID Name",
* "assignUserRoles": [
* { "role": "Investigator", "username": "userc"},
* { "role": "Clinical Research Coordinator", "username": "userb"},
* { "role": "Monitor","username": "dm_normal"},
* { "role": "Data Entry Person","username": "sd_root"}
* ],
* "uniqueSiteProtocolID": "Site Protocol ID",
* "startDate": "2011-11-11"
* }
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "message": "SUCCESS",
* "siteOid": "S_SITEPROT",
* "uniqueSiteProtocolID": "Site Protocol IDqq"
* }
*/
@RequestMapping(value = "/{uniqueProtocolID}/sites", method = RequestMethod.POST)
public ResponseEntity<Object> createNewSites(HttpServletRequest request, @RequestBody HashMap<String, Object> map, @PathVariable("uniqueProtocolID") String uniqueProtocolID) throws Exception {
System.out.println("I'm in Create Sites ");
ArrayList<ErrorObject> errorObjects = new ArrayList();
StudyBean siteBean = null;
ResponseEntity<Object> response = null;
String validation_failed_message = "VALIDATION FAILED";
String validation_passed_message = "SUCCESS";
String name = (String) map.get("briefTitle");
String principalInvestigator = (String) map.get("principalInvestigator");
String uniqueSiteProtocolID = (String) map.get("uniqueProtocolID");
String expectedTotalEnrollment = (String) map.get("expectedTotalEnrollment");
String startDate = (String) map.get("startDate");
String protocolDateVerification = (String) map.get("protocolDateVerification");
String secondaryProId = (String) map.get("secondaryProtocolID");
ArrayList<UserRole> assignUserRoles = (ArrayList<UserRole>) map.get("assignUserRoles");
ArrayList<UserRole> userList = new ArrayList<>();
if (assignUserRoles != null) {
for (Object userRole : assignUserRoles) {
UserRole uRole = new UserRole();
uRole.setUsername((String) ((HashMap<String, Object>) userRole).get("username"));
uRole.setRole((String) ((HashMap<String, Object>) userRole).get("role"));
udao = new UserAccountDAO(dataSource);
UserAccountBean assignedUserBean = (UserAccountBean) udao.findByUserName(uRole.getUsername());
if (assignedUserBean == null || !assignedUserBean.isActive()) {
ErrorObject errorOBject = createErrorObject("Study Object", "The Assigned Username " + uRole.getUsername() + " is not a Valid User", "Assigned User");
errorObjects.add(errorOBject);
}
ResourceBundle resterm = org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
if (getSiteRole(uRole.getRole(), resterm) == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Assigned Role for " + uRole.getUsername() + " is not a Valid Site Role", "Assigned Role");
errorObjects.add(errorOBject);
}
userList.add(uRole);
}
}
SiteDTO siteDTO = buildSiteDTO(uniqueSiteProtocolID, name, principalInvestigator, expectedTotalEnrollment, startDate, protocolDateVerification, secondaryProId, userList);
if (uniqueSiteProtocolID == null) {
ErrorObject errorOBject = createErrorObject("Site Object", "Missing Field", "UniqueProtocolID");
errorObjects.add(errorOBject);
} else {
uniqueSiteProtocolID = uniqueSiteProtocolID.trim();
}
if (name == null) {
ErrorObject errorOBject = createErrorObject("Site Object", "Missing Field", "BriefTitle");
errorObjects.add(errorOBject);
} else {
name = name.trim();
}
if (principalInvestigator == null) {
ErrorObject errorOBject = createErrorObject("Site Object", "Missing Field", "PrincipalInvestigator");
errorObjects.add(errorOBject);
} else {
principalInvestigator = principalInvestigator.trim();
}
if (startDate == null) {
ErrorObject errorOBject = createErrorObject("Site Object", "Missing Field", "StartDate");
errorObjects.add(errorOBject);
} else {
startDate = startDate.trim();
}
if (protocolDateVerification == null) {
ErrorObject errorOBject = createErrorObject("Site Object", "Missing Field", "ProtocolDateVerification");
errorObjects.add(errorOBject);
} else {
protocolDateVerification = protocolDateVerification.trim();
}
if (expectedTotalEnrollment == null) {
ErrorObject errorOBject = createErrorObject("Site Object", "Missing Field", "ExpectedTotalEnrollment");
errorObjects.add(errorOBject);
} else {
expectedTotalEnrollment = expectedTotalEnrollment.trim();
}
if (secondaryProId != null) {
secondaryProId = secondaryProId.trim();
}
if (assignUserRoles == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Missing Field", "AssignUserRoles");
errorObjects.add(errorOBject);
}
request.setAttribute("uniqueProId", uniqueSiteProtocolID);
request.setAttribute("name", name);
request.setAttribute("prinInvestigator", principalInvestigator);
request.setAttribute("expectedTotalEnrollment", expectedTotalEnrollment);
request.setAttribute("startDate", startDate);
request.setAttribute("protocolDateVerification", protocolDateVerification);
request.setAttribute("secondProId", secondaryProId);
String format = "yyyy-MM-dd";
SimpleDateFormat formatter = null;
Date formattedStartDate = null;
Date formattedProtocolDate = null;
if (startDate != "" && startDate != null) {
try {
formatter = new SimpleDateFormat(format);
formattedStartDate = formatter.parse(startDate);
} catch (ParseException e) {
ErrorObject errorOBject = createErrorObject("Site Object", "The StartDate format is not a valid 'yyyy-MM-dd' format", "StartDate");
errorObjects.add(errorOBject);
}
if (formattedStartDate != null) {
if (!startDate.equals(formatter.format(formattedStartDate))) {
ErrorObject errorOBject = createErrorObject("Site Object", "The StartDate format is not a valid 'yyyy-MM-dd' format", "StartDate");
errorObjects.add(errorOBject);
}
}
}
if (protocolDateVerification != "" && protocolDateVerification != null) {
try {
formatter = new SimpleDateFormat(format);
formattedProtocolDate = formatter.parse(protocolDateVerification);
} catch (ParseException e) {
ErrorObject errorOBject = createErrorObject("Site Object", "The Protocol Verification Date format is not a valid 'yyyy-MM-dd' format", "ProtocolDateVerification");
errorObjects.add(errorOBject);
}
if (formattedProtocolDate != null) {
if (!protocolDateVerification.equals(formatter.format(formattedProtocolDate))) {
ErrorObject errorOBject = createErrorObject("Site Object", "The Protocol Verification Date format is not a valid 'yyyy-MM-dd' format", "ProtocolDateVerification");
errorObjects.add(errorOBject);
}
}
}
StudyBean parentStudy = getStudyByUniqId(uniqueProtocolID);
if (parentStudy == null) {
ErrorObject errorOBject = createErrorObject("Study 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("Study 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 = null;
if (parentStudy != null) {
ownerUserAccount = getSiteOwnerAccount(request, parentStudy);
if (ownerUserAccount == null) {
ErrorObject errorOBject = createErrorObject("Site Object", "The Owner User Account is not Valid Account or Does not have rights to Create Sites", "Owner Account");
errorObjects.add(errorOBject);
}
}
Validator v1 = new Validator(request);
v1.addValidation("uniqueProId", Validator.NO_BLANKS);
HashMap vError1 = v1.validate();
if (!vError1.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Site Object", "This field cannot be blank.", "UniqueProtocolId");
errorObjects.add(errorOBject);
}
Validator v2 = new Validator(request);
v2.addValidation("name", Validator.NO_BLANKS);
HashMap vError2 = v2.validate();
if (!vError2.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Site Object", "This field cannot be blank.", "BriefTitle");
errorObjects.add(errorOBject);
}
Validator v3 = new Validator(request);
v3.addValidation("prinInvestigator", Validator.NO_BLANKS);
HashMap vError3 = v3.validate();
if (!vError3.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Site Object", "This field cannot be blank.", "PrincipleInvestigator");
errorObjects.add(errorOBject);
}
Validator v6 = new Validator(request);
HashMap vError6 = v6.validate();
if (uniqueProtocolID != null)
validateUniqueProId(request, vError6);
if (!vError6.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Site Object", "Unique Protocol Id exist in the System", "UniqueProtocolId");
errorObjects.add(errorOBject);
}
Validator v7 = new Validator(request);
v7.addValidation("expectedTotalEnrollment", Validator.NO_BLANKS);
HashMap vError7 = v7.validate();
if (!vError7.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Site Object", "This field cannot be blank.", "ExpectedTotalEnrollment");
errorObjects.add(errorOBject);
}
if (request.getAttribute("name") != null && ((String) request.getAttribute("name")).length() > 100) {
ErrorObject errorOBject = createErrorObject("Site Object", "BriefTitle Length exceeds the max length 100", "BriefTitle");
errorObjects.add(errorOBject);
}
if (request.getAttribute("uniqueProId") != null && ((String) request.getAttribute("uniqueProId")).length() > 30) {
ErrorObject errorOBject = createErrorObject("Site Object", "UniqueProtocolId Length exceeds the max length 30", "UniqueProtocolId");
errorObjects.add(errorOBject);
}
if (request.getAttribute("prinInvestigator") != null && ((String) request.getAttribute("prinInvestigator")).length() > 255) {
ErrorObject errorOBject = createErrorObject("Site Object", "PrincipleInvestigator Length exceeds the max length 255", "PrincipleInvestigator");
errorObjects.add(errorOBject);
}
if (request.getAttribute("expectedTotalEnrollment") != null && Integer.valueOf((String) request.getAttribute("expectedTotalEnrollment")) <= 0) {
ErrorObject errorOBject = createErrorObject("Site Object", "ExpectedTotalEnrollment Length can't be negative", "ExpectedTotalEnrollment");
errorObjects.add(errorOBject);
}
siteDTO.setErrors(errorObjects);
if (errorObjects != null && errorObjects.size() != 0) {
siteDTO.setMessage(validation_failed_message);
response = new ResponseEntity(siteDTO, org.springframework.http.HttpStatus.BAD_REQUEST);
} else {
siteBean = buildSiteBean(uniqueSiteProtocolID, name, principalInvestigator, Integer.valueOf(expectedTotalEnrollment), formattedStartDate, formattedProtocolDate, secondaryProId, ownerUserAccount, parentStudy.getId());
StudyBean sBean = createStudy(siteBean, ownerUserAccount);
siteDTO.setSiteOid(sBean.getOid());
siteDTO.setMessage(validation_passed_message);
ResourceBundle resterm = org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
StudyUserRoleBean sub = null;
for (UserRole userRole : userList) {
sub = new StudyUserRoleBean();
sub.setRole(getSiteRole(userRole.getRole(), resterm));
sub.setStudyId(sBean.getId());
sub.setStatus(Status.AVAILABLE);
sub.setOwner(ownerUserAccount);
udao = new UserAccountDAO(dataSource);
UserAccountBean assignedUserBean = (UserAccountBean) udao.findByUserName(userRole.getUsername());
StudyUserRoleBean surb = createRole(assignedUserBean, sub);
}
ResponseSuccessSiteDTO responseSuccess = new ResponseSuccessSiteDTO();
responseSuccess.setMessage(siteDTO.getMessage());
responseSuccess.setSiteOid(siteDTO.getSiteOid());
responseSuccess.setUniqueSiteProtocolID(siteDTO.getUniqueSiteProtocolID());
response = new ResponseEntity(responseSuccess, org.springframework.http.HttpStatus.OK);
}
return response;
}
use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class CreateSubStudyServlet method confirmStudy.
/**
* Validates the first section of study and save it into study bean
*
* @throws Exception
*/
private void confirmStudy() throws Exception {
Validator v = new Validator(request);
FormProcessor fp = new FormProcessor(request);
v.addValidation("name", Validator.NO_BLANKS);
v.addValidation("uniqueProId", Validator.NO_BLANKS);
// >> tbh
// v.addValidation("description", Validator.NO_BLANKS);
// << tbh, #3943, 07/2009
v.addValidation("prinInvestigator", Validator.NO_BLANKS);
if (!StringUtil.isBlank(fp.getString(INPUT_START_DATE))) {
v.addValidation(INPUT_START_DATE, Validator.IS_A_DATE);
}
if (!StringUtil.isBlank(fp.getString(INPUT_END_DATE))) {
v.addValidation(INPUT_END_DATE, Validator.IS_A_DATE);
}
if (!StringUtil.isBlank(fp.getString("facConEmail"))) {
v.addValidation("facConEmail", Validator.IS_A_EMAIL);
}
if (!StringUtil.isBlank(fp.getString(INPUT_VER_DATE))) {
v.addValidation(INPUT_VER_DATE, Validator.IS_A_DATE);
}
// v.addValidation("statusId", Validator.IS_VALID_TERM);
v.addValidation("secondProId", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
v.addValidation("facName", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
v.addValidation("facCity", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
v.addValidation("facState", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 20);
v.addValidation("facZip", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 64);
v.addValidation("facCountry", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 64);
v.addValidation("facConName", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
v.addValidation("facConDegree", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
v.addValidation("facConPhone", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
v.addValidation("facConEmail", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
// errors = v.validate();
// >> tbh
/*
* StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
* ArrayList<StudyBean> allStudies = (ArrayList<StudyBean>) studyDAO.findAll();
* for (StudyBean thisBean : allStudies) {
* if (fp.getString("uniqueProId").trim().equals(thisBean.getIdentifier())) {
* v.addError(errors, "uniqueProId", resexception.getString("unique_protocol_id_existed"));
* }
* }
* // << tbh #3999 08/2009
* if (fp.getString("name").trim().length() > 100) {
* // Validator.addError(errors, "name", resexception.getString("maximum_lenght_name_100"));
* }
* if (fp.getString("uniqueProId").trim().length() > 30) {
* Validator.addError(errors, "uniqueProId", resexception.getString("maximum_lenght_unique_protocol_30"));
* }
* if (fp.getString("description").trim().length() > 255) {
* Validator.addError(errors, "description", resexception.getString("maximum_lenght_brief_summary_255"));
* }
* if (fp.getString("prinInvestigator").trim().length() > 255) {
* Validator.addError(errors, "prinInvestigator",
* resexception.getString("maximum_lenght_principal_investigator_255"));
* }
* if (fp.getInt("expectedTotalEnrollment") <= 0) {
* Validator.addError(errors, "expectedTotalEnrollment",
* respage.getString("expected_total_enrollment_must_be_a_positive_number"));
* }
*/
StudyBean newSite = this.createStudyBean();
StudyBean parentStudy = (StudyBean) new StudyDAO(sm.getDataSource()).findByPK(newSite.getParentStudyId());
session.setAttribute("newStudy", newSite);
session.setAttribute("definitions", this.createSiteEventDefinitions(parentStudy, v));
if (errors.isEmpty()) {
logger.info("no errors");
forwardPage(Page.CONFIRM_CREATE_SUB_STUDY);
}
/*
* else {
* try {
* local_df.parse(fp.getString(INPUT_START_DATE));
* fp.addPresetValue(INPUT_START_DATE, local_df.format(fp.getDate(INPUT_START_DATE)));
* } catch (ParseException pe) {
* fp.addPresetValue(INPUT_START_DATE, fp.getString(INPUT_START_DATE));
* }
* try {
* local_df.parse(fp.getString(INPUT_END_DATE));
* fp.addPresetValue(INPUT_END_DATE, local_df.format(fp.getDate(INPUT_END_DATE)));
* } catch (ParseException pe) {
* fp.addPresetValue(INPUT_END_DATE, fp.getString(INPUT_END_DATE));
* }
* try {
* local_df.parse(fp.getString(INPUT_VER_DATE));
* fp.addPresetValue(INPUT_VER_DATE, local_df.format(fp.getDate(INPUT_VER_DATE)));
* } catch (ParseException pe) {
* fp.addPresetValue(INPUT_VER_DATE, fp.getString(INPUT_VER_DATE));
* }
* setPresetValues(fp.getPresetValues());
* logger.info("has validation errors");
* request.setAttribute("formMessages", errors);
* // request.setAttribute("facRecruitStatusMap",
* // CreateStudyServlet.facRecruitStatusMap);
* request.setAttribute("statuses", Status.toActiveArrayList());
* forwardPage(Page.CREATE_SUB_STUDY);
* }
*/
}
use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class EditFilterServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
String action = request.getParameter("action");
if ("validate".equalsIgnoreCase(action)) {
// check name, description, status for right now
Validator v = new Validator(request);
v.addValidation("fName", Validator.NO_BLANKS);
v.addValidation("fDesc", Validator.NO_BLANKS);
v.addValidation("fStatusId", Validator.IS_VALID_TERM, TermType.STATUS);
HashMap errors = v.validate();
if (!errors.isEmpty()) {
String[] fieldNames = { "fName", "fDesc" };
fp.setCurrentStringValuesAsPreset(fieldNames);
fp.addPresetValue("fStatusId", fp.getInt("fStatusId"));
addPageMessage(respage.getString("errors_in_submission_see_below"));
setInputMessages(errors);
setPresetValues(fp.getPresetValues());
// TODO determine if this is necessary
int filterId = fp.getInt("filterId");
FilterDAO fDAO = new FilterDAO(sm.getDataSource());
FilterBean showFilter = (FilterBean) fDAO.findByPK(filterId);
request.setAttribute("filter", showFilter);
// maybe just set the above to the session?
request.setAttribute("statuses", getStatuses());
forwardPage(Page.EDIT_FILTER);
} else {
int filterId = fp.getInt("filterId");
FilterDAO fDAO = new FilterDAO(sm.getDataSource());
FilterBean filter = (FilterBean) fDAO.findByPK(filterId);
filter.setName(fp.getString("fName"));
filter.setDescription(fp.getString("fDesc"));
filter.setStatus(Status.get(fp.getInt("fStatusId")));
fDAO.update(filter);
addPageMessage(respage.getString("the_filter_was_succesfully_updated"));
// Collection filters = fDAO.findAll();
// TODO make findAllByProject?
// FormProcessor fp = new FormProcessor(request);
FilterDAO fdao = new FilterDAO(sm.getDataSource());
EntityBeanTable table = fp.getEntityBeanTable();
// TODO make
ArrayList filters = (ArrayList) fdao.findAll();
// findAllByProject
ArrayList filterRows = FilterRow.generateRowsFromBeans(filters);
String[] columns = { resword.getString("filter_name"), resword.getString("description"), resword.getString("created_by"), resword.getString("created_date"), resword.getString("status"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(5);
table.setQuery("CreateFiltersOne", new HashMap());
table.setRows(filterRows);
table.computeDisplay();
request.setAttribute("table", table);
forwardPage(Page.CREATE_FILTER_SCREEN_1);
// forwardPage(Page.VALIDATE_EDIT_FILTER);
}
} else {
int filterId = fp.getInt("filterId");
FilterDAO fDAO = new FilterDAO(sm.getDataSource());
FilterBean showFilter = (FilterBean) fDAO.findByPK(filterId);
request.setAttribute("filter", showFilter);
request.setAttribute("statuses", getStatuses());
forwardPage(Page.EDIT_FILTER);
}
}
Aggregations