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