001/* 002 * Copyright 2023 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.cms.content.consistency; 017 018import java.util.ArrayList; 019import java.util.HashMap; 020import java.util.Iterator; 021import java.util.LinkedHashMap; 022import java.util.List; 023import java.util.Map; 024 025import org.apache.avalon.framework.component.Component; 026import org.apache.avalon.framework.service.ServiceException; 027import org.apache.avalon.framework.service.ServiceManager; 028import org.apache.avalon.framework.service.Serviceable; 029 030import org.ametys.core.ui.Callable; 031import org.ametys.plugins.workflow.support.WorkflowHelper; 032import org.ametys.runtime.i18n.I18nizableText; 033 034import com.opensymphony.workflow.loader.StepDescriptor; 035 036/** 037 * Provide the search model for Content consistency search 038 */ 039public class ContentConstitencySearchModel implements Component, Serviceable 040{ 041 /** The avalon role */ 042 public static final String ROLE = ContentConstitencySearchModel.class.getName(); 043 private WorkflowHelper _workflowHelper; 044 045 public void service(ServiceManager manager) throws ServiceException 046 { 047 _workflowHelper = (WorkflowHelper) manager.lookup(WorkflowHelper.ROLE); 048 } 049 050 /** 051 * Get the model for a content consistency search 052 * @return the model 053 */ 054 @Callable 055 public Map<String, Object> getModel() 056 { 057 Map<String, Object> model = new HashMap<>(); 058 059 // Proxy configuration 060 model.put("searchMethodName", "searchResults"); 061 model.put("searchRole", "org.ametys.cms.content.consistency.ContentConsistencySearcher"); 062 063 model.put("columns", getColumns()); 064 065 model.put("criteria", getCriteria()); 066 067 model.put("facets", getFacets()); 068 069 return model; 070 } 071 072 /** 073 * Provide the list of column. 074 * Any column additional column must not be sortable as there info won't be present in the search result. 075 * @return a json description of the column 076 */ 077 protected List<Map<String, Object>> getColumns() 078 { 079 // Columns configuration 080 List<Map<String, Object>> columns = new ArrayList<>(); 081 columns.add(Map.of( 082 "id", ContentConsistencyResult.TITLE, 083 "label", new I18nizableText("plugin.cms", "PLUGINS_CMS_METADATA_TITLE_LABEL"), 084 "type", "string", 085 "multiple", false)); 086 columns.add(Map.of( 087 "id", ContentConsistencyResult.CONTENT_TYPES, 088 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_ALL_CONTENT_TYPE"), 089 "type", "string", 090 "multiple", true, 091 "renderer", "Ametys.plugins.cms.content.tool.GlobalContentConsistencyTool.renderContentType")); 092 columns.add(Map.of( 093 "id", ContentConsistencyResult.CREATOR, 094 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_CREATOR"), 095 "type", "user", 096 "multiple", false, 097 "hidden", true, 098 "renderer", "Ametys.plugins.cms.search.SearchGridHelper.renderUser")); 099 columns.add(Map.of( 100 "id", ContentConsistencyResult.CREATION_DATE, 101 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_CREATIONDATE"), 102 "type", "datetime", 103 "hidden", true, 104 "multiple", false)); 105 columns.add(Map.of( 106 "id", ContentConsistencyResult.LAST_CONTRIBUTOR, 107 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_AUTHOR"), 108 "type", "user", 109 "multiple", false, 110 "renderer", "Ametys.plugins.cms.search.SearchGridHelper.renderUser")); 111 columns.add(Map.of( 112 "id", ContentConsistencyResult.LAST_MODIFICATION_DATE, 113 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_LASTMODIFIED"), 114 "type", "datetime", 115 "hidden", true, 116 "multiple", false)); 117 columns.add(Map.of( 118 "id", ContentConsistencyResult.LAST_VALIDATOR, 119 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_LAST_VALIDATOR"), 120 "type", "user", 121 "multiple", false, 122 "hidden", true, 123 "renderer", "Ametys.plugins.cms.search.SearchGridHelper.renderUser")); 124 columns.add(Map.of( 125 "id", ContentConsistencyResult.LAST_VALIDATION_DATE, 126 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_LASTVALIDATION"), 127 "type", "datetime", 128 "hidden", true, 129 "multiple", false)); 130 columns.add(Map.of( 131 "id", ContentConsistencyResult.WORKFLOW_STEP, 132 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_WORKFLOW_STEP"), 133 "type", "int", 134 "multiple", false, 135 "renderer", "Ametys.plugins.cms.search.SearchGridHelper.renderWorkflowStep", 136 "converter", "Ametys.plugins.cms.search.SearchGridHelper.convertWorkflowStep")); 137 columns.add(Map.of( 138 "id", ContentConsistencyResult.DATE, 139 "label", new I18nizableText("plugin.cms", "PLUGINS_CMS_GLOBAL_CONTENT_CONSISTENCY_CHECK_DATE"), 140 "type", "datetime", 141 "multiple", false)); 142 columns.add(Map.of( 143 "id", ContentConsistencyResult.SUCCESS, 144 "label", new I18nizableText("plugin.cms", "PLUGINS_CMS_GLOBAL_CONTENT_CONSISTENCY_SUCCESS_COUNT"), 145 "hidden", true, 146 "type", "int", 147 "multiple", false)); 148 columns.add(Map.of( 149 "id", ContentConsistencyResult.UNAUTHORIZED, 150 "label", new I18nizableText("plugin.cms", "PLUGINS_CMS_GLOBAL_CONTENT_CONSISTENCY_UNAUTHORIZED_COUNT"), 151 "type", "int", 152 "multiple", false)); 153 columns.add(Map.of( 154 "id", ContentConsistencyResult.UNKNOWN, 155 "label", new I18nizableText("plugin.cms", "PLUGINS_CMS_GLOBAL_CONTENT_CONSISTENCY_UNKNOWN_COUNT"), 156 "type", "int", 157 "multiple", false)); 158 columns.add(Map.of( 159 "id", ContentConsistencyResult.NOT_FOUND, 160 "label", new I18nizableText("plugin.cms", "PLUGINS_CMS_GLOBAL_CONTENT_CONSISTENCY_NOT_FOUND_COUNT"), 161 "type", "int", 162 "multiple", false)); 163 columns.add(Map.of( 164 "id", ContentConsistencyResult.SERVER_ERROR, 165 "label", new I18nizableText("plugin.cms", "PLUGINS_CMS_GLOBAL_CONTENT_CONSISTENCY_SERVER_ERROR_COUNT"), 166 "type", "int", 167 "multiple", false)); 168 return columns; 169 } 170 171 /** 172 * Get the criteria for the search 173 * @return the JSON description of the criteria 174 */ 175 protected Map<String, Object> getCriteria() 176 { 177 Map<String, Object> criteria = new LinkedHashMap<>(); // order is important here 178 criteria.put("title", Map.of( 179 "label", new I18nizableText("plugin.cms", "PLUGINS_CMS_METADATA_TITLE_LABEL"), 180 "description", new I18nizableText("plugin.cms", "PLUGINS_CMS_METADATA_TITLE_DESCRIPTION"), 181 "type", "STRING" 182 )); 183 184 List<Map<String, Object>> workflowStep = new ArrayList<>(); 185 workflowStep.add(Map.of("label", new I18nizableText("plugin.cms", "WIDGET_COMBOBOX_ALL_OPTIONS"), "value", 0)); 186 for (Iterator iterator = _workflowHelper.getWorkflowDescriptor("content").getSteps().iterator(); iterator.hasNext();) 187 { 188 StepDescriptor step = (StepDescriptor) iterator.next(); 189 workflowStep.add(Map.of("label", new I18nizableText(null, step.getName()), "value", step.getId())); 190 } 191 192 criteria.put("workflowStep", Map.of( 193 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_WORKFLOW_STEP"), 194 "description", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_WORKFLOW_STEP"), 195 "type", "LONG", 196 "enumeration", workflowStep, 197 "default-value", 0 // - Tous - 198 )); 199 200 Map<String, Object> ctype = new HashMap<>(); 201 ctype.put("label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_ALL_CONTENT_TYPE")); 202 ctype.put("description", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_ALL_CONTENT_TYPE")); 203 ctype.put("type", "STRING"); 204 ctype.put("multiple", false); 205 ctype.put("enumeration", null); 206 ctype.put("widget", "edition.select-content-types"); 207 ctype.put("widget-params", Map.of("emptyText", new I18nizableText("plugin.cms", "WIDGET_COMBOBOX_ALL_OPTIONS"))); 208 criteria.put("contentTypes", ctype); 209 210 criteria.put(ContentConsistencyResult.CREATOR, Map.of( 211 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_CREATOR"), 212 "description", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_CREATOR"), 213 "type", "USER" 214 )); 215 criteria.put("contributor", Map.of( 216 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_AUTHOR"), 217 "description", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_AUTHOR"), 218 "type", "USER" 219 )); 220 criteria.put(ContentConsistencyResult.LAST_VALIDATOR, Map.of( 221 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_LAST_VALIDATOR"), 222 "description", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_LAST_VALIDATOR"), 223 "type", "USER" 224 )); 225 return criteria; 226 } 227 228 /** 229 * Get the facets for the search 230 * @return the JSON description of the facets 231 */ 232 protected List<Map<String, Object>> getFacets() 233 { 234 List<Map<String, Object>> facets = new ArrayList<>(); 235 facets.add(Map.of( 236 "name", ContentConsistencyResult.CREATOR, 237 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_CREATOR"), 238 "type", "criterion", 239 "children", new ArrayList())); 240 facets.add(Map.of( 241 "name", ContentConsistencyResult.LAST_CONTRIBUTOR, 242 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_AUTHOR"), 243 "type", "criterion", 244 "children", new ArrayList())); // needs to be mutable to add the value later 245 facets.add(Map.of( 246 "name", ContentConsistencyResult.LAST_VALIDATOR, 247 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_LAST_VALIDATOR"), 248 "type", "criterion", 249 "children", new ArrayList())); // needs to be mutable to add the value later 250 facets.add(Map.of( 251 "name", ContentConsistencyResult.WORKFLOW_STEP, 252 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_WORKFLOW_STEP"), 253 "type", "criterion", 254 "children", new ArrayList())); // needs to be mutable to add the value later 255 facets.add(Map.of( 256 "name", ContentConsistencyResult.CONTENT_TYPES, 257 "label", new I18nizableText("plugin.cms", "UITOOL_SEARCH_CONTENT_ALL_CONTENT_TYPE"), 258 "type", "criterion", 259 "children", new ArrayList())); // needs to be mutable to add the value later 260 return facets; 261 } 262}