// THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD. // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. // // Copyright 2000-2004 © Softaris Pty.Ltd. All Rights Reserved. package com.hatbuyer.services; import com.hatbuyer.suppliers.hatmaker.coredomainsupport.UserDetails; import com.hatbuyer.suppliers.hatmaker.coredomainsupport.datamanagement.GetAllUsersInput; import com.hatbuyer.suppliers.hatmaker.coredomainsupport.datamanagement.GetAllUsersResult; import com.hatbuyer.suppliers.hatmaker.maindomainsupport.ClientDetails; import com.hatbuyer.suppliers.hatmaker.maindomainsupport.ProductDetails; import com.hatbuyer.suppliers.hatmaker.maindomainsupport.ProductKey; import com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.GetAllClientsInput; import com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.GetAllClientsResult; import com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.GetAllProductsInput; import com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.GetAllProductsResult; import com.hatbuyer.suppliers.hatmaker.miscellaneousservices.marketingqueries.GetClientsWhoOrderedProductsOrServicesInput; import com.hatbuyer.suppliers.hatmaker.miscellaneousservices.marketingqueries.GetClientsWhoOrderedProductsOrServicesResult; /** Simple Web Services client */ public class SampleService { com.hatbuyer.suppliers.hatmaker.coredomainsupport.datamanagement.WSPType_Stub mCoreDomainSupportStub = null; com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.WSPType_Stub mMainDomainSupportStub = null; com.hatbuyer.suppliers.hatmaker.miscellaneousservices.marketingqueries.WSPType_Stub mMarketingQueriesStub = null; UserDetails[] mLastUserDetails = null; ClientDetails[] mLastClientDetails = null; ProductDetails[] mLastProductDetails = null; public static void main(String[] args) { System.out.println(); System.out.println("Sample Java Client for the HatMaker Web Services"); System.out.println(); System.out.println(); try { SampleService client = new SampleService(); client.testGetAllUsers(); client.testGetAllClients(); client.testGetAllProducts(); client.testGetClientsWhoOrderedProductsOrServices(); } catch (Exception ex) { ex.printStackTrace(); } } public SampleService() { try { mCoreDomainSupportStub = (com.hatbuyer.suppliers.hatmaker.coredomainsupport.datamanagement.WSPType_Stub ) (new com.hatbuyer.suppliers.hatmaker.coredomainsupport.datamanagement.DataManagementWebService_Impl().getWSP()); mMainDomainSupportStub = (com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.WSPType_Stub ) (new com.hatbuyer.suppliers.hatmaker.maindomainsupport.datamanagement.DataManagementWebService_Impl().getWSP()); mMarketingQueriesStub = (com.hatbuyer.suppliers.hatmaker.miscellaneousservices.marketingqueries.WSPType_Stub ) (new com.hatbuyer.suppliers.hatmaker.miscellaneousservices.marketingqueries.MarketingQueriesWebService_Impl().getWSP()); } catch (Exception ex) { ex.printStackTrace(); } } public void testGetAllUsers() throws Exception { System.out.println("Running GetAllUsers()."); GetAllUsersInput lInput = new GetAllUsersInput(); GetAllUsersResult lResult = mCoreDomainSupportStub.getAllUsers(lInput); mLastUserDetails = lResult.getUsers(); if (mLastUserDetails != null) { System.out.println("Got " + mLastUserDetails.length + " users"); for (int i = 0; i < mLastUserDetails.length;i++) { UserDetails lUserDetail = mLastUserDetails[i]; System.out.println("User #" + Integer.toString(i+1) + ". Id: " + lUserDetail.getInstanceId() + " Name: " + lUserDetail.getName()); } } else System.out.println("No users were found"); } public void testGetAllClients() throws Exception { System.out.println("Running GetAllClients()."); GetAllClientsInput lInput = new GetAllClientsInput(); GetAllClientsResult lResult = mMainDomainSupportStub.getAllClients(lInput); mLastClientDetails = lResult.getClients(); if (mLastClientDetails != null) { System.out.println("Got " + mLastClientDetails.length + " clients"); for (int i = 0; i < mLastClientDetails.length;i++) { ClientDetails lClientDetail = mLastClientDetails[i]; System.out.println("Client #" + Integer.toString(i+1) + ". Id: " + lClientDetail.getInstanceId() + " Name: " + lClientDetail.getCompanyName()); } } else System.out.println("No clients were found"); } public void testGetAllProducts() throws Exception { System.out.println("Running GetAllProducts()."); GetAllProductsInput lInput = new GetAllProductsInput(); GetAllProductsResult lResult = mMainDomainSupportStub.getAllProducts(lInput); mLastProductDetails = lResult.getProducts(); if (mLastProductDetails != null) { System.out.println("Got " + mLastProductDetails.length + " products"); for (int i = 0; i < mLastProductDetails.length;i++) { ProductDetails lProductDetail = mLastProductDetails[i]; System.out.println("Product #" + Integer.toString(i+1) + ". Id: " + lProductDetail.getInstanceId() + " Name: " + lProductDetail.getName()); } } else System.out.println("No products were found"); } public void testGetClientsWhoOrderedProductsOrServices() throws Exception { if (mLastProductDetails == null) { System.out.println("The GetClientsWhoOrderedProductsOrServices() test requires GetAllProducts() test."); testGetAllProducts(); if (mLastProductDetails == null) return; } System.out.println("Running GetClientsWhoOrderedProductsOrServices()."); for (int i = 0; i < mLastProductDetails.length;i++) { ProductDetails lProductDetail = mLastProductDetails[i]; ProductKey lProductKey = new ProductKey(); lProductKey.setInstanceId(lProductDetail.getInstanceId()); GetClientsWhoOrderedProductsOrServicesInput lInput = new GetClientsWhoOrderedProductsOrServicesInput(); lInput.setProducts(new ProductKey[] { lProductKey } ); GetClientsWhoOrderedProductsOrServicesResult lResult = mMarketingQueriesStub.getClientsWhoOrderedProductsOrServices(lInput); ClientDetails[] lInterestedClientDetails = lResult.getClients(); if (lInterestedClientDetails != null) { System.out.println("Product " + lProductDetail.getName() + " have been ordered by " + lInterestedClientDetails.length + " clients:"); for (int j = 0; j < lInterestedClientDetails.length;j++) { ClientDetails lClientDetail = lInterestedClientDetails[j]; System.out.println(" Client #" + Integer.toString(j+1) + ". Id: " + lClientDetail.getInstanceId() + " Name: " + lClientDetail.getCompanyName()); } } else System.out.println("No matching client records found."); } } }