aboutsummaryrefslogtreecommitdiff
path: root/src/uk/org/ury/library/viewer/LibraryViewer.java
diff options
context:
space:
mode:
authorMatt Windsor <mattwindsor@btinternet.com>2011-03-20 01:40:08 +0000
committerMatt Windsor <mattwindsor@btinternet.com>2011-03-20 01:40:08 +0000
commit0a4133a08038b1d867a78be20dd6afafbd0b09d1 (patch)
tree86f765376ccf930f5ef91c44e35708df7fa17bcd /src/uk/org/ury/library/viewer/LibraryViewer.java
parent8f0360d9e72843d527b2db28047ae5f0498f3a3e (diff)
Cleanup and fixery.
Diffstat (limited to 'src/uk/org/ury/library/viewer/LibraryViewer.java')
-rw-r--r--src/uk/org/ury/library/viewer/LibraryViewer.java79
1 files changed, 24 insertions, 55 deletions
diff --git a/src/uk/org/ury/library/viewer/LibraryViewer.java b/src/uk/org/ury/library/viewer/LibraryViewer.java
index 3e09594..9e854b7 100644
--- a/src/uk/org/ury/library/viewer/LibraryViewer.java
+++ b/src/uk/org/ury/library/viewer/LibraryViewer.java
@@ -8,14 +8,6 @@ import java.util.Set;
import uk.org.ury.client.Client;
-import uk.org.ury.config.ConfigReader;
-
-import uk.org.ury.database.DatabaseDriver;
-import uk.org.ury.database.UserClass;
-
-import uk.org.ury.database.exceptions.MissingCredentialsException;
-import uk.org.ury.database.exceptions.QueryFailureException;
-
import uk.org.ury.frontend.AbstractFrontendModule;
import uk.org.ury.frontend.FrontendMaster;
import uk.org.ury.frontend.FrontendModulePanel;
@@ -26,9 +18,10 @@ import uk.org.ury.library.exceptions.EmptySearchException;
import uk.org.ury.library.item.LibraryItem;
import uk.org.ury.library.item.LibraryItemProperty;
-import uk.org.ury.server.protocol.DecodeFailureException;
-import uk.org.ury.server.protocol.Directive;
-import uk.org.ury.server.protocol.Status;
+import uk.org.ury.protocol.Directive;
+import uk.org.ury.protocol.ProtocolUtils;
+import uk.org.ury.protocol.exceptions.DecodeFailureException;
+import uk.org.ury.protocol.exceptions.InvalidMessageException;
/**
@@ -47,7 +40,6 @@ public class LibraryViewer extends AbstractFrontendModule
private static final long serialVersionUID = -2782366476480563739L;
private List<LibraryItem> libraryList;
private LibraryViewerPanel panel;
- private ConfigReader config;
/**
@@ -56,16 +48,7 @@ public class LibraryViewer extends AbstractFrontendModule
public
LibraryViewer ()
- {
- try
- {
- config = new ConfigReader ("res/conf.xml");
- }
- catch (MissingCredentialsException e)
- {
- System.out.println(e);
- }
-
+ {
libraryList = new ArrayList<LibraryItem> ();
panel = null;
}
@@ -77,23 +60,7 @@ public class LibraryViewer extends AbstractFrontendModule
public FrontendModulePanel
runFrontend (FrontendMaster master)
- {
- dd = null;
-
- try
- {
- dd = new DatabaseDriver (config, UserClass.READ_ONLY);
- }
- catch (MissingCredentialsException e)
- {
- // TODO: Privilege de-escalation
- master.fatalError (e.getMessage ());
- }
- catch (Exception f)
- {
- master.fatalError (f.getMessage ());
- }
-
+ {
try
{
panel = new LibraryViewerPanel (this, master);
@@ -119,16 +86,20 @@ public class LibraryViewer extends AbstractFrontendModule
* @throws EmptySearchException if the search string is
* empty or null (from LibraryUtils.search).
*
- * @throws QueryFailureException if the search query
- * fails (from LibraryUtils.search).
+ * @throws InvalidMessageException if the response from
+ * the server is invalid.
*/
public void
doSearch (String search)
- throws EmptySearchException, QueryFailureException
+ throws EmptySearchException, InvalidMessageException
{
// TODO: fan out?
+ if (search == null || search == "")
+ throw new EmptySearchException ();
+
+
Client cl = new Client ();
Map<?, ?> response = null;
libraryList.clear ();
@@ -139,25 +110,23 @@ public class LibraryViewer extends AbstractFrontendModule
}
catch (DecodeFailureException e)
{
- throw new QueryFailureException (e.getMessage ());
+ throw new InvalidMessageException (e.getMessage ());
}
// Check to see if this is Map<String, ?> by looking for the status,
// which should always be in a valid response.
- if (response.containsKey (Directive.STATUS.toString ()) == false
- || (response.get (Directive.STATUS.toString ()) instanceof String) == false)
- throw new QueryFailureException ("Status not provided.");
+
- if (((String) response.get (Directive.STATUS.toString ()))
- .equals (Status.OK.toString ()) == false)
- throw new QueryFailureException ((String) response.get (Directive.REASON.toString ()));
+ if (ProtocolUtils.responseIsOK (response) == false)
+ throw new InvalidMessageException ((String)
+ response.get (Directive.REASON.toString ()));
// Should contain a list of items, even if there are no items.
if (response.containsKey (Directive.ITEMS.toString ()) == false)
- throw new QueryFailureException ("No item set returned.");
+ throw new InvalidMessageException ("No item set returned.");
if ((response.get (Directive.ITEMS.toString ()) instanceof List<?>) == false)
- throw new QueryFailureException ("Malformed item list.");
+ throw new InvalidMessageException ("Malformed item list.");
for (Object obj : (List<?>) response.get (Directive.ITEMS.toString ()))
@@ -166,7 +135,7 @@ public class LibraryViewer extends AbstractFrontendModule
= new HashMap<LibraryItemProperty, String> ();
if (obj instanceof Map<?, ?> == false)
- throw new QueryFailureException ("Malformed item.");
+ throw new InvalidMessageException ("Malformed item.");
Set<?> keySet = ((Map<?, ?>) obj).keySet ();
@@ -176,10 +145,10 @@ public class LibraryViewer extends AbstractFrontendModule
if ((key instanceof String
&& ((Map<?, ?>) obj).get (key) instanceof String)
== false)
- throw new QueryFailureException ("Not a valid property.");
+ throw new InvalidMessageException ("Not a valid property.");
else if (LibraryItemProperty.valueOf ((String) key) == null)
- throw new QueryFailureException ("Property type "
- + key + " not recognised.");
+ throw new InvalidMessageException ("Property type "
+ + key + " not recognised.");
else
properties.put (LibraryItemProperty.valueOf ((String) key),
(String) ((Map<?, ?>) obj).get (key));