Java Code Examples for org.apache.struts.action.ActionMessages#size()

The following examples show how to use org.apache.struts.action.ActionMessages#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecipientAction.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
private int saveTargetGroup(RecipientForm aForm, ComAdmin admin, ActionMessages errors, ActionMessages validationErrors) throws Exception {
      final int errorCount = errors.size();
      if (!aForm.checkParenthesisBalance()) {
          errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.target.bracketbalance"));
      }
      if (aForm.getTargetShortname() != null && aForm.getTargetShortname().length() < 1 ) {
          errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.name.too.short"));
      }
      if (aForm.getNumTargetNodes() == 0) {
          errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.target.norule"));
      }
      if (errorCount != errors.size()) {
          return 0;
      }
      ComTarget newTarget = targetFactory.newTarget();
      newTarget.setId(0);
      newTarget.setTargetName(aForm.getTargetShortname());
      newTarget.setTargetDescription(aForm.getTargetDescription());
      newTarget.setTargetStructure(recipientQueryBuilder.createTargetRepresentationFromForm(aForm, targetRepresentationFactory, targetNodeFactory, admin.getCompanyID()));
      newTarget.setEQL(eqlFacade.convertTargetRepresentationToEql(newTarget.getTargetStructure(), admin.getCompanyID()));
      newTarget.setCompanyID(admin.getCompanyID());

ComTarget target = targetDao.getTarget(aForm.getTargetID(), admin.getCompanyID());
return targetService.saveTarget(admin, newTarget, target, validationErrors, this::writeUserActivityLog);
  }
 
Example 2
Source File: RoomFeatureEditAction.java    From unitime with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward saveRoomFeature(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response) throws Exception {
	RoomFeatureEditForm roomFeatureEditForm = (RoomFeatureEditForm) form;
	ActionMessages errors = new ActionMessages();
	
	//Validate input prefs
       errors = roomFeatureEditForm.validate(mapping, request);
       if(errors.size()==0) {
		update(mapping, roomFeatureEditForm, request, response);
       }else {
       	saveErrors(request, errors);
       	editRoomFeature(mapping, form, request, response);
       	return mapping.findForward("showEdit");
       }
			
       roomFeatureEditForm.setDeptCode((String)sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom));
	if (roomFeatureEditForm.getId()!=null)
		request.setAttribute("hash", "A"+roomFeatureEditForm.getId());
	return mapping.findForward("showRoomFeatureList");
}
 
Example 3
Source File: RoomGroupEditAction.java    From unitime with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward saveRoomGroup(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response) throws Exception {
	RoomGroupEditForm roomGroupEditForm = (RoomGroupEditForm) form;
	ActionMessages errors = new ActionMessages();
	
	//Validate input prefs
       errors = roomGroupEditForm.validate(mapping, request);
       if(errors.size()==0) {
		update(mapping, roomGroupEditForm, request, response);
       } else {
       	saveErrors(request, errors);
		editRoomGroup(mapping, form, request, response);
		return mapping.findForward("showEdit");
       }
			
	if (roomGroupEditForm.getId()!=null)
		request.setAttribute("hash", "A"+roomGroupEditForm.getId());
	return mapping.findForward("showRoomGroupList");
}
 
