private User refUser(String name) { for (User user : users) { if (name.equals(user.name())) return user; } return null; }
private void list() { System.out.println("The customers are"); if (users.size() > 0) { for (User user : users) System.out.println(" " + user.toString()); } else { System.out.println(" none"); } }
private void use() { System.out.print(" Name: "); String input = In.nextLine(); User user = refUser(input); if (user != null) user.use(); else System.out.println(" No such customer"); }
/** * Creates a notification to a Group coordinator signaling that a user wants to join their group * * <p>- Requires a groupId request parameter for the GET * * @param req The HTTP Request * @param res The HTTP Response */ public void inviteAction(HttpServletRequest req, HttpServletResponse res) { // Ensure there is a cookie for the session user if (AccountController.redirectIfNoCookie(req, res)) return; Map<String, Object> viewData = new HashMap<String, Object>(); int groupId = Integer.parseInt(req.getParameter("groupId")); try { // Get the session user HttpSession session = req.getSession(); Session userSession = (Session) session.getAttribute("userSession"); User user = userSession.getUser(); // Get the coordinator for the group GroupManager groupMan = new GroupManager(); Group group = groupMan.get(groupId); User coordinator = groupMan.getCoordinator(groupId); // Send a notification to the coordinator for them to permit access to the group NotificationManager notificationMan = new NotificationManager(); Notification notification = new Notification( coordinator.getId(), coordinator, groupId, group, user.getFullName() + " wants to join your group " + group.getGroupName(), "/home/notifications?addUserId=" + user.getId() + "&groupId=" + group.getId()); notificationMan.createNotification(notification); redirectToLocal(req, res, "/home/dashboard"); return; } catch (Exception e) { redirectToLocal(req, res, "/home/dashboard"); } }
/* * Add a new record to the Organization table, * creates an admin account when SA creates a new consulting company * @param OrganizationCode (based on Company Name) * @param OrganizationName (based on Company Description) * @param FKCompanyID * @param NameSequence * @param PKUser * @param nomRater * @throws SQLException * @throws Exception * @author: Mark Oei * @since v.1.3.12.63 09 Mar 2010 */ public boolean addOrganisationByCons( String OrganizationCode, String OrganizationName, int FKCompanyID, int NameSequence, int PKUser, String nomRater) throws SQLException, Exception { Connection con = null; Statement st = null; boolean bIsAdded = false; String sql = "INSERT INTO tblOrganization (OrganizationCode, OrganizationName, FKCompanyID, NameSequence, NominationModule)"; sql = sql + " VALUES ('" + OrganizationCode + "', '" + OrganizationName + "', " + FKCompanyID + ", " + NameSequence + ", '" + Boolean.parseBoolean(nomRater) + "')"; try { con = ConnectionBean.getConnection(); st = con.createStatement(); int iSuccess = st.executeUpdate(sql); System.out.println(iSuccess); if (iSuccess != 0) bIsAdded = true; } catch (Exception E) { System.err.println("Organization.java - AddRecord - " + E); } finally { ConnectionBean.closeStmt(st); // Close statement ConnectionBean.close(con); // Close connection } System.out.println("1. Add Organization"); // add default under the organization. String defaultName = "NA"; int FKOrganization = checkOrgExist(OrganizationCode, OrganizationName, FKCompanyID); // Change to disable print statement. Used for debugging only // Mark Oei 19 Mar 2010 // System.out.println("testing " + FKOrganization); System.out.println("2. Check Organization Exist"); if (FKOrganization != 0) { // Add Division div.addRecord(defaultName, FKOrganization, PKUser); System.out.println("3. Add Division"); // Add Department dept.addRecord(defaultName, FKOrganization, PKUser); System.out.println("4. Add Department"); // Add Group G.addRecord(defaultName, FKOrganization, PKUser); System.out.println("5. Add Group"); // Check whether exists int FKDivision = div.checkDivExist(defaultName, FKOrganization); int FKDepartment = dept.checkDeptExist(defaultName, FKOrganization); int FKGroup = G.checkGroupExist(defaultName, FKOrganization); // Create links dept.linkDepartment(FKDivision, FKDepartment); G.linkGroup(FKDepartment, FKGroup); // Establish new admin account and password Date timeStamp = new java.util.Date(); SimpleDateFormat dFormat = new SimpleDateFormat("ddMMyyHHmmss"); String temp = dFormat.format(timeStamp); String loginName = OrganizationCode + "admin"; String password = OrganizationCode + temp; int userType = 6; // Insert record into database U.addRecord( FKDepartment, FKDivision, userType, "Admin", "Admin", loginName, "NA", "NA", FKGroup, password, 1, FKCompanyID, FKOrganization, "NA", PKUser); System.out.println("6. Add User"); int userExist = U.checkUserExist( FKDepartment, FKDivision, userType, "Admin", "Admin", loginName, "NA", "NA", FKGroup, password, 1, FKCompanyID, FKOrganization); System.out.println( "FKDivision = " + FKDivision + ", FKDepartment = " + FKDepartment + ", FKGroup = " + FKGroup + " and User Exist = " + userExist); if (userExist != 0) { try { U.insertRelation(userExist, userExist, 0); } catch (SQLException SE) { System.out.println(SE.getMessage()); } // Send email notification String content = template.ForgotPass_temp(loginName, password); String email = "*****@*****.**"; // Edited By Roger 13 June 2008 Email.sendMail( server.getAdminEmail(), email, "New Admin Assignment for " + OrganizationName, content, FKOrganization); } System.out.println("8. Add User Relation"); } sDetail = detail.getUserDetail(PKUser); ev.addRecord("Insert", itemName, OrganizationName, sDetail[2], sDetail[11], sDetail[10]); return bIsAdded; } // End Method for addOrganisationByCons
/** * Process the specified HTTP request, and create the corresponding HTTP response (or forward to * another web component that will create it). Return an <code>ActionForward</code> instance * describing where and how control should be forwarded, or <code>null</code> if the response has * already been completed. * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * @exception Exception if business logic throws an exception */ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need MessageResources messages = getResources(request); // save errors ActionMessages errors = new ActionMessages(); // START check for login (security) if (!SecurityService.getInstance().checkForLogin(request.getSession(false))) { return (mapping.findForward("welcome")); } // END check for login (security) // START get id of current project from either request, attribute, or cookie // id of project from request String projectId = null; projectId = request.getParameter("projectViewId"); // check attribute in request if (projectId == null) { projectId = (String) request.getAttribute("projectViewId"); } // id of project from cookie if (projectId == null) { projectId = StandardCode.getInstance().getCookie("projectViewId", request.getCookies()); } // default project to last if not in request or cookie if (projectId == null) { java.util.List results = ProjectService.getInstance().getProjectList(); ListIterator iterScroll = null; for (iterScroll = results.listIterator(); iterScroll.hasNext(); iterScroll.next()) {} iterScroll.previous(); Project p = (Project) iterScroll.next(); projectId = String.valueOf(p.getProjectId()); } Integer id = Integer.valueOf(projectId); // END get id of current project from either request, attribute, or cookie // get project Project p = ProjectService.getInstance().getSingleProject(id); // get user (project manager) User u = UserService.getInstance() .getSingleUserRealName( StandardCode.getInstance().getFirstName(p.getPm()), StandardCode.getInstance().getLastName(p.getPm())); // START process pdf try { PdfReader reader = new PdfReader("C://templates/CL01_001.pdf"); // the template // save the pdf in memory ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); // the filled-in pdf PdfStamper stamp = new PdfStamper(reader, pdfStream); // stamp.setEncryption(true, "pass", "pass", PdfWriter.AllowCopy | PdfWriter.AllowPrinting); AcroFields form1 = stamp.getAcroFields(); Date cDate = new Date(); Integer month = cDate.getMonth(); Integer day = cDate.getDate(); Integer year = cDate.getYear() + 1900; String[] monthName = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; // set the field values in the pdf form // form1.setField("", projectId) form1.setField("currentdate", monthName[month] + " " + day + ", " + year); form1.setField( "firstname", StandardCode.getInstance().noNull(p.getContact().getFirst_name())); form1.setField("pm", p.getPm()); form1.setField("emailpm", u.getWorkEmail1()); if (u.getWorkPhoneEx() != null && u.getWorkPhoneEx().length() > 0) { // ext present form1.setField( "phonepm", StandardCode.getInstance().noNull(u.getWorkPhone()) + " ext " + StandardCode.getInstance().noNull(u.getWorkPhoneEx())); } else { // no ext present form1.setField("phonepm", StandardCode.getInstance().noNull(u.getWorkPhone())); } form1.setField("faxpm", StandardCode.getInstance().noNull(u.getLocation().getFax_number())); form1.setField("postalpm", StandardCode.getInstance().printLocation(u.getLocation())); // START add images // if(u.getPicture() != null && u.getPicture().length() > 0) { // PdfContentByte over; // Image img = Image.getInstance("C:/Program Files (x86)/Apache Software // Foundation/Tomcat 7.0/webapps/logo/images/" + u.getPicture()); // img.setAbsolutePosition(200, 200); // over = stamp.getOverContent(1); // over.addImage(img, 54, 0,0, 65, 47, 493); // } // END add images form1.setField("productname", StandardCode.getInstance().noNull(p.getProduct())); form1.setField("project", p.getNumber() + p.getCompany().getCompany_code()); form1.setField("description", StandardCode.getInstance().noNull(p.getProductDescription())); form1.setField("additional", p.getProjectRequirements()); // get sources and targets StringBuffer sources = new StringBuffer(""); StringBuffer targets = new StringBuffer(""); if (p.getSourceDocs() != null) { for (Iterator iterSource = p.getSourceDocs().iterator(); iterSource.hasNext(); ) { SourceDoc sd = (SourceDoc) iterSource.next(); sources.append(sd.getLanguage() + " "); if (sd.getTargetDocs() != null) { for (Iterator iterTarget = sd.getTargetDocs().iterator(); iterTarget.hasNext(); ) { TargetDoc td = (TargetDoc) iterTarget.next(); if (!td.getLanguage().equals("All")) targets.append(td.getLanguage() + " "); } } } } form1.setField("source", sources.toString()); form1.setField("target", targets.toString()); form1.setField( "start", (p.getStartDate() != null) ? DateFormat.getDateInstance(DateFormat.SHORT).format(p.getStartDate()) : ""); form1.setField( "due", (p.getDueDate() != null) ? DateFormat.getDateInstance(DateFormat.SHORT).format(p.getDueDate()) : ""); if (p.getCompany().getCcurrency().equalsIgnoreCase("USD")) { form1.setField( "cost", (p.getProjectAmount() != null) ? "$ " + StandardCode.getInstance().formatDouble(p.getProjectAmount()) : ""); } else { form1.setField( "cost", (p.getProjectAmount() != null) ? "€ " + StandardCode.getInstance() .formatDouble(p.getProjectAmount() / p.getEuroToUsdExchangeRate()) : ""); } // stamp.setFormFlattening(true); stamp.close(); // write to client (web browser) response.setHeader( "Content-disposition", "attachment; filename=" + p.getNumber() + p.getCompany().getCompany_code() + "-Order-Confirmation" + ".pdf"); OutputStream os = response.getOutputStream(); pdfStream.writeTo(os); os.flush(); } catch (Exception e) { System.err.println("PDF Exception:" + e.getMessage()); throw new RuntimeException(e); } // END process pdf // Forward control to the specified success URI return (mapping.findForward("Success")); }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { JspFactory _jspxFactory = null; javax.servlet.jsp.PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; try { _jspxFactory = JspFactory.getDefaultFactory(); response.setContentType("text/html;charset=ISO-8859-1"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); User user = null; UserFactory userFactory = UserFactory.getInstance(); String userID = request.getParameter("userID"); try { UserFactory.init(); user = userFactory.getUser(userID); } catch (Exception e) { throw new ServletException("Could not find user " + userID + " in user factory.", e); } out.write("\n"); out.write("<html>\n"); out.write("<head>\n "); out.write("<title>WebTelemetry - | User Management | User Detail"); out.write("</title>\n "); out.write("<base HREF=\""); out.print(org.opennms.web.Util.calculateUrlBase(request)); out.write("\" />\n "); out.write( "<link rel=\"stylesheet\" type=\"text/css\" href=\"/wt-portal/css/default.css\" />\n\t"); out.write("<script type=\"text/javascript\" src=\"/wt-portal/javascript/WTtools.js\">"); out.write("</script>\n"); out.write("</head>\n"); out.write("<body>\n"); String title = " User Management - Detail Summary for: " + userID; out.write("\n"); /* ---- c:if ---- */ org.apache.taglibs.standard.tag.el.core.IfTag _jspx_th_c_if_0 = (org.apache.taglibs.standard.tag.el.core.IfTag) _jspx_tagPool_c_if_test.get(org.apache.taglibs.standard.tag.el.core.IfTag.class); _jspx_th_c_if_0.setPageContext(pageContext); _jspx_th_c_if_0.setParent(null); _jspx_th_c_if_0.setTest("${not param.orgAdminPopup}"); int _jspx_eval_c_if_0 = _jspx_th_c_if_0.doStartTag(); if (_jspx_eval_c_if_0 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) { do { out.write("\n "); JspRuntimeLibrary.include( request, response, "/includes/header.jsp" + "?" + "title=" + java.net.URLEncoder.encode("" + title) + "&" + "help=" + "monitoringadmin%2Fusers%2FWTHelp_User.html", out, false); out.write("\n"); int evalDoAfterBody = _jspx_th_c_if_0.doAfterBody(); if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN) break; } while (true); } if (_jspx_th_c_if_0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) return; _jspx_tagPool_c_if_test.reuse(_jspx_th_c_if_0); out.write("\n"); if (_jspx_meth_c_if_1(pageContext)) return; out.write("\n\n"); out.write("<!-- BEGIN FRAMING TABLE:open tags, keep at 100%-->\n"); out.write("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t"); out.write("<tr>\n\t\t"); out.write("<td width=\"10\">"); out.write( "<img src=\"/wt-portal/images/spacers/spacer.gif\" height=\"1\" width=\"10\" border=\"0\" alt=\"WebTelemetry\">"); out.write("</td>\n\t\t"); out.write("<td>\n"); out.write("<!-- END FRAMING TABLE:open tags, keep at 100%-->\n"); out.write("<table width=\"98%\"border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n "); out.write("<tr class=\"tableHeader\">\n "); out.write("<td class=\"tableHeader\" colspan=\"2\">User Information"); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" width=\"25%\">"); out.write("<b>Full Name:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\" width=\"75%\">"); out.print(user.getFullName()); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowDark\">\n "); out.write("<td class=\"tableText\">"); out.write("<b>Comments:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\">"); out.print(user.getUserComments()); out.write("</td>\n "); out.write("</tr>\n"); out.write("</table>\n"); out.write("<br>\n"); out.write("<table width=\"98%\"border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n "); out.write("<tr class=\"tableHeader\">\n "); out.write("<td class=\"tableHeader\" colspan=\"2\">Notification Information"); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" width=\"25%\">"); out.write("<b>Email:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\" width=\"75%\">"); out.print(userFactory.getEmail(userID)); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowDark\">\n "); out.write("<td class=\"tableText\">"); out.write("<b>Pager Email:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\">"); out.print(userFactory.getPagerEmail(userID)); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\">"); out.write("<b>Numerical Service:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\">"); out.print(userFactory.getNumericPage(userID)); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowDark\">\n "); out.write("<td class=\"tableText\">"); out.write("<b>Numerical Pin:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\">"); out.print(userFactory.getNumericPin(userID)); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\">"); out.write("<b>Text Service:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\">"); out.print(userFactory.getTextPage(userID)); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowDark\">\n "); out.write("<td class=\"tableText\">"); out.write("<b>Text Pin:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\">"); out.print(userFactory.getTextPin(userID)); out.write("</td>\n "); out.write("</tr>\n"); out.write("</table>\n"); out.write("<br>\n"); out.write("<table width=\"98%\"border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n "); out.write("<tr class=\"tableHeader\">\n "); out.write("<td class=\"tableHeader\" colspan=\"2\">Duty Schedules"); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" colspan=\"2\">"); out.write("<br />\n "); out.write("<!-- weekly schedule -->\n "); out.write( "<table width=\"50%\" border=\"1\" bordercolor=\"#999999\" cellspacing=\"0\" cellpadding=\"2\" >\n\t\t\t"); Collection dutySchedules = user.getDutyScheduleCollection(); out.write("\n "); int i = 0; Iterator iter = dutySchedules.iterator(); while (iter.hasNext()) { DutySchedule tmp = new DutySchedule((String) iter.next()); Vector curSched = tmp.getAsVector(); i++; out.write("\n "); out.write("<tr>\n "); ChoiceFormat days = new ChoiceFormat("0#Mo|1#Tu|2#We|3#Th|4#Fr|5#Sa|6#Su"); for (int j = 0; j < 7; j++) { Boolean curDay = (Boolean) curSched.get(j); out.write("\n "); out.write("<td width=\"5%\">\n "); out.print((curDay.booleanValue() ? days.format(j) : "X")); out.write("\n "); out.write("</td>\n "); } out.write("\n "); out.write("<td width=\"5%\">\n "); out.print(curSched.get(7)); out.write("\n "); out.write("</td>\n "); out.write("<td width=\"5%\">\n "); out.print(curSched.get(8)); out.write("\n "); out.write("</td>\n "); out.write("</tr>\n "); } out.write("\n "); out.write("</table>\n "); out.write("<!-- end weekly schedule --> \n "); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" colspan=\"2\">"); out.write( "<img src=\"/wt-portal/images/spacers/spacer.gif\" height=\"4\" width=\"10\" border=\"0\" alt=\"WebTelemetry\">"); out.write("</td>\n "); out.write("</tr> \n"); out.write("</table>\n"); out.write("<br>"); out.write("<br>\n"); out.write("<b>Member of the Following Organizations & Groups:"); out.write("</b>\n"); out.write("<!-- BEGIN: NEW ASSIGNED GROUPS TABLE -->\n"); out.write("<table width=\"98%\"border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\n "); // Get the user's orgs WTOrganizationDAO orgDAO = DAOImpl.OrgDAO; WTOrganization[] orgs = orgDAO.getWTOrganization(); if (orgs != null) { // Loop thru orgs for (int idx = 0; idx < orgs.length; idx++) { out.write("\n\n "); out.write("<tr class=\"tableHeader\">\n "); out.write("<td class=\"tableHeader\" colspan=\"2\">Organization Name: "); out.print(orgs[idx].getName()); out.write("</td>\n\t"); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" width=\"25%\">"); out.write("<b>Assigned Groups:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\" width=\"75%\">\n "); // Get the orgs groups WTGroupManager grpMgr = ManagersImpl.GroupManager; int[] orgids = {orgs[idx].getID()}; List groups = grpMgr.getUserGroups(user.getUserId(), orgids); if (groups != null) { // Loop thru the groups for (Iterator iterGrps = groups.iterator(); iterGrps.hasNext(); ) { WTGroup group = (WTGroup) iterGrps.next(); WTRole role = (group.getRoles() == null ? null : (WTRole) group.getRoles().get(0)); out.write("\n "); out.print(group.getName()); out.write(" ("); out.print((role == null ? "" : role.getName())); out.write(")"); out.write("<br/>\n "); } } out.write("\n\n "); out.write("</td>\n\t"); out.write("</tr>\n\n "); } } out.write("\n\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" colspan=\"2\">"); out.write( "<img src=\"/wt-portal/images/spacers/spacer.gif\" height=\"4\" width=\"10\" border=\"0\" alt=\"WebTelemetry\">"); out.write("</td>\n "); out.write("</tr> \n"); out.write("</table>\n"); out.write("<!-- END: NEW ASSIGNED GROUPS TABLE -->\n\n\n"); out.write("<!-- BEGIN FRAMING TABLE:close tags-->\n\t\t"); out.write("</td>\n\t"); out.write("</tr>\n"); out.write("</table>\n"); out.write("<!-- END FRAMING TABLE:close tags-->\n"); out.write("<br>\n\n"); JspRuntimeLibrary.include(request, response, "/includes/footer.jsp", out, false); out.write("\n"); out.write("</body>\n"); out.write("</html>\n\n"); } catch (Throwable t) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (pageContext != null) pageContext.handlePageException(t); } finally { if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext); } }
/** * Displays a given Research Group page for a HTTP Get, or creates a new Group for a HTTP Post * * <p>- Requires a cookie for the session user - Requires a groupId request parameter for a GET - * Requires a groupName, description, createdByUserId request parameters for a POST * * @param req The HTTP Request * @param res The HTTP Response */ public void researchgroupAction(HttpServletRequest req, HttpServletResponse res) { // Ensure there is a cookie for the session user if (AccountController.redirectIfNoCookie(req, res)) return; Map<String, Object> viewData = new HashMap<String, Object>(); viewData.put("title", "Research Group"); if (req.getMethod() == HttpMethod.Get) { // Load group data into Map GroupManager gm = new GroupManager(); int groupId = Integer.parseInt(req.getParameter("groupId")); Group group = gm.get(groupId); if (group != null) { // Load Group into map viewData.put("group", group); // Load group members into Map List<String> groupMembers = gm.getGroupMembers(groupId); viewData.put("groupMembers", groupMembers); // Load meetings into map MeetingManager meetMan = new MeetingManager(); List<Meeting> groupMeetings = meetMan.getGroupMeetings(groupId); viewData.put("groupMeetings", groupMeetings); // Load Document Data into Map DocumentManager docMan = new DocumentManager(); List<Document> groupDocuments = docMan.getGroupDocuments(groupId); viewData.put("groupDocuments", groupDocuments); // Load discussion threads DiscussionManager dm = new DiscussionManager(); viewData.put("groupDiscussions", dm.getThreads(groupId)); // Check if the user is a member boolean isMember = false; HttpSession session = req.getSession(); Session userSession = (Session) session.getAttribute("userSession"); User user = userSession.getUser(); for (Group g : gm.getAllGroups(user.getId())) { if (g.getId() == group.getId()) { isMember = true; break; } } viewData.put("notMember", !isMember); // View group page. view(req, res, "/views/group/ResearchGroup.jsp", viewData); } else { httpNotFound(req, res); } } else if (req.getMethod() == HttpMethod.Post) { // Create Group // Get data from parameters String groupName = req.getParameter("groupName"); String description = req.getParameter("description"); int adminId = Integer.parseInt(req.getParameter("createdByUserId")); // Create the Group GroupManager groupMan = new GroupManager(); Group group = new Group(); group.setGroupName(groupName); group.setDescription(description); group.setCoordinatorId(adminId); // Create the mapping groupMan.createGroup(group); int groupId = groupMan.getIdFor(group); groupMan.createMapping(groupId, adminId); group.setId(groupId); // Update the User Session to show new group HttpSession session = req.getSession(); Session userSession = (Session) session.getAttribute("userSession"); User admin = userSession.getUser(); admin.getGroups().add(group); // Show the Group Page viewData.put("groupName", group.getGroupName()); List<String> groupMembers = groupMan.getGroupMembers(groupId); viewData.put("groupMembers", groupMembers); view(req, res, "/views/group/ResearchGroup.jsp", viewData); } }
/** * Displays the Create Discussion page for a HTTP Get, or creates a Discussion Thread for a HTTP * Post * * <p>- Requires a cookie for the session user - Requires a groupId request parameter for a GET - * Requires a groupId and threadName request parameter for a POST - Requires a document request * part for a POST * * @param req The HTTP Request * @param res The HTTP Response */ public void createDiscussionAction(HttpServletRequest req, HttpServletResponse res) { // Ensure there is a cookie for the session user if (AccountController.redirectIfNoCookie(req, res)) return; Map<String, Object> viewData = new HashMap<>(); if (req.getMethod() == HttpMethod.Get) { viewData.put("title", "Create Discussion"); viewData.put("groupId", req.getParameter("groupId")); view(req, res, "/views/group/CreateDiscussion.jsp", viewData); return; } else if (req.getMethod() == HttpMethod.Post) { // save discussion GroupManager groupMan = new GroupManager(); DiscussionThread thread = new DiscussionThread(); int groupId = Integer.parseInt(req.getParameter("groupId")); thread.setGroupId(groupId); thread.setGroup(groupMan.get(groupId)); thread.setThreadName(req.getParameter("threadName")); DiscussionManager dm = new DiscussionManager(); dm.createDiscussion(thread); try { Part documentPart = req.getPart("document"); // if we have a document to upload if (documentPart.getSize() > 0) { String uuid = DocumentController.saveDocument(this.getServletContext(), documentPart); Document doc = new Document(); doc.setDocumentName(getFileName(documentPart)); doc.setDocumentPath(uuid); doc.setVersionNumber(1); doc.setThreadId(thread.getId()); doc.setGroupId(thread.getGroupId()); DocumentManager docMan = new DocumentManager(); docMan.createDocument(doc); // Get uploading User HttpSession session = req.getSession(); Session userSession = (Session) session.getAttribute("userSession"); User uploader = userSession.getUser(); // Create a notification to all in the group NotificationManager notificationMan = new NotificationManager(); groupMan = new GroupManager(); List<User> groupUsers = groupMan.getGroupUsers(groupId); for (User u : groupUsers) { Notification notification = new Notification( u.getId(), u, groupId, null, "User " + uploader.getFullName() + " has uploaded a document", "/document/document?documentId=" + doc.getId()); notificationMan.createNotification(notification); } } } catch (Exception e) { logger.log(Level.SEVERE, "Document save error", e); } redirectToLocal(req, res, "/group/discussion/?threadId=" + thread.getId()); return; } httpNotFound(req, res); }
/** * Displays a given Meeting page for a HTTP Get, or creates a new Meeting for a HTTP Post * * <p>- Requires a cookie for the session user - Requires a meetingId request parameter for a GET * - Requires description, createdByUserId, datepicker, meetingTime, groupId request parameters * for a POST * * @param req The HTTP Request * @param res The HTTP Response */ public void meetingAction(HttpServletRequest req, HttpServletResponse res) { // Ensure there is a cookie for the session user if (AccountController.redirectIfNoCookie(req, res)) return; Map<String, Object> viewData = new HashMap<String, Object>(); viewData.put("title", "Meeting"); // Initialise Manager connections MeetingManager meetingMan = new MeetingManager(); GroupManager groupMan = new GroupManager(); if (req.getMethod() == HttpMethod.Get) { // Get request parameter int meetingId = Integer.parseInt(req.getParameter("meetingId")); Meeting meeting = meetingMan.get(meetingId); if (meeting != null) { List<User> meetingUsers = groupMan.getGroupUsers(meeting.getGroupId()); viewData.put("meetingUsers", meetingUsers); viewData.put("meeting", meeting); view(req, res, "/views/group/Meeting.jsp", viewData); } else { httpNotFound(req, res); } } else if (req.getMethod() == HttpMethod.Post) { // Get details from request String description = req.getParameter("description"); int createdByUserId = Integer.parseInt(req.getParameter("createdByUserId")); Date dateCreated = new Date(); String meetingDate = req.getParameter("datepicker"); String meetingTime = req.getParameter("meetingTime"); // Parse meeting date time details DateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm"); Date dateDue = new Date(); try { dateDue = format.parse(meetingDate + " " + meetingTime); } catch (ParseException e) { // Unable to parse date. This shouldn't happen since we are // performing javascript validation. } int groupId = Integer.parseInt(req.getParameter("groupId")); // Create a Meeting Meeting meeting = new Meeting(); meeting.setDescription(description); meeting.setCreatedByUserId(createdByUserId); meeting.setDateCreated(dateCreated); meeting.setDateDue(dateDue); meeting.setGroupId(groupId); meetingMan.createMeeting(meeting); int meetingId = meetingMan.getIdFor(meeting); meeting.setId(meetingId); UserManager userMan = new UserManager(); User createdByUser = userMan.get(createdByUserId); // Create a notification for all users in group NotificationManager notificationMan = new NotificationManager(); List<User> users = groupMan.getGroupUsers(groupId); for (User u : users) { Notification notification = new Notification( u.getId(), u, groupId, null, "Meeting " + description + " was created by " + createdByUser.getFullName(), "/group/meeting?meetingId=" + meetingId); notificationMan.createNotification(notification); } // Update the User Session to show new meeting HttpSession session = req.getSession(); Session userSession = (Session) session.getAttribute("userSession"); User admin = userSession.getUser(); admin.getMeetings().add(meeting); // Show meeting page viewData.put("meetingUsers", users); viewData.put("meeting", meeting); view(req, res, "/views/group/Meeting.jsp", viewData); } }