1 | /*
|
---|
2 | * SimpleGraphicalClient.java
|
---|
3 | * Copyright (C) 2001 New Zealand Digital Library Project
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
18 | */
|
---|
19 | package org.nzdl.gsdl.SimpleGraphicalClient;
|
---|
20 |
|
---|
21 | import java.util.*;
|
---|
22 | import java.util.Set;
|
---|
23 | import java.util.TreeSet;
|
---|
24 | import java.util.Iterator;
|
---|
25 | import java.util.Vector;
|
---|
26 |
|
---|
27 | // local libraries
|
---|
28 |
|
---|
29 | import org.nzdl.gsdl.service.NzdlService;
|
---|
30 | import org.nzdl.gsdl.service.NzdlCollectionInfo;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Class
|
---|
34 | *
|
---|
35 | * A class to
|
---|
36 | *
|
---|
37 | * @author Dave Nichols ([email protected])
|
---|
38 | * @author stuart yeates ([email protected])
|
---|
39 | * @version $Revision: 2278 $
|
---|
40 | * @see org.nzdl.gsdl.service.SimpleGraphicalClient.SimpleGraphicalClient
|
---|
41 | */
|
---|
42 |
|
---|
43 | class CSModel extends Object
|
---|
44 | {
|
---|
45 |
|
---|
46 | Vector collectionList;
|
---|
47 | TreeMap collectionInfoMap;
|
---|
48 | HashMap collectionNameMap;
|
---|
49 | String currentCollection;
|
---|
50 | ResultModel results;
|
---|
51 | NzdlService nzdl;
|
---|
52 | QueryHistoryModel queryHistoryModel;
|
---|
53 |
|
---|
54 |
|
---|
55 | public CSModel(NzdlService newNzdl)
|
---|
56 | {
|
---|
57 | nzdl = newNzdl;
|
---|
58 | results = new ResultModel();
|
---|
59 | collectionList = new Vector();
|
---|
60 | collectionInfoMap = new TreeMap();
|
---|
61 | collectionNameMap = new HashMap();
|
---|
62 | queryHistoryModel = new QueryHistoryModel();
|
---|
63 | currentCollection = "";
|
---|
64 | initialiseCollection();
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | public NzdlService getNzdlService()
|
---|
69 | {
|
---|
70 | return nzdl;
|
---|
71 | }
|
---|
72 |
|
---|
73 | public QueryHistoryModel getQueryHistoryModel() {
|
---|
74 | return queryHistoryModel;
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | /* Result methods */
|
---|
79 |
|
---|
80 | public ResultModel getResultsModel()
|
---|
81 | {
|
---|
82 | return results;
|
---|
83 | }
|
---|
84 |
|
---|
85 | public void addResult(Result result)
|
---|
86 | {
|
---|
87 | results.add(result);
|
---|
88 | }
|
---|
89 |
|
---|
90 | public void clearResults()
|
---|
91 | {
|
---|
92 | //System.out.println("Clearing resultModel");
|
---|
93 | results.clear();
|
---|
94 | }
|
---|
95 |
|
---|
96 | /* collectionList methods */
|
---|
97 |
|
---|
98 | public Vector getCollectionList() {
|
---|
99 | return new Vector(collectionInfoMap.keySet());
|
---|
100 | }
|
---|
101 |
|
---|
102 | public Collection getCollectionAsCollection() {
|
---|
103 | return (Collection)collectionInfoMap;
|
---|
104 | }
|
---|
105 |
|
---|
106 | public int getCollectionListSize() {
|
---|
107 | return collectionInfoMap.size();
|
---|
108 | }
|
---|
109 |
|
---|
110 | public NzdlCollectionInfo getCollectionInfo(String collectionName) {
|
---|
111 | return (NzdlCollectionInfo) collectionInfoMap.get(collectionName);
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 | public String getLongCollectionName(String collectionName) {
|
---|
116 | return (String) collectionNameMap.get(collectionName);
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | public String getCollectionDescription(String collectionName) {
|
---|
121 | Set descSet = nzdl.getMetaData(collectionName, "collection", "collectionextra");
|
---|
122 | if (descSet.size() == 1)
|
---|
123 | return (String) descSet.toArray()[0];
|
---|
124 | else
|
---|
125 | return "collectionName has more than 1 collectionextra entry";
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | public void setCurrentCollection(String collection )
|
---|
130 | {
|
---|
131 | currentCollection = collection;
|
---|
132 | }
|
---|
133 |
|
---|
134 | public String getCurrentCollection()
|
---|
135 | {
|
---|
136 | return currentCollection;
|
---|
137 | }
|
---|
138 |
|
---|
139 | public String getFirstCollection()
|
---|
140 | {
|
---|
141 | if (getCollectionListSize() > 0)
|
---|
142 | return (String)collectionInfoMap.firstKey();
|
---|
143 | else
|
---|
144 | return "no collections";
|
---|
145 | }
|
---|
146 | /**
|
---|
147 | *
|
---|
148 | */
|
---|
149 | public void initialiseCollection()
|
---|
150 | {
|
---|
151 | Set collectionSet = nzdl.getCollectionSet(); // set of strings of collection titles
|
---|
152 | TreeSet orderedCollectionSet = new TreeSet(collectionSet);
|
---|
153 | // TreeSet automatically puts strings in alphabetical order
|
---|
154 | System.out.println("Number of collections on the server: " +
|
---|
155 | orderedCollectionSet.size());
|
---|
156 | Iterator collectionSetIterator = orderedCollectionSet.iterator();
|
---|
157 | while (collectionSetIterator.hasNext() ) {
|
---|
158 | // object -> String
|
---|
159 | String collectionName = (String)collectionSetIterator.next();
|
---|
160 | NzdlCollectionInfo info = nzdl.getCollectionInfo(collectionName);
|
---|
161 |
|
---|
162 | if (info != null &&
|
---|
163 | info.getBuildDate() != 0 &&
|
---|
164 | nzdl.pingCollection(collectionName)) {
|
---|
165 | collectionInfoMap.put(collectionName, info);
|
---|
166 | String longCollectionName = "";
|
---|
167 | Set n = nzdl.getMetaData(collectionName, "collection", "collectionname");
|
---|
168 | if (n != null) {
|
---|
169 | if (n.size() == 1)
|
---|
170 | longCollectionName = (String) n.toArray()[0];
|
---|
171 | else
|
---|
172 | longCollectionName = collectionName + " has more than 1 collectionname";
|
---|
173 | collectionNameMap.put(collectionName,longCollectionName );
|
---|
174 | System.err.println("Adding " + collectionName + " to collection list...");
|
---|
175 | }
|
---|
176 | } // end if
|
---|
177 | else {
|
---|
178 | System.err.println("Collection " + collectionName + " getBuildDate() returned 0");
|
---|
179 | } // end else
|
---|
180 | } // end while
|
---|
181 | setCurrentCollection(getFirstCollection()); //assume at least one collection
|
---|
182 |
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | }
|
---|