Class ParentChildService


  • public class ParentChildService
    extends Object
    The ParentChildService is the main entry way and API for the entire Parent Child back end service. It provides several API calls that take return the current state of parent child trees in the datastore and also provides ways for users to make modifications to those trees on the datastore. The ParentChildService is guaranteed to interact with the WhatIf engine to submit tree changes to the back end.
    Author:
    ActiveViam
    • Constructor Detail

      • ParentChildService

        public ParentChildService()
    • Method Detail

      • getParentChildNodes

        public BookParentChildNode getParentChildNodes​(String user,
                                                       String branch,
                                                       LocalDate asOfDate)
        This method provides a way to retrieve the book parent child nodes of a particular branch and asofDate from the book parent child datastore. Nodes retrieved from the datastore are converted to the business model class BookParentChildNode. All nodes that match the branch and asOfDate provided will be returned in a hierarchy structure. This hierarchy structure will simple be nodes linked to one another as children with the root node at the top and having no additional parent. If branch argument is null then the tree retrieved will come from the master branch.
        Parameters:
        user - The user we are getting the tree for. Must be authorized to get any tree.
        branch - The branch we are getting the tree from. If null we default to the master branch.
        asOfDate - The asOfDate we are getting the tree from.
        Returns:
        The map of all book parent nodes that were filtered by branch and asOfDate. Uses name as the key.
      • createBranchFromMaster

        public void createBranchFromMaster​(String definition,
                                           String user,
                                           String branch,
                                           LocalDate asOfDate,
                                           ParentChildNode<?> newTree)
                                    throws ParentChildWhatIfException
        This method provides a way to both create a branch and submit changes off of the master branch. If this method was called to create a branch that already exists this method will act as an updater. It will still use create branch definition names as defaults but it behave similar to updateParentChildFromTree(java.lang.String, java.lang.String, java.lang.String, java.time.LocalDate, com.activeviam.risk.ref.parentchild.nodes.ParentChildNode<?>). Trees submitted here will be checked against the datastore's data filtered by the asofDate. If the hierarchy field from ParentChildNode.getParent() differs from the datastore's then that node will be submitted to the WhatIf engine to modify the underlying datastore. All nodes that match the branch and asOfDate provided will be returned in a hierarchy structure. This hierarchy structure will simple be nodes linked to one another as children with the root node at the top and having no additional parent. As of now this operation is not atomic and multiple calls to this method that make changes to underlying datastore might cause race conditions in which users might overwrite each others changes.
        Parameters:
        definition - The custom definition name that will be used when creating the WhatIf definition.
        user - The user we are getting the tree for. Must be authorized to make changes to the tree.
        branch - The branch we are creating the tree for.
        asOfDate - The asOfDate we are getting the tree from.
        newTree - The new tree changes that will be submitted to the datastore.
        Throws:
        ParentChildWhatIfException - An exception thrown from the WhatIf engine. Can be a user authorization or internally thrown exception.
      • updateParentChildFromTree

        public void updateParentChildFromTree​(String submission,
                                              String user,
                                              String branch,
                                              LocalDate asOfDate,
                                              ParentChildNode<?> newTree)
                                       throws ParentChildWhatIfException
        This method provides a way to update a currently existing branch with changes. Trees submitted here will be checked against the datastore's data filtered by the asofDate. If the hierarchy field from ParentChildNode.getParent() differs from the datastore's then that node will be submitted to the WhatIf engine to modify the underlying datastore. All nodes that match the branch and asOfDate provided will be returned in a hierarchy structure. This hierarchy structure will simple be nodes linked to one another as children with the root node at the top and having no additional parent. As of now this operation is not atomic and multiple calls to this method that make changes to underlying datastore might cause race conditions in which users might overwrite each others changes.
        Parameters:
        submission - The custom definition name that will be used when creating the WhatIf submission.
        user - The user we are getting the tree for. Must be authorized to make changes to the tree.
        branch - The branch we are updating the tree for.
        asOfDate - The asOfDate we are getting the tree from.
        newTree - The new tree changes that will be submitted to the datastore.
        Throws:
        ParentChildWhatIfException - An exception thrown from the WhatIf engine. Can be a user authorization or internally thrown exception.
      • generateNewFlattenedMergedParentTree

        public List<ParentChildNode<?>> generateNewFlattenedMergedParentTree​(String user,
                                                                             String branch,
                                                                             LocalDate asOfDate,
                                                                             ParentChildNode<?> newTree)
        generateNewFlattenedMergedParentTree is a very specific method for creating the intersected and merged tree of two existing trees. Further the tree created will be flattened. The purpose for creating this tree (and have it flattened) is so that later on the Parent Child Service will use this new tree to make necessary changes on the datastore. We don't want to use the tree directly provided by the user as it may contain additional nodes the user is restricted to modify, or don't exist on the tree. Further it is useful to remove nodes the user can't modify early on so that we can make assumptions about the data before we operate on it (like in making datastore conditions for the WhatIf engine.) If newTree contains nodes not in currentTree then they are ignored. Right now there is no system in place to allow the user to know this happened. For now they will see their change for the one node didn't take place by using the Task Manager. In the future we will probably change this system.
        Parameters:
        user - The user we are getting the current tree for.
        branch - The branch we are getting the current tree from.
        asOfDate - The asOfDate we are getting the current tree from.
        newTree - Every node in this tree will be iterated over and found in the currentTree. Matched nodes will be merged and flatten into a array.
        Returns:
        The merged, intersected and flattened tree in a hierarchy format.