persproduct.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00009 /*
00010   AUTHOR(S): Stephan Broennimann (vb)
00011 
00012   RCS information
00013    $Name: OSB_060808 $
00014    $Revision: 1.166 $
00015 
00016   License
00017    OSB rating and billing library for communication networks
00018    Copyright (C) 2004, 2005, 2006  OSB systems
00019 
00020    This file may be distributed and/or modify under the terms of the
00021    GNU General Public License (GPL) as published by the Free Software
00022    Foundation which is provided in the file LICENSE.GPL included in the
00023    packaging of this file.
00024 
00025    The file is distributed in the hope that it will be useful, but WITHOUT
00026    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00027    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00028    for more details.
00029 
00030    Holders of a OSB Commercial License may use this file under the terms
00031    and conditions of this commercial license.
00032  */
00033 #ifndef _PERSPRODUCT_H_
00034 #define _PERSPRODUCT_H_
00035 
00036 // ************************************************************************
00037 // included header files
00038 // + standard includes
00039 #include <list>
00040 
00041 // + local headers
00042 #include "chrono.h"
00043 #include "osbid.h"
00044 #include "persitem.h"
00045 #include "persitems.h"
00046 #include "product.h"
00047 #include "status.h"
00048 #include "statuschange.h"
00049 #include "statusrequest.h"
00050 
00051 // + class declarations
00052 namespace OSB_DB {
00053     class PersProductGw;
00054 }
00055 
00056 namespace OSB_LIB {
00057     class Associate;
00058     class Contract;
00059     class OsbErrors;
00060     class PersCredit;
00061     class RequestHandler;
00062     class TariffSystem;
00063 }
00064 
00065 // ************************************************************************
00066 // namespace extensions
00067 namespace OSB_LIB {
00068 
00069     // forwards
00070     class PersProduct;
00071 
00081     class PersProductNode {
00082         friend class OSB_DB::PersProductGw;
00084         friend class PersProduct;
00085 
00086     public:
00095         typedef Id2<PersProductNode> Oid;
00096 
00097     public:
00101         PersProductNode(const Oid& id) : oid_(id) {}
00102 
00103     public:
00105 
00106 
00107         const Oid& oid() const { return oid_; }
00109         Id<PersProduct> persProductId() const;
00117         ProductNode::Oid productNodeId() const;
00119         const PersProductItems& persItems() const
00120         {
00121             return persItems_;
00122         }
00123 
00125         const DateTime& created() const
00126         {
00127             return created_;
00128         }
00129 
00131         const Status& effStatus() const
00132         {
00133             return effStatus_;
00134         }
00135 
00137         const DateTime& effStatusDate() const
00138         {
00139             return effStatusDate_;
00140         }
00141 
00143         const Status& prefStatus() const
00144         {
00145             return prefStatus_;
00146         }
00147 
00149         const DateTime& prefStatusDate() const
00150         {
00151             return prefStatusDate_;
00152         }
00153 
00155         const StatusChanges& statusChanges() const
00156         {
00157             return chngs_;
00158         }
00159 
00161         const StatusRequests& statusRequests() const
00162         {
00163             return reqs_;
00164         }
00165 
00167 
00195         void assignItem(
00196             std::auto_ptr<PersProductItem> persItem
00197         );
00198 
00200 
00201 
00208         const PersProductItem* findPersItem(
00209             const Id<PersProductItem>& ppiId
00210         ) const;
00211 
00220         const PersProductItem& getPersItem(
00221             const Id<PersProductItem>& ppiId
00222         ) const;
00224 
00237         bool read(
00238             const OSB_DB::Session& session
00239         );
00240 
00242 
00243 
00253         void readStatusChanges(
00254             const OSB_DB::Session& session,
00255             const Period&          period
00256         );
00257 
00268         void readStatusRequests(
00269             const OSB_DB::Session& session,
00270             const Period&          period
00271         );
00273 
00274     private:
00297         bool requestStatus(
00298             const OSB_DB::Session& session,
00299             const ProductNode&     node,
00300                   StatusRequest&   request,
00301                   OsbErrors&       errors
00302         );
00303 
00314         OsbError setPrefStatus(
00315             const OSB_DB::Session& session,
00316             const StatusRequest&   request
00317         );
00318 
00332         bool changeStatus(          // pers. product only
00333             const OSB_DB::Session& session,
00334                   StatusChange&    change,
00335                   OsbErrors&       errors
00336         );
00338 
00340 
00341 
00357         const Id<PersProductItem> addPersItem(
00358             const OSB_DB::Session&               session,
00359                   std::auto_ptr<PersProductItem> apPpi
00360         );
00361 
00375         bool delPersItem(
00376             const OSB_DB::Session&     session,
00377             const Id<PersProductItem>& ppiId
00378         );
00379 
00392         Id<PersProductItem> updPersItem(
00393             const OSB_DB::Session& session,
00394                   PersProductItem& ppi
00395         );
00397 
00412         bool remove(const OSB_DB::Session& session) const;
00413 
00414     private:
00416         Oid oid_;
00418         DateTime created_;
00420         Status prefStatus_;
00422         DateTime prefStatusDate_;
00424         Status effStatus_;
00426         DateTime effStatusDate_;
00428         StatusChanges chngs_;
00430         StatusRequests reqs_;
00432         PersProductItems persItems_;
00433     };                                  // class PersProductNode
00434 
00436     typedef std::list<PersProductNode> PersProductNodes;
00437 
00438     class PersPart;
00440     typedef std::vector<PersPart> PersParts;
00441 
00445     class PersPart {
00447         friend class PersProduct;
00448     public:
00450         PersPart()
00451           : pProductNode_(0),
00452             pPersNode_(0),
00453             isSubscribed_(false)
00454         {
00455             // empty
00456         }
00457 
00459         int mandatory() const
00460         {
00461             return pProductNode_->mandatory();
00462         }
00463 
00465         const ProductNode* pProductNode() const
00466         {
00467             return pProductNode_;
00468         }
00469 
00471         const PersProductNode* pPersNode() const
00472         {
00473             return pPersNode_;
00474         }
00475 
00477         const PersParts& persParts() const
00478         {
00479             return persParts_;
00480         }
00481 
00483         bool isSubscribed() const
00484         {
00485             return isSubscribed_;
00486         }
00487 
00488 
00489     private:
00491         const ProductNode*     pProductNode_;
00493         const PersProductNode* pPersNode_;
00495         PersParts persParts_;
00505         bool isSubscribed_;
00506     };
00507 
00513     class PersProduct {
00515         friend class OSB_DB::PersProductGw;
00520         friend class Contract;
00524         friend class RequestHandler;
00525 
00527         typedef Id<Product>     ProductId;
00529         typedef Id<Contract>    ContractId;
00530 
00531     public:
00533         typedef Id<PersProduct> Oid;
00535         typedef Id<Associate>   UserId;
00536 
00537     public:
00539         PersProduct(const Oid& oid)
00540           : oid_(oid), objVs_(0)
00541         {
00542             // empty
00543         }
00544 
00553         PersProduct(const Oid&         oid,
00554                     const ProductId&   productId,
00555                     const ContractId&  contractId,
00556                     const UserId&      userId
00557         ) : oid_(oid), objVs_(0), productId_(productId),
00558             contractId_(contractId), userId_(userId)
00559         {
00560             // empty
00561         }
00562 
00564         PersProduct(const PersProduct& rhs);
00565 
00567         PersProduct& operator=(const PersProduct& rhs);
00568 
00569     public:
00571 
00572 
00573         inline const Oid& oid() const;
00575         inline long objVs() const;
00577         inline const ProductId& productId() const;
00579         inline const ContractId& contractId() const;
00581         inline const UserId& userId() const;
00583         inline const DateTime& created() const;
00585         inline const Status& effStatus() const;
00587         inline const DateTime& effStatusDate() const;
00589         inline const Status& prefStatus() const;
00591         inline const DateTime& prefStatusDate() const;
00593         inline const StatusChanges& statusChanges() const;
00595         inline const StatusRequests& statusRequests() const;
00597         inline const PersProductNodes& persNodes() const;
00599         inline const PersParts& persParts() const;
00600 
00606         const Product& getProduct() const;
00617         const StatusChanges& statusChanges(
00618             const ProductNode::Oid& pnId
00619         ) const;
00621 
00623 
00624 
00625         void setUserId(const UserId& userId);
00627 
00645         bool read(
00646             const OSB_DB::Session& session
00647         );
00648 
00659         void readStatusChanges(
00660             const OSB_DB::Session& session,
00661             const Period&          period
00662         );
00663 
00674         void readStatusRequests(
00675             const OSB_DB::Session& session,
00676             const Period&          period
00677         );
00678 
00679 
00688         void updProductUser(OSB_DB::Session& session);
00689 
00691 
00692 
00699         const PersProductNode* findPersNode(
00700             const ProductNode::Oid& pnId
00701         ) const;
00702 
00710         PersProductNode* persNode(
00711             const ProductNode::Oid& pnId
00712         );
00713 
00722         const PersProductNode& getPersNode(
00723             const ProductNode::Oid& pnId
00724         ) const;
00725 
00740         bool addPersNode(
00741                   OSB_DB::Session&  session,
00742             const ProductNode::Oid& pnId
00743         );
00744 
00762         bool delPersNode(
00763                   OSB_DB::Session&  session,
00764             const ProductNode::Oid& oid
00765         );
00767 
00769 
00770 
00784         bool buildPersParts();
00785 
00793         const PersPart* findPersPart(
00794             const ProductNode::Oid& pnId
00795         ) const;
00796 
00804         PersPart* persPart(
00805             const ProductNode::Oid& pnId
00806         );
00807 
00816         const PersPart& getPersPart(
00817             const ProductNode::Oid& pnId
00818         ) const;
00819 
00826         void sortPersPartByName(bool desc = false);
00827 
00835         void sortPersPartByName(
00836             PersParts& persParts,
00837             bool       desc = false
00838         );
00840 
00852         PersCredit* getCredit(
00853             const DateTime& dt = DateTime::now()
00854         );
00855 
00867         Id<TariffSystem> getTariffSystem(
00868             const DateTime& dt = DateTime::now()
00869         ) const;
00870 
00877         ObjectStatus checkObjVs(
00878             const OSB_DB::Session& session
00879         ) const;
00880 
00882 
00883 
00903         bool requestStatus(
00904             const OSB_DB::Session& session,
00905                   StatusRequest&   request,
00906                   OsbErrors&       errors,
00907                   bool             noWait
00908         );
00910 
00923         bool subscribe(
00924                   OSB_DB::Session&  session,
00925             const ProductNode::Oid& nodeId
00926         );
00927 
00929 
00930 
00949         PersProductItem::Oid addPersItem(
00950                   OSB_DB::Session&         session,
00951                   PersProductItem::AutoPtr apPpi,
00952             const ProductNode::Oid&        pnId
00953         );
00954 
00976         bool delPersItem(
00977                   OSB_DB::Session&      session,
00978             const PersProductItem::Oid& ppiId,
00979             const ProductNode::Oid&     pnId
00980         );
00981 
01000         PersProductItem::Oid updPersItem(
01001                   OSB_DB::Session&  session,
01002                   PersProductItem&  ppi,
01003             const ProductNode::Oid& pnId
01004         );
01006 
01008 
01009 
01030         bool requestStatus(
01031             const OSB_DB::Session&  session,
01032             const ProductNode::Oid& pnId,
01033                   StatusRequest&    request,
01034                   OsbErrors&        errors,
01035                   bool              noWait
01036         );
01038 
01039     private:
01041 
01042 
01053         static void handleObjectStatus(
01054                   ObjectStatus      os,
01055             const PersProduct::Oid& id
01056         );
01057 
01068         static void lock(
01069             const OSB_DB::Session&  session,
01070             const PersProduct::Oid& id,
01071                   bool              noWait
01072         );
01073 
01082         void lock(
01083             const OSB_DB::Session& session,
01084                   bool             noWait
01085         ) const;
01086 
01102         void incObjVs(const OSB_DB::Session& session);
01104 
01105     private:
01107 
01108 
01118         OsbError setPrefStatus(
01119             const OSB_DB::Session& session,
01120             const StatusRequest&   request
01121         );
01122 
01137         bool changeStatus(
01138             const OSB_DB::Session& session,
01139                   StatusChange&    change,
01140                   OsbErrors&       errors
01141         );
01142 
01155         bool applyChange(
01156             const OSB_DB::Session& session,
01157             const StatusChange&    change,
01158                   OsbErrors&       errors
01159         );
01160 
01172         OsbError setPrefStatus(
01173             const OSB_DB::Session&  session,
01174             const ProductNode::Oid& pnId,
01175             const StatusRequest&    request
01176         );
01177 
01192         bool changeStatus(
01193             const OSB_DB::Session&  session,
01194             const ProductNode::Oid& pnId,
01195                   StatusChange&     change,
01196                   OsbErrors&        errors
01197         );
01199 
01211         bool insert(const OSB_DB::Session& session);
01212 
01223         bool remove(const OSB_DB::Session& session);
01224 
01233         void readItems(const OSB_DB::Session& session);
01234 
01248         void buildPersParts(
01249                   PersParts&        partList,
01250             const ProductNodeParts& parts,
01251                   bool              parentSubscribed
01252         );
01253 
01255         const StatusChanges* statusChanges(
01256             const ProductNode::Oid& pnId,
01257             const StatusChanges*    pParentChanges,
01258             const PersParts&        persParts
01259         ) const;
01260 
01272         const PersPart* findPersPart(
01273             const PersParts&        persParts,
01274             const ProductNode::Oid& oid
01275         ) const;
01276 
01289         void setPersPart(
01290             const ProductNode::Oid& pnId,
01291                   bool              add
01292         );
01293 
01306         bool parentNodeAvail(
01307             const Product&          product,
01308             const ProductNode::Oid& pnId
01309         ) const;
01310 
01324         bool childSubscribed(
01325             const Product&          product,
01326             const ProductNode::Oid& pnId
01327         ) const;
01328 
01343         bool delPpn(
01344             const OSB_DB::Session&  session,
01345             const ProductNode::Oid& oid
01346         );
01347 
01357         bool schTsInPersParts(
01358             const DateTime&         dt,
01359             const PersParts&        persParts,
01360                   Id<TariffSystem>& oid
01361         ) const;
01362 
01363     private:
01365         Oid oid_;
01366     public:
01368 
01375         long objVs_;
01376     private:
01378         ProductId productId_;
01380         ContractId contractId_;
01382         UserId userId_;
01383 
01385         DateTime created_;
01387         Status   prefStatus_;
01389         DateTime prefStatusDate_;
01390 
01392         Status effStatus_;
01394         DateTime effStatusDate_;
01395 
01397         StatusChanges chngs_;
01399         StatusRequests reqs_;
01400 
01402         PersProductNodes persNodes_;
01404         PersParts persParts_;
01405 
01406     private:
01408         void constructFrom(const PersProduct& rhs);
01409 
01415         void setNodePointers();
01422         void setNodePointers(PersParts& parts);
01423     };                                  // class PersProduct
01424 
01426     typedef std::list<PersProduct> PersProducts;
01427 
01428 
01429 // ************************************************************************
01430 // inline definitions
01431 
01432     // ********************************************************************
01433     // PersProduct
01434     inline const PersProduct::Oid& PersProduct::oid() const
01435     {
01436         return oid_;
01437     }
01438 
01439     inline long PersProduct::objVs() const
01440     {
01441         return objVs_;
01442     }
01443 
01444     inline const PersProduct::ProductId& PersProduct::productId() const
01445     {
01446         return productId_;
01447     }
01448 
01449     inline const PersProduct::ContractId& PersProduct::contractId() const
01450     {
01451         return contractId_;
01452     }
01453 
01454     inline const PersProduct::UserId& PersProduct::userId() const
01455     {
01456         return userId_;
01457     }
01458 
01459     inline const DateTime& PersProduct::created() const
01460     {
01461         return created_;
01462     }
01463 
01464     inline const Status& PersProduct::effStatus() const
01465     {
01466         return effStatus_;
01467     }
01468 
01469     inline const DateTime& PersProduct::effStatusDate() const
01470     {
01471         return effStatusDate_;
01472     }
01473 
01474     inline const Status& PersProduct::prefStatus() const
01475     {
01476         return prefStatus_;
01477     }
01478 
01479     inline const DateTime& PersProduct::prefStatusDate() const
01480     {
01481         return prefStatusDate_;
01482     }
01483 
01484     inline const StatusChanges& PersProduct::statusChanges() const
01485     {
01486         return chngs_;
01487     }
01488 
01489     inline const StatusRequests& PersProduct::statusRequests() const
01490     {
01491         return reqs_;
01492     }
01493 
01494     inline const PersProductNodes& PersProduct::persNodes() const
01495     {
01496         return persNodes_;
01497     }
01498 
01499     inline const PersParts& PersProduct::persParts() const
01500     {
01501         return persParts_;
01502     }
01503 
01504     // ********************************************************************
01505     // PersProductNode
01506     inline PersProduct::Oid
01507     PersProductNode::persProductId() const
01508     {
01509         return PersProduct::Oid(oid_.id1_);
01510     }
01511 
01512     inline ProductNode::Oid
01513     PersProductNode::productNodeId() const
01514     {
01515         return ProductNode::Oid(oid_.id2_);
01516     }
01517 }                                       // namespace OSB_LIB
01518 #endif                                  // #ifndef _PERSPRODUCT_H_

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