001/*
002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others.
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 *
016 * Contributors:
017 *     btatar
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.platform.userworkspace.api;
023
024import java.io.Serializable;
025
026import org.nuxeo.ecm.core.api.CoreSession;
027import org.nuxeo.ecm.core.api.DocumentModel;
028import org.nuxeo.ecm.core.api.NuxeoPrincipal;
029
030/**
031 * User workspace service class that is used to get the document model for the personal workspace of the current user.
032 *
033 * @author btatar
034 */
035public interface UserWorkspaceService extends Serializable {
036
037    /**
038     * Gets the current user personal workspace.
039     * <p>
040     * If this personal workspace does not exist then a new one will be created for the user owning the core session.
041     *
042     * @param userCoreSession the user core session
043     * @return the user personal workspace
044     * @since 9.3
045     */
046    DocumentModel getCurrentUserPersonalWorkspace(CoreSession userCoreSession);
047
048    /**
049     * Gets the current user personal workspace from a lower level.
050     * <p>
051     * If this personal workspace does not exist then a new one will be created for the user who is represented by first
052     * argument.
053     *
054     * @param userName the current user
055     * @param currentDocument the current document on which the user was on
056     * @return the DocumentModel for the personal workspace of the current user
057     */
058    DocumentModel getCurrentUserPersonalWorkspace(String userName, DocumentModel currentDocument);
059
060    /**
061     * @deprecated since 9.3. User personal workspaces have always been stored in default domain. The context is
062     *             useless. Simply use {@link #getCurrentUserPersonalWorkspace(CoreSession)}.
063     */
064    @Deprecated
065    DocumentModel getCurrentUserPersonalWorkspace(CoreSession userCoreSession, DocumentModel context);
066
067    /**
068     * Gets a detached user workspace of a specified user.
069     *
070     * @param userName is the username of the wanted user's workspace owner
071     * @param context is a document to determine the domain
072     * @return the DocumentModel for the personal workspace
073     * @since 5.5
074     */
075    DocumentModel getUserPersonalWorkspace(String userName, DocumentModel context);
076
077    /**
078     * Gets a detached user workspace of a specified user depending of the passed principal.
079     *
080     * @param principal of the wanted user's workspace owner
081     * @param context is a document to determine the domain
082     * @return the DocumentModel for the personal workspace
083     * @since 5.7
084     */
085    DocumentModel getUserPersonalWorkspace(NuxeoPrincipal principal, DocumentModel context);
086
087    /**
088     * Checks whether the passed document is under the user's workspace (or is the workspace itself).
089     *
090     * @param principal the user
091     * @param username the username, if principal is not available
092     * @param doc the document
093     * @return {@code true} if the document is under the user's workspace
094     * @since 9.2
095     */
096    boolean isUnderUserWorkspace(NuxeoPrincipal principal, String username, DocumentModel doc);
097
098    /**
099     * Invalidates the user workspace service and force re-computation of user workspace root location.
100     *
101     * @since 9.3
102     */
103    void invalidate();
104
105}