AdminUserFieldHome.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.user.attribute;

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

  38. import java.util.List;

  39. /**
  40.  *
  41.  * AdminUserFieldHome
  42.  *
  43.  */
  44. public final class AdminUserFieldHome
  45. {
  46.     private static IAdminUserFieldDAO _dao = SpringContextService.getBean( "adminUserFieldDAO" );

  47.     /**
  48.      * Private constructor
  49.      */
  50.     private AdminUserFieldHome( )
  51.     {
  52.     }

  53.     /**
  54.      * Load the user field
  55.      *
  56.      * @param nIdUserField
  57.      *            ID
  58.      * @return AdminUserField
  59.      */
  60.     public static AdminUserField findByPrimaryKey( int nIdUserField )
  61.     {
  62.         return _dao.load( nIdUserField );
  63.     }

  64.     /**
  65.      * Insert a new user field
  66.      *
  67.      * @param userField
  68.      *            the user field
  69.      */
  70.     public static void create( AdminUserField userField )
  71.     {
  72.         if ( userField.getFile( ) != null )
  73.         {
  74.             userField.getFile( ).setIdFile( FileHome.create( userField.getFile( ) ) );
  75.         }

  76.         _dao.insert( userField );
  77.     }

  78.     /**
  79.      * Update an user field
  80.      *
  81.      * @param userField
  82.      *            the user field
  83.      */
  84.     public static void update( AdminUserField userField )
  85.     {
  86.         if ( userField.getFile( ) != null )
  87.         {
  88.             FileHome.update( userField.getFile( ) );
  89.         }

  90.         _dao.store( userField );
  91.     }

  92.     /**
  93.      * Delete an attribute.
  94.      *
  95.      * @param userField
  96.      *            the user field
  97.      */
  98.     public static void remove( AdminUserField userField )
  99.     {
  100.         if ( userField != null )
  101.         {
  102.             if ( userField.getFile( ) != null )
  103.             {
  104.                 FileHome.remove( userField.getFile( ).getIdFile( ) );
  105.             }

  106.             _dao.delete( userField.getIdUserField( ) );
  107.         }
  108.     }

  109.     /**
  110.      * Delete all user fields from given id field
  111.      *
  112.      * @param nIdField
  113.      *            id field
  114.      */
  115.     public static void removeUserFieldsFromIdField( int nIdField )
  116.     {
  117.         _dao.deleteUserFieldsFromIdField( nIdField );
  118.     }

  119.     /**
  120.      * Delete all user fields from given id user
  121.      *
  122.      * @param nIdUser
  123.      *            id user
  124.      */
  125.     public static void removeUserFieldsFromIdUser( int nIdUser )
  126.     {
  127.         _dao.deleteUserFieldsFromIdUser( nIdUser );
  128.     }

  129.     /**
  130.      * Delete all user fields from given id attribute
  131.      *
  132.      * @param nIdAttribute
  133.      *            id attribute
  134.      */
  135.     public static void removeUserFieldsFromIdAttribute( int nIdAttribute )
  136.     {
  137.         _dao.deleteUserFieldsFromIdAttribute( nIdAttribute );
  138.     }

  139.     /**
  140.      * Load all the user field by a given ID user and a given ID attribute
  141.      *
  142.      * @param nIdUser
  143.      *            the ID user
  144.      * @param nIdAttribute
  145.      *            the attribute identifier
  146.      * @return a list of adminuserfield
  147.      */
  148.     public static List<AdminUserField> selectUserFieldsByIdUserIdAttribute( int nIdUser, int nIdAttribute )
  149.     {
  150.         return _dao.selectUserFieldsByIdUserIdAttribute( nIdUser, nIdAttribute );
  151.     }

  152.     /**
  153.      * Load users by a given filter
  154.      *
  155.      * @param auFieldFilter
  156.      *            the filter
  157.      * @return a list of users
  158.      */
  159.     public static List<AdminUser> findUsersByFilter( AdminUserFieldFilter auFieldFilter )
  160.     {
  161.         return _dao.selectUsersByFilter( auFieldFilter );
  162.     }

  163.     /**
  164.      * Select by filter
  165.      *
  166.      * @param auFieldFilter
  167.      *            the filter
  168.      * @return a list of admin user field
  169.      */
  170.     public static List<AdminUserField> findByFilter( AdminUserFieldFilter auFieldFilter )
  171.     {
  172.         return _dao.selectByFilter( auFieldFilter );
  173.     }

  174.     /**
  175.      * Remove by filter
  176.      *
  177.      * @param auFieldFilter
  178.      *            the filter
  179.      */
  180.     public static void removeByFilter( AdminUserFieldFilter auFieldFilter )
  181.     {
  182.         List<AdminUserField> listUserFields = findByFilter( auFieldFilter );

  183.         for ( AdminUserField userField : listUserFields )
  184.         {
  185.             remove( userField );
  186.         }
  187.     }

  188.     /**
  189.      * Is the file associated with an attribute
  190.      *
  191.      * @param nIdFile
  192.      *            the id file
  193.      * @return wheter the file is associated with an attribute
  194.      */
  195.     public static boolean existsWithFile( int nIdFile )
  196.     {
  197.         return _dao.existsWithFile( nIdFile );
  198.     }

  199. }