001/* 002 * Copyright 2016 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.contentio.synchronize; 017 018import java.util.List; 019import java.util.Map; 020import java.util.Set; 021 022import org.slf4j.Logger; 023 024import org.ametys.cms.data.ContentSynchronizationResult; 025import org.ametys.cms.repository.ModifiableContent; 026import org.ametys.core.right.RightAssignmentContext; 027import org.ametys.core.schedule.progression.ContainerProgressionTracker; 028import org.ametys.plugins.contentio.synchronize.search.SCCSearchModelConfiguration; 029import org.ametys.runtime.i18n.I18nizableText; 030 031/** 032 * This interface represents a synchronizable collection of contents 033 * 034 */ 035public interface SynchronizableContentsCollection 036{ 037 /** The name for the metadata indicating the ids of the collections */ 038 public static final String COLLECTION_ID_DATA_NAME = "scc"; 039 /** The name of the metadata indicating the date of the last synchronization */ 040 public static final String LAST_SYNCHRONIZATION_DATA_NAME = "lastSynchronization"; 041 /** The name of the metadata indicating the user that launched the last synchronization */ 042 public static final String LAST_SYNCHRONIZATION_USER_DATA_NAME = "lastSynchronizationUser"; 043 044 /** The result map key for number of created contents */ 045 public static final String RESULT_NB_CREATED_CONTENTS = "nbCreatedContents"; 046 /** The result map key for number of synchronized contents */ 047 public static final String RESULT_NB_SYNCHRONIZED_CONTENTS = "nbSynchronizedContents"; 048 /** The result map key for number of synchronized contents */ 049 public static final String RESULT_NB_NOT_CHANGED_CONTENTS = "nbNotChangedContents"; 050 /** The result map key for number of deleted contents */ 051 public static final String RESULT_NB_DELETED_CONTENTS = "nbDeletedContents"; 052 053 /** 054 * Get the id of synchronizable collection. 055 * @return the id 056 */ 057 String getId(); 058 059 /** 060 * Get the label of synchronizable collection 061 * @return the label 062 */ 063 I18nizableText getLabel(); 064 065 /** 066 * Get the type of content handled by this collection 067 * @return the type of content 068 */ 069 String getContentType(); 070 071 /** 072 * Get the languages handled by this collection 073 * @return the list of language 074 */ 075 List<String> getLanguages(); 076 077 /** 078 * Get the id of controller responsible of synchronization of this collection 079 * @return The id of controller 080 */ 081 String getSynchronizeCollectionModelId(); 082 083 /** 084 * Get the untyped values of parameters for controller 085 * @return the untyped values 086 */ 087 Map<String, Object> getParameterValues(); 088 089 /** 090 * When returns <code>true</code>, a content created by a previous synchro will be removed if it does not exist anymore during the current synchro. 091 * @return <code>true</code> if a content created by a previous synchro has to be removed if it does not exist anymore during the current synchro. 092 */ 093 boolean removalSync(); 094 095 /** 096 * When returns <code>true</code>, the process ignore restrictions on attributes to synchronize it. 097 * @return <code>true</code> to ignore restrictions on synchronization 098 */ 099 boolean ignoreRestrictions(); 100 101 /** 102 * Get the name of the workflow to use for the synchronized contents 103 * @return the name of the workflow to use for the synchronized contents 104 */ 105 String getWorkflowName(); 106 107 /** 108 * Get the id of the initial action of the workflow 109 * @return The id of the initial action of the workflow 110 */ 111 int getInitialActionId(); 112 113 /** 114 * Get the id of the synchronize action of the workflow 115 * @return The id of the synchronize action of the workflow 116 */ 117 int getSynchronizeActionId(); 118 119 /** 120 * Get the id of the validate action of the workflow 121 * @return The id of the validate action of the workflow 122 */ 123 int getValidateActionId(); 124 125 /** 126 * Get the prefix to use for the creation of contents 127 * @return The prefix to use for the creation of contents 128 */ 129 String getContentPrefix(); 130 131 /** 132 * True to validate the contents after import 133 * @return True to validate the contents after import 134 */ 135 boolean validateAfterImport(); 136 137 /** 138 * If an exception occurs during synchronization, an error report mail will be sent to those email addresses (separated by new lines) 139 * @return The email addresses to send an error report if an exception occurs during synchronization (separated by new lines) 140 */ 141 String getReportMails(); 142 143 /** 144 * Gets the id of the {@link SynchronizingContentOperator} extension to use during synchronization 145 * @return the id of the {@link SynchronizingContentOperator} extension to use during synchronization 146 */ 147 String getSynchronizingContentOperator(); 148 149 /** 150 * Get the path of boolean metadata for restricted content. 151 * If true, the content will be visible only for connected users. 152 * @return the path to the metadata. Can be null. 153 */ 154 String getRestrictedField(); 155 156 /** 157 * Get the path of metadata holding the unique identifier 158 * @return the path to the metadata. Can be null. 159 */ 160 String getIdField(); 161 162 /** 163 * Get the path of tri-state fields (with local and external values) 164 * @param additionalParameters Additional parameters 165 * @return the synchronized fields 166 */ 167 Set<String> getLocalAndExternalFields(Map<String, Object> additionalParameters); 168 169 /** 170 * Get the search UI model for search tool (columns, criterias, url for buttons, etc.) 171 * @return A {@link SCCSearchModelConfiguration} 172 */ 173 SCCSearchModelConfiguration getSearchModelConfiguration(); 174 175 /** 176 * True to synchronize only existing contents 177 * @return True to synchronize only existing contents 178 */ 179 boolean synchronizeExistingContentsOnly(); 180 181 /** 182 * Empty the collection of its synchronized contents 183 * @param logger The logger 184 */ 185 public void empty(Logger logger); 186 187 /** 188 * Populates contents 189 * @param logger The logger 190 * @param progressionTracker A progression tracker 191 * @return Return the populated contents (imported or synchronized) 192 */ 193 public List<ModifiableContent> populate(Logger logger, ContainerProgressionTracker progressionTracker); 194 195 /** 196 * Import a content from remote values. 197 * @param idValue Id (for import/synchronization) of the content to import 198 * @param additionalParameters Additional parameters 199 * @param logger The logger 200 * @return A list of created contents 201 * @throws Exception if an error occurs. 202 */ 203 public List<ModifiableContent> importContent(String idValue, Map<String, Object> additionalParameters, Logger logger) throws Exception; 204 205 /** 206 * Synchronize a content with remove values. 207 * @param content The content to synchronize 208 * @param logger The logger 209 * @throws Exception if an error occurs. 210 */ 211 public void synchronizeContent(ModifiableContent content, Logger logger) throws Exception; 212 213 /** 214 * Add specific fields to the content. 215 * @param content Content to update 216 * @param additionalParameters Additional parameters 217 * @param logger The logger 218 * @return The synchronization result of the import additional operations 219 */ 220 public default ContentSynchronizationResult additionalImportOperations(ModifiableContent content, Map<String, Object> additionalParameters, Logger logger) 221 { 222 return additionalCommonOperations(content, additionalParameters, logger); 223 } 224 225 /** 226 * Add specific fields to the content. 227 * @param content Content to update 228 * @param additionalParameters Additional parameters 229 * @param logger The logger 230 * @return The synchronization result of the synchronize additional operations 231 */ 232 public default ContentSynchronizationResult additionalSynchronizeOperations(ModifiableContent content, Map<String, Object> additionalParameters, Logger logger) 233 { 234 return additionalCommonOperations(content, additionalParameters, logger); 235 } 236 237 /** 238 * Add specific fields to the content during import or synchronization. 239 * @param content Content to update 240 * @param additionalParameters Additional parameters 241 * @param logger The logger 242 * @return The synchronization result of the additional operations 243 */ 244 public default ContentSynchronizationResult additionalCommonOperations(ModifiableContent content, Map<String, Object> additionalParameters, Logger logger) 245 { 246 // Do nothing by default 247 return new ContentSynchronizationResult(); 248 } 249 250 /** 251 * Gets the content in the repository 252 * @param lang the language 253 * @param idValue the content name 254 * @return the content in the repository, or null if does not exist 255 */ 256 public ModifiableContent getContent(String lang, String idValue); 257 258 /** 259 * Search the data to import from parameters. 260 * @param searchParameters Parameters for the search 261 * @param offset Begin of the search 262 * @param limit Number of results 263 * @param sort Sort of results (ignored for LDAP results) 264 * @param logger The logger 265 * @return A map of remote values by content 266 */ 267 public Map<String, Map<String, Object>> search(Map<String, Object> searchParameters, int offset, int limit, List<Object> sort, Logger logger); 268 269 /** 270 * Method to update the synchronisation informations (collection and value of the ID field). 271 * @param content Content to update 272 * @param syncCode New synchronization code 273 * @param logger The logger 274 * @throws Exception if an error occurs. 275 */ 276 public void updateSyncInformations(ModifiableContent content, String syncCode, Logger logger) throws Exception; 277 278 /** 279 * Return the total number of results for the search. 280 * @param searchParameters Parameters for the search 281 * @param logger The logger 282 * @return The total count 283 */ 284 public int getTotalCount(Map<String, Object> searchParameters, Logger logger); 285 286 /** 287 * Retrieves the result of the synchronization as a map of key / content count containing 288 * <ul> 289 * <li>The number of created contents</li> 290 * <li>The number of synchronized contents</li> 291 * <li>The number of unchanged contents</li> 292 * <li>The number of deleted contents</li> 293 * </ul> 294 * @return the result of the synchronization 295 */ 296 public Map<String, Integer> getSynchronizationResult(); 297 298 /** 299 * Return true if a {@link RightAssignmentContext} should be automatically generated for the contents of this SCC 300 * @return true to automatically generate a {@link RightAssignmentContext}. Return false if the rights of contents of this SCC are handle by its own {@link RightAssignmentContext} 301 */ 302 public default boolean handleRightAssignmentContext() 303 { 304 return true; 305 } 306}