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.repository.ModifiableDefaultContent; 025import org.ametys.core.right.RightAssignmentContext; 026import org.ametys.plugins.contentio.synchronize.search.SCCSearchModelConfiguration; 027import org.ametys.plugins.repository.RepositoryConstants; 028import org.ametys.runtime.i18n.I18nizableText; 029 030/** 031 * This interface represents a synchronizable collection of contents 032 * 033 */ 034public interface SynchronizableContentsCollection 035{ 036 /** The name for the metadata indicating the ids of the collections */ 037 public static final String COLLECTION_ID_PROPERTY = RepositoryConstants.NAMESPACE_PREFIX_INTERNAL + ":scc"; 038 039 /** 040 * Get the id of synchronizable collection. 041 * @return the id 042 */ 043 String getId(); 044 045 /** 046 * Get the label of synchronizable collection 047 * @return the label 048 */ 049 I18nizableText getLabel(); 050 051 /** 052 * Get the type of content handled by this collection 053 * @return the type of content 054 */ 055 String getContentType(); 056 057 /** 058 * Get the languages handled by this collection 059 * @return the list of language 060 */ 061 List<String> getLanguages(); 062 063 /** 064 * Get the id of controller responsible of synchronization of this collection 065 * @return The id of controller 066 */ 067 String getSynchronizeCollectionModelId(); 068 069 /** 070 * Get the untyped values of parameters for controller 071 * @return the untyped values 072 */ 073 Map<String, Object> getParameterValues(); 074 075 /** 076 * When returns true, a content created by a previous synchro will be removed if it does not exist anymore during the current synchro. 077 * @return true if a content created by a previous synchro has to be removed if it does not exist anymore during the current synchro. 078 */ 079 boolean removalSync(); 080 081 /** 082 * Get the name of the workflow to use for the synchronized contents 083 * @return the name of the workflow to use for the synchronized contents 084 */ 085 String getWorkflowName(); 086 087 /** 088 * Get the id of the initial action of the workflow 089 * @return The id of the initial action of the workflow 090 */ 091 int getInitialActionId(); 092 093 /** 094 * Get the id of the synchronize action of the workflow 095 * @return The id of the synchronize action of the workflow 096 */ 097 int getSynchronizeActionId(); 098 099 /** 100 * Get the id of the validate action of the workflow 101 * @return The id of the validate action of the workflow 102 */ 103 int getValidateActionId(); 104 105 /** 106 * Get the prefix to use for the creation of contents 107 * @return The prefix to use for the creation of contents 108 */ 109 String getContentPrefix(); 110 111 /** 112 * True to validate the contents after import 113 * @return True to validate the contents after import 114 */ 115 boolean validateAfterImport(); 116 117 /** 118 * If an exception occurs during synchronization, an error report mail will be sent to those email addresses (separated by new lines) 119 * @return The email addresses to send an error report if an exception occurs during synchronization (separated by new lines) 120 */ 121 String getReportMails(); 122 123 /** 124 * Gets the id of the {@link SynchronizingContentOperator} extension to use during synchronization 125 * @return the id of the {@link SynchronizingContentOperator} extension to use during synchronization 126 */ 127 String getSynchronizingContentOperator(); 128 129 /** 130 * Get the path of boolean metadata for restricted content. 131 * If true, the content will be visible only for connected users. 132 * @return the path to the metadata. Can be null. 133 */ 134 String getRestrictedField(); 135 136 /** 137 * Get the path of metadata holding the unique identifier 138 * @return the path to the metadata. Can be null. 139 */ 140 String getIdField(); 141 142 /** 143 * Get the path of tri-state fields (with local and external values) 144 * @param additionalParameters Additional parameters 145 * @return the synchronized fields 146 */ 147 Set<String> getLocalAndExternalFields(Map<String, Object> additionalParameters); 148 149 /** 150 * Get the path of field that are valued externally only. 151 * @param additionalParameters Additional parameters 152 * @return the external fields 153 */ 154 Set<String> getExternalOnlyFields(Map<String, Object> additionalParameters); 155 156 /** 157 * Get the search UI model for search tool (columns, criterias, url for buttons, etc.) 158 * @return A {@link SCCSearchModelConfiguration} 159 */ 160 SCCSearchModelConfiguration getSearchModelConfiguration(); 161 162 /** 163 * True to synchronize only existing contents 164 * @return True to synchronize only existing contents 165 */ 166 boolean synchronizeExistingContentsOnly(); 167 168 /** 169 * Populates contents 170 * @param logger The logger 171 * @return Return the populated contents (imported or synchronized) 172 */ 173 public List<ModifiableDefaultContent> populate(Logger logger); 174 175 /** 176 * Import a content from remote values. 177 * @param idValue Id (for import/synchronization) of the content to import 178 * @param additionalParameters Additional parameters 179 * @param logger The logger 180 * @return A list of created contents 181 * @throws Exception if an error occurs. 182 */ 183 public List<ModifiableDefaultContent> importContent(String idValue, Map<String, Object> additionalParameters, Logger logger) throws Exception; 184 185 /** 186 * Synchronize a content with remove values. 187 * @param content The content to synchronize 188 * @param logger The logger 189 * @throws Exception if an error occurs. 190 */ 191 public void synchronizeContent(ModifiableDefaultContent content, Logger logger) throws Exception; 192 193 /** 194 * Gets the content in the repository 195 * @param lang the language 196 * @param idValue the content name 197 * @return the content in the repository, or null if does not exist 198 */ 199 public ModifiableDefaultContent getContent(String lang, String idValue); 200 201 /** 202 * Search the data to import from parameters. 203 * @param parameters Parameters for the search 204 * @param offset Begin of the search 205 * @param limit Number of results 206 * @param sort Sort of results (ignored for LDAP results) 207 * @param logger The logger 208 * @return A map of remote values by content 209 */ 210 public Map<String, Map<String, Object>> search(Map<String, Object> parameters, int offset, int limit, List<Object> sort, Logger logger); 211 212 /** 213 * Method to update the synchronisation informations (collection and value of the ID field). 214 * @param content Content to update 215 * @param syncCode New synchronization code 216 * @param logger The logger 217 * @throws Exception if an error occurs. 218 */ 219 public void updateSyncInformations(ModifiableDefaultContent content, String syncCode, Logger logger) throws Exception; 220 221 /** 222 * Return the total number of results for the search. 223 * @param parameters Parameters for the search 224 * @param logger The logger 225 * @return The total count 226 */ 227 public int getTotalCount(Map<String, Object> parameters, Logger logger); 228 229 /** 230 * Return true if a {@link RightAssignmentContext} should be automatically generated for the contents of this SCC 231 * @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} 232 */ 233 public default boolean handleRightAssignmentContext() 234 { 235 return true; 236 } 237}