Project

General

Profile

« Previous | Next » 

Revision 4698

Added by daigle over 15 years ago

Renamed MetaCatUtil to MetacatUtil

View differences:

DocumentIdQuery.java
31 31
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
32 32

  
33 33
/**
34
 * Generate a pathquery document representing a metacat query for a list of 
34
 * Generate a pathquery document representing a metacat query for a list of
35 35
 * document IDs.
36 36
 */
37
public class DocumentIdQuery
38
{
37
public class DocumentIdQuery {
39 38

  
40
    
41
    /**
42
     * Create an squery parameters table using an already-initialized hashtable
43
     * 
44
     * @param docidList an array of document identifiers to search for
45
     * @param params the hashtable to add the query parameters to.
46
     * 
47
     */
48
    public static Hashtable createDocidQueryParams(String[] docidList, Hashtable params)
49
    {
50
        params = getDefaultQueryParams();
51
        if (docidList != null) {
52
            params.put("/eml/@packageId", docidList);
53
        }
54
        return params;
55
    }
56
    
57
    
58
    /**
59
     * Create an squery using some preset values for the query parameters, only
60
     * passing in the document ids to be searched.
61
     * 
62
     * @param docidList an array of document identifiers to search for
63
     */
64
    public static String createDocidQuery(String[] docidList) throws PropertyNotFoundException
65
    {
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
    {
83
        Hashtable params = new Hashtable();
84
        
85
        String[] operator = new String[1];
86
        operator[0] = "UNION";
87
        params.put("operator", operator);
88
        
89
        String[] doctypes = new String[5];
90
        doctypes[0] = "eml://ecoinformatics.org/eml-2.0.1";
91
        doctypes[1] = "eml://ecoinformatics.org/eml-2.0.0";
92
        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 no arguments used in this main method
118
     */
119
    public static void main(String[] args)
120
    {
121
        String CONFIG_DIR = "lib";
122
        File dirPath = new File(CONFIG_DIR);
123
        try {
124
        	PropertyService.getInstance(dirPath.getPath());
125
        } catch (ServiceException ioe) {
126
            System.err.println("Error in loading properties: "
127
                    + ioe.getMessage());
128
        }
129
        
130
        String[] ids = new String[3];
131
        ids[0] = "ces_dataset.23.1";
132
        ids[1] = "knb-lter-vcr.97.1";
133
        ids[2] = "obfs.400.1";
134
        
135
        String pathquery = null;
136
        try {
137
        	pathquery = createDocidQuery(ids);
138
        } catch (PropertyNotFoundException pnfe) {
139
        	System.out.println("Could not create doc id query: " + pnfe.getMessage());
140
        }
141
        System.out.println(pathquery);
142
    }
39
	/**
40
	 * Create an squery parameters table using an already-initialized hashtable
41
	 * 
42
	 * @param docidList
43
	 *            an array of document identifiers to search for
44
	 * @param params
45
	 *            the hashtable to add the query parameters to.
46
	 * 
47
	 */
48
	public static Hashtable createDocidQueryParams(String[] docidList, Hashtable params) {
49
		params = getDefaultQueryParams();
50
		if (docidList != null) {
51
			params.put("/eml/@packageId", docidList);
52
		}
53
		return params;
54
	}
143 55

  
56
	/**
57
	 * Create an squery using some preset values for the query parameters, only
58
	 * passing in the document ids to be searched.
59
	 * 
60
	 * @param docidList
61
	 *            an array of document identifiers to search for
62
	 */
63
	public static String createDocidQuery(String[] docidList)
64
			throws PropertyNotFoundException {
65
		String pathQuery = "";
66
		Hashtable params = getDefaultQueryParams();
67
		if (docidList != null) {
68
			params.put("/eml/@packageId", docidList);
69
		}
70

  
71
		pathQuery = DBQuery.createSQuery(params);
72
		return pathQuery;
73
	}
74

  
75
	/**
76
	 * Create a paramter list containing default parameters for a query
77
	 * 
78
	 * @return Hashtable containing the default parameters
79
	 */
80
	public static Hashtable getDefaultQueryParams() {
81
		Hashtable params = new Hashtable();
82

  
83
		String[] operator = new String[1];
84
		operator[0] = "UNION";
85
		params.put("operator", operator);
86

  
87
		String[] doctypes = new String[5];
88
		doctypes[0] = "eml://ecoinformatics.org/eml-2.0.1";
89
		doctypes[1] = "eml://ecoinformatics.org/eml-2.0.0";
90
		doctypes[2] = "-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN";
91
		doctypes[3] = "-//ecoinformatics.org//eml-dataset-2.0.0beta4//EN";
92
		doctypes[4] = "metadata";
93
		params.put("returndoctype", doctypes);
94

  
95
		String[] fields = new String[11];
96
		fields[0] = "originator/individualName/surName";
97
		fields[1] = "originator/individualName/givenName";
98
		fields[2] = "creator/individualName/surName";
99
		fields[3] = "creator/individualName/givenName";
100
		fields[4] = "originator/organizationName";
101
		fields[5] = "creator/organizationName";
102
		fields[6] = "dataset/title";
103
		fields[7] = "keyword";
104
		fields[8] = "idinfo/citation/citeinfo/title";
105
		fields[9] = "idinfo/citation/citeinfo/origin";
106
		fields[10] = "idinfo/keywords/theme/themekey";
107
		params.put("returnfield", fields);
108

  
109
		return params;
110
	}
111

  
112
	/**
113
	 * Main method used for testing the class output
114
	 * 
115
	 * @param args
116
	 *            no arguments used in this main method
117
	 */
118
	public static void main(String[] args) {
119
		String CONFIG_DIR = "lib";
120
		File dirPath = new File(CONFIG_DIR);
121
		try {
122
			PropertyService.getInstance();
123
		} catch (ServiceException ioe) {
124
			System.err.println("Error in loading properties: " + ioe.getMessage());
125
		}
126

  
127
		String[] ids = new String[3];
128
		ids[0] = "ces_dataset.23.1";
129
		ids[1] = "knb-lter-vcr.97.1";
130
		ids[2] = "obfs.400.1";
131

  
132
		String pathquery = null;
133
		try {
134
			pathquery = createDocidQuery(ids);
135
		} catch (PropertyNotFoundException pnfe) {
136
			System.out.println("Could not create doc id query: " + pnfe.getMessage());
137
		}
138
		System.out.println(pathquery);
139
	}
140

  
144 141
}

Also available in: Unified diff