001: // This file is generated by MetaBoss at Sat Feb 21 10:22:26 EST 2004
002: // Generator class is com.metaboss.sdlctools.services.codegeneration.serviceproxygenerator.transactionmanagementproxy.BSServiceProxyGeneratorImpl
003: // MetaBoss release identifier is 0.5.0419
004: // MetaBoss is Copyright 2000-2004 © Softaris Pty.Ltd. All Rights Reserved.
005: // Source code in this file is owned by MetaBoss licensee
006: // Use and distribution of source code in this file governed by MetaBoss licensee
007: package com.hatmaker.crm.services.miscellaneousservices.defaultimpl;
008:
009: import javax.naming.Context;
010: import javax.naming.InitialContext;
011:
012: import org.apache.commons.logging.Log;
013: import org.apache.commons.logging.LogFactory;
014:
015: import com.hatmaker.crm.types.main.SupplierCategory;
016: import com.hatmaker.crm.domains.main.BODomain;
017: import com.hatmaker.crm.domains.main.BOProduct;
018: import com.hatmaker.crm.domains.main.BOSupplier;
019: import com.hatmaker.crm.services.maindomainsupport.STProductKey;
020: import com.hatmaker.crm.services.maindomainsupport.STSupplierKey;
021: import com.hatmaker.crm.services.maindomainsupport.generatedimpl.TRBOProduct;
022: import com.hatmaker.crm.services.maindomainsupport.generatedimpl.TRBOSupplier;
023: import com.hatmaker.crm.services.miscellaneousservices.BSBackofficeFunctions;
024: import com.metaboss.enterprise.bo.BOException;
025: import com.metaboss.enterprise.bs.BSDomainObjectInvocationException;
026: import com.metaboss.enterprise.bs.BSException;
027: import com.metaboss.enterprise.bs.BSNamingAndDirectoryServiceInvocationException;
028:
029: /** This class contains implementation of the service */
030: public class BSBackofficeFunctionsImpl
031: implements
032: com.hatmaker.crm.services.miscellaneousservices.BSBackofficeFunctions {
033: private static final Log sLogger = LogFactory
034: .getLog(BSBackofficeFunctionsImpl.class);
035:
036: /** Constructor. */
037: BSBackofficeFunctionsImpl() throws Exception {
038: }
039:
040: /** Implementation for {@link com.hatmaker.crm.services.miscellaneousservices.BSBackofficeFunctions#modifySupplierProducts(com.hatmaker.crm.services.miscellaneousservices.BSBackofficeFunctions.STModifySupplierProductsInput) modifySupplierProducts} method */
041: public com.hatmaker.crm.services.miscellaneousservices.BSBackofficeFunctions.STModifySupplierProductsResult modifySupplierProducts(
042: com.hatmaker.crm.services.miscellaneousservices.BSBackofficeFunctions.STModifySupplierProductsInput pInput)
043: throws BSException {
044: BSBackofficeFunctions.STModifySupplierProductsResult lOperationResult = new BSBackofficeFunctions.STModifySupplierProductsResult();
045: STSupplierKey lSupplierKey = pInput.getSupplierKey();
046: STProductKey[] lProductKeysToAdd = pInput.getProductsToAdd();
047: STProductKey[] lProductKeysToRemove = pInput
048: .getProductsToRemove();
049: try {
050: Context lContext = new InitialContext();
051: BODomain lDomain = (BODomain) lContext
052: .lookup(BODomain.COMPONENT_URL);
053: lDomain.beginEdit();
054: BOSupplier lSupplier = TRBOSupplier.getBOSupplier(lDomain,
055: lSupplierKey);
056: lSupplier.beginEdit();
057:
058: // --------------------------------------------------------------------------------------------------
059: // The line below is not necessary from the business logic point of view
060: // It is inserted to test an old bug which was preventing noop updates from working
061: // lDomain.saveChanges(); // Changes were not done yet, so there should be no updates to database and no version id changes
062: // --------------------------------------------------------------------------------------------------
063:
064: // Add everything there is to add
065: if (lProductKeysToAdd != null
066: && lProductKeysToAdd.length > 0) {
067: for (int i = 0; i < lProductKeysToAdd.length; i++) {
068: BOProduct lProduct = TRBOProduct.getBOProduct(
069: lDomain, lProductKeysToAdd[i]);
070: lSupplier.addProduct(lProduct);
071: }
072: }
073: // Remove everything there is to remove
074: if (lProductKeysToRemove != null
075: && lProductKeysToRemove.length > 0) {
076: for (int i = 0; i < lProductKeysToRemove.length; i++) {
077: BOProduct lProduct = TRBOProduct.getBOProduct(
078: lDomain, lProductKeysToRemove[i]);
079: lSupplier.removeProduct(lProduct);
080: }
081: }
082: // Save changes so the query below will reflect them
083: lDomain.saveChanges();
084: // Now return the collection of products after applying the changes
085: BOProduct[] lSupplierProducts = lSupplier.getProducts()
086: .toProductsArray();
087: lOperationResult.setSupplierProducts(TRBOProduct
088: .convertToDetailsStructureArray(lSupplierProducts));
089: // As a byproduct, set the supplier category for less than 2 and for more than 2 products
090: if (lSupplierProducts.length == 1)
091: lSupplier.setCategory(SupplierCategory.SINGLEPRODUCT);
092: else if (lSupplierProducts.length >= 3)
093: lSupplier.setCategory(SupplierCategory.CATEGORYKILLER);
094: else
095: lSupplier.setCategory(SupplierCategory.createEmpty());
096: return lOperationResult;
097: } catch (javax.naming.NamingException e) {
098: throw new BSNamingAndDirectoryServiceInvocationException(
099: "Unable to complete addProductsToSupplier operation.",
100: e);
101: } catch (BOException e) {
102: throw new BSDomainObjectInvocationException(
103: "Unable to complete addProductsToSupplier operation.",
104: e);
105: }
106: }
107: }
|