Example 4
Source File: RoomFeatureAddAction.java    From unitime with Apache License 2.0 4 votes vote down vote up
/** 
 * Method execute
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward execute(
	ActionMapping mapping,
	ActionForm form,
	HttpServletRequest request,
	HttpServletResponse response) throws Exception {
	RoomFeatureEditForm roomFeatureEditForm = (RoomFeatureEditForm) form;
	
	MessageResources rsc = getResources(request);
	String doit = roomFeatureEditForm.getDoit();
	
	if (doit != null) {
		//add new
		if(doit.equals(rsc.getMessage("button.addNew"))) {
			ActionMessages errors = new ActionMessages();
			errors = roomFeatureEditForm.validate(mapping, request);
	        if(errors.size()==0) {
	        	save(mapping, roomFeatureEditForm, request, response);
				return mapping.findForward("showRoomFeatureList");
	        } else {
	        	saveErrors(request, errors);
	        }
		}
		
		//return to room list
		if(doit.equals(rsc.getMessage("button.returnToRoomFeatureList"))) {
			return mapping.findForward("showRoomFeatureList");
		}
	}
	
	//get depts owned by user
	LookupTables.setupDepartments(request, sessionContext, false);
	LookupTables.setupExamTypes(request, sessionContext.getUser(), DepartmentStatusType.Status.ExamView, DepartmentStatusType.Status.ExamTimetable);
	request.setAttribute("featureTypes", RoomFeatureTypeDAO.getInstance().findAll(Order.asc("label")));
	
       //set default department
	TreeSet<Department> departments = Department.getUserDepartments(sessionContext.getUser());
       if (departments.size() == 1) {
       	roomFeatureEditForm.setDeptCode(departments.first().getDeptCode());
       } else {
       	String deptCode = (String)sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom);
       	if (deptCode != null && !deptCode.isEmpty() && !deptCode.equals("All") && !deptCode.matches("Exam[0-9]*"))
       		roomFeatureEditForm.setDeptCode(deptCode);
	}
	
	if (roomFeatureEditForm.getDeptCode() == null || roomFeatureEditForm.getDeptCode().isEmpty() || roomFeatureEditForm.getDeptCode().matches("Exam[0-9]*") ||
			!sessionContext.hasPermission(roomFeatureEditForm.getDeptCode(), "Department", Right.DepartmentRoomFeatureAdd)) {
		sessionContext.checkPermission(Right.GlobalRoomFeatureAdd);
		roomFeatureEditForm.setGlobal(true);
	} else {
		sessionContext.checkPermission(roomFeatureEditForm.getDeptCode(), "Department", Right.DepartmentRoomFeatureAdd);
		roomFeatureEditForm.setGlobal(false);
	}
	
	roomFeatureEditForm.setSessionId(sessionContext.getUser().getCurrentAcademicSessionId());
	
	return mapping.findForward("showAdd");
}
 
Example 5
Source File: ManagerSettingsAction.java    From unitime with Apache License 2.0 4 votes vote down vote up
/** 
   * Method execute
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) throws Exception {
      
      // Check Access
  	sessionContext.checkPermission(Right.SettingsUser);
      
MessageResources rsc = getResources(request);
      ManagerSettingsForm frm = (ManagerSettingsForm) form;
      String op = frm.getOp();
 
      if(op==null) {
          op = request.getParameter("op");
          if(op==null) {
              frm.setOp("List");
           op = "List";
          }
      }
      
      // Reset Form
      if(op.equals(rsc.getMessage("button.cancelUpdateSetting"))) {
          frm.reset(mapping, request);
          frm.setOp("List");
      }

      // Edit - Load setting with allowed values for user to update
      if(op.equals("Edit")) {
          // Load Settings object
          Settings s = SettingsDAO.getInstance().get(Long.valueOf(request.getParameter("id")));

          // Set Form values
          frm.setOp("Edit");            
          frm.setAllowedValues(s.getAllowedValues());
          frm.setKey(s.getKey());
          frm.setName(s.getDescription());
          frm.setDefaultValue(s.getDefaultValue());
          frm.setValue(sessionContext.getUser().getProperty(s.getKey(), s.getDefaultValue()));

          return mapping.findForward("editManagerSettings");
      }
 
      // Save changes made by the user
      if(op.equals(rsc.getMessage("button.updateSetting"))) {
          ActionMessages errors = frm.validate(mapping, request);
          if(errors.size()>0) {
              saveErrors(request, errors);
              frm.setOp("Edit");
          } else {
          	sessionContext.getUser().setProperty(frm.getKey(), frm.getValue());
  	    }
      }

      // Read all existing settings and store in request
      getSettingsList(request);        
      return mapping.findForward("showManagerSettings");
  }
 
Example 6
Source File: RoomGroupListAction.java    From unitime with Apache License 2.0 4 votes vote down vote up
/** 
 * Method execute
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward execute(
	ActionMapping mapping,
	ActionForm form,
	HttpServletRequest request,
	HttpServletResponse response) throws Exception {
	RoomGroupListForm roomGroupListForm = (RoomGroupListForm) form;
	
	sessionContext.checkPermission(Right.RoomGroups);
	
	ActionMessages errors = new ActionMessages();
	
	//get deptCode from request - for user with only one department
	String deptCode = (String)request.getAttribute("deptCode");
	if (deptCode != null) {
		roomGroupListForm.setDeptCodeX(deptCode);
	}
	
	if (sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom) != null && roomGroupListForm.getDeptCodeX() == null) {
		deptCode = (String)sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom);
		if (deptCode != null && ("All".equals(deptCode) || deptCode.matches("Exam[0-9]*")))
			roomGroupListForm.setDeptCodeX((String)sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom));
	}

	// Set Session Variable
	if (roomGroupListForm.getDeptCodeX() != null && !roomGroupListForm.getDeptCodeX().isEmpty())
		sessionContext.setAttribute(SessionAttribute.DepartmentCodeRoom, roomGroupListForm.getDeptCodeX());

	//set request attribute for department
	LookupTables.setupDepartments(request, sessionContext, true);
	LookupTables.setupExamTypes(request, sessionContext.getUser(), DepartmentStatusType.Status.ExamView, DepartmentStatusType.Status.ExamTimetable);
	
	// Validate input
	errors = roomGroupListForm.validate(mapping, request);

	// Validation fails
	if (errors.size() > 0) {
		saveErrors(request, errors);
		return mapping.findForward("showRoomGroupSearch");
	}

	buildGroupTable(request, roomGroupListForm);
	
	if ("Export PDF".equals(request.getParameter("op"))) {
		sessionContext.checkPermission(Right.RoomGroupsExportPdf);
		OutputStream out = ExportUtils.getPdfOutputStream(response, "roomGroups");
		printPdfGroupTable(out, sessionContext, roomGroupListForm);
		out.flush(); out.close();
		return null;
	}

	return mapping.findForward("showRoomGroupList");
}
 
Example 7
Source File: RoomGroupAddAction.java    From unitime with Apache License 2.0 4 votes vote down vote up
/** 
 * Method execute
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward execute(
	ActionMapping mapping,
	ActionForm form,
	HttpServletRequest request,
	HttpServletResponse response) throws Exception{
	RoomGroupEditForm roomGroupEditForm = (RoomGroupEditForm) form;
	
	MessageResources rsc = getResources(request);
	String doit = roomGroupEditForm.getDoit();
	
	if (doit != null) {
		//add new
		if(doit.equals(rsc.getMessage("button.addNew"))) {
			ActionMessages errors = new ActionMessages();
			errors = roomGroupEditForm.validate(mapping, request);
	        if(errors.size()==0) {
	        	save(mapping, roomGroupEditForm, request, response);
				return mapping.findForward("showRoomGroupList");
	        } else {
	        	saveErrors(request, errors);
	        }
		}
		
		//return to room list
		if(doit.equals(rsc.getMessage("button.returnToRoomGroupList"))) {
			return mapping.findForward("showRoomGroupList");
		}
	}
	
	//get depts owned by user
	LookupTables.setupDepartments(request, sessionContext, false);
	
       //set default department
	TreeSet<Department> departments = Department.getUserDepartments(sessionContext.getUser());
       if (departments.size() == 1) {
       	roomGroupEditForm.setDeptCode(departments.first().getDeptCode());
       } else {
       	String deptCode = (String)sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom);
       	if (deptCode != null && !deptCode.isEmpty() && !deptCode.equals("All") && !deptCode.matches("Exam[0-9]*"))
       		roomGroupEditForm.setDeptCode(deptCode);
	}
	
	if (roomGroupEditForm.getDeptCode() == null || roomGroupEditForm.getDeptCode().isEmpty() || roomGroupEditForm.getDeptCode().matches("Exam[0-9]*") ||
		!sessionContext.hasPermission(roomGroupEditForm.getDeptCode(), "Department", Right.DepartmentRoomGroupAdd)) {
		sessionContext.checkPermission(Right.GlobalRoomGroupAdd);
		roomGroupEditForm.setGlobal(true);
	} else {
		sessionContext.checkPermission(roomGroupEditForm.getDeptCode(), "Department", Right.DepartmentRoomGroupAdd);
		roomGroupEditForm.setGlobal(false);
	}
	
	roomGroupEditForm.setSessionId(sessionContext.getUser().getCurrentAcademicSessionId());
	
	return mapping.findForward("showAdd");
}
 
Example 8
Source File: AddNonUnivLocationAction.java    From unitime with Apache License 2.0 4 votes vote down vote up
/** 
 * Method execute
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws Exception 
 */
