001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.gwt.shared.rpc;
029
030import org.opencms.db.CmsResourceState;
031import org.opencms.gwt.CmsRpcException;
032import org.opencms.gwt.shared.CmsBroadcastMessage;
033import org.opencms.gwt.shared.CmsCategoryTreeEntry;
034import org.opencms.gwt.shared.CmsContextMenuEntryBean;
035import org.opencms.gwt.shared.CmsCoreData;
036import org.opencms.gwt.shared.CmsCoreData.AdeContext;
037import org.opencms.gwt.shared.CmsCoreData.UserInfo;
038import org.opencms.gwt.shared.CmsResourceCategoryInfo;
039import org.opencms.gwt.shared.CmsReturnLinkInfo;
040import org.opencms.gwt.shared.CmsUserSettingsBean;
041import org.opencms.gwt.shared.CmsValidationQuery;
042import org.opencms.gwt.shared.CmsValidationResult;
043import org.opencms.util.CmsUUID;
044
045import java.util.List;
046import java.util.Map;
047import java.util.Set;
048
049import com.google.gwt.user.client.rpc.RemoteService;
050
051/**
052 * Provides general core services.<p>
053 *
054 * @since 8.0.0
055 *
056 * @see org.opencms.gwt.CmsCoreService
057 * @see org.opencms.gwt.shared.rpc.I_CmsCoreService
058 * @see org.opencms.gwt.shared.rpc.I_CmsCoreServiceAsync
059 */
060public interface I_CmsCoreService extends RemoteService {
061
062    /**
063     * Changes the password of the current user.<p>
064     *
065     * @param oldPassword the old password
066     * @param newPassword the value entered for the new password
067     * @param newPasswordConfirm the value entered for the confirmation of the new password
068     *
069     * @return an error message if an error occurred, or null if the password was successfully changed
070     *
071     * @throws CmsRpcException if something goes wrong
072     */
073    String changePassword(String oldPassword, String newPassword, String newPasswordConfirm) throws CmsRpcException;
074
075    /**
076    * Creates a new UUID.<p>
077    *
078    * @return the created UUID
079    *
080    * @throws CmsRpcException if something goes wrong
081    */
082    CmsUUID createUUID() throws CmsRpcException;
083
084    /**
085     * Returns the latest messages for the current user.<p>
086     *
087     * @return the messages
088     *
089     * @throws CmsRpcException if anything goes wrong
090     */
091    List<CmsBroadcastMessage> getBroadcast() throws CmsRpcException;
092
093    /**
094     * Returns the categories for the given search parameters.<p>
095     *
096     * @param fromCatPath the category path to start with, can be <code>null</code> or empty to use the root
097     * @param includeSubCats if to include all categories, or first level child categories only
098     * @param refVfsPath the reference path (site-relative path according to which the available category repositories are determined),
099     *        can be <code>null</code> to only use the system repository
100     *
101     * @return the resource categories
102     *
103     * @throws CmsRpcException if something goes wrong
104     */
105    List<CmsCategoryTreeEntry> getCategories(String fromCatPath, boolean includeSubCats, String refVfsPath)
106    throws CmsRpcException;
107
108    /**
109     * Returns the categories for the given search parameters.<p>
110     *
111     * @param fromCatPath the category path to start with, can be <code>null</code> or empty to use the root
112     * @param includeSubCats if to include all categories, or first level child categories only
113     * @param refVfsPath the reference path (site-relative path according to which the available category repositories are determined),
114     *        can be <code>null</code> to only use the system repository
115     * @param withRepositories flag, indicating if also the category repositories should be returned as category
116     *
117     * @return the resource categories
118     *
119     * @throws CmsRpcException if something goes wrong
120     */
121    List<CmsCategoryTreeEntry> getCategories(
122        String fromCatPath,
123        boolean includeSubCats,
124        String refVfsPath,
125        boolean withRepositories)
126    throws CmsRpcException;
127
128    /**
129     * Returns the categories for the given reference site-path.<p>
130     *
131     * @param sitePath the reference site-path
132     *
133     * @return the categories for the given reference site-path
134     *
135     * @throws CmsRpcException if something goes wrong
136     */
137    List<CmsCategoryTreeEntry> getCategoriesForSitePath(String sitePath) throws CmsRpcException;
138
139    /**
140     * Returns the category information for the given resource.<p>
141     *
142     * @param structureId the resource structure id
143     *
144     * @return the category information
145     *
146     * @throws CmsRpcException if something goes wrong
147     */
148    CmsResourceCategoryInfo getCategoryInfo(CmsUUID structureId) throws CmsRpcException;
149
150    /**
151     * Returns the context menu entries for the given URI.<p>
152     *
153     * @param structureId the currently requested structure id
154     * @param context the ade context (sitemap or containerpage)
155     *
156     * @return the context menu entries
157     *
158     * @throws CmsRpcException if something goes wrong
159     */
160    List<CmsContextMenuEntryBean> getContextMenuEntries(CmsUUID structureId, AdeContext context) throws CmsRpcException;
161
162    /**
163     * Given a return code, returns the link to the page which corresponds to the return code.<p>
164     *
165     * @param returnCode the return code
166     *
167     * @return the link for the return code
168     *
169     * @throws CmsRpcException if something goes wrong
170     */
171    CmsReturnLinkInfo getLinkForReturnCode(String returnCode) throws CmsRpcException;
172
173    /**
174     * Gets the resource state for a resource with a given path.<p>
175     *
176     * @param structureId the resource structure id
177     *
178     * @return the resource state of the resource
179     *
180     * @throws CmsRpcException if something goes wrong
181     */
182    CmsResourceState getResourceState(CmsUUID structureId) throws CmsRpcException;
183
184    /**
185     * Returns a unique filename for the given base name and the parent folder.<p>
186     *
187     * @param parentFolder the parent folder of the file
188     * @param baseName the proposed file name
189     *
190     * @return the unique file name
191     *
192     * @throws CmsRpcException if something goes wrong
193     */
194    String getUniqueFileName(String parentFolder, String baseName) throws CmsRpcException;
195
196    /**
197     * Returns the user info.<p>
198     *
199     * @return the user info
200     *
201     * @throws CmsRpcException in case something goes wrong
202     */
203    UserInfo getUserInfo() throws CmsRpcException;
204
205    /**
206     * Returns a link for the OpenCms workplace that will reload the whole workplace, switch to the explorer view, the
207     * site of the given explorerRootPath and show the folder given in the explorerRootPath.<p>
208     *
209     * @param structureId the structure id of the resource for which to open the workplace
210     *
211     * @return a link for the OpenCms workplace that will reload the whole workplace, switch to the explorer view, the
212     *         site of the given explorerRootPath and show the folder given in the explorerRootPath.
213     *
214     * @throws CmsRpcException if something goes wrong
215     */
216    String getWorkplaceLink(CmsUUID structureId) throws CmsRpcException;
217
218    /**
219     * Gets the workplace link for the given path.
220     *
221     * @param path the path
222     * @return the workplace link for the path
223     * @throws CmsRpcException if something goes wrong
224     */
225    String getWorkplaceLinkForPath(String path) throws CmsRpcException;
226
227    /**
228     * Loads the user settings for the current user.<p>
229     *
230     * @return the user settings for the current user
231     *
232     * @throws CmsRpcException if something goes wrong
233     */
234    CmsUserSettingsBean loadUserSettings() throws CmsRpcException;
235
236    /**
237     * Locks the given resource with a temporary lock if it exists.<p>
238     * If the resource does not exist yet, the closest existing ancestor folder will check if it is lockable.<p>
239     *
240     * @param sitePath the site path of the resource to lock
241     *
242     * @return <code>null</code> if successful, an error message if not
243     *
244     * @throws CmsRpcException if something goes wrong
245     */
246    String lockIfExists(String sitePath) throws CmsRpcException;
247
248    /**
249     * Locks the given resource with a temporary lock if it exists.<p>
250     * If the resource does not exist yet, the closest existing ancestor folder will check if it is lockable.<p>
251     *
252     * @param sitePath the site path of the resource to lock
253     * @param loadTime the time when the requested resource was loaded
254     *
255     * @return <code>null</code> if successful, an error message if not
256     *
257     * @throws CmsRpcException if something goes wrong
258     */
259    String lockIfExists(String sitePath, long loadTime) throws CmsRpcException;
260
261    /**
262     * Locks the given resource with a temporary lock.<p>
263     *
264     * @param structureId the structure id of the resource to lock
265     *
266     * @return <code>null</code> if successful, an error message if not
267     *
268     * @throws CmsRpcException if something goes wrong
269     */
270    String lockTemp(CmsUUID structureId) throws CmsRpcException;
271
272    /**
273     * Locks the given resource with a temporary lock.<p>
274     * Locking will fail in case the requested resource has been changed since the given load time.<p>
275     *
276     * @param structureId the resource structure id
277     * @param loadTime the time when the requested resource was loaded
278     *
279     * @return <code>null</code> if successful, an error message if not
280     *
281     * @throws CmsRpcException if something goes wrong
282     */
283    String lockTemp(CmsUUID structureId, long loadTime) throws CmsRpcException;
284
285    /**
286     * Generates core data for prefetching in the host page.<p>
287     *
288     * @return the core data
289     *
290     * @throws CmsRpcException if something goes wrong
291     */
292    CmsCoreData prefetch() throws CmsRpcException;
293
294    /**
295     * Saves the user settings for the current user.<p>
296     *
297     * @param userSettings the new values for the user settings
298     * @param edited the keys of the user settings which were actually edited
299     *
300     * @throws CmsRpcException if something goes wrong
301     */
302    void saveUserSettings(Map<String, String> userSettings, Set<String> edited) throws CmsRpcException;
303
304    /**
305     * Sets the categories of the given resource. Will remove all other categories.<p>
306     *
307     * @param structureId the resource structure id
308     * @param categories the categories to set
309     *
310     * @throws CmsRpcException if something goes wrong
311     */
312    void setResourceCategories(CmsUUID structureId, List<String> categories) throws CmsRpcException;
313
314    /**
315     * Sets the show editor help flag.<p>
316     *
317     * @param showHelp the show help flag
318     *
319     * @throws CmsRpcException if something goes wrong
320     */
321    void setShowEditorHelp(boolean showHelp) throws CmsRpcException;
322
323    /**
324     * Writes the tool-bar visibility into the session cache.<p>
325     *
326     * @param visible <code>true</code> if the tool-bar is visible
327     *
328     * @throws CmsRpcException if something goes wrong
329     */
330    void setToolbarVisible(boolean visible) throws CmsRpcException;
331
332    /**
333     * Unlocks the given resource.<p>
334     *
335     * @param structureId the structure id of the resource to unlock
336     *
337     * @return <code>null</code> if successful, an error message if not
338     *
339     * @throws CmsRpcException if something goes wrong
340     */
341    String unlock(CmsUUID structureId) throws CmsRpcException;
342
343    /**
344     * Unlocks the given resource.<p>
345     *
346     * @param rootPath the root path of the resource to unlock
347     *
348     * @return <code>null</code> if successful, an error message if not
349     *
350     * @throws CmsRpcException if something goes wrong
351     */
352    String unlock(String rootPath) throws CmsRpcException;
353
354    /**
355     * Performs a batch of validations and returns the results.<p>
356     *
357     * @param validationQueries a map from field names to validation queries
358     *
359     * @return a map from field names to validation results
360     *
361     * @throws CmsRpcException if something goes wrong
362     */
363    Map<String, CmsValidationResult> validate(Map<String, CmsValidationQuery> validationQueries) throws CmsRpcException;
364
365    /**
366     * Performs a batch of validations using a custom form validator class.<p>
367     *
368     * @param formValidatorClass the class name of the form validator
369     * @param validationQueries a map from field names to validation queries
370     * @param values the map of all field values
371     * @param config the form validator configuration string
372     *
373     * @return a map from field names to validation results
374     *
375     * @throws CmsRpcException if the RPC call goes wrong
376     */
377    Map<String, CmsValidationResult> validate(
378        String formValidatorClass,
379        Map<String, CmsValidationQuery> validationQueries,
380        Map<String, String> values,
381        String config)
382    throws CmsRpcException;
383
384}