FeatureGroup.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.right;

  35. import fr.paris.lutece.portal.service.i18n.I18nService;
  36. import fr.paris.lutece.util.ReferenceItem;

  37. import java.util.ArrayList;
  38. import java.util.Collection;
  39. import java.util.Locale;

  40. /**
  41.  * This class represents business objects feature group
  42.  */
  43. public class FeatureGroup
  44. {
  45.     // ///////////////////////////////////////////////////////////////////////////////
  46.     // Constants
  47.     private static final String EMPTY_STRING = "";

  48.     // ///////////////////////////////////////////////////////////////////////////////
  49.     // Variables
  50.     private String _strId;
  51.     private String _strDescriptionKey;
  52.     private String _strLabelKey;
  53.     private String _strIcon;
  54.     private int _nOrder;
  55.     private Collection<Right> _aFeaturesList = new ArrayList<>( );
  56.     private Locale _locale;

  57.     /**
  58.      * Sets the locale to use
  59.      *
  60.      * @param locale
  61.      *            the locale to use
  62.      */
  63.     public void setLocale( Locale locale )
  64.     {
  65.         _locale = locale;
  66.     }

  67.     /**
  68.      * Returns the identifier of this feature group
  69.      *
  70.      * @return the identifier of this feature group
  71.      */
  72.     public String getId( )
  73.     {
  74.         return _strId;
  75.     }

  76.     /**
  77.      * Sets the identifier of the feature group to the specified string.
  78.      *
  79.      * @param strId
  80.      *            the new identifier
  81.      */
  82.     public void setId( String strId )
  83.     {
  84.         _strId = strId;
  85.     }

  86.     /**
  87.      * Returns the label of this feature group.
  88.      *
  89.      * @return the feature group label
  90.      */
  91.     public String getLabelKey( )
  92.     {
  93.         return _strLabelKey;
  94.     }

  95.     /**
  96.      * Returns the label of this feature group.
  97.      *
  98.      * @return the feature group label
  99.      */
  100.     public String getLabel( )
  101.     {
  102.         String strLocalizedLabel = I18nService.getLocalizedString( _strLabelKey, _locale );
  103.         if ( !strLocalizedLabel.isEmpty( ) )
  104.         {
  105.             return strLocalizedLabel;
  106.         }
  107.         else
  108.         {
  109.             return _strLabelKey;
  110.         }
  111.     }

  112.     /**
  113.      * Sets the label of the feature group to the specified string.
  114.      *
  115.      * @param strLabelKey
  116.      *            the new label
  117.      */
  118.     public void setLabelKey( String strLabelKey )
  119.     {
  120.         _strLabelKey = ( strLabelKey == null ) ? EMPTY_STRING : strLabelKey;
  121.     }

  122.     /**
  123.      * Returns the order of this feature group.
  124.      *
  125.      * @return the feature group order
  126.      */
  127.     public int getOrder( )
  128.     {
  129.         return _nOrder;
  130.     }

  131.     /**
  132.      * Sets the order of the feature group to the specified int.
  133.      *
  134.      * @param nOrder
  135.      *            the new level
  136.      */
  137.     public void setOrder( int nOrder )
  138.     {
  139.         _nOrder = nOrder;
  140.     }

  141.     /**
  142.      * Returns the description of this feature group.
  143.      *
  144.      * @return the feature group description
  145.      */
  146.     public String getDescriptionKey( )
  147.     {
  148.         return _strDescriptionKey;
  149.     }

  150.     /**
  151.      * Returns the description of this feature group.
  152.      *
  153.      * @return the feature group description
  154.      */
  155.     public String getDescription( )
  156.     {
  157.         String strLocalizedDescription = I18nService.getLocalizedString( _strDescriptionKey, _locale );
  158.         if ( !strLocalizedDescription.isEmpty( ) )
  159.         {
  160.             return strLocalizedDescription;
  161.         }
  162.         else
  163.         {
  164.             return _strDescriptionKey;
  165.         }
  166.     }

  167.     /**
  168.      * Sets the description of the feature group to the specified string.
  169.      *
  170.      * @param strDescriptionKey
  171.      *            the new description
  172.      */
  173.     public void setDescriptionKey( String strDescriptionKey )
  174.     {
  175.         _strDescriptionKey = ( strDescriptionKey == null ) ? EMPTY_STRING : strDescriptionKey;
  176.     }

  177.     /**
  178.      * Add a feature to the group
  179.      *
  180.      * @param right
  181.      *            The feature to add
  182.      */
  183.     public void addFeature( Right right )
  184.     {
  185.         _aFeaturesList.add( right );
  186.     }

  187.     /**
  188.      * Tells whether or not the feature list is empty
  189.      *
  190.      * @return _aFeaturesList
  191.      */
  192.     public boolean isEmpty( )
  193.     {
  194.         return _aFeaturesList.isEmpty( );
  195.     }

  196.     /**
  197.      * Returns all features affected to the group
  198.      *
  199.      * @return a collection
  200.      */
  201.     public Collection<Right> getFeatures( )
  202.     {
  203.         return _aFeaturesList;
  204.     }

  205.     /**
  206.      * Returns a reference item for the feature group
  207.      *
  208.      * @return a reference item
  209.      */
  210.     public ReferenceItem getReferenceItem( )
  211.     {
  212.         ReferenceItem item = new ReferenceItem( );
  213.         item.setCode( _strId );
  214.         item.setName( getLabel( ) );
  215.         item.setChecked( true );
  216.         return item;
  217.     }

  218.     /**
  219.      * Returns the icon of this feature group.
  220.      *
  221.      * @return the feature group icon
  222.      */
  223.     public String getIcon( )
  224.     {
  225.         return _strIcon;
  226.     }

  227.     /**
  228.      * Sets the icon of the feature group to the specified string.
  229.      *
  230.      * @param strIcon
  231.      *            the new icon
  232.      */
  233.     public void setIcon( String strIcon )
  234.     {
  235.         _strIcon = ( strIcon == null ) ? EMPTY_STRING : strIcon;
  236.     }
  237.    
  238. }