View Javadoc
1   /*
2    * Copyright 2013 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.v3.client.cli;
17  
18  import org.apache.juddi.api_v3.AccessPointType;
19  import org.apache.juddi.v3.client.config.UDDIClient;
20  import org.apache.juddi.v3.client.ext.wsdm.WSDMQosConstants;
21  import org.apache.juddi.v3.client.compare.TModelInstanceDetailsComparator;
22  import org.uddi.api_v3.AccessPoint;
23  import org.uddi.api_v3.BindingTemplate;
24  import org.uddi.api_v3.BindingTemplates;
25  import org.uddi.api_v3.BusinessEntity;
26  import org.uddi.api_v3.BusinessService;
27  import org.uddi.api_v3.BusinessServices;
28  import org.uddi.api_v3.Contact;
29  import org.uddi.api_v3.Contacts;
30  import org.uddi.api_v3.Description;
31  import org.uddi.api_v3.DiscoveryURL;
32  import org.uddi.api_v3.DiscoveryURLs;
33  import org.uddi.api_v3.InstanceDetails;
34  import org.uddi.api_v3.Name;
35  import org.uddi.api_v3.PersonName;
36  import org.uddi.api_v3.TModelInstanceDetails;
37  import org.uddi.api_v3.TModelInstanceInfo;
38  
39  /**
40   * doesn't make changes to a remote server, just creates a few businesses and compares the two by qos parameters
41   * @author Alex O'Ree
42   */
43  public class CompareByTModelInstanceInfoQOS {
44  
45      
46      public static void main(String[] args) throws Exception {
47              BusinessEntity mary = CreateMary();
48              BindingTemplate bt1 = mary.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0);
49              BindingTemplate bt2 = mary.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(1);
50              
51              TModelInstanceDetailsComparator tidc = new TModelInstanceDetailsComparator(WSDMQosConstants.METRIC_FAULT_COUNT_KEY, true, false, false);
52              int compare = tidc.compare(bt1.getTModelInstanceDetails(), bt2.getTModelInstanceDetails());
53              if (compare > 0)
54                      System.out.println(mary.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0).getAccessPoint().getValue() +
55                              " is greater than " + mary.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(1).getAccessPoint().getValue());
56              if (compare < 0)
57                      System.out.println(mary.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0).getAccessPoint().getValue() +
58                              " is less than " + mary.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(1).getAccessPoint().getValue());
59              if (compare== 0)
60                      System.out.println(mary.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0).getAccessPoint().getValue() +
61                              " is equal to " + mary.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(1).getAccessPoint().getValue());
62              
63      }
64  
65      
66  
67      /**
68       * creates a business, service, bt with tmodel instance details with qos
69       * parameters
70       *
71       * @param rootAuthToken
72       * @throws Exception
73       */
74      private static BusinessEntity CreateMary() throws Exception {
75          BusinessEntity be = new BusinessEntity();
76          be.setBusinessKey("uddi:uddi.marypublisher.com:marybusinessone");
77          be.setDiscoveryURLs(new DiscoveryURLs());
78          be.getDiscoveryURLs().getDiscoveryURL().add(new DiscoveryURL("home", "http://www.marybusinessone.com"));
79          be.getDiscoveryURLs().getDiscoveryURL().add(new DiscoveryURL("serviceList", "http://www.marybusinessone.com/services"));
80          be.getName().add(new Name("Mary Doe Enterprises", "en"));
81          be.getName().add(new Name("Maria Negocio Uno", "es"));
82          be.getDescription().add(new Description("This is the description for Mary Business One.", "en"));
83          be.setContacts(new Contacts());
84          Contact c = new Contact();
85          c.setUseType("administrator");
86          c.getPersonName().add(new PersonName("Mary Doe", "en"));
87          c.getPersonName().add(new PersonName("Juan Doe", "es"));
88          c.getDescription().add(new Description("This is the administrator of the service offerings.", "en"));
89          be.getContacts().getContact().add(c);
90          be.setBusinessServices(new BusinessServices());
91          BusinessService bs = new BusinessService();
92          bs.setBusinessKey("uddi:uddi.marypublisher.com:marybusinessone");
93          bs.setServiceKey("uddi:uddi.marypublisher.com:marybusinessoneservice");
94          bs.getName().add(new Name("name!", "en"));
95          bs.setBindingTemplates(new BindingTemplates());
96          BindingTemplate bt = new BindingTemplate();
97          bt.setAccessPoint(new AccessPoint("http://localhost/endpoint1BAD", AccessPointType.WSDL_DEPLOYMENT.toString()));
98          bt.setTModelInstanceDetails(new TModelInstanceDetails());
99          TModelInstanceInfo tii = new TModelInstanceInfo();
100         tii.setTModelKey(WSDMQosConstants.METRIC_FAULT_COUNT_KEY);
101 
102         tii.setInstanceDetails(new InstanceDetails());
103         tii.getInstanceDetails().setInstanceParms("400");
104         bt = UDDIClient.addSOAPtModels(bt);
105         bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tii);
106         bs.getBindingTemplates().getBindingTemplate().add(bt);
107         
108         bt = new BindingTemplate();
109         bt.setAccessPoint(new AccessPoint("http://localhost/endpoint2BETTER", AccessPointType.WSDL_DEPLOYMENT.toString()));
110         bt.setTModelInstanceDetails(new TModelInstanceDetails());
111          tii = new TModelInstanceInfo();
112         tii.setTModelKey(WSDMQosConstants.METRIC_FAULT_COUNT_KEY);
113 
114         tii.setInstanceDetails(new InstanceDetails());
115         tii.getInstanceDetails().setInstanceParms("4");
116         bt = UDDIClient.addSOAPtModels(bt);
117         bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tii);
118         bs.getBindingTemplates().getBindingTemplate().add(bt);
119         
120         
121         be.getBusinessServices().getBusinessService().add(bs);
122         
123         return be;
124     }
125 }