Revision 2916
Added by Matt Jones almost 19 years ago
src/edu/ucsb/nceas/metacat/DocumentIdQuery.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Copyright: 2006 Regents of the University of California and the |
|
4 |
* National Center for Ecological Analysis and Synthesis |
|
5 |
* |
|
6 |
* '$Author$' |
|
7 |
* '$Date$' |
|
8 |
* '$Revision$' |
|
9 |
* |
|
10 |
* This program is free software; you can redistribute it and/or modify |
|
11 |
* it under the terms of the GNU General Public License as published by |
|
12 |
* the Free Software Foundation; either version 2 of the License, or |
|
13 |
* (at your option) any later version. |
|
14 |
* |
|
15 |
* This program is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
* GNU General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU General Public License |
|
21 |
* along with this program; if not, write to the Free Software |
|
22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
*/ |
|
24 |
package edu.ucsb.nceas.metacat; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import java.io.IOException; |
|
28 |
import java.util.Hashtable; |
|
29 |
|
|
30 |
import edu.ucsb.nceas.utilities.Options; |
|
31 |
|
|
32 |
/** |
|
33 |
* Generate a pathquery document representing a metacat query for a list of |
|
34 |
* document IDs. |
|
35 |
*/ |
|
36 |
public class DocumentIdQuery |
|
37 |
{ |
|
38 |
|
|
39 |
/** |
|
40 |
* Create an squery using some preset values for the query parameters, only |
|
41 |
* passing in the document ids to be searched. |
|
42 |
* |
|
43 |
* @param docidList an arrany of document identifiers to search for |
|
44 |
*/ |
|
45 |
public static String createDocidQuery(String[] docidList) |
|
46 |
{ |
|
47 |
String pathQuery = ""; |
|
48 |
Hashtable params = getDefaultQueryParams(); |
|
49 |
if (docidList != null) { |
|
50 |
params.put("/eml/@packageId", docidList); |
|
51 |
} |
|
52 |
|
|
53 |
pathQuery = DBQuery.createSQuery(params); |
|
54 |
return pathQuery; |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Create a paramter list containing default parameters for a query |
|
59 |
* |
|
60 |
* @return Hashtable containing the default parameters |
|
61 |
*/ |
|
62 |
public static Hashtable getDefaultQueryParams() |
|
63 |
{ |
|
64 |
Hashtable params = new Hashtable(); |
|
65 |
|
|
66 |
String[] operator = new String[1]; |
|
67 |
operator[0] = "UNION"; |
|
68 |
params.put("operator", operator); |
|
69 |
|
|
70 |
String[] doctypes = new String[4]; |
|
71 |
doctypes[0] = "eml://ecoinformatics.org/eml-2.0.1"; |
|
72 |
doctypes[1] = "eml://ecoinformatics.org/eml-2.0.0"; |
|
73 |
doctypes[2] = "-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN"; |
|
74 |
doctypes[3] = "-//ecoinformatics.org//eml-dataset-2.0.0beta4//EN"; |
|
75 |
params.put("returndoctype", doctypes); |
|
76 |
|
|
77 |
String[] fields = new String[8]; |
|
78 |
fields[0]="originator/individualName/surName"; |
|
79 |
fields[1]="originator/individualName/givenName"; |
|
80 |
fields[2]="creator/individualName/surName"; |
|
81 |
fields[3]="creator/individualName/givenName"; |
|
82 |
fields[4]="originator/organizationName"; |
|
83 |
fields[5]="creator/organizationName"; |
|
84 |
fields[6]="dataset/title"; |
|
85 |
fields[7]="keyword"; |
|
86 |
params.put("returnfield", fields); |
|
87 |
|
|
88 |
return params; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Main method used for testing the class output |
|
93 |
* |
|
94 |
* @param args no arguments used in this main method |
|
95 |
*/ |
|
96 |
public static void main(String[] args) |
|
97 |
{ |
|
98 |
String CONFIG_DIR = "lib"; |
|
99 |
String CONFIG_NAME = "metacat.properties"; |
|
100 |
File dirPath = new File(CONFIG_DIR); |
|
101 |
File propertyFile = new File(dirPath, CONFIG_NAME); |
|
102 |
Options options = null; |
|
103 |
try { |
|
104 |
options = Options.initialize(propertyFile); |
|
105 |
} catch (IOException ioe) { |
|
106 |
System.err.println("Error in loading options: " |
|
107 |
+ ioe.getMessage()); |
|
108 |
} |
|
109 |
|
|
110 |
String[] ids = new String[3]; |
|
111 |
ids[0] = "ces_dataset.23.1"; |
|
112 |
ids[1] = "knb-lter-vcr.97.1"; |
|
113 |
ids[2] = "obfs.400.1"; |
|
114 |
|
|
115 |
String pathquery = createDocidQuery(ids); |
|
116 |
System.out.println(pathquery); |
|
117 |
} |
|
118 |
|
|
119 |
} |
|
0 | 120 |
Also available in: Unified diff
This is a utility class for generating a pathquery document from an array of docids that one wants to query for. Its hacked together in that the default query parameters are all hardcoded into the class, which is obviously wrong. Need to figure out where those default params should be derived from.