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     * Empty the collection of its synchronized contents
170     * @param logger The logger
171     */
172    public void empty(Logger logger);
173    
174    /**
175     * Populates contents
176     * @param logger The logger
177     * @return Return the populated contents (imported or synchronized)
178     */
179    public List<ModifiableDefaultContent> populate(Logger logger);
180    
181    /**
182     * Import a content from remote values.
183     * @param idValue Id (for import/synchronization) of the content to import
184     * @param additionalParameters Additional parameters
185     * @param logger The logger
186     * @return A list of created contents
187     * @throws Exception if an error occurs.
188     */
189    public List<ModifiableDefaultContent> importContent(String idValue, Map<String, Object> additionalParameters, Logger logger) throws Exception;
190    
191    /**
192     * Synchronize a content with remove values.
193     * @param content The content to synchronize
194     * @param logger The logger
195     * @throws Exception if an error occurs.
196     */
197    public void synchronizeContent(ModifiableDefaultContent content, Logger logger) throws Exception;
198    
199    /**
200     * Gets the content in the repository
201     * @param lang the language
202     * @param idValue the content name
203     * @return the content in the repository, or null if does not exist
204     */
205    public ModifiableDefaultContent getContent(String lang, String idValue);
206    
207    /**
208     * Search the data to import from parameters.
209     * @param parameters Parameters for the search
210     * @param offset Begin of the search
211     * @param limit Number of results
212     * @param sort Sort of results (ignored for LDAP results)
213     * @param logger The logger
214     * @return A map of remote values by content
215     */
216    public Map<String, Map<String, Object>> search(Map<String, Object> parameters, int offset, int limit, List<Object> sort, Logger logger);
217
218    /**
219     * Method to update the synchronisation informations (collection and value of the ID field).
220     * @param content Content to update
221     * @param syncCode New synchronization code
222     * @param logger The logger
223     * @throws Exception if an error occurs.
224     */
225    public void updateSyncInformations(ModifiableDefaultContent content, String syncCode, Logger logger) throws Exception;
226    
227    /**
228     * Return the total number of results for the search.
229     * @param parameters Parameters for the search
230     * @param logger The logger
231     * @return The total count
232     */
233    public int getTotalCount(Map<String, Object> parameters, Logger logger);
234    
235    /**
236     * Return true if a {@link RightAssignmentContext} should be automatically generated for the contents of this SCC
237     * @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}
238     */
239    public default boolean handleRightAssignmentContext()
240    {
241        return true;
242    }
243}