Project

General

Profile

1 4971 daigle
 /*
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 4948 daigle
/*
28
 * Generate a workflow query string.  this assumes that search fields meet the
29
 * following criteria in the web page:
30 4971 daigle
 * -- search input fields have an ID that starts with sf-
31 4948 daigle
 * -- if there is a search mode dropdown for an input field in the form, it's ID
32 4971 daigle
 *    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 4948 daigle
 */
35
function setWorkflowQueryFormField(formId) {
36
	var queryString = "";
37
	queryString += "<pathquery version='1.2'>";
38 5311 daigle
	/*queryString += "<returndoctype>entity</returndoctype>";
39 4948 daigle
	queryString += "<returndoctype>-//UC Berkeley//DTD MoML 1//EN</returndoctype>";
40 4966 daigle
	queryString += "<returnfield>/entity/@name</returnfield>";
41 4976 daigle
	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 4966 daigle
	queryString += "<returnfield>/entity/property[@name=\'karLSID\']/@value</returnfield>";
46 5311 daigle
	queryString += "<returnfield>/entity/property[@name=\'entityId\']/@value</returnfield>";*/
47 5354 tao
	/*queryString += "<returndoctype>kar</returndoctype>";*/
48
	queryString += "<returndoctype>http://www.kepler-project.org/kar-2.0.0</returndoctype>";
49 5806 tao
	queryString += "<returndoctype>http://www.kepler-project.org/kar-2.1.0</returndoctype>";
50 5354 tao
  queryString += "<returnfield>karEntry/karEntryXML/entity/@name</returnfield>";
51
  queryString += "<returnfield>karEntry/karEntryXML/entity/property[@name=\'KeplerDocumentation\']/property[@name=\'author\']/configure</returnfield>";
52
  queryString += "<returnfield>karEntry/karEntryXML/entity/property[@name=\'KeplerDocumentation\']/property[@name=\'description\']/configure</returnfield>";
53
  queryString += "<returnfield>karEntry/karEntryXML/entity/property[@name=\'KeplerDocumentation\']/property[@name=\'createDate\']/configure</returnfield>";
54
  queryString += "<returnfield>karEntry/karEntryXML/entity/property[@name=\'KeplerDocumentation\']/property[@name=\'workflowId\']/configure</returnfield>";
55
  queryString += "<returnfield>mainAttributes/lsid</returnfield>";
56
  queryString += "<returnfield>karEntry/karEntryXML/entity/property[@name=\'entityId\']/@value</returnfield>";
57
	queryString += "<returnfield>karEntry/karEntryXML/property[@name=\'WorkflowRun\']/@class</returnfield>";
58 4948 daigle
	queryString += "<querygroup operator='INTERSECT'>";
59
60
	var elementList = document.getElementById(formId).elements;
61
	for(var i = 0; i < elementList.length; i++) {
62
	//alert("form element: " + elementList[i].id);
63
		if((elementList[i].id.indexOf("sf-") == 0) && (elementList[i].value != '')) {
64
			queryString += getQueryTerm(elementList[i]);
65
		}
66
	}
67
68
	queryString += "</querygroup>";
69
	queryString += "</pathquery>";
70
71
	//alert(queryString);
72
73
	var queryField = document.getElementById("query");
74
75
	queryField.value = queryString;
76
}
77
78 4971 daigle
/*
79
 * Generate individual query terms for all the search input fields in a search
80
 * form.  There must be a case for each search field handle explicitly below.
81
 * This assumes:
82
 * -- search input fields have an ID that starts with sf-
83
 * -- if there is a search mode dropdown for an input field in the form, it's ID
84
 *    should use the same convention as the input field, but start with sm-
85
 *    (i.e. the search mode input for the sf-firstname input would be sm-firstname)
86
 */
