001/*
002 *  Copyright 2021 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.plugins.cart;
017
018import java.util.Collections;
019import java.util.List;
020
021import org.ametys.core.util.DateUtils;
022import org.ametys.plugins.queriesdirectory.Query;
023import org.ametys.runtime.i18n.I18nizableText;
024
025/**
026 * Implementation of a {@link CartElement} wrapping a query from directory
027 */
028public class QueryFromDirectoryElement extends QueryElement
029{
030    private Query _query;
031    
032    /**
033     * Constructor
034     * @param query the query
035     */
036    public QueryFromDirectoryElement (Query query)
037    {
038        super(query.getId(), query.getContent(), query.getAuthor(), DateUtils.asCalendar(query.getLastModificationDate()), query.getTitle());
039        _query = query;
040    }
041    
042    @Override
043    public String getType()
044    {
045        return "cartQueryFromDirectory";
046    }
047    
048    @Override
049    public List<I18nizableText> getGroups()
050    {
051        return Collections.singletonList(new I18nizableText("plugin.cart", "PLUGINS_CART_UITOOL_CART_QUERIES_FROM_DIRECTORY_GROUP"));
052    }
053    
054    @Override
055    public String getGlyphIcon()
056    {
057        String type = _query.getType();
058        switch (type)
059        {
060            case "solr":
061                return "ametysicon-solr";
062            case "script":
063                return "ametysicon-development";
064            case "formatting":
065                return "ametysicon-paintbrush";
066            case "simple":
067            case "advanced":
068                return "ametysicon-magnifier41";
069            default:
070                return super.getGlyphIcon();
071        }
072    }
073    
074    /**
075     * Get the query from id
076     * @return the query
077     */
078    public Query getQuery()
079    {
080        return _query;
081    }
082}