private void printRemainingDataSourcesList(PrintWriter out, User user, ConnectToDB ctdb) throws SQLException { DataSource dataSource = null; String dataSourceName = null; Vector remainingDataSourcesList = ctdb.getDataSourceListsDifference( this.dataSourceVectorForDataSourceNames( ctdb.getValuesVectorForOneColumnUnderOneCondition( new Column("DATASOURCENAME"), new Column("ISCANDIDATE", "no"), "ACDATASOURCE")), user.getDataSourceList()); if (remainingDataSourcesList.size() == 0) { out.println("<table class=transparenttable>"); out.println("<tr><td><FONT COLOR=#000000>No virtaul sensor is available.</td></tr>"); out.println("</table>"); } else { out.println("<table>"); out.println("<tr><th> virtual sensor name </th>"); out.println("<th> access right</th></tr>"); for (int i = 0; i < remainingDataSourcesList.size(); i++) { dataSource = (DataSource) (remainingDataSourcesList.get(i)); dataSourceName = dataSource.getDataSourceName(); if (ctdb.valueExistsForThisColumnUnderTwoConditions( new Column("ISUSERWAITING", "yes"), new Column("USERNAME", user.getUserName()), new Column("DATASOURCENAME", dataSource.getDataSourceName()), "ACUSER_ACDATASOURCE")) { out.println("<tr><td>" + dataSourceName + " </td>"); } else { out.println("<FORM ACTION=/gsn/MyUpdateUserWaitingForDataSourceServlet METHOD=POST>"); out.println("<tr><td>" + dataSourceName + " </td>"); out.println("<td><INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 1> read "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 2> write "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=3> read/write "); } if (ctdb.valueExistsForThisColumnUnderTwoConditions( new Column("ISUSERWAITING", "yes"), new Column("USERNAME", user.getUserName()), new Column("DATASOURCENAME", dataSource.getDataSourceName()), "ACUSER_ACDATASOURCE")) { out.println("<td>" + "<FONT COLOR=#0000FF>in updates waiting list!</td></tr>"); } else { out.println( "   <INPUT TYPE=SUBMIT TYPE=SUBMIT class= buttonstyle VALUE=\"add\"></td></tr>"); out.println("</FORM>"); } } out.println("</table>"); } }
/** * ************************************************************************************************* */ public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); ConnectToDB ctdb = null; // Get the session HttpSession session = req.getSession(); User user = (User) session.getAttribute("user"); if (user == null) { this.redirectToLogin(req, res); } else { this.checkSessionScheme(req, res); if (user.isAdmin() == false) { res.sendError(WebConstants.ACCESS_DENIED, "Access denied."); } else { this.printHeader(out); this.printLayoutMastHead(out, user); this.printLayoutContent(out); try { ctdb = new ConnectToDB(); Vector waitingUsers = ctdb.getWaitingUsers(); if (waitingUsers.size() == 0) { out.println("<p><B> There is no entry in the waiting user list !</B> </p>"); } for (int i = 0; i < waitingUsers.size(); i++) { // printForm(out,(User)(waitingUsers.get(i))); this.printNewEntry(out, (User) (waitingUsers.get(i))); } } catch (Exception e) { out.println("<p><B> Can not print the form</B> </p>"); logger.error("ERROR IN DOGET"); logger.error(e.getMessage(), e); } finally { if (ctdb != null) { ctdb.closeStatement(); ctdb.closeConnection(); } } // out.println("</BODY>"); this.printLayoutFooter(out); } } }
public static void FillMusicType() { PreparedStatement ps = null; Connection conn; String sql = "INSERT INTO music_type (type_name) VALUES (?)"; try { conn = ConnectToDB.getConnection(); ps = conn.prepareStatement(sql); ps.setString(1, "Rock"); ps.executeUpdate(); ps.setString(1, "Rap"); ps.executeUpdate(); ps.setString(1, "Club"); ps.executeUpdate(); ps.setString(1, "Classic"); ps.executeUpdate(); ps.setString(1, "Jazz"); ps.executeUpdate(); ps.setString(1, "Funk"); ps.executeUpdate(); } catch (SQLException e1) { e1.printStackTrace(); } finally { if (ps != null) { try { ps.close(); } catch (Exception e) { } } } }
private void printRemainingGroupsList(PrintWriter out, User user, ConnectToDB ctdb) throws SQLException { Vector remainingGroupList = ctdb.getGroupListsDifference(ctdb.getGroupList(), user.getGroupList()); Group group = null; String groupName = null; String userName = user.getUserName(); if (remainingGroupList.size() == 0) { out.println("<table class =transparenttable>"); out.println("<tr><td><FONT COLOR=#000000>No group is available.</td></tr>"); out.println("</table>"); } else { out.println("<table>"); out.println("<tr>"); out.println("<th>group name</th>"); out.println("<th>group structure</th>"); out.println("<th>updates</th>"); out.println("</tr>"); for (int i = 0; i < remainingGroupList.size(); i++) { group = (Group) (remainingGroupList.get(i)); groupName = group.getGroupName(); out.println("<tr>"); out.println("<td>" + groupName + "</td>"); this.printGroupStructureLink(out, groupName); if (ctdb.valueExistsForThisColumnUnderTwoConditions( new Column("ISUSERWAITING", "yes"), new Column("GROUPNAME", groupName), new Column("USERNAME", userName), "ACUSER_ACGROUP") == false) { out.println("<FORM ACTION=/gsn/MyUpdateUserWaitingForGroupServlet METHOD=POST>"); out.println("<INPUT TYPE=HIDDEN NAME=groupname VALUE=" + groupName + ">"); out.println("<INPUT TYPE=HIDDEN NAME=addgroup VALUE=Yes>"); out.println( "<td style=text-align:center><INPUT TYPE=SUBMIT class= buttonstyle VALUE=\"add\"></td>"); out.println("</FORM>"); } else { out.println("<td>" + "<FONT COLOR=#0000FF>in updates waiting list!</td>"); } out.println("</tr>"); } out.println("</table>"); } }
/// gsn/MyLogoutHandlerServlet private void printForm(PrintWriter out, User user) { ConnectToDB ctdb = null; try { ctdb = new ConnectToDB(); this.printLayoutMastHead(out, user); this.printLayoutContent(out, user, ctdb); this.printLayoutSideBar(out, user, ctdb); this.printLayoutFooter(out); } catch (Exception e) { logger.error("ERROR IN printForm"); logger.error(e.getMessage(), e); } finally { if (ctdb != null) { ctdb.closeStatement(); ctdb.closeConnection(); } } }
public static void main(String args[]) { FillTablesRoleAndMusicTypes.FillRole(); FillTablesRoleAndMusicTypes.FillMusicType(); Role role = new Role(2, "Moderator"); Address address = new Address(4, "coury", "steeeet", 6122); MusicType type1 = new MusicType(1, "rock"); MusicType type2 = new MusicType(3, "rap"); Set<MusicType> MT = new HashSet<MusicType>(); MT.add(type1); MT.add(type2); User user2 = new User(1, "login", "paword", "ftname", "ltname", 58, address, role, MT); UserDaoImpl Ivan2 = new UserDaoImpl(); try { Ivan2.delete(user2); } catch (SQLException e) { e.printStackTrace(); } ConnectToDB.closeConn(); }
public static void FillRole() { PreparedStatement ps = null; Connection conn; String sql = "INSERT INTO role (role_name) VALUES (?)"; try { conn = ConnectToDB.getConnection(); ps = conn.prepareStatement(sql); ps.setString(1, "Registered"); ps.executeUpdate(); ps.setString(1, "Moderator"); ps.executeUpdate(); ps.setString(1, "Administrator"); ps.executeUpdate(); } catch (SQLException e1) { e1.printStackTrace(); } finally { if (ps != null) { try { ps.close(); } catch (Exception e) { } } } }
private void printUserDataSourceList(PrintWriter out, User user, ConnectToDB ctdb) throws SQLException { DataSource dataSource = null; String dataSourceName = null; String dataSourceType = null; if (user.getDataSourceList().size() == 0) { out.println("<table class =transparenttable>"); out.println("<tr><td><FONT COLOR=#000000>No virtaul sensor is available.</td></tr>"); out.println("</table>"); } else { out.println("<table>"); out.println("<tr><th> virtual sensor name </th>"); out.println("<th> access right</th></tr>"); for (int j = 0; j < user.getDataSourceList().size(); j++) { dataSource = (DataSource) user.getDataSourceList().get(j); dataSourceName = dataSource.getDataSourceName(); dataSourceType = dataSource.getDataSourceType(); if (dataSourceType.equals("4")) { out.println("<tr><td>" + dataSourceName + " </td>"); out.println("<td>own</td></tr>"); } else { if (ctdb.valueExistsForThisColumnUnderTwoConditions( new Column("ISUSERWAITING", "yes"), new Column("USERNAME", user.getUserName()), new Column("DATASOURCENAME", dataSourceName), "ACUSER_ACDATASOURCE")) { out.println("<tr><td>" + dataSourceName + " </td>"); } else { out.println("<FORM ACTION=/gsn/MyUpdateUserWaitingForDataSourceServlet METHOD=POST>"); out.println("<tr><td>" + dataSourceName + " </td>"); if (dataSourceType.charAt(0) == '1') { out.println( "<td><INPUT CHECKED TYPE=RADIO NAME=" + dataSourceName + " VALUE= 1>read"); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 2>write "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=3>read/write"); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=0>delete "); } if (dataSourceType.charAt(0) == '2') { out.println("<td><INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 1> read "); out.println("<INPUT CHECKED TYPE=RADIO NAME=" + dataSourceName + " VALUE= 2> write "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=3> read/write "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=0> delete "); } if (dataSourceType.charAt(0) == '3') { out.println("<td><INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 1> read "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 2> write "); out.println( "<INPUT CHECKED TYPE=RADIO NAME=" + dataSourceName + " VALUE=3> read/write "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=0> delete "); } } if (ctdb.valueExistsForThisColumnUnderTwoConditions( new Column("ISUSERWAITING", "yes"), new Column("USERNAME", user.getUserName()), new Column("DATASOURCENAME", dataSourceName), "ACUSER_ACDATASOURCE")) { out.println("<td>" + "<FONT COLOR=#0000FF>in updates waiting list!</td></tr>"); } else { out.println( "   <INPUT TYPE=SUBMIT class= buttonstyle VALUE=\"update\"></td></tr>"); out.println("</FORM>"); } } } out.println("</table>"); } }