Right.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.portal.service.i18n.Localizable;

  37. import java.io.Serializable;

  38. import java.util.Locale;

  39. /**
  40.  * This class represents business objects right
  41.  */
  42. public class Right implements Localizable, Comparable<Right>, Serializable
  43. {
  44.     private static final long serialVersionUID = 4075896005615205007L;

  45.     // ///////////////////////////////////////////////////////////////////////////////
  46.     // Constants
  47.     private static final String EMPTY_STRING = "";
  48.     private String _strId;
  49.     private String _strNameKey;
  50.     private String _strDescriptionKey;
  51.     private int _nLevel;
  52.     private String _strUrl;
  53.     private String _strPluginName;
  54.     private String _strFeatureGroup;
  55.     private String _strIconUrl;
  56.     private String _strDocumentationUrl;
  57.     private Locale _locale;
  58.     private int _nIdOrder;
  59.     private boolean _bIsExternalFeature;

  60.     /**
  61.      * Set the local used by this right
  62.      *
  63.      * @param locale
  64.      *            the local to use
  65.      */
  66.     @Override
  67.     public void setLocale( Locale locale )
  68.     {
  69.         _locale = locale;
  70.     }

  71.     /**
  72.      * Returns the identifier of this right
  73.      *
  74.      * @return the identifier of this right
  75.      */
  76.     public String getId( )
  77.     {
  78.         return _strId;
  79.     }

  80.     /**
  81.      * Sets the identifier of the right to the specified string.
  82.      *
  83.      * @param strId
  84.      *            the new identifier
  85.      */
  86.     public void setId( String strId )
  87.     {
  88.         _strId = strId;
  89.     }

  90.     /**
  91.      * Returns the name of this right.
  92.      *
  93.      * @return the right name
  94.      */
  95.     public String getNameKey( )
  96.     {
  97.         return _strNameKey;
  98.     }

  99.     /**
  100.      * Returns the name of this right if the i18n key exists; else return the i18n key.
  101.      *
  102.      * @return the right name
  103.      */
  104.     public String getName( )
  105.     {
  106.         String strReturn = I18nService.getLocalizedString( _strNameKey, _locale );
  107.         if ( !strReturn.equals( "" ) )
  108.         {
  109.             return I18nService.getLocalizedString( _strNameKey, _locale );
  110.         }
  111.         return _strNameKey;
  112.     }

  113.     /**
  114.      * Sets the name of the right to the specified string.
  115.      *
  116.      * @param strNameKey
  117.      *            the new name
  118.      */
  119.     public void setNameKey( String strNameKey )
  120.     {
  121.         _strNameKey = ( strNameKey == null ) ? EMPTY_STRING : strNameKey;
  122.     }

  123.     /**
  124.      * Returns the level of this right.
  125.      *
  126.      * @return the right level
  127.      */
  128.     public int getLevel( )
  129.     {
  130.         return _nLevel;
  131.     }

  132.     /**
  133.      * Sets the level of the right to the specified int.
  134.      *
  135.      * @param nLevel
  136.      *            the new level
  137.      */
  138.     public void setLevel( int nLevel )
  139.     {
  140.         _nLevel = nLevel;
  141.     }

  142.     /**
  143.      * Returns the url of the jsp component which manages this right.
  144.      *
  145.      * @return the right url function
  146.      */
  147.     public String getUrl( )
  148.     {
  149.         return _strUrl;
  150.     }

  151.     /**
  152.      * Sets the url of the right to the specified string.
  153.      *
  154.      * @param strUrl
  155.      *            the new url
  156.      */
  157.     public void setUrl( String strUrl )
  158.     {
  159.         _strUrl = strUrl;
  160.     }

  161.     /**
  162.      * Returns the description of this right.
  163.      *
  164.      * @return the right description
  165.      */
  166.     public String getDescriptionKey( )
  167.     {
  168.         return _strDescriptionKey;
  169.     }

  170.     /**
  171.      * Returns the description of this right if the i18nk exists; else return the key.
  172.      *
  173.      * @return the right description
  174.      */
  175.     public String getDescription( )
  176.     {
  177.         String strReturn = I18nService.getLocalizedString( _strDescriptionKey, _locale );
  178.         if ( !strReturn.equals( "" ) )
  179.         {
  180.             return I18nService.getLocalizedString( _strDescriptionKey, _locale );
  181.         }
  182.         return _strDescriptionKey;
  183.     }

  184.     /**
  185.      * Sets the description of the right to the specified string.
  186.      *
  187.      * @param strDescriptionKey
  188.      *            the new description
  189.      */
  190.     public void setDescriptionKey( String strDescriptionKey )
  191.     {
  192.         _strDescriptionKey = ( strDescriptionKey == null ) ? EMPTY_STRING : strDescriptionKey;
  193.     }

  194.     /**
  195.      * Returns the isUpdatable tag of this right ( 1 if the right is updatable, 0 if not ).
  196.      *
  197.      * @return the is_upda
  198.      */
  199.     public String getPluginName( )
  200.     {
  201.         return _strPluginName;
  202.     }

  203.     /**
  204.      * Sets the name of the right to the specified string.
  205.      *
  206.      * @param strPluginName
  207.      *            the new name
  208.      */
  209.     public void setPluginName( String strPluginName )
  210.     {
  211.         _strPluginName = ( strPluginName == null ) ? EMPTY_STRING : strPluginName;
  212.     }

  213.     /**
  214.      * Returns the feature group of this right.
  215.      *
  216.      * @return the right feature group
  217.      * @since 1.1.1
  218.      */
  219.     public String getFeatureGroup( )
  220.     {
  221.         return _strFeatureGroup;
  222.     }

  223.     /**
  224.      * Sets the feature group of the right to the specified string.
  225.      *
  226.      * @param strFeatureGroup
  227.      *            the new feature group
  228.      * @since 1.1.1
  229.      */
  230.     public void setFeatureGroup( String strFeatureGroup )
  231.     {
  232.         _strFeatureGroup = strFeatureGroup;
  233.     }

  234.     /**
  235.      * Returns the url of the icon associated to the right.
  236.      *
  237.      * @return the icon url
  238.      */
  239.     public String getIconUrl( )
  240.     {
  241.         return _strIconUrl;
  242.     }

  243.     /**
  244.      * Sets the url of the icon associated to the right.
  245.      *
  246.      * @param strIconUrl
  247.      *            the new url
  248.      */
  249.     public void setIconUrl( String strIconUrl )
  250.     {
  251.         _strIconUrl = strIconUrl;
  252.     }

  253.     /**
  254.      * Returns the url of the documentation associated to the right.
  255.      *
  256.      * @return the _strDocumentationUrl
  257.      */
  258.     public String getDocumentationUrl( )
  259.     {
  260.         return _strDocumentationUrl;
  261.     }

  262.     /**
  263.      * Sets the url of the documentation associated to the right.
  264.      *
  265.      * @param strDocumentationUrl
  266.      *            the _strDocumentationUrl to set
  267.      */
  268.     public void setDocumentationUrl( String strDocumentationUrl )
  269.     {
  270.         _strDocumentationUrl = strDocumentationUrl;
  271.     }

  272.     /**
  273.      * Get the right order
  274.      *
  275.      * @return the _order
  276.      */
  277.     public int getOrder( )
  278.     {
  279.         return _nIdOrder;
  280.     }

  281.     /**
  282.      * Set the right order in feature group
  283.      *
  284.      * @param nOrder
  285.      *            the _order to set
  286.      */
  287.     public void setOrder( int nOrder )
  288.     {
  289.         this._nIdOrder = nOrder;
  290.     }

  291.     /**
  292.      * Get the external feature boolean
  293.      *
  294.      * @return the _isExternalFeature
  295.      */
  296.     public boolean isExternalFeature( )
  297.     {
  298.         return _bIsExternalFeature;
  299.     }

  300.     /**
  301.      * Set the external feature boolean
  302.      *
  303.      * @param bExternalFeature
  304.      *            the _isExternalFeature to set
  305.      */
  306.     public void setExternalFeature( boolean bExternalFeature )
  307.     {
  308.         this._bIsExternalFeature = bExternalFeature;
  309.     }

  310.     /**
  311.      * Compare the right with the specified right
  312.      *
  313.      * @param o
  314.      *            The right to be compared with the instanced right
  315.      * @return The result of comparison
  316.      */
  317.     @Override
  318.     public int compareTo( Right o )
  319.     {
  320.         if ( this.getOrder( ) > o.getOrder( ) )
  321.         {
  322.             return 1;
  323.         }
  324.         else
  325.             if ( this.getOrder( ) < o.getOrder( ) )
  326.             {
  327.                 return -1;
  328.             }
  329.             else
  330.             {
  331.                 return this.getId( ).compareTo( o.getId( ) );
  332.             }
  333.     }

  334.     /**
  335.      * {@inheritDoc}
  336.      */
  337.     @Override
  338.     public boolean equals( Object o )
  339.     {
  340.         if ( !( o instanceof Right ) )
  341.         {
  342.             return false;
  343.         }

  344.         return compareTo( (Right) o ) == 0;
  345.     }

  346.     /**
  347.      * {@inheritDoc}
  348.      */
  349.     @Override
  350.     public int hashCode( )
  351.     {
  352.         int nIdHash = ( getId( ) == null ) ? 0 : getId( ).hashCode( );

  353.         return ( getOrder( ) * 100 ) + nIdHash;
  354.     }
  355. }