associate.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008              Lilian Qin Lan (lan)
00009 
00010   RCS information
00011    $Name: OSB_060808 $
00012    $Revision: 1.110 $
00013 
00014   License
00015    OSB rating and billing library for communication networks
00016    Copyright (C) 2004, 2005, 2006  OSB systems
00017 
00018    This file may be distributed and/or modify under the terms of the
00019    GNU General Public License (GPL) as published by the Free Software
00020    Foundation which is provided in the file LICENSE.GPL included in the
00021    packaging of this file.
00022 
00023    The file is distributed in the hope that it will be useful, but WITHOUT
00024    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00025    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00026    for more details.
00027 
00028    Holders of a OSB Commercial License may use this file under the terms
00029    and conditions of this commercial license.
00030  */
00031 #ifndef _ASSOCIATE_H_
00032 #define _ASSOCIATE_H_
00033 
00034 // *********************************************************************
00035 // included header files
00036 // + standard includes
00037 #include <set>
00038 #include <string>
00039 #include <map>
00040 
00041 // + local headers
00042 #include "address.h"
00043 #include "osbid.h"
00044 #include "status.h"
00045 #include "statuschange.h"
00046 #include "statusrequest.h"
00047 #include "taxkey.h"
00048 #include "account.h"
00049 
00050 // + class declarations
00051 namespace OSB_DB {
00052     class AssociateGw;
00053 }
00054 
00055 namespace OSB_LIB {
00056     class AnCList;
00057     class Contract;
00058     class OsbErrors;
00059 }
00060 
00061 // *********************************************************************
00062 // namespace extensions
00063 namespace OSB_LIB {
00064 
00073     class Associate {
00074         friend class OSB_DB::AssociateGw;
00079         friend class AnCList;
00084         friend class RequestHandler;
00085 
00086     public:
00097         enum Type {
00099             atUnknown  = '\0',
00101             atCustomer = 'c'
00102         };
00103 
00105         typedef Id<Associate> Oid;
00107         typedef std::map<Oid, Type> ChildrenList;
00109         typedef Id<Contract> ContractId;
00111         typedef std::set<ContractId> ContractIds;
00112 
00119         typedef std::auto_ptr<Associate> AutoPtr;
00120 
00121     public:
00123         Associate(const Oid& id)
00124           : oid_(id), levelId_(0), pAncList_(0)
00125         {
00126         }
00127 
00129         virtual ~Associate();
00130 
00131     protected:
00132         // unfortunately this does not prevent assignments from within the
00133         // class: commented out
00134         // Copying for derived classes only.
00135         // Associate(const Associate& rhs);
00136         // Assignment for derived classes only.
00137         // Associate& operator=(const Associate& rhs);
00138 
00139     public:
00147         static char toChar(Type at);
00155         static Type type(char at);
00156 
00157     public:
00159 
00160 
00180         virtual Type typeId() const = 0;
00181 
00182         const Oid&            oid()            const;
00183         const std::string&    name()           const;
00184         const Oid&            parentId()       const;
00185         unsigned int          levelId()        const;
00186         const TaxKey::Oid&    taxkey()         const;
00187         const Account&        salesLedger()    const;
00188         const Account&        purchaseLedger() const;
00189         const std::string&    accountNo()      const;
00190         const Status&         effStatus()      const;
00191         const DateTime&       effStatusDate()  const;
00192         const Status&         prefStatus()     const;
00193         const DateTime&       prefStatusDate() const;
00194         long                  objVs()          const;
00201         const StatusChanges&  statusChanges()  const;
00208         const StatusRequests& statusRequests() const;
00209         const AddressList&    addressList()    const;
00210         const ChildrenList&   childrenList()   const;
00211         const ContractIds&    contractIds()    const;
00213 
00215 
00216         void setName(const std::string& name);
00217         void setTaxKey(const TaxKey::Oid& tkId);
00218         void setSalesLedger(const Account& sl);
00219         void setPurchaseLedger(const Account& pl);
00220         void setAccountNo(const std::string& accountNo);
00222 
00230         bool read(
00231             const OSB_DB::Session& session
00232         );
00233 
00244         void readStatusChanges(
00245             const OSB_DB::Session& session,
00246             const Period&          period
00247         );
00248 
00259         void readStatusRequests(
00260             const OSB_DB::Session& session,
00261             const Period&          period
00262         );
00263 
00272         void update(OSB_DB::Session& session);
00273 
00274     private:
00283         bool insert(const OSB_DB::Session& session);
00284 
00297         bool remove(const OSB_DB::Session& session);
00298 
00310         static void handleObjectStatus(
00311                   ObjectStatus    os,
00312             const Associate::Oid& id
00313         );
00314 
00325         static void lock(
00326             const OSB_DB::Session& session,
00327             const Associate::Oid&  id,
00328                   bool             noWait
00329         );
00330 
00332 
00333 
00341         void lock(
00342             const OSB_DB::Session& session,
00343                   bool             noWait
00344         ) const;
00345 
00361         void incObjVs(const OSB_DB::Session& session);
00362 
00372         void lockChildren(
00373             const OSB_DB::Session& session,
00374                   bool             noWait
00375         );
00377 
00379 
00380 
00390         OsbError setPrefStatus(
00391             const OSB_DB::Session& session,
00392             const StatusRequest&   request
00393         );
00394 
00411         bool changeStatus(
00412             const OSB_DB::Session& session,
00413                   StatusChange&    change,
00414                   OsbErrors&       errors,
00415                   bool             noWait
00416         );
00417 
00433         bool applyChange(
00434             const OSB_DB::Session& session,
00435             const StatusChange&    change,
00436                   OsbErrors&       errors,
00437                   bool             noWait
00438         );
00440 
00446         void addressListErase(AddressType type);
00447 
00448     public:
00450 
00451 
00469         bool requestStatus(
00470             const OSB_DB::Session& session,
00471                   StatusRequest&   request,
00472                   OsbErrors&       errors,
00473                   bool             noWait
00474         );
00476 
00478 
00479 
00492         bool addAddress(
00493                   OSB_DB::Session& session,
00494             const Address&         addr
00495         );
00496 
00507         bool updAddress(
00508                   OSB_DB::Session& session,
00509             const Address&         addr
00510         );
00511 
00532         bool delAddress(
00533             OSB_DB::Session& session,
00534             AddressType      type,
00535             OsbErrors&       errors
00536         );
00537 
00556         bool linkAddressType(
00557             OSB_DB::Session& session,
00558             AddressType      type,
00559             AddressType      newType
00560         );
00561 
00579         bool unlinkAddressType(
00580             OSB_DB::Session& session,
00581             AddressType      type
00582         );
00583 
00591         const Address* findAddress(AddressType at) const;
00592 
00600         Address* address(AddressType at);
00601 
00610         const Address& getAddress(AddressType at) const;
00612 
00614 
00615 
00636         void addChild(
00637             OSB_DB::Session& session,
00638             Associate&       child
00639         );
00640 
00658         void delChild(
00659             OSB_DB::Session& session,
00660             Associate&       child
00661         );
00663 
00669         AutoPtr clone() const;
00670 
00698         template<typename A> A* isa(A*& ptr);
00700         template<typename A> const A* isa(const A*& ptr) const;
00701 
00702     private:
00708         virtual Associate* clone_() const = 0;
00709 
00711 
00712 
00723         bool addContract(
00724             const OSB_DB::Session& session,
00725             const ContractId&      coId
00726         );
00727 
00737         void delContract(
00738             const OSB_DB::Session& session,
00739             const ContractId&      coId
00740         );
00742 
00754         void getChildEffStatus(
00755             const OSB_DB::Session& session,
00756                   StatusChanges&   dest
00757         );
00758 
00759     protected:
00761         Oid oid_;
00763         std::string name_;
00765         Oid parentId_;
00772         unsigned int levelId_;
00774         Account salesLedger_;
00776         Account purchaseLedger_;
00778         std::string accountNo_;
00780         TaxKey::Oid taxkey_;
00782         Status effStatus_;
00784         DateTime effStatusDate_;
00786         Status prefStatus_;
00788         DateTime prefStatusDate_;
00790         long objVs_;
00792         StatusChanges chngs_;
00794         StatusRequests reqs_;
00796         AddressList addressList_;
00798         ChildrenList childrenList_;
00800         ContractIds contractIds_;
00807         AnCList* pAncList_;
00808     };                                  // class Associate
00809 
00815     class Customer : public Associate {
00817         static const Type typeId_ = atCustomer;
00818     public:
00819         // Documentation from base class.
00820         typedef std::auto_ptr<Customer> AutoPtr;
00821 
00823         Customer(const Oid& id) : Associate(id) {}
00824 
00825         // Documentation from base class.
00826         AutoPtr clone() const;
00827 
00828     private:
00829         // Documentation from base class.
00830         virtual Associate* clone_() const;
00832         virtual Type typeId() const { return typeId_; }
00833     };
00834 
00835 
00836     // *****************************************************************
00837     // AssociateFactory
00848     class AssociateFactory {
00849     public:
00862         static Associate::AutoPtr create(
00863                   Associate::Type  type,
00864             const Associate::Oid&  oid
00865         );
00866 
00867     private:
00869         AssociateFactory();
00871         AssociateFactory(const AssociateFactory& rhs);
00872     };
00873 }                                       // namespace OSB_LIB
00874 
00875 // ************************************************************************
00876 // template and inline definitions
00877 namespace OSB_LIB {
00878 
00879     // *****************************************************************
00880     // Associate
00881     template<typename A>
00882     inline A* Associate::isa(A*& ptr)
00883     {
00884         ptr = dynamic_cast<A*>(this);
00885         return ptr;
00886     }
00887 
00888     template<typename A>
00889     inline const A* Associate::isa(const A*& ptr) const
00890     {
00891         ptr = dynamic_cast<const A*>(this);
00892         return ptr;
00893     }
00894 
00895     inline const Associate::Oid& Associate::oid() const
00896     {
00897         return oid_;
00898     }
00899 
00900     inline const std::string& Associate::name() const
00901     {
00902         return name_;
00903     }
00904 
00905     inline const Associate::Oid& Associate::parentId() const
00906     {
00907         return parentId_;
00908     }
00909 
00910     inline unsigned int Associate::levelId() const
00911     {
00912         return levelId_;
00913     }
00914 
00915     inline const TaxKey::Oid& Associate::taxkey() const
00916     {
00917         return taxkey_;
00918     }
00919 
00920     inline const Account& Associate::salesLedger() const
00921     {
00922         return salesLedger_;
00923     }
00924 
00925     inline const Account& Associate::purchaseLedger() const
00926     {
00927         return purchaseLedger_;
00928     }
00929 
00930     inline const std::string& Associate::accountNo() const
00931     {
00932         return accountNo_;
00933     }
00934 
00935     inline const Status& Associate::effStatus() const
00936     {
00937         return effStatus_;
00938     }
00939 
00940     inline const DateTime& Associate::effStatusDate() const
00941     {
00942         return effStatusDate_;
00943     }
00944 
00945     inline const Status& Associate::prefStatus() const
00946     {
00947         return prefStatus_;
00948     }
00949 
00950     inline const DateTime& Associate::prefStatusDate() const
00951     {
00952         return prefStatusDate_;
00953     }
00954 
00955     inline long Associate::objVs() const
00956     {
00957         return objVs_;
00958     }
00959 
00960     inline const StatusChanges& Associate::statusChanges() const
00961     {
00962         return chngs_;
00963     }
00964 
00965     inline const StatusRequests& Associate::statusRequests() const
00966     {
00967         return reqs_;
00968     }
00969 
00970     inline const AddressList& Associate::addressList() const
00971     {
00972         return addressList_;
00973     }
00974 
00975     inline const Associate::ChildrenList& Associate::childrenList() const
00976     {
00977         return childrenList_;
00978     }
00979 
00980     inline const Associate::ContractIds& Associate::contractIds() const
00981     {
00982         return contractIds_;
00983     }
00984 }                                       // namespace OSB_LIB
00985 #endif                                  // #ifndef _ASSOCIATE_H_

Generated on Sat Sep 2 14:06:31 2006 for OSB Library by  doxygen 1.4.7