-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Police Officer Dashboard Controller (#39)
* fix : Typo in getMethod * feat: Created Police Officer Model * feat: Added Police Officer Session * feat: Added Police Session * feat : Added PoliceOfficer Login Handler * feat: Added PoliceDashboard Controller(Work in progress) * fix :formatting * feat: Finish police verification controller Co-authored-by: Vishwas-Adiga <[email protected]>
- Loading branch information
1 parent
e632461
commit 33e384a
Showing
13 changed files
with
416 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
200 changes: 200 additions & 0 deletions
200
SIMPLE/src/edu/manipal/icas/simple/controllers/PoliceDashboardViewController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
package edu.manipal.icas.simple.controllers; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.awt.event.WindowAdapter; | ||
import java.awt.event.WindowEvent; | ||
import java.util.List; | ||
import java.util.ResourceBundle; | ||
|
||
import javax.swing.JComboBox; | ||
import javax.swing.JFrame; | ||
import javax.swing.JOptionPane; | ||
import javax.swing.JPanel; | ||
import javax.swing.table.DefaultTableModel; | ||
|
||
import org.icepdf.ri.common.SwingController; | ||
import org.icepdf.ri.common.SwingViewBuilder; | ||
import org.icepdf.ri.util.PropertiesManager; | ||
|
||
import edu.manipal.icas.simple.models.PoliceOfficer; | ||
import edu.manipal.icas.simple.models.application.AcceptedDocumentType; | ||
import edu.manipal.icas.simple.models.application.Application; | ||
import edu.manipal.icas.simple.models.application.ApplicationStatus; | ||
import edu.manipal.icas.simple.session.PoliceOfficerSession; | ||
import edu.manipal.icas.simple.session.Session; | ||
import edu.manipal.icas.simple.views.PoliceDashboardView; | ||
import edu.manipal.icas.simple.views.View; | ||
|
||
public class PoliceDashboardViewController { | ||
|
||
private PoliceDashboardView poView; | ||
private Session session; | ||
private Application application; | ||
private PoliceOfficer policeOfficer; | ||
|
||
public PoliceDashboardViewController(PoliceDashboardView poView) { | ||
this.poView = poView; | ||
application = null; | ||
|
||
poView.getFrame().addWindowListener(new WindowAdapter() { | ||
@Override | ||
public void windowOpened(WindowEvent e) { | ||
session = SessionController.getController().getCurrentSession(); | ||
policeOfficer = ((PoliceOfficerSession) session).getOfficer(); | ||
initPoliceOfficerFields(); | ||
} | ||
}); | ||
|
||
initLogOutHandlers(); | ||
initAppplicationNavigationButtons(); | ||
|
||
} | ||
|
||
private void initPoliceOfficerFields() { | ||
final List<Application> applications = policeOfficer.getApplications(); | ||
poView.getOfficerIdLabel().setText("" + policeOfficer.getBadgeId()); | ||
poView.getApplicationIdComboBox().removeAllItems(); | ||
for (Application application : applications) { | ||
poView.getApplicationIdComboBox().addItem(application.getApplicationId()); | ||
} | ||
|
||
poView.getApplicationIdComboBox().addActionListener(new ActionListener() { | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
application = applications.get(poView.getApplicationIdComboBox().getSelectedIndex()); | ||
boolean editable = application.getStatus() == ApplicationStatus.PENDING_ADDRESS_VERIFICATION; | ||
poView.getIncompleteButton().setEnabled(editable); | ||
poView.getAdverseButton().setEnabled(editable); | ||
poView.getClearButton().setEnabled(editable); | ||
} | ||
}); | ||
|
||
try { | ||
poView.getApplicationIdComboBox().setSelectedIndex(0); | ||
} catch (Exception e) { | ||
// officer has no applications to process | ||
} | ||
|
||
DefaultTableModel model = (DefaultTableModel) poView.getPendingVerificationTable().getModel(); | ||
for (int i = model.getRowCount() - 1; i >= 0; --i) { | ||
model.removeRow(i); | ||
} | ||
|
||
for (Application app : applications) { | ||
model.addRow( | ||
new Object[] { app.getApplicationId(), app.getApplicant().getName(), app.getPresentAddress() }); | ||
} | ||
|
||
poView.getAdverseButton().addActionListener(new ActionListener() { | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
policeOfficer.verifyAddress(application.getApplicant(), | ||
application.getDocument(AcceptedDocumentType.ADDRESS_PROOF)); | ||
application.setStatus(ApplicationStatus.ADDRESS_VERIFICATION_ADVERSE); | ||
application.setStatus(ApplicationStatus.REJECTED); | ||
disableButtons(); | ||
} | ||
}); | ||
|
||
poView.getClearButton().addActionListener(new ActionListener() { | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
policeOfficer.verifyAddress(application.getApplicant(), | ||
application.getDocument(AcceptedDocumentType.ADDRESS_PROOF)); | ||
application.setStatus(ApplicationStatus.ADDRESS_VERIFICATION_CLEAR); | ||
application.setStatus(ApplicationStatus.COMPLETED_AND_SUCCESSFUL); | ||
disableButtons(); | ||
} | ||
}); | ||
|
||
poView.getIncompleteButton().addActionListener(new ActionListener() { | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
policeOfficer.verifyAddress(application.getApplicant(), | ||
application.getDocument(AcceptedDocumentType.ADDRESS_PROOF)); | ||
application.setStatus(ApplicationStatus.ADDRESS_VERIFICATION_INCOMPLETE); | ||
application.setStatus(ApplicationStatus.REJECTED); | ||
disableButtons(); | ||
} | ||
}); | ||
|
||
poView.getViewDocumentButton().addActionListener(new ActionListener() { | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
PropertiesManager properties = new PropertiesManager(System.getProperties(), | ||
ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE)); | ||
properties.setBoolean("application.viewerpreferences.hidetoolbar", Boolean.TRUE); | ||
SwingController pdfController = new SwingController(); | ||
pdfController.openDocument(application.getDocument(AcceptedDocumentType.ADDRESS_PROOF).getPath()); | ||
|
||
SwingViewBuilder factory = new SwingViewBuilder(pdfController, properties); | ||
JFrame frame = new JFrame(); | ||
frame.add(factory.buildViewerPanel()); | ||
frame.setSize(1000, 1000); | ||
frame.setVisible(true); | ||
} | ||
}); | ||
} | ||
|
||
public View getPoliceOfficerView() { | ||
return poView; | ||
} | ||
|
||
private void initLogOutHandlers() { | ||
ActionListener logOutListener = new ActionListener() { | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
SessionController.getController().endCurrentSession(); | ||
RouteController.getController().routeTo(Route.OFFICER_LOGIN); | ||
} | ||
}; | ||
poView.getLogOutButton().addActionListener(logOutListener); | ||
} | ||
|
||
private void initAppplicationNavigationButtons() { | ||
poView.getNextApplicationIdButton() | ||
.addActionListener(new NavigationListener(poView.getApplicationIdComboBox(), true)); | ||
poView.getPreviousApplicationIdButton() | ||
.addActionListener(new NavigationListener(poView.getApplicationIdComboBox(), false)); | ||
|
||
} | ||
|
||
private void showError(String message) { | ||
JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE); | ||
} | ||
|
||
private class NavigationListener implements ActionListener { | ||
private JComboBox<?> comboBox; | ||
private boolean isEventForNavigatingToNext; | ||
|
||
NavigationListener(JComboBox<?> comboBox, boolean flag) { | ||
this.comboBox = comboBox; | ||
isEventForNavigatingToNext = flag; | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent event) { | ||
int newIndex = comboBox.getSelectedIndex() + (isEventForNavigatingToNext ? 1 : -1); | ||
if (newIndex < 0 || newIndex >= comboBox.getItemCount()) { | ||
showError("You've reached the end of the list!"); | ||
return; | ||
} | ||
comboBox.setSelectedIndex(newIndex); | ||
} | ||
|
||
} | ||
|
||
private void disableButtons() { | ||
poView.getAdverseButton().setEnabled(false); | ||
poView.getClearButton().setEnabled(false); | ||
poView.getIncompleteButton().setEnabled(false); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
package edu.manipal.icas.simple.impl.databases; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.healthmarketscience.jackcess.Row; | ||
import com.healthmarketscience.jackcess.Table; | ||
|
||
import edu.manipal.icas.simple.databases.PoliceDatabase; | ||
|
||
/** | ||
* Concrete class that implements persistence API operations from | ||
* {@link PoliceDatabase} | ||
* | ||
* | ||
* @author Vishwas Adiga ([email protected]) | ||
* | ||
*/ | ||
|
@@ -16,7 +23,7 @@ private MsAccessPoliceDatabase() { | |
super("Police"); | ||
} | ||
|
||
public static MsAccessPoliceDatabase geDatabase() { | ||
public static MsAccessPoliceDatabase getDatabase() { | ||
return DATABASE; | ||
} | ||
|
||
|
@@ -25,4 +32,25 @@ public Boolean policeExists(Integer badgeId) { | |
return rowExists(badgeId); | ||
} | ||
|
||
@Override | ||
public List<Integer> fetchApplications(Integer badgeId) throws IOException { | ||
List<Integer> applicationIds = new ArrayList<>(); | ||
|
||
Table applicationsTable = MsAccessApplicationDatabase.getDatabase().table; | ||
Row row = null; | ||
while ((row = applicationsTable.getNextRow()) != null) { | ||
try { | ||
String applicantId = row.getString(MsAccessApplicationDatabase.FIELD_APPLICANT_ID); | ||
Integer rowBadgeId = MsAccessCitizenDatabase.getDatabase().fetchPoliceBadgeId(applicantId); | ||
if (rowBadgeId == badgeId) { | ||
applicationIds.add(row.getInt(MsAccessApplicationDatabase.FIELD_ID)); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
continue; | ||
} | ||
} | ||
return applicationIds; | ||
} | ||
|
||
} |
Oops, something went wrong.