public ActionForward execute(
	ActionMapping mapping,
	ActionForm form,
	HttpServletRequest request,
	HttpServletResponse response) throws Exception {
	NonUnivLocationForm nonUnivLocationForm = (NonUnivLocationForm) form;
	MessageResources rsc = getResources(request);
	ActionMessages errors = new ActionMessages();
	
	sessionContext.checkPermission(Right.AddNonUnivLocation);
	
	Set<Department> departments = Department.getUserDepartments(sessionContext.getUser());
	
	if (nonUnivLocationForm.getDoit() != null) {
		String doit = nonUnivLocationForm.getDoit();
		if (doit.equals(rsc.getMessage("button.returnToRoomList"))) {
			return mapping.findForward("showRoomList");
		}
		if (doit.equals(rsc.getMessage("button.addNew"))) {
		     // Validate input prefs
            errors = nonUnivLocationForm.validate(mapping, request);
            
            if (errors.isEmpty() && !sessionContext.hasPermission(nonUnivLocationForm.getDeptCode(), "Department", Right.AddNonUnivLocation)) {
            	errors.add("nonUniversityLocation", new ActionMessage("errors.generic", "Acess denied."));
            }
            
            // No errors
            if(errors.size()==0) {
            	update(request, nonUnivLocationForm);
				return mapping.findForward("showRoomList");
            }
            else {
            	setDepts(request, departments);
                saveErrors(request, errors);
				return mapping.findForward("showAdd");
            }
		}
	}
	
	setDepts(request, departments);
	
       nonUnivLocationForm.setDeptSize(departments.size());
       if (departments.size() == 1) {
       	Department d = departments.iterator().next();
       	nonUnivLocationForm.setDeptCode(d.getDeptCode());
       } else if (sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom) != null) {
		nonUnivLocationForm.setDeptCode((String) sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom));
	}
	
	return mapping.findForward("showAdd");
}
 
