View Javadoc
1   /*
2    * Copyright 2001-2008 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.webconsole.hub.builders;
17  
18  import java.util.List;
19  import org.apache.commons.lang.StringEscapeUtils;
20  import org.uddi.api_v3.FindQualifiers;
21  import org.uddi.sub_v3.Subscription;
22  
23  /**
24   * Provides some basic helper functions for the edit Subscription page
25   *
26   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
27   */
28  public class SubscriptionHelper {
29  
30      /**
31       * returns
32       *
33       * @param sub
34       * @param key
35       * @return
36       */
37      public static String containsFindQualifier(Subscription sub, String key) {
38          if (sub == null) {
39              return "";
40          }
41          if (sub.getSubscriptionFilter() == null) {
42              return "";
43          }
44          if (sub.getSubscriptionFilter().getFindBinding() != null) {
45              return contains(sub.getSubscriptionFilter().getFindBinding().getFindQualifiers(), key);
46          }
47          if (sub.getSubscriptionFilter().getFindBusiness() != null) {
48              return contains(sub.getSubscriptionFilter().getFindBusiness().getFindQualifiers(), key);
49          }
50          if (sub.getSubscriptionFilter().getFindRelatedBusinesses() != null) {
51              return contains(sub.getSubscriptionFilter().getFindRelatedBusinesses().getFindQualifiers(), key);
52          }
53          if (sub.getSubscriptionFilter().getFindService() != null) {
54              return contains(sub.getSubscriptionFilter().getFindService().getFindQualifiers(), key);
55          }
56          if (sub.getSubscriptionFilter().getFindTModel() != null) {
57              return contains(sub.getSubscriptionFilter().getFindTModel().getFindQualifiers(), key);
58          }
59          return "";
60      }
61  
62      public static String getSearchName(Subscription sub) {
63          if (sub == null) {
64              return "";
65          }
66          if (sub.getSubscriptionFilter() == null) {
67              return "";
68          }
69          if (sub.getSubscriptionFilter().getFindBinding() != null) {
70              return sub.getSubscriptionFilter().getFindBinding().getServiceKey();
71          }
72          if (sub.getSubscriptionFilter().getFindBusiness() != null) {
73              return Printers.ListNamesToString(sub.getSubscriptionFilter().getFindBusiness().getName());
74          }
75          if (sub.getSubscriptionFilter().getFindService() != null) {
76              return Printers.ListNamesToString(sub.getSubscriptionFilter().getFindService().getName());
77          }
78          if (sub.getSubscriptionFilter().getFindTModel() != null) {
79              return (sub.getSubscriptionFilter().getFindTModel().getName().getValue());
80          }
81          return "";
82      }
83  
84      public static String getSearchLang(Subscription sub) {
85          if (sub == null) {
86              return "";
87          }
88          if (sub.getSubscriptionFilter() == null) {
89              return "";
90          }
91          if (sub.getSubscriptionFilter().getFindBusiness() != null) {
92              if (!sub.getSubscriptionFilter().getFindBusiness().getName().isEmpty()) {
93                  return sub.getSubscriptionFilter().getFindBusiness().getName().get(0).getLang();
94              }
95          }
96          if (sub.getSubscriptionFilter().getFindService() != null) {
97              if (!sub.getSubscriptionFilter().getFindService().getName().isEmpty()) {
98                  return sub.getSubscriptionFilter().getFindService().getName().get(0).getLang();
99              }
100         }
101         if (sub.getSubscriptionFilter().getFindTModel() != null) {
102             if (sub.getSubscriptionFilter().getFindTModel().getName()!=null) {
103                 return (sub.getSubscriptionFilter().getFindTModel().getName().getLang());
104             }
105         }
106         return "";
107     }
108 
109     public static String getItemKeySpecific(Subscription sub) {
110         if (sub == null) {
111             return "";
112         }
113         if (sub.getSubscriptionFilter() == null) {
114             return "";
115         }
116         if (sub.getSubscriptionFilter().getGetAssertionStatusReport() != null && sub.getSubscriptionFilter().getGetAssertionStatusReport().getCompletionStatus() != null) {
117             return sub.getSubscriptionFilter().getGetAssertionStatusReport().getCompletionStatus().toString();
118         }
119 
120         if (sub.getSubscriptionFilter().getGetBindingDetail() != null) {
121             return ToHtmlOption(sub.getSubscriptionFilter().getGetBindingDetail().getBindingKey());
122         }
123 
124         if (sub.getSubscriptionFilter().getGetBusinessDetail() != null) {
125             return ToHtmlOption(sub.getSubscriptionFilter().getGetBusinessDetail().getBusinessKey());
126         }
127 
128         if (sub.getSubscriptionFilter().getGetServiceDetail() != null) {
129             return ToHtmlOption(sub.getSubscriptionFilter().getGetServiceDetail().getServiceKey());
130         }
131 
132         if (sub.getSubscriptionFilter().getGetTModelDetail() != null) {
133             return ToHtmlOption(sub.getSubscriptionFilter().getGetTModelDetail().getTModelKey());
134         }
135         return "";
136     }
137 
138     public static String ToHtmlOption(List<String> items) {
139         StringBuilder sb = new StringBuilder();
140         if (items == null || items.isEmpty()) {
141             return null;
142         }
143         for (int i = 0; i < items.size(); i++) {
144             if (items.get(i) == null) {
145                 continue;
146             }
147             if (items.get(i).trim().isEmpty()) {
148                 continue;
149             }
150             sb.append("<option value\"").append(StringEscapeUtils.escapeHtml(items.get(i).trim()))
151                     .append("\">")
152                     .append(StringEscapeUtils.escapeHtml(items.get(i)))
153                     .append("</option>");
154         }
155         return sb.toString();
156     }
157 
158     public static boolean isSpecificItem(Subscription sub) {
159         if (sub == null) {
160             throw new IllegalArgumentException();
161         }
162         if (sub.getSubscriptionFilter() == null) {
163             throw new IllegalArgumentException();
164         }
165         return (sub.getSubscriptionFilter().getGetAssertionStatusReport() != null
166                 || sub.getSubscriptionFilter().getGetBindingDetail() != null
167                 || sub.getSubscriptionFilter().getGetBusinessDetail() != null
168                 || sub.getSubscriptionFilter().getGetServiceDetail() != null
169                 || sub.getSubscriptionFilter().getGetTModelDetail() != null);
170     }
171 
172     public static String isBindingSpecific(Subscription sub) {
173         if (sub == null) {
174             return "";
175         }
176         if (sub.getSubscriptionFilter() == null) {
177             return "";
178         }
179 
180         if (sub.getSubscriptionFilter().getGetBindingDetail() != null && !sub.getSubscriptionFilter().getGetBindingDetail().getBindingKey().isEmpty()) {
181             return " active ";
182         }
183         return "";
184     }
185 
186     public static String isBusinessSpecific(Subscription sub) {
187         if (sub == null) {
188             return "";
189         }
190         if (sub.getSubscriptionFilter() == null) {
191             return "";
192         }
193         if (sub.getSubscriptionFilter().getGetBusinessDetail() != null && !sub.getSubscriptionFilter().getGetBusinessDetail().getBusinessKey().isEmpty()) {
194             return " active ";
195         }
196         return "";
197     }
198 
199     public static String isServiceSpecific(Subscription sub) {
200         if (sub == null) {
201             return "";
202         }
203         if (sub.getSubscriptionFilter() == null) {
204             return "";
205         }
206         if (sub.getSubscriptionFilter().getGetServiceDetail() != null && !sub.getSubscriptionFilter().getGetServiceDetail().getServiceKey().isEmpty()) {
207             return " active ";
208         }
209         return "";
210     }
211 
212     public static String isTModelSpecific(Subscription sub) {
213         if (sub == null) {
214             return "";
215         }
216         if (sub.getSubscriptionFilter() == null) {
217             return "";
218         }
219         if (sub.getSubscriptionFilter().getGetTModelDetail() != null && !sub.getSubscriptionFilter().getGetTModelDetail().getTModelKey().isEmpty()) {
220             return " active ";
221         }
222         return "";
223     }
224 
225     public static String isPublisherAssertionSpecific(Subscription sub) {
226         if (sub == null) {
227             return "";
228         }
229         if (sub.getSubscriptionFilter() == null) {
230             return "";
231         }
232 
233         if (sub.getSubscriptionFilter().getGetAssertionStatusReport() != null && sub.getSubscriptionFilter().getGetAssertionStatusReport().getCompletionStatus() != null) {
234             return " active ";
235         }
236         return "";
237     }
238 
239     public static String isFindBusiness(Subscription sub) {
240         if (sub == null) {
241             return "";
242         }
243 
244         if (sub.getSubscriptionFilter().getFindBusiness() != null) {
245             return " active ";
246         }
247         return "";
248     }
249 
250     public static String isFindBinding(Subscription sub) {
251         if (sub == null) {
252             return "";
253         }
254         if (sub.getSubscriptionFilter() == null) {
255             return "";
256         }
257 
258         if (sub.getSubscriptionFilter().getFindBinding() != null) {
259             return " active ";
260         }
261         return "";
262     }
263 
264     public static String isFindRelatedBusinesses(Subscription sub) {
265         if (sub == null) {
266             return "";
267         }
268         if (sub.getSubscriptionFilter() == null) {
269             return "";
270         }
271 
272         if (sub.getSubscriptionFilter().getFindRelatedBusinesses() != null) {
273             return " active ";
274         }
275         return "";
276     }
277 
278     public static String isFindService(Subscription sub) {
279         if (sub == null) {
280             return "";
281         }
282         if (sub.getSubscriptionFilter() == null) {
283             return "";
284         }
285 
286         if (sub.getSubscriptionFilter().getFindService() != null) {
287             return " active ";
288         }
289         return "";
290     }
291 
292     public static String isFindTModel(Subscription sub) {
293         if (sub == null) {
294             return "";
295         }
296         if (sub.getSubscriptionFilter() == null) {
297             return "";
298         }
299 
300         if (sub.getSubscriptionFilter().getFindTModel() != null) {
301             return " active ";
302         }
303         return "";
304     }
305 
306     private static String contains(FindQualifiers findQualifiers, String key) {
307         if (findQualifiers == null) {
308             return "";
309         }
310         for (int i = 0; i < findQualifiers.getFindQualifier().size(); i++) {
311             if (findQualifiers.getFindQualifier().get(i).equalsIgnoreCase(key)) {
312                 return " checked ";
313             }
314         }
315         return "";
316     }
317 }