Class UnitService

  • All Implemented Interfaces:
    IUnitService

    public class UnitService
    extends java.lang.Object
    implements IUnitService
    UnitService
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String BEAN_UNIT_SERVICE  
    • Constructor Summary

      Constructors 
      Constructor Description
      UnitService()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canCreateSubUnit​(int nIdUnit)
      Check if the given id unit, we can create sub unit.
      int createUnit​(Unit unit, javax.servlet.http.HttpServletRequest request)
      Create a unit
      java.util.List<Unit> getAllSubUnits​(Unit unit, boolean bGetAdditionalInfos)
      Get all the sub units in the unit tree from the specified unit
      java.util.List<Unit> getAllUnits​(boolean bGetAdditionalInfos)
      Get all units
      java.util.List<IAction> getListActions​(java.lang.String strActionType, java.util.Locale locale, Unit unit, fr.paris.lutece.portal.business.user.AdminUser user, UnittreeRBACRecursiveType recursiveType)
      Get the list of actions
      java.util.List<Unit> getListParentUnits​(Unit givenUnit)
      Get the unit parent list, from a given unit.
      Unit getRootUnit​(boolean bGetAdditionalInfos)
      Get the root unit
      java.util.List<Unit> getSubUnits​(int nIdUnit, boolean bGetAdditionalInfos)
      Get the direct sub units from a given id unit
      fr.paris.lutece.util.ReferenceList getSubUnitsAsReferenceList​(int nIdUnit, java.util.Locale locale)
      Get the direct sub units as a ReferenceList
      javax.xml.transform.Source getTreeXsl()
      Get the XSL of the tree
      Unit getUnit​(int nIdUnit, boolean bGetAdditionalInfos)
      Get the unit
      Unit getUnitByCode​(java.lang.String strCode, boolean bGetAdditionalInfos)
      Get the unit by code
      java.util.List<Unit> getUnitsByIdUser​(int nIdUser, boolean bGetAdditionalInfos)
      Get the unit by id user
      java.util.List<Unit> getUnitsFirstLevel​(boolean bGetAdditionalInfos)
      Get the units first level
      java.util.List<Unit> getUnitWithNoChildren()
      Return all the Unit with no children (level 0)
      java.lang.String getXMLUnits​(fr.paris.lutece.portal.business.user.AdminUser user)
      Get the XML units
      boolean hasSubUnits​(int nIdUnit)
      Check if the given id unit has sub units
      boolean isAuthorized​(Unit unit, java.lang.String strPermission, fr.paris.lutece.portal.business.user.AdminUser user, UnittreeRBACRecursiveType recursiveType)
      Check if the given user is authorized to do the action for a given unit.
      boolean isAuthorized​(java.lang.String strIdUnit, java.lang.String strPermission, fr.paris.lutece.portal.business.user.AdminUser user, UnittreeRBACRecursiveType recursiveType)
      See #isAuthorized(Unit, String, AdminUser)
      boolean isParent​(Unit unitParent, Unit unitRef)
      Check if the first unit in parameter is parent of the second unit in parameter
      boolean isUnitInList​(Unit unitToCheck, java.util.Collection<Unit> listUnits)
      Check if an unit is in a given list of unit
      boolean moveSubTree​(Unit unitToMove, Unit newUnitParent)
      Change the parent of a unit.
      void populateTreeUnit​(TreeUnit treeUnit, fr.paris.lutece.portal.business.user.AdminUser user, boolean bGetAdditionnalInfos)
      populate a TreeUnit with all sub units (recursive)
      void removeUnit​(int nIdUnit, javax.servlet.http.HttpServletRequest request)
      Remove the unit only if the unit does not have sub units
      void updateUnit​(Unit unit, javax.servlet.http.HttpServletRequest request)
      Update the unit
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • BEAN_UNIT_SERVICE

        public static final java.lang.String BEAN_UNIT_SERVICE
        See Also:
        Constant Field Values
    • Constructor Detail

      • UnitService

        public UnitService()
    • Method Detail

      • getUnit

        public Unit getUnit​(int nIdUnit,
                            boolean bGetAdditionalInfos)
        Get the unit
        Specified by:
        getUnit in interface IUnitService
        Parameters:
        nIdUnit - the id unit
        bGetAdditionalInfos - true if it must get the additional infos
        Returns:
        an instance of Unit
      • getRootUnit

        public Unit getRootUnit​(boolean bGetAdditionalInfos)
        Get the root unit
        Specified by:
        getRootUnit in interface IUnitService
        Parameters:
        bGetAdditionalInfos - true if it must get the additionnal infos
        Returns:
        an instance of Unit
      • getUnitsByIdUser

        public java.util.List<Unit> getUnitsByIdUser​(int nIdUser,
                                                     boolean bGetAdditionalInfos)
        Get the unit by id user
        Specified by:
        getUnitsByIdUser in interface IUnitService
        Parameters:
        nIdUser - the id user
        bGetAdditionalInfos - true if it must get the additionnal infos
        Returns:
        a list of Unit
      • getAllUnits

        public java.util.List<Unit> getAllUnits​(boolean bGetAdditionalInfos)
        Get all units
        Specified by:
        getAllUnits in interface IUnitService
        Parameters:
        bGetAdditionalInfos - true if it must get the additionnal infos
        Returns:
        a list of Unit
      • getUnitsFirstLevel

        public java.util.List<Unit> getUnitsFirstLevel​(boolean bGetAdditionalInfos)
        Get the units first level
        Specified by:
        getUnitsFirstLevel in interface IUnitService
        Parameters:
        bGetAdditionalInfos - true if it must get the additionnal infos
        Returns:
        a list of Unit
      • getSubUnits

        public java.util.List<Unit> getSubUnits​(int nIdUnit,
                                                boolean bGetAdditionalInfos)
        Get the direct sub units from a given id unit
        Specified by:
        getSubUnits in interface IUnitService
        Parameters:
        nIdUnit - the id unit
        bGetAdditionalInfos - true if it must get the additionnal infos
        Returns:
        a list of Unit
      • getAllSubUnits

        public java.util.List<Unit> getAllSubUnits​(Unit unit,
                                                   boolean bGetAdditionalInfos)
        Get all the sub units in the unit tree from the specified unit
        Specified by:
        getAllSubUnits in interface IUnitService
        Parameters:
        unit - the unit
        bGetAdditionalInfos - true if it must get the additionnal infos
        Returns:
        a list of Unit
      • getListActions

        public java.util.List<IAction> getListActions​(java.lang.String strActionType,
                                                      java.util.Locale locale,
                                                      Unit unit,
                                                      fr.paris.lutece.portal.business.user.AdminUser user,
                                                      UnittreeRBACRecursiveType recursiveType)
        Get the list of actions
        Specified by:
        getListActions in interface IUnitService
        Parameters:
        strActionType - the action type
        locale - the locale
        unit - the unit
        user - the user
        recursiveType - the recursive type
        Returns:
        a list of IAction
      • getSubUnitsAsReferenceList

        public fr.paris.lutece.util.ReferenceList getSubUnitsAsReferenceList​(int nIdUnit,
                                                                             java.util.Locale locale)
        Get the direct sub units as a ReferenceList
        Specified by:
        getSubUnitsAsReferenceList in interface IUnitService
        Parameters:
        nIdUnit - the id unit
        locale - the locale
        Returns:
        a ReferenceList
      • populateTreeUnit

        public void populateTreeUnit​(TreeUnit treeUnit,
                                     fr.paris.lutece.portal.business.user.AdminUser user,
                                     boolean bGetAdditionnalInfos)
        populate a TreeUnit with all sub units (recursive)
        Specified by:
        populateTreeUnit in interface IUnitService
        Parameters:
        treeUnit - the treeUnit
        user - the admin user (for RBAC)
        bGetAdditionnalInfos - if true, populate the tree units with additionnal infos
      • getXMLUnits

        public java.lang.String getXMLUnits​(fr.paris.lutece.portal.business.user.AdminUser user)
        Get the XML units
        Specified by:
        getXMLUnits in interface IUnitService
        Parameters:
        user - the admin user
        Returns:
        an XML
      • getTreeXsl

        public javax.xml.transform.Source getTreeXsl()
        Get the XSL of the tree
        Specified by:
        getTreeXsl in interface IUnitService
        Returns:
        the XSL
      • getUnitWithNoChildren

        public java.util.List<Unit> getUnitWithNoChildren()
        Return all the Unit with no children (level 0)
        Specified by:
        getUnitWithNoChildren in interface IUnitService
        Returns:
        all the Unit with no children (level 0)
      • hasSubUnits

        public boolean hasSubUnits​(int nIdUnit)
        Check if the given id unit has sub units
        Specified by:
        hasSubUnits in interface IUnitService
        Parameters:
        nIdUnit - the id unit
        Returns:
        true if the unit has sub units, false otherwise
      • isParent

        public boolean isParent​(Unit unitParent,
                                Unit unitRef)
        Check if the first unit in parameter is parent of the second unit in parameter
        Specified by:
        isParent in interface IUnitService
        Parameters:
        unitParent - the parent unit
        unitRef - the unit to check
        Returns:
        true if there is a parent link between those two units
      • canCreateSubUnit

        public boolean canCreateSubUnit​(int nIdUnit)
        Check if the given id unit, we can create sub unit.
        Return false if the unit can not be created
        Specified by:
        canCreateSubUnit in interface IUnitService
        Parameters:
        nIdUnit - the id unit
        Returns:
        true if we can create sub unit, false otherwise
      • isAuthorized

        public boolean isAuthorized​(Unit unit,
                                    java.lang.String strPermission,
                                    fr.paris.lutece.portal.business.user.AdminUser user,
                                    UnittreeRBACRecursiveType recursiveType)
        Check if the given user is authorized to do the action for a given unit.
        This method calls the service RBACService to check the permission. However, the resource on which the permission must be checked is not necessarily the given unit. It may be a parent unit of the given unit.
        There are 5 cases to handle :
        • 1) The given user is admin => The user is always authorized
        • 2) The given user does not belong to any unit => The user is not authorized
        • 3) The given user belongs to the given unit => Check with RBACService with the given unit
        • 4) The given user belongs to a parent unit of the given unit => Check with RBACService with the parent unit
        • 5) The given user belongs to an unit who is not a parent unit of the given unit => The user is not authorized
        Specified by:
        isAuthorized in interface IUnitService
        Parameters:
        unit - the unit
        strPermission - the permission
        user - the user
        recursiveType - the recursive type of RBAC
        Returns:
        true if he is authorized, false otherwise
      • isAuthorized

        public boolean isAuthorized​(java.lang.String strIdUnit,
                                    java.lang.String strPermission,
                                    fr.paris.lutece.portal.business.user.AdminUser user,
                                    UnittreeRBACRecursiveType recursiveType)
        See #isAuthorized(Unit, String, AdminUser)
        Specified by:
        isAuthorized in interface IUnitService
        Parameters:
        strIdUnit - the id resource
        strPermission - the permission
        user - the user
        recursiveType - the recursive type of RBAC
        Returns:
        true if he is authorized, false otherwise
      • createUnit

        @Transactional("unittree.transactionManager")
        public int createUnit​(Unit unit,
                              javax.servlet.http.HttpServletRequest request)
                       throws UnitErrorException
        Create a unit
        Specified by:
        createUnit in interface IUnitService
        Parameters:
        unit - the unit
        request - the HTTP request
        Returns:
        the id unit
        Throws:
        UnitErrorException - exception if there is an application error
      • removeUnit

        @Transactional("unittree.transactionManager")
        public void removeUnit​(int nIdUnit,
                               javax.servlet.http.HttpServletRequest request)
        Remove the unit only if the unit does not have sub units
        Specified by:
        removeUnit in interface IUnitService
        Parameters:
        nIdUnit - the id unit
        request - the HTTP request
      • updateUnit

        @Transactional("unittree.transactionManager")
        public void updateUnit​(Unit unit,
                               javax.servlet.http.HttpServletRequest request)
                        throws UnitErrorException
        Update the unit
        Specified by:
        updateUnit in interface IUnitService
        Parameters:
        unit - the unit
        request - the HTTP request
        Throws:
        UnitErrorException - exception if there is an application error
      • moveSubTree

        @Transactional("unittree.transactionManager")
        public boolean moveSubTree​(Unit unitToMove,
                                   Unit newUnitParent)
        Change the parent of a unit.
        Specified by:
        moveSubTree in interface IUnitService
        Parameters:
        unitToMove - The unit to change the parent of.
        newUnitParent - The new parent of the unit
        Returns:
        True if the sub tree was successfully move, false if the new parent is a child of the unit.
      • getListParentUnits

        public java.util.List<Unit> getListParentUnits​(Unit givenUnit)
        Get the unit parent list, from a given unit. The unit itselft is included
        Specified by:
        getListParentUnits in interface IUnitService
        Parameters:
        givenUnit - the unit
        Returns:
        the list of parent units.
      • isUnitInList

        public boolean isUnitInList​(Unit unitToCheck,
                                    java.util.Collection<Unit> listUnits)
        Check if an unit is in a given list of unit
        Specified by:
        isUnitInList in interface IUnitService
        Parameters:
        unitToCheck - the unit to check
        listUnits - the list of units
        Returns:
        true if the unit is in the given list, false otherwise
      • getUnitByCode

        public Unit getUnitByCode​(java.lang.String strCode,
                                  boolean bGetAdditionalInfos)
        Get the unit by code
        Specified by:
        getUnitByCode in interface IUnitService
        Parameters:
        strCode - the unit code
        bGetAdditionalInfos - true if it must get the additional infos
        Returns:
        an instance of Unit