This project has retired. For details please refer to its
Attic page.
001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.oozie.store;
019
020 import java.util.List;
021 import java.util.Map;
022
023 import org.apache.oozie.client.OozieClient;
024
025 public class StoreStatusFilter {
026 public static final String coordSeletStr = "Select w.id, w.appName, w.status, w.user, w.group, w.startTimestamp, w.endTimestamp, w.appPath, w.concurrency, w.frequency, w.lastActionTimestamp, w.nextMaterializedTimestamp, w.createdTimestamp, w.timeUnitStr, w.timeZone, w.timeOut from CoordinatorJobBean w";
027
028 public static final String coordCountStr = "Select count(w) from CoordinatorJobBean w";
029
030 public static final String wfSeletStr = "Select w.id, w.appName, w.status, w.run, w.user, w.group, w.createdTimestamp, w.startTimestamp, w.lastModifiedTimestamp, w.endTimestamp from WorkflowJobBean w";
031
032 public static final String wfCountStr = "Select count(w) from WorkflowJobBean w";
033
034 public static final String bundleSeletStr = "Select w.id, w.appName, w.appPath, w.conf, w.status, w.kickoffTimestamp, w.startTimestamp, w.endTimestamp, w.pauseTimestamp, w.createdTimestamp, w.user, w.group, w.timeUnitStr, w.timeOut from BundleJobBean w";
035
036 public static final String bundleCountStr = "Select count(w) from BundleJobBean w";
037
038 public static void filter(Map<String, List<String>> filter, List<String> orArray, List<String> colArray,
039 List<String> valArray, StringBuilder sb, String seletStr, String countStr) {
040 boolean isStatus = false;
041 boolean isGroup = false;
042 boolean isAppName = false;
043 boolean isUser = false;
044 boolean isEnabled = false;
045 boolean isFrequency = false;
046 boolean isId = false;
047
048 int index = 0;
049
050 for (Map.Entry<String, List<String>> entry : filter.entrySet()) {
051 String colName = null;
052 String colVar = null;
053 if (entry.getKey().equals(OozieClient.FILTER_GROUP)) {
054 List<String> values = filter.get(OozieClient.FILTER_GROUP);
055 colName = "group";
056 for (int i = 0; i < values.size(); i++) {
057 colVar = "group";
058 colVar = colVar + index;
059 if (!isEnabled && !isGroup) {
060 sb.append(seletStr).append(" where w.group IN (:group" + index);
061 isGroup = true;
062 isEnabled = true;
063 }
064 else {
065 if (isEnabled && !isGroup) {
066 sb.append(" and w.group IN (:group" + index);
067 isGroup = true;
068 }
069 else {
070 if (isGroup) {
071 sb.append(", :group" + index);
072 }
073 }
074 }
075 if (i == values.size() - 1) {
076 sb.append(")");
077 }
078 index++;
079 valArray.add(values.get(i));
080 orArray.add(colName);
081 colArray.add(colVar);
082 }
083 }
084 else {
085 if (entry.getKey().equals(OozieClient.FILTER_STATUS)) {
086 List<String> values = filter.get(OozieClient.FILTER_STATUS);
087 colName = "status";
088 for (int i = 0; i < values.size(); i++) {
089 colVar = "status";
090 colVar = colVar + index;
091 if (!isEnabled && !isStatus) {
092 sb.append(seletStr).append(" where w.status IN (:status" + index);
093 isStatus = true;
094 isEnabled = true;
095 }
096 else {
097 if (isEnabled && !isStatus) {
098 sb.append(" and w.status IN (:status" + index);
099 isStatus = true;
100 }
101 else {
102 if (isStatus) {
103 sb.append(", :status" + index);
104 }
105 }
106 }
107 if (i == values.size() - 1) {
108 sb.append(")");
109 }
110 index++;
111 valArray.add(values.get(i));
112 orArray.add(colName);
113 colArray.add(colVar);
114 }
115 }
116 else {
117 if (entry.getKey().equals(OozieClient.FILTER_NAME)) {
118 List<String> values = filter.get(OozieClient.FILTER_NAME);
119 colName = "appName";
120 for (int i = 0; i < values.size(); i++) {
121 colVar = "appName";
122 colVar = colVar + index;
123 if (!isEnabled && !isAppName) {
124 sb.append(seletStr).append(" where w.appName IN (:appName" + index);
125 isAppName = true;
126 isEnabled = true;
127 }
128 else {
129 if (isEnabled && !isAppName) {
130 sb.append(" and w.appName IN (:appName" + index);
131 isAppName = true;
132 }
133 else {
134 if (isAppName) {
135 sb.append(", :appName" + index);
136 }
137 }
138 }
139 if (i == values.size() - 1) {
140 sb.append(")");
141 }
142 index++;
143 valArray.add(values.get(i));
144 orArray.add(colName);
145 colArray.add(colVar);
146 }
147 }
148 else {
149 if (entry.getKey().equals(OozieClient.FILTER_USER)) {
150 List<String> values = filter.get(OozieClient.FILTER_USER);
151 colName = "user";
152 for (int i = 0; i < values.size(); i++) {
153 colVar = "user";
154 colVar = colVar + index;
155 if (!isEnabled && !isUser) {
156 sb.append(seletStr).append(" where w.user IN (:user" + index);
157 isUser = true;
158 isEnabled = true;
159 }
160 else {
161 if (isEnabled && !isUser) {
162 sb.append(" and w.user IN (:user" + index);
163 isUser = true;
164 }
165 else {
166 if (isUser) {
167 sb.append(", :user" + index);
168 }
169 }
170 }
171 if (i == values.size() - 1) {
172 sb.append(")");
173 }
174 index++;
175 valArray.add(values.get(i));
176 orArray.add(colName);
177 colArray.add(colVar);
178 }
179 }
180 else if (entry.getKey().equals(OozieClient.FILTER_FREQUENCY)) {
181 List<String> values = filter.get(OozieClient.FILTER_FREQUENCY);
182 colName = "frequency";
183 for (int i = 0; i < values.size(); i++) {
184 colVar = "frequency";
185 colVar = colVar + index;
186 if (!isEnabled && !isFrequency) {
187 sb.append(seletStr).append(" where w.frequency IN (:frequency" + index);
188 isFrequency = true;
189 isEnabled = true;
190 }
191 else {
192 if (isEnabled && !isFrequency) {
193 sb.append(" and w.frequency IN (:frequency" + index);
194 isFrequency = true;
195 }
196 else {
197 if (isFrequency) {
198 sb.append(", :frequency" + index);
199 }
200 }
201 }
202 if (i == values.size() - 1) {
203 sb.append(")");
204 }
205 index++;
206 valArray.add(values.get(i));
207 orArray.add(colName);
208 colArray.add(colVar);
209 }
210 }
211 else if (entry.getKey().equals(OozieClient.FILTER_ID)) {
212 List<String> values = filter.get(OozieClient.FILTER_ID);
213 colName = "id";
214 for (int i = 0; i < values.size(); i++) {
215 colVar = "id";
216 colVar = colVar + index;
217 if (!isEnabled && !isId) {
218 sb.append(seletStr).append(" where w.id IN (:id" + index);
219 isId = true;
220 isEnabled = true;
221 }
222 else {
223 if (isEnabled && !isId) {
224 sb.append(" and w.id IN (:id" + index);
225 isId = true;
226 }
227 else {
228 if (isId) {
229 sb.append(", :id" + index);
230 }
231 }
232 }
233 if (i == values.size() - 1) {
234 sb.append(")");
235 }
236 index++;
237 valArray.add(values.get(i));
238 orArray.add(colName);
239 colArray.add(colVar);
240 }
241 }
242 }
243 }
244 }
245 }
246 }
247 }