Example 9
Source File: RoomFeatureListAction.java    From unitime with Apache License 2.0 4 votes vote down vote up
/**
 * Method execute
 * 
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws HibernateException
 */
public ActionForward execute(ActionMapping mapping, ActionForm form,
		HttpServletRequest request, HttpServletResponse response)
		throws Exception {
	RoomFeatureListForm roomFeatureListForm = (RoomFeatureListForm) form;

	sessionContext.checkPermission(Right.RoomFeatures);

	ActionMessages errors = new ActionMessages();
	
	//get deptCode from request - for user with only one department
	String deptCode = (String)request.getAttribute("deptCode");
	if (deptCode != null) {
		roomFeatureListForm.setDeptCodeX(deptCode);
	}

	if (sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom) != null && roomFeatureListForm.getDeptCodeX() == null) {
		deptCode = (String)sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom);
		if (deptCode != null && ("All".equals(deptCode) || deptCode.matches("Exam[0-9]*")))
			roomFeatureListForm.setDeptCodeX((String)sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom));
	}

	// Set Session Variable
	if (roomFeatureListForm.getDeptCodeX() != null && !roomFeatureListForm.getDeptCodeX().isEmpty())
		sessionContext.setAttribute(SessionAttribute.DepartmentCodeRoom, roomFeatureListForm.getDeptCodeX());
	
	// Validate input
	errors = roomFeatureListForm.validate(mapping, request);

	//set request attribute for department
	LookupTables.setupDepartments(request, sessionContext, true);
	LookupTables.setupExamTypes(request, sessionContext.getUser(), DepartmentStatusType.Status.ExamView, DepartmentStatusType.Status.ExamTimetable);

	// Validation fails
	if (errors.size() > 0) {
		saveErrors(request, errors);
		return mapping.findForward("showRoomFeatureSearch");
	}
	
	roomFeatureListForm.setGlobalRoomFeatures(RoomFeature.getAllGlobalRoomFeatures(sessionContext.getUser().getCurrentAcademicSessionId()));
	
	Set<DepartmentRoomFeature> departmentRoomFeatures = new TreeSet<DepartmentRoomFeature>();
	for (Department d: Department.getUserDepartments(sessionContext.getUser())) {
		if ("All".equals(roomFeatureListForm.getDeptCodeX()) || d.getDeptCode().equals(roomFeatureListForm.getDeptCodeX()))
			departmentRoomFeatures.addAll(RoomFeature.getAllDepartmentRoomFeatures(d));
	}
       if (roomFeatureListForm.getDeptCodeX() != null && !roomFeatureListForm.getDeptCodeX().isEmpty() && !"All".equals(roomFeatureListForm.getDeptCodeX()) && !roomFeatureListForm.getDeptCodeX().matches("Exam[0-9]*")) {
       	Department department = Department.findByDeptCode(roomFeatureListForm.getDeptCodeX(), sessionContext.getUser().getCurrentAcademicSessionId());
       	if (department != null && department.isExternalManager())
       		departmentRoomFeatures.addAll(RoomFeature.getAllDepartmentRoomFeatures(department));
       }
	roomFeatureListForm.setDepartmentRoomFeatures(departmentRoomFeatures);

	buildFeatureTable(request, roomFeatureListForm);
	
	if ("Export PDF".equals(request.getParameter("op"))) {
		sessionContext.checkPermission(Right.RoomFeaturesExportPdf);
		OutputStream out = ExportUtils.getPdfOutputStream(response, "roomFeatures");
		printPdfFeatureTable(out, sessionContext, roomFeatureListForm);
		out.flush(); out.close();
		return null;
	}

	return mapping.findForward("showRoomFeatureList");

}
 
