This project has retired. For details please refer to its Attic page.
XRegisterHelper xref
View Javadoc
1   /*
2    * Copyright 2001-2009 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   */
17  package org.apache.juddi.api.impl;
18  
19  import org.apache.commons.logging.Log;
20  import org.apache.commons.logging.LogFactory;
21  import org.apache.juddi.api_v3.Clerk;
22  import org.apache.juddi.v3.client.config.UDDIClerk;
23  import org.apache.juddi.v3.client.config.XRegistration;
24  import org.uddi.api_v3.BindingDetail;
25  import org.uddi.api_v3.BindingTemplate;
26  import org.uddi.api_v3.BusinessDetail;
27  import org.uddi.api_v3.BusinessEntity;
28  import org.uddi.api_v3.BusinessInfo;
29  import org.uddi.api_v3.BusinessService;
30  import org.uddi.api_v3.ServiceDetail;
31  import org.uddi.api_v3.ServiceInfo;
32  import org.uddi.sub_v3.SubscriptionResultsList;
33  
34  /**
35   * Used to factor out inquiry functionality as it is used in more than one spot.
36   * 
37   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
38   */
39  public class XRegisterHelper {
40  
41  	private static Log log = LogFactory.getLog(XRegisterHelper.class);
42  
43  	public static void handle(Clerk fromClerk, Clerk toClerk, SubscriptionResultsList list) {
44  
45  		UDDIClerk uddiToClerk = new UDDIClerk(toClerk);
46  		UDDIClerk uddiFromClerk = new UDDIClerk(fromClerk);
47  		//SERVICE LIST
48  		if (list.getServiceList()!=null) {
49  			log.info("Subscription result for ServiceList with subscription key=" + list.getSubscription().getSubscriptionKey());
50  			for (ServiceInfo serviceInfo : list.getServiceList().getServiceInfos().getServiceInfo() ) {
51  				
52  				BusinessEntity existingBusinessEntity = null;
53  				try {
54  					if (existingBusinessEntity==null) {
55  						existingBusinessEntity = uddiToClerk.findBusiness(serviceInfo.getBusinessKey(), toClerk.getNode());
56  					}
57  					if (existingBusinessEntity!=null) {
58  						log.debug("Found business with key " +  existingBusinessEntity.getBusinessKey() + ". No need to add it again");
59  					} else {
60  						log.info("Business was not found in the destination UDDI " + toClerk.getNode().getName() 
61  								+ ", going to add it in.");
62  						new XRegistration(serviceInfo.getBusinessKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterBusiness();
63  					}
64  					new XRegistration(serviceInfo.getServiceKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterServiceAndBindings();
65  				} catch (Exception e) {
66  					log.error(e.getMessage(),e);	
67  				}
68  			}
69  		}
70  		//SERVICE DETAIL
71  		if (list.getServiceDetail()!=null) {
72  			log.info("Subscription result for ServiceDetail with subscription key=" + list.getSubscription().getSubscriptionKey());
73  			ServiceDetail serviceDetail = list.getServiceDetail();
74  			if (serviceDetail.isTruncated()) {
75  				log.info("The serviceDetail is truncated, the maxEntries must have been hit. The number of services is " + serviceDetail.getBusinessService().size());
76  			}
77  			for (BusinessService service : serviceDetail.getBusinessService()) {
78  				BusinessEntity existingBusinessEntity = null;
79  				try {
80  					if (existingBusinessEntity==null) {
81  						existingBusinessEntity = uddiToClerk.findBusiness(service.getBusinessKey(), toClerk.getNode());
82  					}
83  					if (existingBusinessEntity!=null) {
84  						log.debug("Found business with key " +  existingBusinessEntity.getBusinessKey() + ". No need to add it again");
85  					} else {
86  						log.info("Business was not found in the destination UDDI " + toClerk.getNode().getName() 
87  								+ ", going to add it in.");
88  						new XRegistration(service.getBusinessKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterBusiness();
89  					}
90  					new XRegistration(service.getServiceKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterServiceAndBindings();
91  				} catch (Exception e) {
92  					log.error(e.getMessage(),e);	
93  				}
94  			}
95  		}
96  		
97  		//BUSINESS LIST
98  		if (list.getBusinessList()!=null) {
99  			log.info("Subscription result for BusinessList with subscription key=" + list.getSubscription().getSubscriptionKey());
100 			for (BusinessInfo businessInfo : list.getBusinessList().getBusinessInfos().getBusinessInfo()) {
101 				new XRegistration(businessInfo.getBusinessKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterBusinessAndServices();
102 			}
103 		}
104 		
105 		//BUSINESS DETAIL
106 		if (list.getBusinessDetail()!=null) {
107 			log.info("Subscription result for BusinessDetail with subscription key=" + list.getSubscription().getSubscriptionKey());
108 			BusinessDetail businessDetail = list.getBusinessDetail();
109 			if (businessDetail.isTruncated()) {
110 				log.info("The businessDetail is truncated, the maxEntries must have been hit. The number of businesses is " + businessDetail.getBusinessEntity().size());
111 			}
112 			for (BusinessEntity businessEntity : businessDetail.getBusinessEntity()) {
113 				new XRegistration(businessEntity.getBusinessKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterBusinessAndServices();
114 			}
115 		}
116 		
117 		//KEY BAG, NOT IMPLEMENTED
118 		if (list.getKeyBag()!=null) {
119 			log.info("Returning results when a 'brief' format is selected, please do not use 'brief' results when using the XRegistration functionality");
120 		}
121 		
122 		//BINDING DETAIL
123 		if (list.getBindingDetail()!=null) {
124 			log.info("Subscription result for BindingDetail with subscription key=" + list.getSubscription().getSubscriptionKey());
125 			BindingDetail bindingDetail = list.getBindingDetail();
126 			if (bindingDetail.isTruncated()) {
127 				log.info("The bindingDetail is truncated, the maxEntries must have been hit. The number of bindings is " + bindingDetail.getBindingTemplate().size());
128 			}
129 			for (BindingTemplate bindingTemplate : bindingDetail.getBindingTemplate()) {
130 				try {
131 					//check if the service exist
132 					BusinessService existingToService = uddiToClerk.findService(bindingTemplate.getServiceKey(), toClerk.getNode());
133 					if (existingToService!=null) {
134 						log.debug("Found service with key " +  existingToService.getServiceKey() + ". No need to add it again");
135 					} else {
136 						BusinessService fromService = uddiFromClerk.findService(bindingTemplate.getServiceKey(), fromClerk.getNode());
137 						//check if the business exist
138 						BusinessEntity existingBusinessEntity = uddiToClerk.findBusiness(fromService.getBusinessKey(), toClerk.getNode());
139 						if (existingBusinessEntity!=null) {
140 							log.debug("Found business with key " +  existingBusinessEntity.getBusinessKey() + ". No need to add it again");
141 						} else {
142 							log.info("Business was not found in the destination UDDI " + toClerk.getNode().getName() 
143 									+ ", going to add it in.");
144 							new XRegistration(fromService.getBusinessKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterBusiness();
145 						}
146 						log.info("Service was not found in the destination UDDI " + toClerk.getNode().getName() 
147 								+ ", going to add it in.");
148 						new XRegistration(fromService.getServiceKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterService();
149 					} 
150 					//now the service exists in the toNode and we can add this binding
151 					new XRegistration(bindingTemplate.getBindingKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterServiceBinding();
152 				} catch (Exception e) {
153 					log.error(e.getMessage(),e);	
154 				}
155 			}
156 		}
157 		
158 		//RELATED BUSINESSES
159 		if (list.getRelatedBusinessesList()!=null) {
160 			log.info("Subscription result for RelatedBusinesses with subscription key=" + list.getSubscription().getSubscriptionKey());
161 			log.info("The jUDDI Listener is not doing anything with this subscription at this moment");
162 		}
163 		
164 		//ASSERTION STATUS REPORT
165 		if (list.getAssertionStatusReport()!=null) {
166 			log.info("Subscription result for AssertionStatusReport with subscription key=" + list.getSubscription().getSubscriptionKey());
167 			log.info("The jUDDI Listener is not doing anything with this subscription at this moment");
168 		}
169 		
170 		//TMODELS
171 		if (list.getTModelList()!=null ){
172 			log.info("Subscription result for tModelList with subscription key=" + list.getSubscription().getSubscriptionKey());
173 			log.info("The jUDDI Listener is not doing anything with this subscription at this moment");
174 		}
175 	}
176 
177 }