001/*
002 *  Copyright 2022 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.program;
017
018import org.apache.avalon.framework.configuration.Configurable;
019import org.apache.avalon.framework.configuration.Configuration;
020import org.apache.avalon.framework.configuration.ConfigurationException;
021import org.apache.commons.lang3.ArrayUtils;
022
023import org.ametys.cms.contenttype.MetadataType;
024import org.ametys.cms.contenttype.indexing.CustomIndexingField;
025import org.ametys.cms.repository.Content;
026import org.ametys.runtime.i18n.I18nizableText;
027
028/**
029 * Indexing field for the order of degree
030 */
031public class DegreeOrderIndexingField implements CustomIndexingField, Configurable
032{
033    /** The field name */
034    private String _name;
035    /** The label field */
036    private I18nizableText _label;
037    /** The description field */
038    private I18nizableText _description;
039
040    
041    public void configure(Configuration configuration) throws ConfigurationException
042    {
043        _name = configuration.getAttribute("name");
044        _label = I18nizableText.parseI18nizableText(configuration.getChild("label"), "plugin.odf");
045        _description = I18nizableText.parseI18nizableText(configuration.getChild("description"), "plugin.odf");
046    }
047
048    public String getName()
049    {
050        return _name;
051    }
052
053    public I18nizableText getLabel()
054    {
055        return _label;
056    }
057
058    public I18nizableText getDescription()
059    {
060        return _description;
061    }
062
063    public MetadataType getType()
064    {
065        return MetadataType.LONG;
066    }
067
068    public Object[] getValues(Content content)
069    {
070        if (content instanceof Program)
071        {
072            return ArrayUtils.toArray(content.getValue("degree/order", false, Long.MAX_VALUE));
073        }
074        return null;
075    }
076}