Example 10
Source File: InstructorAddAction.java    From unitime with Apache License 2.0 4 votes vote down vote up
/** 
 * Method execute
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward execute(
	ActionMapping mapping,
	ActionForm form,
	HttpServletRequest request,
	HttpServletResponse response) throws Exception {
	
	super.execute(mapping, form, request, response);
	
	InstructorEditForm frm = (InstructorEditForm) form;
	frm.setMatchFound(null);
	ActionMessages errors = new ActionMessages();
	String op = frm.getOp();
	
       // Cancel adding an instructor - Go back to Instructors screen
       if(op.equals(MSG.actionBackToInstructors())) {
       	response.sendRedirect( response.encodeURL("instructorList.do"));
       	return null;
       }
       
	//get department
	if (sessionContext.getAttribute(SessionAttribute.DepartmentId) != null) {
		String deptId = (String) sessionContext.getAttribute(SessionAttribute.DepartmentId);
		Department d = new DepartmentDAO().get(new Long(deptId));
		frm.setDeptName(d.getName().trim());
		frm.setDeptCode(d.getDeptCode());
	}
	
	sessionContext.checkPermission(frm.getDeptCode(), "Department", Right.InstructorAdd);
			
       //update - Update the instructor and go back to Instructor List Screen
       if(op.equals(MSG.actionSaveInstructor()) ) {
           errors = frm.validate(mapping, request);
           if(errors.size()==0 && isDeptInstructorUnique(frm, request)) {
        	doUpdate(frm, request);
        	response.sendRedirect( response.encodeURL("instructorList.do"));
        	return null;
           } else {
               if (errors.size()==0) {
                   errors.add( "uniqueId", 
                       	new ActionMessage("errors.generic", MSG.errorInstructorIdAlreadyExistsInList()));
           	}
           	saveErrors(request, errors);
           	return mapping.findForward("showAdd");
           }
       }
	
       // lookup 
       if(op.equals(MSG.actionLookupInstructor()) ) {
           errors = frm.validate(mapping, request);
           if(errors.size()==0) {
               findMatchingInstructor(frm, request);
               if (frm.getMatchFound()==null || !frm.getMatchFound().booleanValue()) {
                   errors.add("lookup", 
                           	new ActionMessage("errors.generic", MSG.errorNoMatchingRecordsFound()));
               }
           }
           
       	saveErrors(request, errors);
       	return mapping.findForward("showAdd");
       }
       
       // search select
       if(op.equals(MSG.actionSelectInstructor()) ) {
           String select = frm.getSearchSelect();            
           if (select!=null && select.trim().length()>0) {
            if (select.equalsIgnoreCase("i2a2")) {
                fillI2A2Info(frm, request);
            }
            else {
                fillStaffInfo(frm, request);
            }
           }
           else {
               errors.add("lookup", 
                   	new ActionMessage("errors.generic", MSG.errorNoInstructorSelectedFromList()));
           	saveErrors(request, errors);
           }
       	return mapping.findForward("showAdd");
       }
       
	return mapping.findForward("showAdd");
}
 
Example 11
Source File: DepartmentEditAction.java    From unitime with Apache License 2.0 4 votes vote down vote up
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
	try {
	    
		DepartmentEditForm myForm = (DepartmentEditForm) form;
		MessageResources rsc = getResources(request);
	
		// Check Access
		sessionContext.checkPermission(Right.Departments);
		
		// Read operation to be performed
		String op = (myForm.getOp()!=null?myForm.getOp():request.getParameter("op"));
		
		request.setAttribute(Department.DEPT_ATTR_NAME, Department.findAllNonExternal(sessionContext.getUser().getCurrentAcademicSessionId()));
		
        // Edit
        if(rsc.getMessage("op.edit").equalsIgnoreCase(op)) {
            String id = request.getParameter("id");
            Department department = (new DepartmentDAO()).get(Long.valueOf(id));
            if (department!=null) {
            	if (sessionContext.hasPermission(department, Right.DepartmentLimitedEdit)) {
            		myForm.setFullyEditable(false);
            	} else {
            		myForm.setFullyEditable(true);
            		sessionContext.checkPermission(department, Right.DepartmentEdit);
            	}
            	myForm.load(department);
            	return mapping.findForward("edit");
            }
        }
        
        // Add
        if(rsc.getMessage("button.addDepartment").equalsIgnoreCase(op)) {
           	myForm.reset(mapping, request);
           	myForm.setSessionId(sessionContext.getUser().getCurrentAcademicSessionId());
           	myForm.setInheritInstructorPreferences(true);
           	myForm.setAllowStudentScheduling(true);
           	myForm.setFullyEditable(true);
       		sessionContext.checkPermission(Right.DepartmentAdd);
           	return mapping.findForward("add");
        }
        
        // Update/Save
        if (rsc.getMessage("button.updateDepartment").equalsIgnoreCase(op)
        		|| rsc.getMessage("button.saveDepartment").equalsIgnoreCase(op)) {
            // Validate input
            ActionMessages errors = myForm.validate(mapping, request);
            if(errors.size()>0) {
                saveErrors(request, errors);
                if (myForm.getId()!=null)
                	return mapping.findForward("edit");
                else
                	return mapping.findForward("add");
            } else {
            	if (myForm.getId() == null || myForm.getId().equals(0l))
            		sessionContext.checkPermission(Right.DepartmentAdd);
            	else if (!myForm.isFullyEditable())
            		sessionContext.checkPermission(myForm.getId(), "Department", Right.DepartmentLimitedEdit);
            	else
            		sessionContext.checkPermission(myForm.getId(), "Department", Right.DepartmentEdit);
            	myForm.save(sessionContext);
            }
        }
        
        if ("Add Status".equals(op)) {
        	myForm.addBlankDependentDepartment();
        	return mapping.findForward(myForm.getId() == null ? "add" : "edit");
        }
        
        if ("Delete All".equals(op)) {
        	myForm.deleteAllDependentDepartments();
        	return mapping.findForward(myForm.getId() == null ? "add" : "edit");
        }

        if ("Delete".equals(op) && request.getParameter("deleteId") != null && !request.getParameter("deleteId").isEmpty()) {
        	myForm.deleteDependentDepartment(Integer.parseInt(request.getParameter("deleteId")));
        	return mapping.findForward(myForm.getId() == null ? "add" : "edit");
        }
        
        // Delete
        if(rsc.getMessage("button.deleteDepartment").equalsIgnoreCase(op)) {
        	doDelete(myForm);
        }
        
       	if (myForm.getId()!=null)
          		request.setAttribute(Constants.JUMP_TO_ATTR_NAME, myForm.getId().toString());
       	
        return mapping.findForward("back");
	} catch (Exception e) {
		Debug.error(e);
		throw e;
	}
}
 
Example 12
Source File: RoomListAction.java    From unitime with Apache License 2.0 4 votes vote down vote up
/**
 * Method execute
 * 
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws HibernateException
 */
