Project

General

Profile

1
 /*
2
  *   '$RCSfile$'
3
  *     Purpose: Basic funtions to support searching workflows
4
  *   Copyright: 2009 Regents of the University of California and the
5
  *               National Center for Ecological Analysis and Synthesis
6
  *     Authors: Michael Daigle
7
  *
8
  *    '$Author: leinfelder $'
9
  *      '$Date: 2008-06-17 13:16:32 -0700 (Tue, 17 Jun 2008) $'
10
  *  '$Revision: 4006 $'
11
  *
12
  * This program is free software; you can redistribute it and/or modify
13
  * it under the terms of the GNU General Public License as published by
14
  * the Free Software Foundation; either version 2 of the License, or
15
  * (at your option) any later version.
16
  *
17
  * This program is distributed in the hope that it will be useful,
18
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
  * GNU General Public License for more details.
21
  *
22
  * You should have received a copy of the GNU General Public License
23
  * along with this program; if not, write to the Free Software
24
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
  */ 
26

    
27
/*
28
 * Generate a workflow query string.  this assumes that search fields meet the
29
 * following criteria in the web page:
30
 * -- search input fields have an ID that starts with sf- 
31
 * -- if there is a search mode dropdown for an input field in the form, it's ID 
32
 *    should use the same convention as the input field, but start with sm-
33
 *    (i.e. the search mode input for the sf-firstname input would be sm-firstname) 
34
 */
35
function setWorkflowQueryFormField(formId) {
36
	var queryString = ""; 
37
	queryString += "<pathquery version='1.2'>";
38
	/*queryString += "<returndoctype>entity</returndoctype>";
39
	queryString += "<returndoctype>-//UC Berkeley//DTD MoML 1//EN</returndoctype>";
40
	queryString += "<returnfield>/entity/@name</returnfield>";
41
	queryString += "<returnfield>/entity/property[@name=\'KeplerDocumentation\']/property[@name=\'author\']/configure</returnfield>";
42
	queryString += "<returnfield>/entity/property[@name=\'KeplerDocumentation\']/property[@name=\'description\']/configure</returnfield>";
43
	queryString += "<returnfield>/entity/property[@name=\'KeplerDocumentation\']/property[@name=\'createDate\']/configure</returnfield>";
44
	queryString += "<returnfield>/entity/property[@name=\'KeplerDocumentation\']/property[@name=\'workflowId\']/configure</returnfield>";
45
	queryString += "<returnfield>/entity/property[@name=\'karLSID\']/@value</returnfield>";				
46
	queryString += "<returnfield>/entity/property[@name=\'entityId\']/@value</returnfield>";*/
47
	queryString += "<returndoctype>kar</returndoctype>";
48
  queryString += "<returnfield>/kar/karEntry/karEntryXML/entity/@name</returnfield>";
49
  queryString += "<returnfield>/kar/karEntry/karEntryXML/entity/property[@name=\'KeplerDocumentation\']/property[@name=\'author\']/configure</returnfield>";
50
  queryString += "<returnfield>/kar/karEntry/karEntryXML/entity/property[@name=\'KeplerDocumentation\']/property[@name=\'description\']/configure</returnfield>";
51
  queryString += "<returnfield>/kar/karEntry/karEntryXML/entity/property[@name=\'KeplerDocumentation\']/property[@name=\'createDate\']/configure</returnfield>";
52
  queryString += "<returnfield>/kar/karEntry/karEntryXML/entity/property[@name=\'KeplerDocumentation\']/property[@name=\'workflowId\']/configure</returnfield>";
53
  queryString += "<returnfield>/kar/mainAttributes/lsid</returnfield>";       
54
  queryString += "<returnfield>/kar/karEntry/karEntryXML/entity/property[@name=\'entityId\']/@value</returnfield>";
55
	queryString += "<returnfield>/kar/karEntry/karEntryXML/property[@name=\'WorkflowRun\']/@class</returnfield>";
56
	queryString += "<querygroup operator='INTERSECT'>";	
57
	
58
	var elementList = document.getElementById(formId).elements;
59
	for(var i = 0; i < elementList.length; i++) {
60
	//alert("form element: " + elementList[i].id);
61
		if((elementList[i].id.indexOf("sf-") == 0) && (elementList[i].value != '')) {					
62
			queryString += getQueryTerm(elementList[i]);
63
		}
64
	} 
65
	
66
	queryString += "</querygroup>";	
67
	queryString += "</pathquery>";
68
	
69
	//alert(queryString);
70
	
71
	var queryField = document.getElementById("query");
72
	
73
	queryField.value = queryString;
74
}
75

    
76
/*
77
 * Generate individual query terms for all the search input fields in a search 
78
 * form.  There must be a case for each search field handle explicitly below.  
79
 * This assumes:
80
 * -- search input fields have an ID that starts with sf- 
81
 * -- if there is a search mode dropdown for an input field in the form, it's ID 
82
 *    should use the same convention as the input field, but start with sm-
83
 *    (i.e. the search mode input for the sf-firstname input would be sm-firstname) 
84
 */
