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