001/*
002 *  Copyright 2013 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.time.ZonedDateTime;
019import java.util.Collections;
020import java.util.List;
021
022import org.ametys.core.user.UserIdentity;
023import org.ametys.runtime.i18n.I18nizableText;
024
025/**
026 * Implementation of a {@link CartElement} wrapping a search query
027 *
028 */
029public class QueryElement implements CartElement
030{
031    private String _id;
032    private String _query;
033    private String _title;
034    private UserIdentity _author;
035    private ZonedDateTime _creationDate;
036    private UserIdentity _contributor;
037    private ZonedDateTime _lastModified;
038
039    /**
040     * Constructor
041     * @param id The id
042     * @param query The query
043     * @param author The author
044     * @param creationDate The creation date
045     * @param contributor The last contributor
046     * @param lastModified The last modification date
047     * @param title The query title
048     */
049    public QueryElement (String id, String query, UserIdentity author, ZonedDateTime creationDate, UserIdentity contributor, ZonedDateTime lastModified, String title)
050    {
051        _id = id;
052        _query = query;
053        _author = author;
054        _creationDate = creationDate;
055        _contributor = contributor;
056        _lastModified = lastModified;
057        _title = title;
058    }
059    
060    @Override
061    public String getId()
062    {
063        return _id;
064    }
065    
066    @Override
067    public I18nizableText getTitle()
068    {
069        return new I18nizableText(_title);
070    }
071
072    @Override
073    public I18nizableText getDescription()
074    {
075        return new I18nizableText("");
076    }
077    
078    /**
079     * Get the content of the query
080     * @return the content as a JSON string
081     */
082    public String getQueryContent()
083    {
084        return _query;
085    }
086    
087    @Override
088    public List<I18nizableText> getGroups()
089    {
090        return Collections.singletonList(new I18nizableText("plugin.cart", "PLUGINS_CART_UITOOL_CART_QUERIES_GROUP"));
091    }
092    
093    @Override
094    public ZonedDateTime getCreationDate()
095    {
096        return _creationDate;
097    }
098    
099    @Override
100    public UserIdentity getCreator()
101    {
102        return _author;
103    }
104    
105    @Override
106    public ZonedDateTime getLastModified()
107    {
108        return _lastModified;
109    }
110
111    @Override
112    public UserIdentity getLastContributor()
113    {
114        return _contributor;
115    }
116    
117    @Override
118    public String getType()
119    {
120        return "cartQuery";
121    }
122
123    public String getGlyphIcon()
124    {
125        return "ametysicon-magnifier12";
126    }
127    
128    @Override
129    public String getSmallIcon()
130    {
131        return null;
132    }
133    
134    @Override
135    public String getMediumIcon()
136    {
137        return null;
138    }
139}