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