001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2004 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.hatbuyer.services;
016:
017: import com.hatbuyer.suppliers.hatmaker.coredomainsupport.UserDetails;
018: import com.hatbuyer.suppliers.hatmaker.coredomainsupport.datamanagement.GetAllUsersInput;
019: import com.hatbuyer.suppliers.hatmaker.coredomainsupport.datamanagement.GetAllUsersResult;
020: import com.hatbuyer.suppliers.hatmaker.maindomainsupport.ClientDetails;
021: import com.hatbuyer.suppliers.hatmaker.maindomainsupport.ProductDetails;
022: import com.hatbuyer.suppliers.hatmaker.maindomainsupport.ProductKey;
023: import com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.GetAllClientsInput;
024: import com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.GetAllClientsResult;
025: import com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.GetAllProductsInput;
026: import com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.GetAllProductsResult;
027: import com.hatbuyer.suppliers.hatmaker.miscellaneousservices.marketingqueries.GetClientsWhoOrderedProductsOrServicesInput;
028: import com.hatbuyer.suppliers.hatmaker.miscellaneousservices.marketingqueries.GetClientsWhoOrderedProductsOrServicesResult;
029:
030: /** Simple Web Services client */
031: public class SampleService {
032:
033: com.hatbuyer.suppliers.hatmaker.coredomainsupport.datamanagement.WSPType_Stub mCoreDomainSupportStub = null;
034: com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.WSPType_Stub mMainDomainSupportStub = null;
035: com.hatbuyer.suppliers.hatmaker.miscellaneousservices.marketingqueries.WSPType_Stub mMarketingQueriesStub = null;
036: UserDetails[] mLastUserDetails = null;
037: ClientDetails[] mLastClientDetails = null;
038: ProductDetails[] mLastProductDetails = null;
039:
040: public static void main(String[] args) {
041: System.out.println();
042: System.out
043: .println("Sample Java Client for the HatMaker Web Services");
044: System.out.println();
045: System.out.println();
046: try {
047: SampleService client = new SampleService();
048: client.testGetAllUsers();
049: client.testGetAllClients();
050: client.testGetAllProducts();
051: client.testGetClientsWhoOrderedProductsOrServices();
052: } catch (Exception ex) {
053: ex.printStackTrace();
054: }
055: }
056:
057: public SampleService() {
058: try {
059: mCoreDomainSupportStub = (com.hatbuyer.suppliers.hatmaker.coredomainsupport.datamanagement.WSPType_Stub) (new com.hatbuyer.suppliers.hatmaker.coredomainsupport.datamanagement.DataManagementWebService_Impl()
060: .getWSP());
061: mMainDomainSupportStub = (com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.WSPType_Stub) (new com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.DataManagementWebService_Impl()
062: .getWSP());
063: mMarketingQueriesStub = (com.hatbuyer.suppliers.hatmaker.miscellaneousservices.marketingqueries.WSPType_Stub) (new com.hatbuyer.suppliers.hatmaker.miscellaneousservices.marketingqueries.MarketingQueriesWebService_Impl()
064: .getWSP());
065: } catch (Exception ex) {
066: ex.printStackTrace();
067: }
068: }
069:
070: public void testGetAllUsers() throws Exception {
071: System.out.println("Running GetAllUsers().");
072: GetAllUsersInput lInput = new GetAllUsersInput();
073: GetAllUsersResult lResult = mCoreDomainSupportStub
074: .getAllUsers(lInput);
075: mLastUserDetails = lResult.getUsers();
076: if (mLastUserDetails != null) {
077: System.out.println("Got " + mLastUserDetails.length
078: + " users");
079: for (int i = 0; i < mLastUserDetails.length; i++) {
080: UserDetails lUserDetail = mLastUserDetails[i];
081: System.out.println("User #" + Integer.toString(i + 1)
082: + ". Id: " + lUserDetail.getInstanceId()
083: + " Name: " + lUserDetail.getName());
084: }
085: } else
086: System.out.println("No users were found");
087: }
088:
089: public void testGetAllClients() throws Exception {
090: System.out.println("Running GetAllClients().");
091: GetAllClientsInput lInput = new GetAllClientsInput();
092: GetAllClientsResult lResult = mMainDomainSupportStub
093: .getAllClients(lInput);
094: mLastClientDetails = lResult.getClients();
095: if (mLastClientDetails != null) {
096: System.out.println("Got " + mLastClientDetails.length
097: + " clients");
098: for (int i = 0; i < mLastClientDetails.length; i++) {
099: ClientDetails lClientDetail = mLastClientDetails[i];
100: System.out.println("Client #" + Integer.toString(i + 1)
101: + ". Id: " + lClientDetail.getInstanceId()
102: + " Name: " + lClientDetail.getCompanyName());
103: }
104: } else
105: System.out.println("No clients were found");
106: }
107:
108: public void testGetAllProducts() throws Exception {
109: System.out.println("Running GetAllProducts().");
110: GetAllProductsInput lInput = new GetAllProductsInput();
111: GetAllProductsResult lResult = mMainDomainSupportStub
112: .getAllProducts(lInput);
113: mLastProductDetails = lResult.getProducts();
114: if (mLastProductDetails != null) {
115: System.out.println("Got " + mLastProductDetails.length
116: + " products");
117: for (int i = 0; i < mLastProductDetails.length; i++) {
118: ProductDetails lProductDetail = mLastProductDetails[i];
119: System.out.println("Product #"
120: + Integer.toString(i + 1) + ". Id: "
121: + lProductDetail.getInstanceId() + " Name: "
122: + lProductDetail.getName());
123: }
124: } else
125: System.out.println("No products were found");
126: }
127:
128: public void testGetClientsWhoOrderedProductsOrServices()
129: throws Exception {
130: if (mLastProductDetails == null) {
131: System.out
132: .println("The GetClientsWhoOrderedProductsOrServices() test requires GetAllProducts() test.");
133: testGetAllProducts();
134: if (mLastProductDetails == null)
135: return;
136: }
137: System.out
138: .println("Running GetClientsWhoOrderedProductsOrServices().");
139: for (int i = 0; i < mLastProductDetails.length; i++) {
140: ProductDetails lProductDetail = mLastProductDetails[i];
141: ProductKey lProductKey = new ProductKey();
142: lProductKey.setInstanceId(lProductDetail.getInstanceId());
143: GetClientsWhoOrderedProductsOrServicesInput lInput = new GetClientsWhoOrderedProductsOrServicesInput();
144: lInput.setProducts(new ProductKey[] { lProductKey });
145: GetClientsWhoOrderedProductsOrServicesResult lResult = mMarketingQueriesStub
146: .getClientsWhoOrderedProductsOrServices(lInput);
147: ClientDetails[] lInterestedClientDetails = lResult
148: .getClients();
149: if (lInterestedClientDetails != null) {
150: System.out
151: .println("Product " + lProductDetail.getName()
152: + " have been ordered by "
153: + lInterestedClientDetails.length
154: + " clients:");
155: for (int j = 0; j < lInterestedClientDetails.length; j++) {
156: ClientDetails lClientDetail = lInterestedClientDetails[j];
157: System.out.println(" Client #"
158: + Integer.toString(j + 1) + ". Id: "
159: + lClientDetail.getInstanceId() + " Name: "
160: + lClientDetail.getCompanyName());
161: }
162: } else
163: System.out.println("No matching client records found.");
164: }
165: }
166: }
|