public ActionForward execute(ActionMapping mapping, ActionForm form,
		HttpServletRequest request, HttpServletResponse response)
		throws Exception {
	
	sessionContext.checkPermission(Right.Rooms);
	
	RoomListForm roomListForm = (RoomListForm) form;
	roomListForm.save(request.getSession());
	ActionMessages errors = new ActionMessages();
	
	//get deptCode from request - for user with only one department
	String dept = (String)request.getAttribute("deptCode");
	if (dept != null) {
		roomListForm.setDeptCodeX(dept);
	}
	
	if (sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom) != null && roomListForm.getDeptCodeX() == null)
		roomListForm.setDeptCodeX((String)sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom));

	// Set Session Variable
	if (roomListForm.getDeptCodeX() != null && !roomListForm.getDeptCodeX().isEmpty()) {
		sessionContext.setAttribute(SessionAttribute.DepartmentCodeRoom, roomListForm.getDeptCodeX());
	}
	
	//set request attribute for department
	LookupTables.setupDepartments(request, sessionContext, true);
	LookupTables.setupExamTypes(request, sessionContext.getUser(), DepartmentStatusType.Status.ExamView, DepartmentStatusType.Status.ExamTimetable);

	// Validate input
	errors = roomListForm.validate(mapping, request);

	// Validation fails
	if (errors.size() > 0) {
		saveErrors(request, errors);
		return mapping.findForward("showRoomSearch");
	}
	
	lookupRooms(roomListForm, request.getParameter("op"));
	
	if (roomListForm.getRooms() == null || roomListForm.getRooms().isEmpty()) {
		errors.add("searchResult", new ActionMessage("errors.generic", "No room matching the above criteria was found."));
		request.setAttribute("colspan","7"); 
		saveErrors(request, errors);
		return mapping.findForward("showRoomSearch");
	}
	
	ExamType examType = null;
	if (roomListForm.getDeptCodeX() != null && roomListForm.getDeptCodeX().matches("Exam[0-9]*"))
		examType = ExamTypeDAO.getInstance().get(Long.valueOf(roomListForm.getDeptCodeX().substring(4)));
	
	if ("Export PDF".equals(request.getParameter("op"))) {
		OutputStream out = ExportUtils.getPdfOutputStream(response, "rooms");
		buildPdfWebTable(out, roomListForm, CommonValues.Yes.eq(UserProperty.RoomFeaturesInOneColumn.get(sessionContext.getUser())), examType);
		out.flush(); out.close();
		return null;
	}
	
	if ("Export CSV".equals(request.getParameter("op"))) {
		PrintWriter pw = ExportUtils.getCsvWriter(response, "rooms");
		buildCsvWebTable(pw, roomListForm, CommonValues.Yes.eq(UserProperty.RoomFeaturesInOneColumn.get(sessionContext.getUser())), examType);
		pw.flush(); pw.close();
		return null;
	}
	
	// build web table for university locations
	buildWebTable(request, roomListForm, CommonValues.Yes.eq(UserProperty.RoomFeaturesInOneColumn.get(sessionContext.getUser())), examType);
	
	return mapping.findForward("showRoomList");

}
 
