AdminWorkgroupHome.java

  1. /*
  2.  * Copyright (c) 2002-2022, City of Paris
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  *  1. Redistributions of source code must retain the above copyright notice
  10.  *     and the following disclaimer.
  11.  *
  12.  *  2. Redistributions in binary form must reproduce the above copyright notice
  13.  *     and the following disclaimer in the documentation and/or other materials
  14.  *     provided with the distribution.
  15.  *
  16.  *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
  17.  *     contributors may be used to endorse or promote products derived from
  18.  *     this software without specific prior written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  24.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30.  * POSSIBILITY OF SUCH DAMAGE.
  31.  *
  32.  * License 1.0
  33.  */
  34. package fr.paris.lutece.portal.business.workgroup;

  35. import fr.paris.lutece.portal.business.user.AdminUser;
  36. import fr.paris.lutece.portal.service.spring.SpringContextService;
  37. import fr.paris.lutece.util.ReferenceList;

  38. import java.util.Collection;

  39. /**
  40.  * This class provides instances management methods (create, find, ...) for AdminWorkgroup objects
  41.  */
  42. public final class AdminWorkgroupHome
  43. {
  44.     // Static variable pointed at the DAO instance
  45.     private static IAdminWorkgroupDAO _dao = SpringContextService.getBean( "adminWorkgroupDAO" );

  46.     /**
  47.      * Private constructor - this class need not be instantiated
  48.      */
  49.     private AdminWorkgroupHome( )
  50.     {
  51.     }

  52.     /**
  53.      * Creation of an instance of workgroup
  54.      *
  55.      * @param workgroup
  56.      *            The instance of the workgroup which contains the informations to store
  57.      * @return The instance of workgroup which has been created with its primary key.
  58.      */
  59.     public static AdminWorkgroup create( AdminWorkgroup workgroup )
  60.     {
  61.         _dao.insert( workgroup );

  62.         return workgroup;
  63.     }

  64.     /**
  65.      * Update of the workgroup which is specified in parameter
  66.      *
  67.      * @param workgroup
  68.      *            The instance of the workgroup which contains the new data to store
  69.      * @return The instance of the workgroup which has been updated
  70.      */
  71.     public static AdminWorkgroup update( AdminWorkgroup workgroup )
  72.     {
  73.         _dao.store( workgroup );

  74.         return workgroup;
  75.     }

  76.     /**
  77.      * Remove the AdminWorkgroup whose identifier is specified in parameter
  78.      *
  79.      * @param strWorkgroupKey
  80.      *            The AdminWorkgroup object to remove
  81.      */
  82.     public static void remove( String strWorkgroupKey )
  83.     {
  84.         _dao.delete( strWorkgroupKey );
  85.     }

  86.     // /////////////////////////////////////////////////////////////////////////
  87.     // Finders

  88.     /**
  89.      * Returns an instance of a workgroup whose identifier is specified in parameter
  90.      *
  91.      * @param strWorkgroupKey
  92.      *            The key of the workgroup
  93.      * @return An instance of workgroup
  94.      */
  95.     public static AdminWorkgroup findByPrimaryKey( String strWorkgroupKey )
  96.     {
  97.         return _dao.load( strWorkgroupKey );
  98.     }

  99.     /**
  100.      * Returns a collection of workgroups objects
  101.      *
  102.      * @return A collection of workgroups
  103.      */
  104.     public static Collection<AdminWorkgroup> findAll( )
  105.     {
  106.         return _dao.selectWorkgroupList( );
  107.     }

  108.     /**
  109.      * Check that the given key points to an existing workgroup
  110.      *
  111.      * @param strWorkgroupKey
  112.      *            The workgroup key
  113.      * @return true if the workgroup exists, false otherwise
  114.      */
  115.     public static boolean checkExistWorkgroup( String strWorkgroupKey )
  116.     {
  117.         return _dao.checkExistWorkgroup( strWorkgroupKey );
  118.     }

  119.     /**
  120.      * Is the user member of the workgroup
  121.      *
  122.      * @param user
  123.      *            The user
  124.      * @param strWorkgroup
  125.      *            The workgroup key
  126.      * @return True if the user is in the workgroup, otherwise false
  127.      */
  128.     public static boolean isUserInWorkgroup( AdminUser user, String strWorkgroup )
  129.     {
  130.         return _dao.isUserInWorkgroup( user.getUserId( ), strWorkgroup );
  131.     }

  132.     /**
  133.      * Is the user member of the workgroup
  134.      *
  135.      * @param nIdUser
  136.      *            The user identifier
  137.      * @return True if the user is in a workgroup, otherwise false
  138.      */
  139.     public static boolean checkUserHasWorkgroup( int nIdUser )
  140.     {
  141.         return _dao.checkUserHasWorkgroup( nIdUser );
  142.     }

  143.     /**
  144.      * Returns the list of all workgroups the user is member
  145.      *
  146.      * @param user
  147.      *            The user
  148.      * @return A reference list of all user's workgroups
  149.      */
  150.     public static ReferenceList getUserWorkgroups( AdminUser user )
  151.     {
  152.         return _dao.getUserWorkgroups( user.getUserId( ) );
  153.     }

  154.     /**
  155.      * Returns the list of all users for a workgroup
  156.      *
  157.      * @param strWorkgroupKey
  158.      *            The workgroup key
  159.      * @return A list of all users of the workgroup
  160.      */
  161.     public static Collection<AdminUser> getUserListForWorkgroup( String strWorkgroupKey )
  162.     {
  163.         return _dao.getUsersListForWorkgroup( strWorkgroupKey );
  164.     }

  165.     /**
  166.      * Add user to the workgroup
  167.      *
  168.      * @param user
  169.      *            The user
  170.      * @param strWorkgroupKey
  171.      *            The workgroup key
  172.      */
  173.     public static void addUserForWorkgroup( AdminUser user, String strWorkgroupKey )
  174.     {
  175.         _dao.insertUserForWorkgroup( user, strWorkgroupKey );
  176.     }

  177.     /**
  178.      * Remove all users of a workgroup
  179.      *
  180.      * @param strWorkgroupKey
  181.      *            The workgroup key
  182.      */
  183.     public static void removeAllUsersForWorkgroup( String strWorkgroupKey )
  184.     {
  185.         _dao.deleteAllUsersForWorkgroup( strWorkgroupKey );
  186.     }

  187.     /**
  188.      * Remove an user from a workgroup
  189.      *
  190.      * @param user
  191.      *            The user
  192.      * @param strWorkgroupKey
  193.      *            The workgroup key
  194.      */
  195.     public static void removeUserFromWorkgroup( AdminUser user, String strWorkgroupKey )
  196.     {
  197.         _dao.deleteUserFromWorkgroup( user.getUserId( ), strWorkgroupKey );
  198.     }

  199.     /**
  200.      * Find workgroups from a filter
  201.      *
  202.      * @param awFilter
  203.      *            the filter
  204.      * @return the list of workgroups
  205.      */
  206.     public static Collection<AdminWorkgroup> findByFilter( AdminWorkgroupFilter awFilter )
  207.     {
  208.         return _dao.selectWorkgroupsByFilter( awFilter );
  209.     }
  210. }