psdi.app.inventory

Class ReorderService

  • All Implemented Interfaces:
    java.rmi.Remote, ReorderServiceRemote, MboServerInterface, MaxRemoteProxy, AppServiceRemote, Dependable, Service, ServiceRemote, FixedLoggerNames, FixedLoggers


    public class ReorderService
    extends AppService
    implements ReorderServiceRemote
    Reorder application service.
    It accepts the reorder requests submitted by users for different storerooms and direct order itmes, and process the requests to generate PRs and/or POs. It allows multiple users to simultaniounsly rorder for different storerooms and forbids reorder process to be performed on the same storeroom at the same time. The process of generating PRs/POs for desktop requisition is also carried out by reorder service.
    Reorder can be performed to one storeroom at a time. All the direct order items is reordered all together at once if a request for direct order item reorder is given. If one user is ordering for direct order items, other users cannot order for them at the same time. If a user reorders for one storeroom and also direct order items, each request will be granted seperately.
    When a client wants to reorder items in the inventory or direct order items, he needs to follow these steps:
    1. Locate the reorder service and call one overloaded form of getReorderSet() method to obtain a reorder set that he can work on. Use getReorderSetForDirectOrderOnly() method instead if you are ordering only for direct order items. The returned reorder set is populated by reorder service according to the parameters passed in to this method.
    2. Call processQuantity() method on the reorder set the service returned. It calculates the reorder quantity for the items in the reorder set according to the pre-defined rules. If the quantity needs to be overwritten, it is the time to do so by locating the proper reorder object and setting its reorderquantity attribute. This step can be skipped if the reorder quantity is set manually.
    3. Call decideVendorAndCost() method on the same reorder set. It chooses the most suitable vendors and unit costs for the items in the set according to the pre-defined rules which takes the contracts and the history pricing records into account. This step can be skipped if the cost and vendor information is set manually.
    4. Call reorder() method on the same set to start the reordering process. After it is done, getReorderWarnings() can be called on the same set to check if any error messages have been reported.
    5. Important! If you didn't call the previous step after the first step, you have to call cancelReorder() method on the returned set by the first step to clear the lock held by this user on the storeroom and/or direct order items you tried to reorder.
    The affected reorder records for a storeroom will be cleared when the same user orderings for the same storeroom the next time. The reorder records for direct order items will be cleared when the same user is ordering for direct order items the next time. Report can be run against the records in the reorderpad table as long as they are valid according to the above rules. The reorder records for desktop requisition(MR) are always temporary and cleared immediately after the process is finished.

    TO DO:
    1. Function to remove mutex when reorder set doesn't exist
    2. A better logging system
    • Constructor Detail

      • ReorderService

        public ReorderService()
                       throws java.rmi.RemoteException
        Construct the reorder service.
        Throws:
        java.rmi.RemoteException
      • ReorderService

        public ReorderService(MXServer mxServer)
                       throws java.rmi.RemoteException
        Construct the reorder service
        Parameters:
        srvEnv - -- the "Server Environment" this Service is being created in.
        mxServer -
        Throws:
        java.rmi.RemoteException
    • Method Detail

      • changeState

        public java.util.Date changeState(UserInfo userInfo,
                                          int requestType,
                                          java.lang.String targetType,
                                          java.lang.String siteID,
                                          java.lang.String orgID)
                                   throws MXException,
                                          java.rmi.RemoteException
        Overloaded form of int changeState(requestType, String targetType, String key). It is used when the reorder type is "DIRECTORDER".
        Specified by:
        changeState in interface ReorderServiceRemote
        Throws:
        MXException
        java.rmi.RemoteException
        See Also:
        changeState(UserInfo,int, String, String)
      • changeState

        public java.util.Date changeState(UserInfo userInfo,
                                          int requestType,
                                          java.lang.String targetType,
                                          java.lang.String key,
                                          java.lang.String siteID,
                                          java.lang.String orgID)
                                   throws MXException,
                                          java.rmi.RemoteException
        Handle state change request.
        This is only used by the reorder object to change the internal state of reordering for a certain user and storeroom. State type indicates which kind of state change is requested. Target type indicates the purpose of the state change request. The combination of the request type and target type determins which corresponding operation should be done. Exception will throw if a request state change cannot be granted. Internal states acts as a critical section to cordinate multiple reordering requests from multiple users. If a request is granted, the corresponding database changes in the reorder mutex table and reorder table are performed. This is a synchronized function.
        Note: The reason for not having a unique id field in mutex table is that in the case of multiple reorder servers, we may rely on the database to forbid adding the same raw to the database.
        Specified by:
        changeState in interface ReorderServiceRemote
        Parameters:
        userInfo - user information used to request a mbo set
        requestType - It can be one of the following intergers: VIEWONLY, REORDER or REORDEREXIT.
        • VIEWONLY: this request type is used when the request is to just view for this storeroom and this user. The actual reorder process won't be performed on these items.
        • REORDER: this request type is used when the request is to reorder the items for this storeroom and this user, which involves creating PR/POs.
        • REORDEREXIST: Use this request type to inform the reorder that the process for this storeroom and this user is canceled or finished.
        targetType - Indicate if reorder is for storeroom items, direct order items or are for MR only. It can be "STOREROOM", ""DIRECTORDER", "MR".
        key - The identifier to the reorder mutex table. It is the value of a field in reorder mutex table which can be used to uniquely identify the entry by the value of this field. Depends on different target type of the reorder, the field name can be different. The key is the value of "mrnum" if the reorder process is called by MR, "location" if the reorder is for storeroom, or null if the reorder is for direct orders.
        Returns:
        void
        Throws:
        MXApplicationException
        - Exception will be thrown if change state request cannot be granted.
        GROUPKEYREASON
        reorderInvalidArgumentif the change state request is not complete or is wrong
        reorderInvalidRequestif the target type is not recognized
        reorderConflictDBAccessif the reorder control object cannot be accessed due to a database access conflict
        reorderForbidOtherAccessIf the request is "viewonly" or "reorder" check if there is an excluding record for this storeroom. If yes, deny the access.
        reorderTryAgainIf a recoverable exception occured and the user can try again.
        MXException
        java.rmi.RemoteException
        See Also:
        psdi.app.inventory.ReorderService#changeState(UserInfo,int, String, String)
      • getMutexWhere

        public java.lang.String getMutexWhere(UserInfo userInfo,
                                              java.lang.String targetType,
                                              java.lang.String key,
                                              java.lang.String siteID,
                                              java.lang.String orgID)
                                       throws MXException,
                                              java.rmi.RemoteException
        Returns the where clause of the reorder mutex record
        Throws:
        MXException
        java.rmi.RemoteException
      • whoHasLock

        public java.lang.String whoHasLock(UserInfo userInfo,
                                           int requestType,
                                           java.lang.String targetType,
                                           java.lang.String key,
                                           java.lang.String siteID,
                                           java.lang.String orgID)
                                    throws MXException,
                                           java.rmi.RemoteException
        Throws:
        MXException
        java.rmi.RemoteException
      • getReorderSet

        @Deprecated
        public ReorderSetRemote getReorderSet(UserInfo userInfo,
                                                          boolean viewOnly,
                                                          InventorySetRemote invs,
                                                          java.lang.String storeRoom,
                                                          java.lang.String siteID,
                                                          int allowanceDays,
                                                          boolean directOrder,
                                                          boolean ignoreReorderPoint)
                                                   throws MXException,
                                                          java.rmi.RemoteException
        Deprecated. as of 7.5 Use @link #getReorderSet(UserInfo, boolean, InventorySetRemote, String, String, int, boolean, boolean, boolean)
        Specified by:
        getReorderSet in interface ReorderServiceRemote
        Throws:
        MXException
        java.rmi.RemoteException
      • getReorderSet

        public ReorderSetRemote getReorderSet(UserInfo userInfo,
                                              boolean viewOnly,
                                              InventorySetRemote invs,
                                              java.lang.String storeRoom,
                                              java.lang.String siteID,
                                              int allowanceDays,
                                              boolean directOrder,
                                              boolean ignoreReorderPoint,
                                              boolean includeSoftReservations)
                                       throws MXException,
                                              java.rmi.RemoteException
        Returns the mbo set containing the requested reorder records.
        This method creates new records physically in the reorderpad table according to the inventory mbo set and other parameters. one record will be created for one corresponding inventory object or one direct order item or service. All of these created records will be returned in a mbo set. Reorder processes including calculating the reorder quantity and generating PR/POs should be operated on this reorder mbo set. Exception will throw if errors occur or if the reorder request cannot be granted due to the exclusive access by some other user to the same storeroom.
        The method continues only if either the specified storeroom or direct order items are free to be reordered, which means no other user are reordering them at the same time. The existing records in the reorderpad table as the result of a previous reorder process by the same user will be cleared if the reorder process is allowed to continue.
        This is the form of the method that all other overloaded methods eventually call.
        Parameters:
        userInfo - UserInfo object of whom is performing this operation.
        directOrder - Indicates if direct order is included in this reorder request. When it is true, this method will include the direct order items specified in wpitem.
        viewOnly - Indicates if the purpose of obtaining the reorder set is for viewing only. If it is true, a lock won't be applied to the same set of records. Another user can still view or reorder for the same storeroom or direct order items.
        invs - The inventory mbo set. All the items specified in this set will be considered reordering. This set has to only contain items in the storeroom specified in parameter storeroom.
        storeRoom - The storeroom of the reorder. It can be null if the user only wants to order for direct order items.
        allowanceDays - Allowance days, considered for order's required date.
        Returns:
        Reorder mbo set.
        Throws:
        MXApplicationException
        -
        GROUPKEYREASON
        reorderForbidOtherAccessif there is another user reordering for the same storeroom.
        reorderStoreRoomMissingif the storeroom is not specified and it is not for direct order only.
        reorderStoreRoomNotGrantedif another user was exclusive access for this storeroom.
        reorderDirectOrderNotGrantedif the direct order request process was skiped. It is being processed already.
        reorderAbortFailed to perform reorder due to exclusive access by another user.
        reorderTryAgainIf a recoverable exception occured and the user can try again.
        MXException
        java.rmi.RemoteException
        See Also:
        ReorderSetRemote.cancelReorder()
      • getReorderSetForMR

        public ReorderSetRemote getReorderSetForMR(boolean viewOnly,
                                                   MRRemote mr)
                                            throws MXException,
                                                   java.rmi.RemoteException
        Creates a reorder mbo set that corresponds to the specified mr item.
        Called by the MR object trying to order for the material. The caller should use the returned mboset to perform the reorder operation. The MR may only reorder one item at a time.
        Specified by:
        getReorderSetForMR in interface ReorderServiceRemote
        Parameters:
        viewOnly - If this set is for preview only.
        mr - MR object which needs to be ordered.
        Returns:
        ReorderSetRemote
        Throws:
        MXApplicationException -
        GROUPKEYREASON
        reorderMRBeingOrderedif an exception is caught in changeState()
        reorderTryAgainIf a recoverable exception occured and the user can try again.
        reorderreorderFailIf something is wrong with more than one item.
        MXException
        java.rmi.RemoteException
        See Also:
        getReorderSet(UserInfo, boolean, InventorySetRemote, String, int, boolean)
      • getReorderSet

        public ReorderSetRemote getReorderSet(UserInfo userInfo,
                                              boolean viewOnly,
                                              InventoryRemote inv)
                                       throws MXException,
                                              java.rmi.RemoteException
        One form of the overloaded function of getReorderSet().
        It is used for only reorder a single item. It will return the mbo set only contains this single item the caller wants to reorder.
        Specified by:
        getReorderSet in interface ReorderServiceRemote
        Parameters:
        userInfo - UserInfo object of whom is performing this operation.
        viewOnly - The request is preview only.
        inv - The inventory record to be reordered.
        Returns:
        Reorder mbo set containing only one record.
        Throws:
        none
        MXException
        java.rmi.RemoteException
        See Also:
        getReorderSet(UserInfo, boolean, InventorySetRemote, String, int, boolean)
      • getReorderSet

        @Deprecated
        public ReorderSetRemote getReorderSet(UserInfo userInfo,
                                                          boolean viewOnly,
                                                          InventorySetRemote invs,
                                                          java.lang.String storeRoom,
                                                          java.lang.String siteID,
                                                          int[] selected,
                                                          int allowanceDays,
                                                          boolean directOrder,
                                                          boolean ignoreReorderPoint)
                                                   throws MXException,
                                                          java.rmi.RemoteException
        Deprecated. as of 7.5 Use @link #getReorderSet(UserInfo, boolean, InventorySetRemote, String, String, int[], int, boolean, boolean, boolean )
        Specified by:
        getReorderSet in interface ReorderServiceRemote
        Throws:
        MXException
        java.rmi.RemoteException
      • getReorderSet

        public ReorderSetRemote getReorderSet(UserInfo userInfo,
                                              boolean viewOnly,
                                              InventorySetRemote invs,
                                              java.lang.String storeRoom,
                                              java.lang.String siteID,
                                              int[] selected,
                                              int allowanceDays,
                                              boolean directOrder,
                                              boolean ignoreReorderPoint,
                                              boolean includeSoftReservations)
                                       throws MXException,
                                              java.rmi.RemoteException
        One overloaded form of getReorderSet().
        Instead of the where clause, an array of indexes is passed in as parameter to specify which items in the inventory set passed in are to be reordered. It is used why only a selected set identified by indexes are to be reordered.
        Parameters:
        userInfo - UserInfo object of whom is performing this operation.
        viewOnly - If the request is for preview only
        invs - The set of inventory record among which the selected ones are to be reordered
        storeRoom - The storeroom which contains those specified inventory items.
        selected - An array of int to identify the indexes of those objects in inventory set. Only these items will be reordered.
        allowanceDays - Allowance days
        directOrder - Whether direct order items will be reordered.
        Returns:
        ReorderSetRemote A Mbo set of reorder objects.
        Throws:
        MXApplicationException -
        GROUPKEYREASON
        reorderFailGetSetif a where clause cannot be generated from the passed in inventory set and index array
        MXException
        java.rmi.RemoteException
        See Also:
        getReorderSet(UserInfo, boolean, InventorySetRemote, String, int, boolean)
      • getReorderSet

        public ReorderSetRemote getReorderSet(UserInfo userInfo,
                                              boolean viewOnly,
                                              InventorySetRemote invs,
                                              java.lang.String storeRoom,
                                              java.lang.String siteID,
                                              java.util.Vector selected,
                                              int allowanceDays,
                                              boolean directOrder,
                                              boolean ignoreReorderPoint)
                                       throws MXException,
                                              java.rmi.RemoteException
        Deprecated. as of 7.5 Use @link @link #getReorderSet(UserInfo, boolean, InventorySetRemote, String, String, Vector, int, boolean, boolean, boolean)
        Specified by:
        getReorderSet in interface ReorderServiceRemote
        Throws:
        MXException
        java.rmi.RemoteException
      • getReorderSet

        public ReorderSetRemote getReorderSet(UserInfo userInfo,
                                              boolean viewOnly,
                                              InventorySetRemote invs,
                                              java.lang.String storeRoom,
                                              java.lang.String siteID,
                                              java.util.Vector selected,
                                              int allowanceDays,
                                              boolean directOrder,
                                              boolean ignoreReorderPoint,
                                              boolean includeSoftReservations)
                                       throws MXException,
                                              java.rmi.RemoteException
        One overloaded form of getReorderSet().
        Instead of the where clause, a vector of selected mbos is passed in as parameter to specify which items are to be reordered. It is used why only a selected sub-set of passed in inventory set are to be reordered.
        Parameters:
        userInfo - UserInfo object of whom is performing this operation.
        viewOnly - If the request is for preview only
        invs - The set of inventory record among which the selected ones are to be reordered
        storeRoom - The storeroom which contains those specified inventory items.
        selected - An vector of inventory mbos to identify those objects in inventory set. Only those will be reordered.
        allowanceDays - Allowance days
        directOrder - Whether direct order items will be reordered.
        Returns:
        ReorderSetRemote A Mbo set of reorder objects.
        Throws:
        MXApplicationException -
        GROUPKEYREASON
        reorderFailGetSetif a where clause cannot be generated from the passed in inventory set and the selected inventory objects vector
        MXException
        java.rmi.RemoteException
        See Also:
        getReorderSet(UserInfo, boolean, InventorySetRemote, String, int, boolean)
      • addFromWPItem

        public void addFromWPItem(DBShortcut dbShortcut,
                                  UserInfo userInfo,
                                  java.lang.String userForThisSet,
                                  int allowanceDays,
                                  java.lang.String siteIDForThisSet,
                                  java.lang.String orgIDForThisSet)
                           throws MXException,
                                  java.rmi.RemoteException
        Directly write items of direct orders to the reorder table from wpitem The method bypasses MboSet and Mbo.
        Parameters:
        userInfo -
        userForThisSet -
        allowanceDays - extra lead time specified during reorder
        Throws:
        none
        MXException
        java.rmi.RemoteException
      • init

        public void init()
        Overwritten the app service's init() to do additional things when the service is loaded. It is only executed once when the service starts up. It removes any leftover reorder mutex records due to abnormal server termination
        Specified by:
        init in interface Service
        Overrides:
        init in class AppService
        See Also:
        Service
      • releaseLocks

        public int releaseLocks(UserInfo userInfo,
                                java.lang.String siteID)
                         throws MXException,
                                java.rmi.RemoteException
        Release reordermutex locks of this user. Only those whose reorder process is not currently running will be removed. The operation commits immediately. No rollback can be done.
        Specified by:
        releaseLocks in interface ReorderServiceRemote
        Parameters:
        userInfo, - the UserInfo object of the login user
        Returns:
        How many locks has been released.
        Throws:
        MXException
        java.rmi.RemoteException
        See Also:
        ReorderService.releaseLocks(UserInfo, String)