1/*2 * Copyright 2001-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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 *16 */17package org.apache.juddi.v3.client.cli;
1819import java.util.ArrayList;
20import java.util.GregorianCalendar;
21import java.util.List;
22import javax.xml.datatype.DatatypeFactory;
23import javax.xml.datatype.XMLGregorianCalendar;
24import javax.xml.ws.Holder;
25import org.apache.juddi.v3.client.config.UDDIClient;
26import org.apache.juddi.v3.client.transport.Transport;
27import org.apache.juddi.v3_service.JUDDIApiPortType;
28import org.uddi.api_v3.*;
29import org.uddi.v3_service.UDDIPublicationPortType;
30import org.uddi.v3_service.UDDISecurityPortType;
3132/**33 * This will create two businesses under different users, then setup a34 * relationship between the two35 *36 * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>37 */38publicclassUddiRelatedBusinesses {
3940privateUDDISecurityPortType security = null;
41privateUDDIPublicationPortType publish = null;
4243publicUddiRelatedBusinesses() {
44try {
45// create a manager and read the config in the archive; 46// you can use your config file name47UDDIClient clerkManager = newUDDIClient("META-INF/simple-publish-uddi.xml");
48Transport transport = clerkManager.getTransport();
49// Now you create a reference to the UDDI API50 security = transport.getUDDISecurityService();
51 publish = transport.getUDDIPublishService();
52 } catch (Exception e) {
53 e.printStackTrace();
54 }
55 }
5657publicvoid fire(String businessKey, String authInfo, String businessKey1, String authInfo1, String relationship) throws Exception {
58try {
5960 GregorianCalendar gcal = new GregorianCalendar();
61 gcal.setTimeInMillis(System.currentTimeMillis());
62//ROOT creates half of the relationship63//create a business relationship (publisher assertion)64 Holder<List<PublisherAssertion>> x = new Holder<List<PublisherAssertion>>();
65PublisherAssertion pa = newPublisherAssertion();
66 pa.setFromKey(businessKey);
67 pa.setToKey(businessKey1);
68 pa.setKeyedReference(newKeyedReference());
69 pa.getKeyedReference().setKeyName("Subsidiary");
70 pa.getKeyedReference().setKeyValue(relationship);
7172 pa.getKeyedReference().setTModelKey("uddi:uddi.org:relationships");
73 x.value = new ArrayList<PublisherAssertion>();
74 x.value.add(pa);
75 publish.setPublisherAssertions(authInfo, x);
7677//now "UDDI" the user, creates the other half. It has to be mirrored exactly78 x = new Holder<List<PublisherAssertion>>();
79 pa = newPublisherAssertion();
80 pa.setFromKey(businessKey);
81 pa.setToKey(businessKey1);
82 pa.setKeyedReference(newKeyedReference());
83 pa.getKeyedReference().setKeyName("Subsidiary");
84 pa.getKeyedReference().setKeyValue(relationship);
8586 pa.getKeyedReference().setTModelKey("uddi:uddi.org:relationships");
87 x.value = new ArrayList<PublisherAssertion>();
88 x.value.add(pa);
89 publish.setPublisherAssertions(authInfo1, x);
9091 System.out.println("Success!");
92/*93 * Here's some notes:94 * You can use95 * List<AssertionStatusItem> assertionStatusReport = publish.getAssertionStatusReport(UDDIAuthToken.getAuthInfo(), CompletionStatus.STATUS_FROM_KEY_INCOMPLETE);96 * to determine if there's any assertions/relationships requests that are pending97 * this should have one item it in, the relationship that's incomplete98 * 99 * There's also publish.deletePublisherAssertions();100 */101 } catch (Exception e) {
102 e.printStackTrace();
103 }
104 }
105106publicstaticvoid main(String args[]) throws Exception {
107UddiRelatedBusinesses sp = newUddiRelatedBusinesses();
108109GetAuthToken getAuthTokenRoot = newGetAuthToken();
110 getAuthTokenRoot.setUserID("root");
111 getAuthTokenRoot.setCred("root");
112113// Making API call that retrieves the authentication token for the 'root' user.114AuthToken rootAuthToken = sp.security.getAuthToken(getAuthTokenRoot);
115 System.out.println("root AUTHTOKEN = " + "don't log auth tokens!");
116BusinessEntity rootbiz = sp.createBusiness("root");
117118 getAuthTokenRoot = newGetAuthToken();
119 getAuthTokenRoot.setUserID("uddi");
120 getAuthTokenRoot.setCred("uddi");
121122// Making API call that retrieves the authentication token for the 'root' user.123AuthToken uddiAuthToken = sp.security.getAuthToken(getAuthTokenRoot);
124 System.out.println("uddi AUTHTOKEN = " + "don't log auth tokens!");
125BusinessEntity uddibiz = sp.createBusiness("uddi");
126127//save user uddi's business128SaveBusiness sb = newSaveBusiness();
129 sb.setAuthInfo(uddiAuthToken.getAuthInfo());
130 sb.getBusinessEntity().add(uddibiz);
131BusinessDetail uddibize = sp.publish.saveBusiness(sb);
132133 sb = newSaveBusiness();
134 sb.setAuthInfo(rootAuthToken.getAuthInfo());
135 sb.getBusinessEntity().add(rootbiz);
136BusinessDetail rootbize = sp.publish.saveBusiness(sb);
137138 sp.fire(rootbize.getBusinessEntity().get(0).getBusinessKey(), rootAuthToken.getAuthInfo(),
139 uddibize.getBusinessEntity().get(0).getBusinessKey(), uddiAuthToken.getAuthInfo(),
140"parent-child");
141 }
142143privateBusinessEntity createBusiness(String user) {
144BusinessEntity be = newBusinessEntity();
145 be.getName().add(new Name(user + "'s business", null));
146return be;
147 }
148149 }