aboutsummaryrefslogtreecommitdiff
path: root/src/uk/org/ury/library
diff options
context:
space:
mode:
Diffstat (limited to 'src/uk/org/ury/library')
-rw-r--r--src/uk/org/ury/library/LibraryItem.java446
-rw-r--r--src/uk/org/ury/library/viewer/LibraryViewer.java197
-rw-r--r--src/uk/org/ury/library/viewer/LibraryViewerPanel.java130
3 files changed, 773 insertions, 0 deletions
diff --git a/src/uk/org/ury/library/LibraryItem.java b/src/uk/org/ury/library/LibraryItem.java
new file mode 100644
index 0000000..0e44be5
--- /dev/null
+++ b/src/uk/org/ury/library/LibraryItem.java
@@ -0,0 +1,446 @@
+/**
+ *
+ */
+package uk.org.ury.library;
+
+/**
+ * An item in the URY library.
+ *
+ * @author Matt Windsor
+ */
+
+public class LibraryItem
+{
+ private String title;
+ private String artist;
+ private String label;
+ private String status;
+ private String medium;
+ private String format;
+ private String dateReleased;
+ private String dateAdded;
+ private String dateEdited;
+ private String shelfLetter;
+ private String shelfNumber;
+ private String addForename;
+ private String addSurname;
+ private String editForename;
+ private String editSurname;
+ private String cdID;
+ private int addMemberID;
+ private int editMemberID;
+
+ public
+ LibraryItem ()
+ {
+ }
+
+
+ /**
+ * @return the title
+ */
+
+ public String
+ getTitle ()
+ {
+ return title;
+ }
+
+
+ /**
+ * @param title the title to set
+ */
+
+ public void
+ setTitle (String title)
+ {
+ this.title = title;
+ }
+
+
+ /**
+ * @return the artist
+ */
+
+ public String
+ getArtist ()
+ {
+ return artist;
+ }
+
+
+ /**
+ * @param artist the artist to set
+ */
+
+ public void
+ setArtist (String artist)
+ {
+ this.artist = artist;
+ }
+
+
+ /**
+ * @return the label
+ */
+
+ public String
+ getLabel ()
+ {
+ return label;
+ }
+
+
+ /**
+ * @param label the label to set
+ */
+
+ public void
+ setLabel (String label)
+ {
+ this.label = label;
+ }
+
+
+ /**
+ * @return the status
+ */
+
+ public String
+ getStatus ()
+ {
+ return status;
+ }
+
+
+ /**
+ * @param status the status to set
+ */
+
+ public void
+ setStatus (String status)
+ {
+ this.status = status;
+ }
+
+
+ /**
+ * @return the medium
+ */
+
+ public String
+ getMedium ()
+ {
+ return medium;
+ }
+
+
+ /**
+ * @param medium the medium to set
+ */
+
+ public void
+ setMedium (String medium)
+ {
+ this.medium = medium;
+ }
+
+
+ /**
+ * @return the format
+ */
+
+ public String
+ getFormat ()
+ {
+ return format;
+ }
+
+
+ /**
+ * @param format the format to set
+ */
+
+ public void
+ setFormat (String format)
+ {
+ this.format = format;
+ }
+
+
+ /**
+ * @return the dateReleased
+ */
+
+ public String
+ getDateReleased ()
+ {
+ return dateReleased;
+ }
+
+
+ /**
+ * @param dateReleased the dateReleased to set
+ */
+
+ public void
+ setDateReleased (String dateReleased)
+ {
+ this.dateReleased = dateReleased;
+ }
+
+
+ /**
+ * @return the dateAdded
+ */
+
+ public String
+ getDateAdded ()
+ {
+ return dateAdded;
+ }
+
+
+ /**
+ * @param dateAdded the dateAdded to set
+ */
+
+ public void
+ setDateAdded (String dateAdded)
+ {
+ this.dateAdded = dateAdded;
+ }
+
+
+ /**
+ * @return the dateEdited
+ */
+
+ public String
+ getDateEdited ()
+ {
+ return dateEdited;
+ }
+
+
+ /**
+ * @param dateEdited the dateEdited to set
+ */
+
+ public void
+ setDateEdited (String dateEdited)
+ {
+ this.dateEdited = dateEdited;
+ }
+
+
+ /**
+ * @return the shelfLetter
+ */
+
+
+ public String
+ getShelfLetter ()
+ {
+ return shelfLetter;
+ }
+
+
+ /**
+ * @param shelfLetter the shelfLetter to set
+ */
+
+ public void
+ setShelfLetter (String shelfLetter)
+ {
+ this.shelfLetter = shelfLetter;
+ }
+
+
+ /**
+ * @return the shelfNumber
+ */
+
+ public String
+ getShelfNumber ()
+ {
+ return shelfNumber;
+ }
+
+
+ /**
+ * @param shelfNumber the shelfNumber to set
+ */
+
+ public void
+ setShelfNumber (String shelfNumber)
+ {
+ this.shelfNumber = shelfNumber;
+ }
+
+
+ /**
+ * @return the addForename
+ */
+
+ public String
+ getAddForename ()
+ {
+ return addForename;
+ }
+
+
+ /**
+ * @param addForename the addForename to set
+ */
+
+ public void
+ setAddForename (String addForename)
+ {
+ this.addForename = addForename;
+ }
+
+
+ /**
+ * @return the addSurname
+ */
+
+ public String
+ getAddSurname ()
+ {
+ return addSurname;
+ }
+
+
+ /**
+ * @param addSurname the addSurname to set
+ */
+
+ public void
+ setAddSurname (String addSurname)
+ {
+ this.addSurname = addSurname;
+ }
+
+
+ /**
+ * @return the editForename
+ */
+
+ public String
+ getEditForename ()
+ {
+ return editForename;
+ }
+
+
+ /**
+ * @param editForename the editForename to set
+ */
+
+ public void
+ setEditForename (String editForename)
+ {
+ this.editForename = editForename;
+ }
+
+
+ /**
+ * @return the editSurname
+ */
+
+ public String
+ getEditSurname ()
+ {
+ return editSurname;
+ }
+
+
+ /**
+ * @param editSurname the editSurname to set
+ */
+
+ public void
+ setEditSurname (String editSurname)
+ {
+ this.editSurname = editSurname;
+ }
+
+
+ /**
+ * @return the cdID
+ */
+
+ public String
+ getCdID ()
+ {
+ return cdID;
+ }
+
+
+ /**
+ * @param cdID the cdID to set
+ */
+
+ public void
+ setCdID (String cdID)
+ {
+ this.cdID = cdID;
+ }
+
+
+ /**
+ * @return the addMemberID
+ */
+
+ public int
+ getAddMemberID ()
+ {
+ return addMemberID;
+ }
+
+
+ /**
+ * @param addMemberID the addMemberID to set
+ */
+
+ public void
+ setAddMemberID (int addMemberID)
+ {
+ this.addMemberID = addMemberID;
+ }
+
+
+ /**
+ * @return the editMemberID
+ */
+
+ public int
+ getEditMemberID ()
+ {
+ return editMemberID;
+ }
+
+
+ /**
+ * @param editMemberID the editMemberID to set
+ */
+
+ public void
+ setEditMemberID (int editMemberID)
+ {
+ this.editMemberID = editMemberID;
+ }
+
+
+ /**
+ * @return a human-readable string representation of the item.
+ */
+
+ @Override
+ public String
+ toString ()
+ {
+ return getArtist () + " - " + getTitle () + " (" + getShelfLetter () + getShelfNumber () + ")";
+ }
+}
diff --git a/src/uk/org/ury/library/viewer/LibraryViewer.java b/src/uk/org/ury/library/viewer/LibraryViewer.java
new file mode 100644
index 0000000..234e1eb
--- /dev/null
+++ b/src/uk/org/ury/library/viewer/LibraryViewer.java
@@ -0,0 +1,197 @@
+package uk.org.ury.library.viewer;
+
+import java.lang.reflect.InvocationTargetException;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.SwingUtilities;
+
+import uk.org.ury.database.DatabaseDriver;
+import uk.org.ury.database.UserClass;
+import uk.org.ury.database.exceptions.MissingCredentialsException;
+import uk.org.ury.frontend.AbstractFrontendModule;
+import uk.org.ury.frontend.FrontendError;
+import uk.org.ury.frontend.FrontendFrame;
+import uk.org.ury.frontend.FrontendModule;
+import uk.org.ury.library.LibraryItem;
+
+public class LibraryViewer extends AbstractFrontendModule
+{
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2782366476480563739L;
+ private List<LibraryItem> libraryList;
+ private LibraryViewerPanel panel;
+ private FrontendFrame frame;
+
+
+ /**
+ * Main function, for running this module as a standalone
+ * application.
+ *
+ * @param args The command-line argument array.
+ */
+
+ public static void
+ main (String[] args)
+ {
+ LibraryViewer lv = new LibraryViewer ();
+ lv.runFrontendInFrame ();
+ }
+
+
+ /**
+ * Construct a new LibraryViewer.
+ */
+
+ public
+ LibraryViewer ()
+ {
+ frame = null;
+ panel = new LibraryViewerPanel (this);
+ }
+
+
+ /**
+ * Initialise the library viewer frontend as an applet.
+ */
+
+ public void
+ init ()
+ {
+ frame = null;
+ panel = new LibraryViewerPanel (this);
+
+
+ try
+ {
+ SwingUtilities.invokeAndWait (new Runnable ()
+ {
+ public void
+ run ()
+ {
+ panel.setOpaque (true);
+ setContentPane (panel);
+
+ runFrontend ();
+ }
+
+ });
+ }
+ catch (InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace ();
+ }
+ catch (InvocationTargetException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace ();
+ }
+ }
+
+
+ /**
+ * Run the library viewer frontend as an applet.
+ */
+
+ public void
+ start ()
+ {
+ frame = null;
+ panel = new LibraryViewerPanel (this);
+
+ add (panel);
+ }
+
+ /**
+ * Run the library viewer frontend in a FrontendFrame.
+ */
+
+ public void
+ runFrontendInFrame ()
+ {
+ FrontendFrame frame = new FrontendFrame (panel);
+ this.frame = frame;
+
+ runFrontend ();
+ }
+
+
+ /**
+ * Run the library viewer frontend.
+ */
+
+ private void
+ runFrontend ()
+ {
+ DatabaseDriver dd = null;
+
+ try
+ {
+ dd = new DatabaseDriver (UserClass.READ_ONLY);
+ }
+ catch (MissingCredentialsException e)
+ {
+ // TODO: Privilege de-escalation
+ FrontendError.reportFatal (e.getMessage (), frame);
+ }
+ catch (Exception f)
+ {
+ FrontendError.reportFatal (f.getMessage (), frame);
+ }
+
+
+ System.out.println ("connection success");
+
+ ResultSet rs = dd.executeQuery ("SELECT title, artist, recordlabel AS label, status, media AS medium, format,"
+ + " datereleased, EXTRACT(EPOCH FROM dateadded) as dateadded,"
+ + " EXTRACT(EPOCH FROM datetime_lastedit) AS dateedited,"
+ + " shelfletter, shelfnumber, cdid, memberid_add, memberid_lastedit,"
+ + " a.fname AS fnameadd, a.sname AS snameadd, b.fname AS fnameedit, b.sname AS snameedit"
+ + " FROM rec_record AS r"
+ + " INNER JOIN member AS a ON (a.memberid = r.memberid_add)"
+ + " LEFT JOIN member AS b ON (b.memberid = r.memberid_lastedit)");
+
+
+ libraryList = new ArrayList<LibraryItem> ();
+
+ try
+ {
+ while (rs.next ())
+ {
+ LibraryItem li = new LibraryItem ();
+
+ li.setTitle (rs.getString ("title"));
+ li.setArtist (rs.getString ("artist"));
+ li.setLabel (rs.getString ("label"));
+ li.setStatus (rs.getString ("status"));
+ li.setMedium (rs.getString ("medium"));
+ li.setFormat (rs.getString ("format"));
+ li.setDateReleased (rs.getString ("datereleased"));
+ li.setDateEdited (rs.getString ("dateedited"));
+ li.setShelfLetter (rs.getString ("shelfletter"));
+ li.setShelfNumber (rs.getString ("shelfnumber"));
+ li.setCdID (rs.getString ("cdid"));
+ li.setAddMemberID (rs.getInt ("memberid_add"));
+ li.setEditMemberID (rs.getInt ("memberid_lastedit"));
+ li.setAddForename (rs.getString ("fnameadd"));
+ li.setAddSurname (rs.getString ("snameadd"));
+ li.setEditForename (rs.getString ("fnameedit"));
+ li.setEditSurname (rs.getString ("snameedit"));
+
+ System.out.println (li);
+
+ libraryList.add (li);
+ }
+ }
+ catch (SQLException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/uk/org/ury/library/viewer/LibraryViewerPanel.java b/src/uk/org/ury/library/viewer/LibraryViewerPanel.java
new file mode 100644
index 0000000..6a100a6
--- /dev/null
+++ b/src/uk/org/ury/library/viewer/LibraryViewerPanel.java
@@ -0,0 +1,130 @@
+/**
+ *
+ */
+package uk.org.ury.library.viewer;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.GroupLayout;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+import javax.swing.SwingConstants;
+
+import uk.org.ury.frontend.FrontendPanel;
+
+/**
+ * @author Matt Windsor
+ */
+
+public class LibraryViewerPanel extends FrontendPanel
+{
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2441616418398056712L;
+
+
+ /* Controller of this panel. */
+ private LibraryViewer master;
+
+ /* Panel widgets. */
+ private JLabel titleLabel;
+ private JLabel artistLabel;
+
+ private JTextField titleField;
+ private JTextField artistField;
+
+ private JButton searchButton;
+
+
+ /**
+ * Construct a new LibraryViewerPanel.
+ *
+ * @param master The LibraryViewer controlling this LibraryViewerPanel.
+ */
+
+ public
+ LibraryViewerPanel (LibraryViewer master)
+ {
+ super ();
+
+ this.master = master;
+
+ GroupLayout layout = new GroupLayout (this);
+
+ setLayout (layout);
+
+ layout.setAutoCreateGaps (true);
+ layout.setAutoCreateContainerGaps (true);
+
+ titleLabel = new JLabel ("By title: ");
+ artistLabel = new JLabel ("By artist: ");
+
+ titleField = new JTextField ("Type part of the title here.");
+ titleLabel.setDisplayedMnemonic ('T');
+ titleLabel.setLabelFor (titleField);
+
+ artistField = new JTextField ("Type part of the artist name here.");
+ artistLabel.setDisplayedMnemonic ('A');
+ artistLabel.setLabelFor (artistField);
+
+ searchButton = new JButton ("Search");
+
+ searchButton.addActionListener (new ActionListener ()
+ {
+ public void
+ actionPerformed (ActionEvent event)
+ {
+ }
+ });
+
+
+ // Layout
+
+
+ layout.setHorizontalGroup
+ (
+ layout.createSequentialGroup ()
+ .addGroup (layout.createParallelGroup (GroupLayout.Alignment.LEADING)
+ .addComponent (titleLabel)
+ .addComponent (artistLabel))
+ .addGroup (layout.createParallelGroup (GroupLayout.Alignment.LEADING)
+ .addComponent (titleField)
+ .addComponent (artistField))
+ .addGroup (layout.createParallelGroup (GroupLayout.Alignment.LEADING)
+ .addComponent (searchButton))
+ );
+
+ layout.setVerticalGroup
+ (
+ layout.createSequentialGroup ()
+ .addGroup (layout.createParallelGroup (GroupLayout.Alignment.LEADING)
+ .addComponent (titleLabel)
+ .addComponent (titleField)
+ .addComponent (searchButton))
+ .addGroup (layout.createParallelGroup (GroupLayout.Alignment.LEADING)
+ .addComponent (artistLabel)
+ .addComponent (artistField))
+ );
+
+ layout.linkSize(SwingConstants.HORIZONTAL, titleField, artistField);
+ layout.linkSize(SwingConstants.VERTICAL, titleField, artistField);
+ }
+
+
+ /**
+ * @return the name of the panel.
+ *
+ * @see uk.org.ury.frontend.FrontendPanel#getName()
+ */
+
+ @Override
+ public String
+ getName ()
+ {
+ return "Library Viewer Demo";
+ }
+
+}