Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: aab8643c5cc19b0702b4e39bd33f0fc40139895b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
/*******************************************************************************
 * Copyright (c) 2001, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.wst.ws.internal.explorer.platform.uddi.actions;

import java.net.MalformedURLException;
import java.util.Vector;
import org.eclipse.wst.ws.internal.explorer.platform.datamodel.ListElement;
import org.eclipse.wst.ws.internal.explorer.platform.datamodel.ListManager;
import org.eclipse.wst.ws.internal.explorer.platform.datamodel.TreeElement;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.Controller;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.FormTool;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.FormToolPropertiesInterface;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.MessageQueue;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.Node;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.NodeManager;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.constants.UDDIActionInputs;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.BusinessElement;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.PublisherAssertionElement;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.RegistryElement;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.perspective.MultipleFormToolPropertiesInterface;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.perspective.UDDIPerspective;
import org.eclipse.wst.ws.internal.explorer.platform.util.MultipartFormDataException;
import org.eclipse.wst.ws.internal.explorer.platform.util.MultipartFormDataParser;
import org.eclipse.wst.ws.internal.explorer.platform.util.Validator;
import org.uddi4j.UDDIException;
import org.uddi4j.client.UDDIProxy;
import org.uddi4j.datatype.business.BusinessEntity;
import org.uddi4j.response.AssertionStatusItem;
import org.uddi4j.response.AssertionStatusReport;
import org.uddi4j.response.CompletionStatus;
import org.uddi4j.response.DispositionReport;
import org.uddi4j.response.RelatedBusinessInfo;
import org.uddi4j.response.RelatedBusinessesList;
import org.uddi4j.response.Result;
import org.uddi4j.response.SharedRelationships;
import org.uddi4j.transport.TransportException;
import org.uddi4j.util.FindQualifiers;
import org.uddi4j.util.KeyedReference;

public class ShowPublisherAssertionsAction extends CommonPublisherAssertionsAction
{

  protected String subQueryKey_;
  protected boolean isSubQueryGet_;
  protected boolean subQueryInitiated_;
  protected String newSubQuery_;
  protected String newSubQueryItem_;

  public ShowPublisherAssertionsAction(Controller controller)
  {
    super(controller);

    subQueryKey_ = null;
    isSubQueryGet_ = false;
    subQueryInitiated_ = false;
  }

  protected final boolean processParsedResults(MultipartFormDataParser parser) throws MultipartFormDataException
  {
    if (registryNode_ == null)
      return false;

    // ids from uddiObjects_table
    String[] selectedBusIds = parser.getParameterValues(UDDIActionInputs.PUBLISHER_ASSERTIONS_SELECTED_BUS_ID);
    if (selectedBusIds != null && selectedBusIds.length > 0)
      propertyTable_.put(UDDIActionInputs.PUBLISHER_ASSERTIONS_SELECTED_BUS_ID, selectedBusIds);

    newSubQuery_ = parser.getParameter(UDDIActionInputs.NEW_SUBQUERY_INITIATED);
    String isSubQueryGetString = parser.getParameter(UDDIActionInputs.SUBQUERY_GET);
    newSubQueryItem_ = parser.getParameter(UDDIActionInputs.NEW_SUBQUERY_QUERY_ITEM);
    subQueryKey_ = parser.getParameter(UDDIActionInputs.SUBQUERY_KEY);

    // Validate the data.
    controller_.getUDDIPerspective();
    FormTool formTool = getSelectedFormTool();
    FormToolPropertiesInterface formToolPI = ((MultipleFormToolPropertiesInterface)formTool).getFormToolProperties(subQueryKey_);
    formToolPI.clearErrors();

    if (newSubQuery_ != null && newSubQuery_.length() > 0)
      subQueryInitiated_ = true;
    else
      subQueryInitiated_ = false;

    if (isSubQueryGetString != null)
      isSubQueryGet_ = Boolean.valueOf(isSubQueryGetString).booleanValue();

    // if not yet logged in, validate the parameters needed to log in
    // NOTE: This action does NOT require the user to be logged in.
    if (!isLoggedIn_) {
      String publishURL = parser.getParameter(UDDIActionInputs.QUERY_INPUT_ADVANCED_PUBLISH_URL);
      String userID = parser.getParameter(UDDIActionInputs.QUERY_INPUT_ADVANCED_USERID);
      String password = parser.getParameter(UDDIActionInputs.QUERY_INPUT_ADVANCED_PASSWORD);

      if (publishURL != null)
      {
        propertyTable_.put(UDDIActionInputs.QUERY_INPUT_ADVANCED_PUBLISH_URL,publishURL);
        formTool.setProperty(UDDIActionInputs.QUERY_INPUT_ADVANCED_PUBLISH_URL,publishURL);
      }

      if (userID != null)
      {
        propertyTable_.put(UDDIActionInputs.QUERY_INPUT_ADVANCED_USERID,userID);
        formTool.setProperty(UDDIActionInputs.QUERY_INPUT_ADVANCED_USERID,userID);
      }

      if (password != null)
      {
        propertyTable_.put(UDDIActionInputs.QUERY_INPUT_ADVANCED_PASSWORD,password);
        formTool.setProperty(UDDIActionInputs.QUERY_INPUT_ADVANCED_PASSWORD,password);
      }
    }

    return true;
  }

  public final boolean isSubQueryInitiated()
  {
    return subQueryInitiated_;
  }

  public final boolean isSubQueryGet()
  {
    return isSubQueryGet_;
  }

  public final String getSubQueryKey()
  {
    return subQueryKey_;
  }

  public final String getNewSubQuery()
  {
    return newSubQuery_;
  }

  public final String getNewSubQueryItem()
  {
    return newSubQueryItem_;
  }

  public boolean run()
  {
    // Synchronize client view and server model (uddiObject_table.jsp)
    synchronizeUDDIObjectTable();

    if (registryNode_ == null)
      return false;

    RegistryElement registryElement = (RegistryElement)registryNode_.getTreeElement();
    UDDIPerspective uddiPerspective = controller_.getUDDIPerspective();
    MessageQueue messageQueue = uddiPerspective.getMessageQueue();
    NodeManager navigatorManager = uddiPerspective.getNavigatorManager();
    Node selectedNode = navigatorManager.getSelectedNode();
    TreeElement selectedElement = selectedNode.getTreeElement();

    if (!(selectedElement instanceof BusinessElement))
      return false;

    // if not yet logged in, log in first
    if (!isLoggedIn_) {
      String publishURL = (String)propertyTable_.get(UDDIActionInputs.QUERY_INPUT_ADVANCED_PUBLISH_URL);
      String userID = (String)propertyTable_.get(UDDIActionInputs.QUERY_INPUT_ADVANCED_USERID);
      String password = (String)propertyTable_.get(UDDIActionInputs.QUERY_INPUT_ADVANCED_PASSWORD);

      try {
        if (Validator.validateURL(publishURL) &&
            Validator.validateString(userID) &&
            password != null) {
          registryElement.performLogin(publishURL, userID, password);
          isLoggedIn_ = registryElement.isLoggedIn();
        }
      }
      catch (TransportException te) {
        messageQueue.addMessage(controller_.getMessage("MSG_ERROR_UNEXPECTED"));
        messageQueue.addMessage("TransportException");
        messageQueue.addMessage(te.getMessage());
        return false;
      }
      catch (UDDIException uddie) {
        messageQueue.addMessage(controller_.getMessage("MSG_ERROR_UNEXPECTED"));
        messageQueue.addMessage("UDDIException");
        messageQueue.addMessage(uddie.toString());
        return false;
      }
      catch (MalformedURLException me) {
        messageQueue.addMessage(controller_.getMessage("MSG_ERROR_UNEXPECTED"));
        messageQueue.addMessage("MalformedURLException");
        messageQueue.addMessage(me.getMessage());
        return false;
      }      
    }

    // show all assertion iff is logged in and business is owned
    // else show only completed ones
    BusinessElement busElement = (BusinessElement)selectedElement;
    if (isLoggedIn_ && isBusinessOwned(busElement))
      return showPublisherAssertionsForOwnedBus(busElement);
    else
      return showPublisherAssertionsForNonOwnedBus(busElement);
  }

  private boolean showPublisherAssertionsForOwnedBus(BusinessElement busElement) {
    UDDIPerspective uddiPerspective = controller_.getUDDIPerspective();
    MessageQueue messageQueue = uddiPerspective.getMessageQueue();

    // try to get a list of all publisher assertion based on the current registry's authToken
    ListManager listManager = new ListManager();
    FormTool formTool = getSelectedFormTool();
    FormToolPropertiesInterface formToolPI = ((MultipleFormToolPropertiesInterface)formTool).getFormToolProperties(subQueryKey_);
    formToolPI.removeProperty(UDDIActionInputs.QUERY_INPUT_EXISTING_PUBLISHER_ASSERTIONS);
    Vector queryInputVector = new Vector();
    RegistryElement registryElement = (RegistryElement)registryNode_.getTreeElement();
    registryElement.getUserId();
    registryElement.getCred();

    // show all publisher assertions
    UDDIProxy proxy = ((RegistryElement)registryNode_.getTreeElement()).getProxy();
    AssertionStatusReport assertionReport;
    try {
      assertionReport = proxy.get_assertionStatusReport(registryElement.getAuthInfoString(), (CompletionStatus)null);
    }
    catch (UDDIException uddie) {
      messageQueue.addMessage(controller_.getMessage("MSG_ERROR_UNEXPECTED"));
      messageQueue.addMessage("UDDIException");
      DispositionReport report = uddie.getDispositionReport();
	  Vector reportErrInfo = report.getResultVector();
      for (int i = 0; i < reportErrInfo.size(); i++) {
        messageQueue.addMessage(((Result) reportErrInfo.get(i)).getErrInfo().getText());
      }
      return false;
    }
    catch (Exception e) {
      messageQueue.addMessage(controller_.getMessage("MSG_ERROR_UNEXPECTED"));
      messageQueue.addMessage("Exception");
      messageQueue.addMessage(e.getMessage());
      return false;
    }
    Vector assertionVector = assertionReport.getAssertionStatusItemVector();
    Vector otherBusinessKeys = new Vector();
    Vector pubAssertionElements = new Vector();

    for (int i = 0; i < assertionVector.size(); i++) {
      AssertionStatusItem assertionItem = (AssertionStatusItem)assertionVector.elementAt(i);
      // determine the from/to business keys
      String fromKey = assertionItem.getFromKey().getText();
      String toKey = assertionItem.getToKey().getText();
      String owningBusinessKey = busElement.getBusinessEntity().getBusinessKey();
      // ignore this assertion if neither the from key nor the to key equals to this business's key
      if (!owningBusinessKey.equals(fromKey) && !owningBusinessKey.equals(toKey))
        continue;
      String otherBusinessKey = ((owningBusinessKey.equals(fromKey)) ? toKey : fromKey);
      // retrieve the information of the "other business"
      otherBusinessKeys.add(otherBusinessKey);

      // retrieve the status of the publisher assertion
      String status = assertionItem.getCompletionStatus().getText();
      KeyedReference keyedRef = assertionItem.getKeyedReference();
      PublisherAssertionElement pubAssertionElement = new PublisherAssertionElement(
                                                                                    fromKey,
                                                                                    toKey,
                                                                                    owningBusinessKey,
                                                                                    null,
                                                                                    -1,
                                                                                    status,
                                                                                    keyedRef);
      pubAssertionElements.add(pubAssertionElement);
    }
    if (otherBusinessKeys.size() > 0) {
      Vector busEntities;
      try {
        busEntities = proxy.get_businessDetail(otherBusinessKeys).getBusinessEntityVector();
      }
      catch (Exception ex) {
        busEntities = new Vector();
        if (otherBusinessKeys.size() > 1) {
          for (int j = 0; j < otherBusinessKeys.size(); j++) {
            try {
              busEntities.add(proxy.get_businessDetail((String)otherBusinessKeys.get(j)).getBusinessEntityVector().get(0));
            }
            catch (Exception exception) {
              pubAssertionElements.remove(j);
            }
          }
        }
        else
          pubAssertionElements.remove(0);
      }
      for (int j = 0; j < busEntities.size(); j++) {
        BusinessEntity be = (BusinessEntity)busEntities.get(j);
        PublisherAssertionElement pubAssertionElement = (PublisherAssertionElement)pubAssertionElements.get(j);
        ListElement le = new ListElement(be);
        queryInputVector.add(le);
        int subQueryItemId = queryInputVector.indexOf(le);
        pubAssertionElement.setServiceProvider(le);
        pubAssertionElement.setSubQueryItemId(subQueryItemId);
        listManager.add(new ListElement(pubAssertionElement));
      }
    }
    busElement.setPublisherAssertions(listManager);
    formToolPI.setProperty(UDDIActionInputs.QUERY_INPUT_EXISTING_PUBLISHER_ASSERTIONS, queryInputVector);
    messageQueue.addMessage(uddiPerspective.getMessage("MSG_INFO_PUBLISHER_ASSERTIONS_REFRESHED"));
    return true;
  }

  private boolean showPublisherAssertionsForNonOwnedBus(BusinessElement busElement) {
    UDDIPerspective uddiPerspective = controller_.getUDDIPerspective();
    MessageQueue messageQueue = uddiPerspective.getMessageQueue();

    // try to get a list of publisher assertions based on the business key
    ListManager listManager = new ListManager();
    FormTool formTool = getSelectedFormTool();
    FormToolPropertiesInterface formToolPI = ((MultipleFormToolPropertiesInterface)formTool).getFormToolProperties(subQueryKey_);
    formToolPI.removeProperty(UDDIActionInputs.QUERY_INPUT_EXISTING_PUBLISHER_ASSERTIONS);
    Vector queryInputVector = new Vector();
    UDDIProxy proxy = ((RegistryElement)registryNode_.getTreeElement()).getProxy();
    RelatedBusinessesList relatedBusList;
    try {
      relatedBusList = proxy.find_relatedBusinesses(busElement.getBusinessEntity().getBusinessKey(),
                                                                                                         (KeyedReference)null,
                                                                                                         (FindQualifiers)null);
    }
    catch (UDDIException uddie) {
      messageQueue.addMessage(controller_.getMessage("MSG_ERROR_UNEXPECTED"));
      messageQueue.addMessage("UDDIException");
      DispositionReport report = uddie.getDispositionReport();
	  Vector reportErrInfo = report.getResultVector();
      for (int i = 0; i < reportErrInfo.size(); i++) {
        messageQueue.addMessage(((Result) reportErrInfo.get(i)).getErrInfo().getText());
      }
      return false;
    }
    catch (Exception e) {
      messageQueue.addMessage(controller_.getMessage("MSG_ERROR_UNEXPECTED"));
      messageQueue.addMessage("Exception");
      messageQueue.addMessage(e.getMessage());
      return false;
    }
    Vector relatedBusVector = relatedBusList.getRelatedBusinessInfos().getRelatedBusinessInfoVector();
    Vector otherBusinessKeys = new Vector();
    Vector pubAssertionElements = new Vector();
    for (int i  = 0; i < relatedBusVector.size(); i++) {
      RelatedBusinessInfo relatedBusInfo = (RelatedBusinessInfo)relatedBusVector.elementAt(i);
      // determine the from/to business keys
      String fromKey;
      String toKey;
      String owningBusinessKey;
      if (relatedBusInfo.getDefaultSharedRelationships().getDirection().equals(SharedRelationships.DIRECTION_FROMKEY)) {
        fromKey = busElement.getBusinessEntity().getBusinessKey();
        toKey = relatedBusInfo.getBusinessKey();
        owningBusinessKey = fromKey;
        otherBusinessKeys.add(toKey);
      }
      else {
        fromKey = relatedBusInfo.getBusinessKey();
        toKey = busElement.getBusinessEntity().getBusinessKey();
        owningBusinessKey = toKey;
        otherBusinessKeys.add(fromKey);
      }

      Vector keyedRefVector = relatedBusInfo.getDefaultSharedRelationships().getKeyedReferenceVector();
      PublisherAssertionElement[] pubAssertionElementArray = new PublisherAssertionElement[keyedRefVector.size()];
      for (int k = 0; k < keyedRefVector.size(); k++) {
        // retrieve the status of the publisher assertion
        String status = CompletionStatus.COMPLETE;
        KeyedReference keyedRef = (KeyedReference)keyedRefVector.elementAt(k);
        PublisherAssertionElement pubAssertionElement = new PublisherAssertionElement(
                                                                                      fromKey,
                                                                                      toKey,
                                                                                      owningBusinessKey,
                                                                                      null,
                                                                                      -1,
                                                                                      status,
                                                                                      keyedRef);
        pubAssertionElementArray[k] = pubAssertionElement;
      }
      pubAssertionElements.add(pubAssertionElementArray);
    }
    if (otherBusinessKeys.size() > 0) {
      Vector busEntities;
      try {
        busEntities = proxy.get_businessDetail(otherBusinessKeys).getBusinessEntityVector();
      }
      catch (Exception ex) {
        busEntities = new Vector();
        if (otherBusinessKeys.size() > 1) {
          for (int j = 0; j < otherBusinessKeys.size(); j++) {
            try {
              busEntities.add(proxy.get_businessDetail((String)otherBusinessKeys.get(j)).getBusinessEntityVector().get(0));
            }
            catch (Exception exception) {
              pubAssertionElements.remove(j);
            }
          }
        }
        else
          pubAssertionElements.remove(0);
      }
      for (int j  = 0; j < busEntities.size(); j++) {
        BusinessEntity be = (BusinessEntity)busEntities.get(j);
        ListElement le = new ListElement(be);
        queryInputVector.add(le);
        int subQueryItemId = queryInputVector.indexOf(le);
        PublisherAssertionElement[] pubAssertionElementArray = (PublisherAssertionElement[])pubAssertionElements.get(j);
        for (int k = 0; k < pubAssertionElementArray.length; k++) {
          pubAssertionElementArray[k].setServiceProvider(le);
          pubAssertionElementArray[k].setSubQueryItemId(subQueryItemId);
          listManager.add(new ListElement(pubAssertionElementArray[k]));
        }
      }
    }
    busElement.setPublisherAssertions(listManager);
    formToolPI.setProperty(UDDIActionInputs.QUERY_INPUT_EXISTING_PUBLISHER_ASSERTIONS, queryInputVector);
    messageQueue.addMessage(uddiPerspective.getMessage("MSG_INFO_PUBLISHER_ASSERTIONS_REFRESHED"));
    return true;
  }
}

Back to the top