Example 13
Source File: SubjectAreaEditAction.java    From unitime with Apache License 2.0 4 votes vote down vote up
/** 
 * Method execute
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward execute(
		ActionMapping mapping, 
		ActionForm form,
		HttpServletRequest request, 
		HttpServletResponse response) throws Exception {
	
	// Check Access
	sessionContext.checkPermission(Right.SubjectAreas);
	
	SubjectAreaEditForm frm = (SubjectAreaEditForm) form;
	MessageResources rsc = getResources(request);
	ActionMessages errors=null;
	
	// Read operation to be performed
	String op = (frm.getOp()!=null
					? frm.getOp()
					: request.getParameter("op"));
	
       // Add
       if(op.equals(rsc.getMessage("button.addSubjectArea"))) {
       	sessionContext.checkPermission(Right.SubjectAreaAdd);
   		LookupTables.setupNonExternalDepts(request, sessionContext.getUser().getCurrentAcademicSessionId());
       	return mapping.findForward("addSubjectArea");
       }
       
       // Edit
       if(op.equals(rsc.getMessage("op.edit"))) {
           doLoad(request, frm);
   		LookupTables.setupNonExternalDepts(request, sessionContext.getUser().getCurrentAcademicSessionId());
       	return mapping.findForward("editSubjectArea");
       }
       
       // Update
       if (op.equals(rsc.getMessage("button.updateSubjectArea"))
       		|| op.equals(rsc.getMessage("button.saveSubjectArea")) ) {
           // Validate input
           errors = frm.validate(mapping, request);
           if(errors.size()==0) {
           	doUpdate(request, frm);
           }
       }
       
       // Delete
       if(op.equals(rsc.getMessage("button.deleteSubjectArea"))) {
           errors = frm.validate(mapping, request);
           if(errors.size()==0) {
           	doDelete(request, frm);
           }
       }
       
   	if (frm.getUniqueId()!=null)
      		request.setAttribute(Constants.JUMP_TO_ATTR_NAME, frm.getUniqueId().toString());
   	
   	if (errors!=null && errors.size()>0) {
        saveErrors(request, errors);
		LookupTables.setupNonExternalDepts(request, sessionContext.getUser().getCurrentAcademicSessionId());
        if (frm.getUniqueId()!=null)
        	return mapping.findForward("editSubjectArea");
        else
        	return mapping.findForward("addSubjectArea");
   	}
   	
       return mapping.findForward("back");
}