1 |
2916
|
jones
|
/**
|
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.util.Hashtable;
|
28 |
|
|
|
29 |
5030
|
daigle
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
30 |
5015
|
daigle
|
import edu.ucsb.nceas.metacat.shared.ServiceException;
|
31 |
5030
|
daigle
|
import edu.ucsb.nceas.utilities.FileUtil;
|
32 |
4080
|
daigle
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
33 |
2916
|
jones
|
|
34 |
|
|
/**
|
35 |
4698
|
daigle
|
* Generate a pathquery document representing a metacat query for a list of
|
36 |
2916
|
jones
|
* document IDs.
|
37 |
|
|
*/
|
38 |
4698
|
daigle
|
public class DocumentIdQuery {
|
39 |
2916
|
jones
|
|
40 |
4698
|
daigle
|
/**
|
41 |
|
|
* Create an squery parameters table using an already-initialized hashtable
|
42 |
|
|
*
|
43 |
|
|
* @param docidList
|
44 |
|
|
* an array of document identifiers to search for
|
45 |
|
|
* @param params
|
46 |
|
|
* the hashtable to add the query parameters to.
|
47 |
|
|
*
|
48 |
|
|
*/
|
49 |
|
|
public static Hashtable createDocidQueryParams(String[] docidList, Hashtable params) {
|
50 |
|
|
params = getDefaultQueryParams();
|
51 |
|
|
if (docidList != null) {
|
52 |
|
|
params.put("/eml/@packageId", docidList);
|
53 |
|
|
}
|
54 |
|
|
return params;
|
55 |
|
|
}
|
56 |
2916
|
jones
|
|
57 |
4698
|
daigle
|
/**
|
58 |
|
|
* Create an squery using some preset values for the query parameters, only
|
59 |
|
|
* passing in the document ids to be searched.
|
60 |
|
|
*
|
61 |
|
|
* @param docidList
|
62 |
|
|
* an array of document identifiers to search for
|
63 |
|
|
*/
|
64 |
|
|
public static String createDocidQuery(String[] docidList)
|
65 |
|
|
throws PropertyNotFoundException {
|
66 |
|
|
String pathQuery = "";
|
67 |
|
|
Hashtable params = getDefaultQueryParams();
|
68 |
|
|
if (docidList != null) {
|
69 |
|
|
params.put("/eml/@packageId", docidList);
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
pathQuery = DBQuery.createSQuery(params);
|
73 |
|
|
return pathQuery;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
/**
|
77 |
|
|
* Create a paramter list containing default parameters for a query
|
78 |
|
|
*
|
79 |
|
|
* @return Hashtable containing the default parameters
|
80 |
|
|
*/
|
81 |
|
|
public static Hashtable getDefaultQueryParams() {
|
82 |
|
|
Hashtable params = new Hashtable();
|
83 |
|
|
|
84 |
|
|
String[] operator = new String[1];
|
85 |
|
|
operator[0] = "UNION";
|
86 |
|
|
params.put("operator", operator);
|
87 |
|
|
|
88 |
|
|
String[] doctypes = new String[5];
|
89 |
|
|
doctypes[0] = "eml://ecoinformatics.org/eml-2.0.1";
|
90 |
|
|
doctypes[1] = "eml://ecoinformatics.org/eml-2.0.0";
|
91 |
4841
|
daigle
|
doctypes[1] = "eml://ecoinformatics.org/eml-2.1.0";
|
92 |
4698
|
daigle
|
doctypes[2] = "-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN";
|
93 |
|
|
doctypes[3] = "-//ecoinformatics.org//eml-dataset-2.0.0beta4//EN";
|
94 |
|
|
doctypes[4] = "metadata";
|
95 |
|
|
params.put("returndoctype", doctypes);
|
96 |
|
|
|
97 |
|
|
String[] fields = new String[11];
|
98 |
|
|
fields[0] = "originator/individualName/surName";
|
99 |
|
|
fields[1] = "originator/individualName/givenName";
|
100 |
|
|
fields[2] = "creator/individualName/surName";
|
101 |
|
|
fields[3] = "creator/individualName/givenName";
|
102 |
|
|
fields[4] = "originator/organizationName";
|
103 |
|
|
fields[5] = "creator/organizationName";
|
104 |
|
|
fields[6] = "dataset/title";
|
105 |
|
|
fields[7] = "keyword";
|
106 |
|
|
fields[8] = "idinfo/citation/citeinfo/title";
|
107 |
|
|
fields[9] = "idinfo/citation/citeinfo/origin";
|
108 |
|
|
fields[10] = "idinfo/keywords/theme/themekey";
|
109 |
|
|
params.put("returnfield", fields);
|
110 |
|
|
|
111 |
|
|
return params;
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
/**
|
115 |
|
|
* Main method used for testing the class output
|
116 |
|
|
*
|
117 |
|
|
* @param args
|
118 |
|
|
* no arguments used in this main method
|
119 |
|
|
*/
|
120 |
|
|
public static void main(String[] args) {
|
121 |
|
|
String CONFIG_DIR = "lib";
|
122 |
|
|
File dirPath = new File(CONFIG_DIR);
|
123 |
|
|
try {
|
124 |
5030
|
daigle
|
PropertyService.getInstance(dirPath.getPath() + FileUtil.getFS() + "metacat.properties");
|
125 |
4698
|
daigle
|
} catch (ServiceException ioe) {
|
126 |
|
|
System.err.println("Error in loading properties: " + ioe.getMessage());
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
String[] ids = new String[3];
|
130 |
|
|
ids[0] = "ces_dataset.23.1";
|
131 |
|
|
ids[1] = "knb-lter-vcr.97.1";
|
132 |
|
|
ids[2] = "obfs.400.1";
|
133 |
|
|
|
134 |
|
|
String pathquery = null;
|
135 |
|
|
try {
|
136 |
|
|
pathquery = createDocidQuery(ids);
|
137 |
|
|
} catch (PropertyNotFoundException pnfe) {
|
138 |
|
|
System.out.println("Could not create doc id query: " + pnfe.getMessage());
|
139 |
|
|
}
|
140 |
|
|
System.out.println(pathquery);
|
141 |
|
|
}
|
142 |
|
|
|
143 |
2916
|
jones
|
}
|