001/* 002 * Copyright 2020 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.mobileapp; 017 018import java.util.List; 019import java.util.Map; 020import java.util.Set; 021 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024import org.slf4j.Logger; 025 026import org.ametys.cms.search.model.SystemPropertyExtensionPoint; 027import org.ametys.cms.search.ui.model.SearchUIColumnHelper; 028import org.ametys.cms.search.ui.model.SearchUIModel; 029import org.ametys.runtime.i18n.I18nizableText; 030import org.ametys.runtime.model.View; 031import org.ametys.runtime.model.ViewHelper; 032import org.ametys.runtime.model.ViewItemContainer; 033 034/** 035 * Wrapper for a SearchUIModel to force LastValidationSystemProperty to be in result fields 036 */ 037public class SearchModelWrapper implements SearchUIModel 038{ 039 /** The logger */ 040 protected Logger _logger; 041 042 /** The service manager */ 043 protected ServiceManager _manager; 044 045 /** The SystemProperty extension point */ 046 protected SystemPropertyExtensionPoint _systemPropertyExtensionPoint; 047 048 private SearchUIModel _realModel; 049 050 /** 051 * Constructor with the SearchUIModel to wrap 052 * @param model the SearchUIModel to wrap 053 * @param manager The service manager 054 * @param logger The logger 055 */ 056 public SearchModelWrapper(SearchUIModel model, ServiceManager manager, Logger logger) 057 { 058 _realModel = model; 059 _manager = manager; 060 _logger = logger; 061 } 062 063 public ViewItemContainer getResultItems(Map<String, Object> contextualParameters) 064 { 065 ViewItemContainer resultItems = _realModel.getResultItems(contextualParameters); 066 067 // If no item is already a LastValidationSearchField, add it 068 if (!resultItems.hasModelViewItem("lastValidation")) 069 { 070 try 071 { 072 View result = new View(); 073 074 result.addViewItems(ViewHelper.copyViewItems(resultItems.getViewItems())); 075 resultItems.addViewItem(SearchUIColumnHelper.createModelItemColumn(getSystemPropertyExtensionPoint().getExtension("lastValidation"))); 076 077 return result; 078 } 079 catch (ServiceException e) 080 { 081 getLogger().error("Error while adding 'lastValidation' in the set of result columns", e); 082 } 083 } 084 085 return resultItems; 086 } 087 088 /** 089 * Retrieves the {@link SystemPropertyExtensionPoint} 090 * @return The {@link SystemPropertyExtensionPoint} 091 * @throws ServiceException if an error occurs while looking to the extension point up 092 */ 093 protected SystemPropertyExtensionPoint getSystemPropertyExtensionPoint() throws ServiceException 094 { 095 if (_systemPropertyExtensionPoint == null) 096 { 097 _systemPropertyExtensionPoint = (SystemPropertyExtensionPoint) _manager.lookup(SystemPropertyExtensionPoint.ROLE); 098 } 099 100 return _systemPropertyExtensionPoint; 101 } 102 103 public Set<String> getContentTypes(Map<String, Object> contextualParameters) 104 { 105 return _realModel.getContentTypes(contextualParameters); 106 } 107 108 public Set<String> getExcludedContentTypes(Map<String, Object> contextualParameters) 109 { 110 return _realModel.getExcludedContentTypes(contextualParameters); 111 } 112 113 public ViewItemContainer getCriteria(Map<String, Object> contextualParameters) 114 { 115 return _realModel.getCriteria(contextualParameters); 116 } 117 118 public ViewItemContainer getFacetedCriteria(Map<String, Object> contextualParameters) 119 { 120 return _realModel.getFacetedCriteria(contextualParameters); 121 } 122 123 public ViewItemContainer getAdvancedCriteria(Map<String, Object> contextualParameters) 124 { 125 return _realModel.getAdvancedCriteria(contextualParameters); 126 } 127 128 public int getPageSize(Map<String, Object> contextualParameters) 129 { 130 return _realModel.getPageSize(contextualParameters); 131 } 132 133 public String getWorkspace(Map<String, Object> contextualParameters) 134 { 135 return _realModel.getWorkspace(contextualParameters); 136 } 137 138 public String getSearchUrl(Map<String, Object> contextualParameters) 139 { 140 return _realModel.getSearchUrl(contextualParameters); 141 } 142 143 public String getSearchUrlPlugin(Map<String, Object> contextualParameters) 144 { 145 return _realModel.getSearchUrlPlugin(contextualParameters); 146 } 147 148 public String getExportCSVUrl(Map<String, Object> contextualParameters) 149 { 150 return _realModel.getExportCSVUrl(contextualParameters); 151 } 152 153 public String getExportCSVUrlPlugin(Map<String, Object> contextualParameters) 154 { 155 return _realModel.getExportCSVUrlPlugin(contextualParameters); 156 } 157 158 public String getPrintUrl(Map<String, Object> contextualParameters) 159 { 160 return _realModel.getPrintUrl(contextualParameters); 161 } 162 163 public String getPrintUrlPlugin(Map<String, Object> contextualParameters) 164 { 165 return _realModel.getPrintUrlPlugin(contextualParameters); 166 } 167 168 public String getSummaryView() 169 { 170 return _realModel.getSummaryView(); 171 } 172 173 public Map<String, Object> toJSON(Map<String, Object> contextualParameters) 174 { 175 return _realModel.toJSON(contextualParameters); 176 } 177 178 public List<Object> resultItemsToJSON(Map<String, Object> contextualParameters) 179 { 180 return _realModel.resultItemsToJSON(contextualParameters); 181 } 182 183 /** 184 * Get the logger. 185 * @return the logger. 186 */ 187 protected final Logger getLogger() 188 { 189 return _logger; 190 } 191 192 public String getName() 193 { 194 return _realModel.getName(); 195 } 196 197 public I18nizableText getLabel() 198 { 199 return _realModel.getLabel(); 200 } 201 202 public I18nizableText getDescription() 203 { 204 return _realModel.getDescription(); 205 } 206 207 public boolean hasTag(String tagName) 208 { 209 return _realModel.hasTag(tagName); 210 } 211 212 public Set<String> getTags() 213 { 214 return _realModel.getTags(); 215 } 216}