85
function getQueryTerm(sfElement) {
86
	var baseId = sfElement.id.substring(3, sfElement.id.length);		
87
	var searchMode = "contains";
88
	var selector = document.getElementById("sm-" + baseId);
89
	if (selector != null) {
90
		searchMode = selector.value;
91
	}
92
	
93
	var pathExpr = '';
94
	if (sfElement.name == 'name') {
95
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
96
		pathExpr += "<value>" + sfElement.value + "</value>";
97
		/*pathExpr += "<pathexpr>entity/@name</pathexpr>";*/
98
		pathExpr += "<pathexpr>/kar/karEntry/karEntryXML/entity/@name</pathexpr>";
99
		pathExpr += "</queryterm>"; 		
100
	} else if (sfElement.name == 'keyword') {
101
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
102
		pathExpr += "<value>" + sfElement.value + "</value>";
103
		pathExpr += "<pathexpr>/kar/karEntry/karEntryXML/entity/property/@value</pathexpr>";
104
		pathExpr += "</queryterm>"; 		
105
	} else if (sfElement.name == 'creator') {
106
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
107
		pathExpr += "<value>" + sfElement.value + "</value>";
108
		pathExpr += "<pathexpr>/kar/karEntry/karEntryXML/entity/property/property/configure</pathexpr>";
109
		pathExpr += "</queryterm>"; 		
110
	} else if (sfElement.name == 'description') {
111
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
112
		pathExpr += "<value>" + sfElement.value + "</value>";
113
		pathExpr += "<pathexpr>/kar/karEntry/karEntryXML/entity/property/property/configure</pathexpr>";
114
		pathExpr += "</queryterm>"; 		
115
	} else if (sfElement.name == 'date-created') {
116
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
117
		pathExpr += "<value>" + sfElement.value + "</value>";
118
		pathExpr += "<pathexpr>/kar/karEntry/karEntryXML/entity/property/property/configure</pathexpr>";
119
		pathExpr += "</queryterm>"; 		
120
	} /*else if (sfElement.name == 'date-executed') {
121
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
122
		pathExpr += "<value>" + sfElement.value + "</value>";
123
		pathExpr += "<pathexpr>/kar/karEntry/karEntryXML/entity/property/property/configure</pathexpr>";
124
		pathExpr += "</queryterm>";		
125
	} */ else if (sfElement.name == 'workflow-lsid') {
126
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
127
		pathExpr += "<value>entityId</value>";
128
		pathExpr += "<pathexpr>/kar/karEntry/karEntryXML/entity/property/@name</pathexpr>";
129
		pathExpr += "</queryterm>"; 
130
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
131
		pathExpr += "<value>" + sfElement.value + "</value>";
132
		pathExpr += "<pathexpr>/kar/karEntry/karEntryXML/entity/property/@value</pathexpr>";
133
		pathExpr += "</queryterm>";		
134
	}/* else if (sfElement.name == 'workflow-run-id') {
135
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
136
		pathExpr += "<value>" + sfElement.value + "</value>";
137
		pathExpr += "<pathexpr>/kar/karEntry/karEntryXML/entity/property/property/configure</pathexpr>";
138
		pathExpr += "</queryterm>"; 		
139
	} else if (sfElement.name == 'status') {
140
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
141
		pathExpr += "<value>" + sfElement.value + "</value>";
142
		pathExpr += "<pathexpr>/kar/karEntry/karEntryXML/entity/property/property/configure</pathexpr>";
143
		pathExpr += "</queryterm>"; 		
144
	}*/
145
	
146
	//alert("returning path expression: " + pathExpr);
147
	return pathExpr;
148
}
149

    
150
	
(24-24/29)