Class OrganizationStructureProvider

  • All Implemented Interfaces:
    OBNotSingleton, OBProvidable

    public class OrganizationStructureProvider
    extends Object
    implements OBNotSingleton
    Builds a tree of organizations to compute the accessible organizations for the current organizations of a user. Is used to check if references from one object to another are correct from an organization structure perspective.

    For example a city refers to a country then: an organization of the country (the refered object) must be in the natural tree of the organization of the city (the referee).

    Author:
    mtaal
    • Constructor Detail

      • OrganizationStructureProvider

        public OrganizationStructureProvider()
    • Method Detail

      • reInitialize

        public void reInitialize()
        Forces the reinitialization of the organization cache. This method should not be used unless the invoker just updated the organization structure and needs to retrieve the updated information. The organization structure is seldom updated and the organization cache is reinitialized periodically every few minutes, most users of OrganizationStructureProvider do not need to reinitialize it each time the use it
      • getNaturalTree

        public Set<String> getNaturalTree​(String orgId)
        Returns the natural tree of an organization.
        Parameters:
        orgId - the id of the organization for which the natural tree is determined.
        Returns:
        the natural tree of the organization.
      • isInNaturalTree

        public boolean isInNaturalTree​(Organization org1,
                                       Organization org2)
        Checks if an organization (org2) is in the natural tree of another organization (org1).
        Parameters:
        org1 - the natural tree of this organization is used to check if org2 is present
        org2 - the organization checked in the natural tree of org1
        Returns:
        true if org2 is in the natural tree of org1, false otherwise
      • getParentTree

        public Set<String> getParentTree​(String orgId,
                                         boolean includeOrg)
        Returns the parent organization tree of an organization.
        Parameters:
        orgId - the id of the organization for which the parent organization tree is determined.
        includeOrg - if true, returns also the given organization as part of the tree
        Returns:
        the parent organization tree of the organization.
      • getParentList

        public List<String> getParentList​(String orgId,
                                          boolean includeOrg)
        Returns an ordered list of parents of an organization. The parents are listed from the organization and up (so parent before grand parent).
        Parameters:
        orgId - the id of the organization for which the parent organization tree is determined.
        includeOrg - if true, returns also the given organization as part of the tree
        Returns:
        the parent organization tree of the organization.
      • getParentOrg

        public String getParentOrg​(String orgId)
        Returns the parent organization of an organization.
        Parameters:
        orgId - the id of the organization for which the parent organization is determined.
        Returns:
        the parent organization.
      • getParentOrg

        public Organization getParentOrg​(Organization org)
        Returns the parent organization of an organization.
        Parameters:
        org - the organization for which the parent organization is determined.
        Returns:
        the parent organization.
      • getChildTree

        public Set<String> getChildTree​(String orgId,
                                        boolean includeOrg)
        Returns the child organization tree of an organization.
        Parameters:
        orgId - the id of the organization for which the child organization tree is determined.
        includeOrg - if true, returns also the given organization as part of the tree
        Returns:
        the child organization tree of the organization.
      • getChildOrg

        public Set<String> getChildOrg​(String orgId)
        Returns the child organizations of an organization.
        Parameters:
        orgId - the id of the organization for which the child organizations are determined.
        Returns:
        the child organizations
      • getClientId

        public String getClientId()
      • setClientId

        public void setClientId​(String clientId)
      • getLegalEntitiesListForSelectedClient

        public List<Organization> getLegalEntitiesListForSelectedClient​(String paramClientId)
      • getLegalEntity

        public Organization getLegalEntity​(Organization org)
        Returns the legal entity of the given organization
        Parameters:
        org - organization to get its legal entity
        Returns:
        legal entity (with or without accounting) organization or null if not found
      • getChildLegalEntitesList

        public List<Organization> getChildLegalEntitesList​(Organization org)
        Returns the list of legal entities that are children of the given organization
        Parameters:
        org - organization to get its child legal entities
        Returns:
        legal entity (with or without accounting) organization or null if not found
      • getLegalEntityOrBusinessUnit

        public Organization getLegalEntityOrBusinessUnit​(Organization org)
        Returns the legal entity or Business Unit of the given organization
        Parameters:
        org - organization to get its legal entity or business unit
        Returns:
        legal entity (with or without accounting) organization or null if not found
      • getPeriodControlAllowedOrganization

        public Organization getPeriodControlAllowedOrganization​(Organization org)
        Returns the organization that is period control allowed for the org Organization. If no organization is found, it returns NULL.
        Parameters:
        org - Organization to get its period control allowed organization.
      • getTransactionAllowedOrgs

        public String getTransactionAllowedOrgs​(String orgIds)
        Checks a list of organizations filtering out those ones that do not allow transactions.
        Parameters:
        orgIds - List of organizations to check represented as a comma separated String, elements can be quoted.
        Returns:
        The list of organization from orgIds that allow transactions represented a String of comma separated quoted elements.
      • getBOBInClosestOrg

        public <T extends BaseOBObjectBaseOBObject getBOBInClosestOrg​(Collection<T> bobs,
                                                                        String orgId)
        Retrieves from a list of BaseOBObject the one whose organization is the closest in the tree structure to the provided organization. To criteria to determine the closest one is the following:
        1. First we take the closest record in the parent list, if multiple records are found then we sort them by ID and return the first one.
        2. If no records are found in the fist step, then we select the record whose organization is present in the child tree. Here it does not make sense to consider the distance, because we can have multiple records with the same distance due to the ramifications that the child tree may have. If multiple records are found, then we sort them by ID and return the first one.
        3. If still we have not selected any record after these two steps, which may be the case of the cross organization references, then we just sort the candidate records by its ID and return the first one.
        Parameters:
        bobs - a collection of objects extending BaseOBObject
        orgId - the organization ID
        Returns:
        an object extending BaseOBObject whose organization is closest to the provided organization. It may be null in case the provided list is empty or if there is no BOB in that list whose organization is in the natural tree of the given organization or if the given organization ID is null