87 4948 daigle
function getQueryTerm(sfElement) {
88
	var baseId = sfElement.id.substring(3, sfElement.id.length);
89
	var searchMode = "contains";
90
	var selector = document.getElementById("sm-" + baseId);
91
	if (selector != null) {
92
		searchMode = selector.value;
93
	}
94
95
	var pathExpr = '';
96
	if (sfElement.name == 'name') {
97
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
98
		pathExpr += "<value>" + sfElement.value + "</value>";
99 5311 daigle
		/*pathExpr += "<pathexpr>entity/@name</pathexpr>";*/
100 5354 tao
		pathExpr += "<pathexpr>karEntry/karEntryXML/entity/@name</pathexpr>";
101 4948 daigle
		pathExpr += "</queryterm>";
102
	} else if (sfElement.name == 'keyword') {
103
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
104
		pathExpr += "<value>" + sfElement.value + "</value>";
105 5354 tao
		pathExpr += "<pathexpr>karEntry/karEntryXML/entity/property/@value</pathexpr>";
106 4948 daigle
		pathExpr += "</queryterm>";
107
	} else if (sfElement.name == 'creator') {
108
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
109
		pathExpr += "<value>" + sfElement.value + "</value>";
110 5354 tao
		pathExpr += "<pathexpr>karEntry/karEntryXML/entity/property/property/configure</pathexpr>";
111 4948 daigle
		pathExpr += "</queryterm>";
112
	} else if (sfElement.name == 'description') {
113
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
114
		pathExpr += "<value>" + sfElement.value + "</value>";
115 5354 tao
		pathExpr += "<pathexpr>karEntry/karEntryXML/entity/property/property/configure</pathexpr>";
116 4948 daigle
		pathExpr += "</queryterm>";
117
	} else if (sfElement.name == 'date-created') {
118
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
119
		pathExpr += "<value>" + sfElement.value + "</value>";
120 5354 tao
		pathExpr += "<pathexpr>karEntry/karEntryXML/entity/property/property/configure</pathexpr>";
121 4948 daigle
		pathExpr += "</queryterm>";
122 5311 daigle
	} /*else if (sfElement.name == 'date-executed') {
123 4948 daigle
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
124
		pathExpr += "<value>" + sfElement.value + "</value>";
125 5354 tao
		pathExpr += "<pathexpr>karEntry/karEntryXML/entity/property/property/configure</pathexpr>";
126 4984 daigle
		pathExpr += "</queryterm>";
127 5311 daigle
	} */ else if (sfElement.name == 'workflow-lsid') {
128 4948 daigle
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
129 4984 daigle
		pathExpr += "<value>entityId</value>";
130 5354 tao
		pathExpr += "<pathexpr>karEntry/karEntryXML/entity/property/@name</pathexpr>";
131 4966 daigle
		pathExpr += "</queryterm>";
132
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
133
		pathExpr += "<value>" + sfElement.value + "</value>";
134 5354 tao
		pathExpr += "<pathexpr>karEntry/karEntryXML/entity/property/@value</pathexpr>";
135 4966 daigle
		pathExpr += "</queryterm>";
136 5311 daigle
	}/* else if (sfElement.name == 'workflow-run-id') {
137 4948 daigle
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
138
		pathExpr += "<value>" + sfElement.value + "</value>";
139 5354 tao
		pathExpr += "<pathexpr>karEntry/karEntryXML/entity/property/property/configure</pathexpr>";
140 4948 daigle
		pathExpr += "</queryterm>";
141
	} else if (sfElement.name == 'status') {
142
		pathExpr += "<queryterm casesensitive='false' searchmode='" + searchMode + "'>";
143
		pathExpr += "<value>" + sfElement.value + "</value>";
144 5354 tao
		pathExpr += "<pathexpr>karEntry/karEntryXML/entity/property/property/configure</pathexpr>";
145 4948 daigle
		pathExpr += "</queryterm>";
146 5311 daigle
	}*/
147 4948 daigle
148
	//alert("returning path expression: " + pathExpr);
149
	return pathExpr;
150
}
151