001/*
002 *  Copyright 2017 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.odf.enumeration;
017
018import java.util.Locale;
019import java.util.Objects;
020
021import org.apache.commons.lang3.StringUtils;
022
023import org.ametys.cms.repository.Content;
024
025/**
026 * This class represents a entry of ODF reference table
027 *
028 */
029public class OdfReferenceTableEntry
030{
031    /** Attribute name for code */
032    public static final String CODE = "code";
033    /** Attribute name for CDM value */
034    public static final String CDM_VALUE = "cdmValue";
035    /** Attribute name for code Apogée */
036    public static final String CODE_APOGEE = "codeApogee";
037    /** Attribute name for code Pégase */
038    public static final String CODE_PEGASE = "codePegase";
039    
040    /** Attribute name for ordering */
041    public static final String ORDER = "order";
042    /** Attribute name for archiving */
043    public static final String ARCHIVED = "archived";
044    
045    private Content _entry;
046    
047    /**
048     * Constructor
049     * @param content The content representing the entry
050     */
051    public OdfReferenceTableEntry(Content content)
052    {
053        _entry = content;
054    }
055    
056    /**
057     * Get the identifier
058     * @return The identifier
059     */
060    public String getId()
061    {
062        return _entry.getId();
063    }
064    
065    /**
066     * Get the label
067     * @param lang The language
068     * @return The label
069     */
070    public String getLabel(String lang)
071    {
072        return _entry.getTitle(new Locale(lang));
073    }
074    
075    /**
076     * Get the code
077     * @return the code
078     */
079    public String getCode()
080    {
081        return _entry.getValue(CODE, false, StringUtils.EMPTY);
082    }
083    
084    /** 
085     * Get the CDM value
086     * @return the CDM value
087     */
088    public String getCdmValue()
089    {
090        return _entry.getValue(CDM_VALUE, false, StringUtils.EMPTY);
091    }
092    
093    /**
094     * Get the order
095     * @return the order
096     */
097    public Long getOrder()
098    {
099        return _entry.getValue(ORDER, false, Long.MAX_VALUE);
100    }
101    
102    /**
103     * Get the archiving state
104     * @return <code>true</code> if the entry is archived, <code>false</code> otherwise
105     */
106    public Boolean isArchived()
107    {
108        return _entry.getValue(ARCHIVED, false, false);
109    }
110    
111    /**
112     * Get the content
113     * @return the content
114     */
115    public Content getContent()
116    {
117        return _entry;
118    }
119
120    @Override
121    public int hashCode()
122    {
123        return Objects.hash(_entry.getId());
124    }
125
126    @Override
127    public boolean equals(Object obj)
128    {
129        if (this == obj)
130        {
131            return true;
132        }
133        if (obj == null)
134        {
135            return false;
136        }
137        if (getClass() != obj.getClass())
138        {
139            return false;
140        }
141        OdfReferenceTableEntry other = (OdfReferenceTableEntry) obj;
142        return Objects.equals(_entry.getId(), other._entry.getId());
143    }
144}