List of usage examples for com.vaadin.server VaadinSession getCurrent
public static VaadinSession getCurrent()
From source file:com.etest.dao.TeamTeachDAO.java
public static boolean removeTeamMember(int teamTeachId, int facultyId) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; boolean result = false; try {//w w w . j ava 2 s . c o m pstmt = conn.prepareStatement( "DELETE FROM team_members " + "WHERE TeamTeachID = ? " + "AND FacultyID = ? "); pstmt.setInt(1, teamTeachId); pstmt.setInt(2, facultyId); pstmt.executeUpdate(); pstmt = conn.prepareStatement( "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? "); pstmt.setInt(1, CommonUtilities .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString())); pstmt.setString(2, "Removed Team Member with FacultyID #" + facultyId); pstmt.executeUpdate(); result = true; } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(TeamTeachDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pstmt.close(); conn.close(); } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(TeamTeachDAO.class.getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.etest.dao.TQCoverageDAO.java
public static boolean insertNewTQCoverage(TopicCoverage coverage, TQItems items, Map<Integer, List<TQAnswerKey>> cellCaseItemKey, Grid grid) { Connection conn = DBConnection.connectToDB(); PreparedStatement tqCoverage = null; PreparedStatement topicCoverage = null; PreparedStatement tqCases = null; PreparedStatement tqItems = null; PreparedStatement tqAnswerKey = null; PreparedStatement pstmt = null; Statement stmt = null;// w w w.ja v a2s .co m ResultSet rs = null; boolean result = false; try { conn.setAutoCommit(false); tqCoverage = conn.prepareStatement( "INSERT INTO tq_coverage SET " + "ExamTitle = ?, " + "CurriculumID = ?, " + "TeamTeachID = ?, " + "DateCreated = now(), " + "TotalHoursCoverage = ?, " + "TotalItems = ? "); tqCoverage.setString(1, coverage.getExamTitle()); tqCoverage.setInt(2, coverage.getCurriculumId()); tqCoverage.setInt(3, coverage.getTeamTeachId()); tqCoverage.setDouble(4, coverage.getTotalHoursCoverage()); tqCoverage.setInt(5, coverage.getTotalItems()); tqCoverage.executeUpdate(); int tqCoverageId = 0; stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT last_insert_id() AS TqCoverageID FROM tq_coverage "); while (rs.next()) { tqCoverageId = CommonUtilities.convertStringToInt(rs.getString("TqCoverageID")); } Collection c = grid.getContainerDataSource().getItemIds(); Iterator iterator = c.iterator(); while (iterator.hasNext()) { Item item = grid.getContainerDataSource().getItem(iterator.next()); topicCoverage = conn.prepareStatement("INSERT INTO topic_coverage SET " + "TqCoverageID = ?, " + "SyllabusID = ?, " + "HoursSpent = ?, " + "Proportion = ?, " + "RememberU = ?, " + "RememberA = ?, " + "UnderstandU = ?, " + "UnderstandA = ?, " + "ApplyU = ?, " + "ApplyA = ?, " + "AnalyzeU = ?, " + "AnalyzeA = ?, " + "EvaluateU = ?, " + "EvaluateA = ?, " + "CreateU = ?, " + "CreateA = ?, " + "TotalItemsRequired = ? "); topicCoverage.setInt(1, tqCoverageId); topicCoverage.setInt(2, coverage.getSyllabusId()); topicCoverage.setDouble(3, (double) item.getItemProperty("Hrs Spent").getValue()); topicCoverage.setDouble(4, (double) item.getItemProperty("Proportion(%)").getValue()); topicCoverage.setInt(5, (item.getItemProperty("Re-U(Pick)").getValue() == null) ? 0 : (int) item.getItemProperty("Re-U(Pick)").getValue()); topicCoverage.setInt(6, (item.getItemProperty("Re-A(Pick)").getValue() == null) ? 0 : (int) item.getItemProperty("Re-A(Pick)").getValue()); topicCoverage.setInt(7, (item.getItemProperty("Un-U(Pick)").getValue() == null) ? 0 : (int) item.getItemProperty("Un-U(Pick)").getValue()); topicCoverage.setInt(8, (item.getItemProperty("Un-A(Pick)").getValue() == null) ? 0 : (int) item.getItemProperty("Un-A(Pick)").getValue()); topicCoverage.setInt(9, (item.getItemProperty("Ap-U(Pick)").getValue() == null) ? 0 : (int) item.getItemProperty("Ap-U(Pick)").getValue()); topicCoverage.setInt(10, (item.getItemProperty("Ap-A(Pick)").getValue() == null) ? 0 : (int) item.getItemProperty("Ap-A(Pick)").getValue()); topicCoverage.setInt(11, (item.getItemProperty("An-U(Pick)").getValue() == null) ? 0 : (int) item.getItemProperty("An-U(Pick)").getValue()); topicCoverage.setInt(12, (item.getItemProperty("An-A(Pick)").getValue() == null) ? 0 : (int) item.getItemProperty("An-A(Pick)").getValue()); topicCoverage.setInt(13, (item.getItemProperty("Ev-U(Pick)").getValue() == null) ? 0 : (int) item.getItemProperty("Ev-U(Pick)").getValue()); topicCoverage.setInt(14, (item.getItemProperty("Ev-A(Pick)").getValue() == null) ? 0 : (int) item.getItemProperty("Ev-A(Pick)").getValue()); topicCoverage.setInt(15, (item.getItemProperty("Cr-U(Pick)").getValue() == null) ? 0 : (int) item.getItemProperty("Cr-U(Pick)").getValue()); topicCoverage.setInt(16, (item.getItemProperty("Cr-A(Pick)").getValue() == null) ? 0 : (int) item.getItemProperty("Cr-A(Pick)").getValue()); topicCoverage.setDouble(17, (double) item.getItemProperty("Max Items").getValue()); topicCoverage.executeUpdate(); } Map<Integer, List<TQAnswerKey>> testMap = cellCaseItemKey; for (Map.Entry<Integer, List<TQAnswerKey>> entrySet : testMap.entrySet()) { Object cellCaseId = entrySet.getKey(); tqCases = conn.prepareStatement("INSERT INTO tq_cases SET " + "TqCoverageID = " + tqCoverageId + ", " + "CellCaseID = " + cellCaseId + " "); tqCases.executeUpdate(); int tqCaseId = 0; stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT last_insert_id() AS TqCaseId FROM tq_cases "); while (rs.next()) { tqCaseId = CommonUtilities.convertStringToInt(rs.getString("TqCaseId")); } List<TQAnswerKey> answerKeyList = entrySet.getValue(); for (TQAnswerKey t : answerKeyList) { tqItems = conn.prepareStatement( "INSERT INTO tq_items SET " + "TqCaseID = ?, " + "CellItemID = ?, " + "ItemKeyID = ? "); tqItems.setInt(1, tqCaseId); tqItems.setInt(2, t.getCellItemId()); tqItems.setInt(3, t.getItemKeyId()); tqItems.executeUpdate(); int tqItemId = 0; stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT last_insert_id() AS TqCaseId FROM tq_cases "); while (rs.next()) { tqItemId = CommonUtilities.convertStringToInt(rs.getString("TqCaseId")); } tqAnswerKey = conn.prepareStatement( "INSERT INTO tq_answer_key SET " + "TqItemID = ?, " + "ItemNo = ?, " + "Answer = ? "); tqAnswerKey.setInt(1, tqItemId); tqAnswerKey.setInt(2, t.getItemNo()); tqAnswerKey.setString(3, t.getAnswer()); tqAnswerKey.executeUpdate(); tqItems = conn.prepareStatement("INSERT INTO key_log_use SET " + "ItemKeyID = ?, " + "DateUsed = now(), " + "TqCoverageID = ? "); tqItems.setInt(1, t.getItemKeyId()); tqItems.setInt(2, tqCoverageId); tqItems.executeUpdate(); if (ItemKeyDAO.isItemKeyInKeyLogUse(t.getItemKeyId())) { tqItems = conn.prepareStatement("UPDATE key_log_use " + "SET UsedItemKey = 1 " + "WHERE ItemKeyID = " + t.getItemKeyId() + " " + "ORDER BY DateUsed ASC LIMIT 1 "); tqItems.executeUpdate(); } } } pstmt = conn.prepareStatement( "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? "); pstmt.setInt(1, CommonUtilities .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString())); pstmt.setString(2, "New TQ Coverage was created with Exam Title: " + coverage.getExamTitle()); pstmt.executeUpdate(); conn.commit(); result = true; } catch (SQLException ex) { try { conn.rollback(); } catch (SQLException ex1) { ErrorDBNotification.showLoggedErrorOnWindow(ex1.toString()); Logger.getLogger(TQCoverageDAO.class.getName()).log(Level.SEVERE, null, ex1); } ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(TQCoverageDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { try { tqCoverage.close(); topicCoverage.close(); tqCases.close(); tqItems.close(); stmt.close(); rs.close(); conn.close(); } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(TQCoverageDAO.class.getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.etest.dao.TQCoverageDAO.java
public static boolean approveTQCoverage(int tqCoverageId) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; boolean result = false; try {//from www .j a v a 2s . co m conn.setAutoCommit(false); pstmt = conn.prepareStatement( "UPDATE tq_coverage " + "SET Status = 1 " + "WHERE TqCoverageID = " + tqCoverageId + " "); pstmt.executeUpdate(); pstmt = conn.prepareStatement( "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? "); pstmt.setInt(1, CommonUtilities .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString())); pstmt.setString(2, "Approved TQ Coverage with TqCoverageID #" + tqCoverageId); pstmt.executeUpdate(); conn.commit(); result = true; } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(TQCoverageDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pstmt.close(); conn.close(); } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(TQCoverageDAO.class.getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.etest.dao.TQCoverageDAO.java
public static boolean deleteTQCoverage(int tqCoverageId) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; boolean result = false; try {/* w w w. j a va 2 s . c o m*/ conn.setAutoCommit(false); pstmt = conn .prepareStatement("DELETE FROM tq_coverage " + "WHERE TqCoverageID = " + tqCoverageId + " "); pstmt.executeUpdate(); pstmt = conn.prepareStatement( "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? "); pstmt.setInt(1, CommonUtilities .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString())); pstmt.setString(2, "Removed TQ Coverage with TqCoverageID #" + tqCoverageId); pstmt.executeUpdate(); conn.commit(); result = true; } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(TQCoverageDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pstmt.close(); conn.close(); } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(TQCoverageDAO.class.getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.etest.dao.TQCoverageDAO.java
public static boolean saveItemAnalysis(Grid grid, int tqCoverageId) { Connection conn = DBConnection.connectToDB(); Statement stmt = null;/* www . j a v a 2 s .c om*/ ResultSet rs = null; PreparedStatement pstmt = null; boolean result = false; try { conn.setAutoCommit(false); Collection c = grid.getContainerDataSource().getItemIds(); Iterator iterator = c.iterator(); while (iterator.hasNext()) { Item item = grid.getContainerDataSource().getItem(iterator.next()); Collection x = item.getItemPropertyIds(); Iterator it = x.iterator(); Object propertyId; while (it.hasNext()) { propertyId = it.next(); if (propertyId.equals("itemId")) { stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT Analyzed FROM cell_items " + "WHERE CellItemID = " + item.getItemProperty(propertyId).getValue() + " "); while (rs.next()) { if (rs.getString("Analyzed").equals("0")) { pstmt = conn.prepareStatement("UPDATE cell_items SET " + "DifficultIndex = ?, " + "DiscriminationIndex = ?, " + "Analyzed = ? " + "WHERE CellItemID = " + item.getItemProperty(propertyId).getValue() + " "); pstmt.setDouble(1, CommonUtilities.convertStringToDouble( item.getItemProperty("difficulty index").getValue().toString())); pstmt.setDouble(2, CommonUtilities.convertStringToDouble( item.getItemProperty("discrimination index").getValue().toString())); pstmt.setInt(3, 1); pstmt.executeUpdate(); } } pstmt = conn.prepareStatement("UPDATE tq_coverage SET " + "Analyzed = 1 " + "WHERE TqCoverageID = " + tqCoverageId + " "); pstmt.executeUpdate(); } } } pstmt = conn.prepareStatement( "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? "); pstmt.setInt(1, CommonUtilities .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString())); pstmt.setString(2, "New Item Analysis was performed with TqCoverageID #" + tqCoverageId); pstmt.executeUpdate(); conn.commit(); result = true; } catch (SQLException ex) { try { conn.rollback(); } catch (SQLException ex1) { ErrorDBNotification.showLoggedErrorOnWindow(ex1.toString()); Logger.getLogger(TQCoverageDAO.class.getName()).log(Level.SEVERE, null, ex1); } ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(TQCoverageDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { try { stmt.close(); rs.close(); pstmt.close(); conn.close(); } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(TQCoverageDAO.class.getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.etest.dao.UsersDAO.java
public static boolean loginResult(String username, String password) { Connection conn = DBConnection.connectToDB(); Statement stmt = null;/*ww w .j av a2s. c o m*/ ResultSet rs = null; PreparedStatement pstmt = null; boolean result = false; try { stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT * FROM users " + "WHERE Username_ = '" + username + "' " + "AND Password_ = '" + password + "' "); while (rs.next()) { VaadinSession.getCurrent().setAttribute("username", rs.getString("Username_")); VaadinSession.getCurrent().setAttribute("userId", rs.getString("UserID")); VaadinSession.getCurrent().setAttribute("userType", rs.getString("UserType")); VaadinSession.getCurrent().setAttribute("facultyId", rs.getString("FacultyID")); result = true; } if (result) { pstmt = conn.prepareStatement("INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? "); pstmt.setInt(1, CommonUtilities .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString())); pstmt.setString(2, "Logged In!"); pstmt.executeUpdate(); } } catch (SQLException ex) { ErrorDBNotification.errorNotificationOnDBAccess("Severe Login ERROR"); ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(UsersDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { try { stmt.close(); rs.close(); if (result) { pstmt.close(); } conn.close(); } catch (SQLException ex) { ErrorDBNotification.errorNotificationOnDBAccess("Cannot close DB Connection"); ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(UsersDAO.class.getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.etest.serviceprovider.UsersServiceImpl.java
@Override public void logout() { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; try {// w w w . j a v a2 s.co m pstmt = conn.prepareStatement( "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? "); pstmt.setInt(1, CommonUtilities .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString())); pstmt.setString(2, "Logged Out!"); pstmt.executeUpdate(); } catch (SQLException ex) { Logger.getLogger(UsersServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.etest.view.notification.NotificationMainUI.java
public NotificationMainUI() { setSizeFull();//from ww w .j a v a2s. co m setSpacing(true); if (VaadinSession.getCurrent().getAttribute("userId") == null) { Page.getCurrent().setLocation("http://localhost:8080/"); } else { addComponent(populateNoficationTable()); } HorizontalLayout h = new HorizontalLayout(); h.setWidth("950px"); Button sendMsgBtn = new Button("Send Message"); sendMsgBtn.setWidthUndefined(); sendMsgBtn.addStyleName(ValoTheme.BUTTON_SMALL); sendMsgBtn.addStyleName(ValoTheme.BUTTON_PRIMARY); sendMsgBtn.addClickListener((Button.ClickEvent event) -> { Notification.show("Send Message!"); }); h.addComponent(sendMsgBtn); h.setComponentAlignment(sendMsgBtn, Alignment.MIDDLE_RIGHT); addComponent(h); }
From source file:com.etest.view.notification.NotificationMainUI.java
Table populateNoficationTable() { notificationTable.removeAllItems();//from w ww . ja va 2 s. c om int i = 0; for (EtestNotification en : ns.getAllNotificationByUser( CommonUtilities.convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()))) { VerticalLayout v = new VerticalLayout(); v.setWidth("100%"); Button read = new Button(); read.setWidthUndefined(); read.setCaption((en.getStatus() == 0) ? "unread" : "read"); read.setData(en.getNotificationId()); read.setIcon(FontAwesome.VIDEO_CAMERA); read.addStyleName(ValoTheme.BUTTON_LINK); read.addStyleName(ValoTheme.BUTTON_TINY); read.addStyleName(ValoTheme.BUTTON_QUIET); read.addStyleName("button-container"); read.addClickListener(buttonClickListener); v.addComponent(read); v.setComponentAlignment(read, Alignment.MIDDLE_LEFT); message.setContentMode(ContentMode.HTML); String[] split = en.getNotice().split(" "); int cellCaseId; if (split[0].equals("CellCaseID")) { message.setCaption(en.getRemarks() + en.getNotice()); cellCaseId = CommonUtilities.convertStringToInt(split[1].replace("#", "")); } else { cellCaseId = cis.getCellItemById(CommonUtilities.convertStringToInt(split[1].replace("#", ""))) .getCellCaseId(); message.setCaption(en.getRemarks() + en.getNotice() + " from CellCaseID #" + cellCaseId); } Button approve = new Button("status"); approve.setSizeFull(); approve.addStyleName(ValoTheme.BUTTON_LINK); approve.addStyleName(ValoTheme.BUTTON_TINY); approve.addStyleName(ValoTheme.BUTTON_QUIET); approve.addStyleName("button-container"); v.addComponent(approve); v.setComponentAlignment(approve, Alignment.MIDDLE_LEFT); if (ccs.getCellCaseById(cellCaseId).getApprovalStatus() == 0) { approve.setIcon(FontAwesome.THUMBS_DOWN); } else { approve.setIcon(FontAwesome.THUMBS_UP); } notificationTable.addItem(new Object[] { message.getCaption().toString(), ss.getUsernameById(en.getSenderId()), en.getNoteDate(), v }, i); i++; } notificationTable.setPageLength(0); notificationTable.setHeight("100%"); return notificationTable; }
From source file:com.firstbanknigeria.ofsaaenhancers.UI.AdjustmentUI.java
public AdjustmentUI() { super("Load Adjustments"); this.setWidth("1000px"); this.setHeight("250px"); objectContext = ObjectStore.getObjectContext(VaadinSession.getCurrent().getSession().getId()); final VerticalLayout layout = new VerticalLayout(); layout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER); layout.setSpacing(true);// www.ja v a 2s .c om AdjustmentFileProcessor adjFileProcessor = new AdjustmentFileProcessor(); adjFileProcessor.setAdjustmentUI(this); Upload uploadComponent = new Upload("", adjFileProcessor); uploadComponent.addSucceededListener(adjFileProcessor); uploadComponent.setButtonCaption("Upload Adjustments"); uploadComponent.setImmediate(true); Button runAdjustmenstButton = new Button("Run Adjustments"); runAdjustmenstButton.addClickListener(new Button.ClickListener() { public void buttonClick(Button.ClickEvent e) { ProcedureQuery query = new ProcedureQuery("RUN_ADJUSTMENTS"); QueryResponse response = objectContext.performGenericQuery(query); } }); layout.addComponents(uploadComponent, runAdjustmenstButton); layout.setMargin(true); layout.setSpacing(true); setContent(layout); }