blob: 9587d5e387b9bdea7569b45c9c2c8af99a1afbae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
package uk.org.ury.library.viewer;
import java.util.ArrayList;
import java.util.List;
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;
import uk.org.ury.frontend.exceptions.UICreationFailureException;
import uk.org.ury.library.LibraryUtils;
import uk.org.ury.library.exceptions.EmptySearchException;
import uk.org.ury.library.item.LibraryItem;
public class LibraryViewer extends AbstractFrontendModule
{
/**
*
*/
private static final long serialVersionUID = -2782366476480563739L;
private DatabaseDriver dd;
private List<LibraryItem> libraryList;
private LibraryViewerPanel panel;
private ConfigReader config;
/**
* Construct a new LibraryViewer as a frontend object.
*/
public
LibraryViewer ()
{
try
{
config = new ConfigReader ("res/conf.xml");
}
catch (MissingCredentialsException e)
{
System.out.println(e);
}
libraryList = new ArrayList<LibraryItem> ();
panel = null;
}
/**
* Run the library viewer frontend.
*/
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);
}
catch (UICreationFailureException e)
{
master.fatalError (e.getMessage ());
}
return panel;
}
/**
* Do a library search.
*
* This will update the library list to reflect the results of the
* search.
*
* @param search The string fragment to use in searches.
* Cannot be empty or null.
*
* @throws EmptySearchException if the search string is
* empty or null (from LibraryUtils.search).
*
* @throws QueryFailureException if the search query
* fails (from LibraryUtils.search).
*/
public void
doSearch (String search)
throws EmptySearchException, QueryFailureException
{
libraryList = LibraryUtils.search (dd, search);
}
/**
* @return the current library list.
*/
public List<LibraryItem>
getLibraryList ()
{
return libraryList;
}
}
|