001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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.kuali.rice.krad.service;
017
018import java.util.List;
019import java.util.Map;
020import java.util.Set;
021
022import org.kuali.rice.kim.api.identity.Person;
023import org.kuali.rice.krad.document.Document;
024import org.kuali.rice.krad.document.authorization.PessimisticLock;
025
026/**
027 * Service interface for documents to use the Pessimistic Locking mechanism
028 *
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 */
031public interface PessimisticLockService {
032
033    /**
034     * This method deletes the given lock object
035     *
036     * @param id - the id of the lock to delete
037     */
038    public void delete(String id);
039
040    /**
041     * This method will generate a new {@link PessimisticLock} object with a 'document'
042     * lock descriptor
043     *
044     * @param documentNumber - the document number of the document associated with the new lock
045     * @return the newly generated document descriptor {@link PessimisticLock}
046     */
047    public PessimisticLock generateNewLock(String documentNumber);
048
049    /**
050     * This method will generate a new {@link PessimisticLock} object with a lock descriptor of
051     * the given parameter
052     *
053     * @param documentNumber - the document number of the document associated with the new lock
054     * @param lockDescriptor - the lock descriptor the new PessimisticLock object should contain
055     * @return the newly generated {@link PessimisticLock} containing the given lockDescriptor
056     */
057    public PessimisticLock generateNewLock(String documentNumber, String lockDescriptor);
058
059    /**
060     * This method will generate a new {@link PessimisticLock} object with a 'document'
061     * lock descriptor
062     *
063     * @param documentNumber - the document number of the document associated with the new lock
064     * @param user - the user to set on the new lock being generated
065     * @return the newly generated document descriptor {@link PessimisticLock}
066     */
067    public PessimisticLock generateNewLock(String documentNumber, Person user);
068
069    /**
070     * This method will generate a new {@link PessimisticLock} object with a lock descriptor of
071     * the given parameter
072     *
073     * @param documentNumber - the document number of the document associated with the new lock
074     * @param lockDescriptor - the lock descriptor the new PessimisticLock object should contain
075     * @param user - the user to set on the new lock being generated
076     * @return the newly generated {@link PessimisticLock} containing the given lockDescriptor
077     */
078    public PessimisticLock generateNewLock(String documentNumber, String lockDescriptor, Person user);
079
080    /**
081     * This method gets all locks associated with the given document number
082     *
083     * @param documentNumber - the document number of the document requiring locks
084     * @return an empty list if no locks are found or the list of {@link PessimisticLock} objects
085     * found for the given documentNumber
086     */
087    public List<PessimisticLock> getPessimisticLocksForDocument(String documentNumber);
088
089    /**
090     * Return all locks associated with the given session id
091     *
092     * @param sessionId - the session id
093     * @return an empty list of no locks are found or the list of {@link PessimisticLock} objects
094     * found for the given sessionId
095     */
096    public List<PessimisticLock> getPessimisticLocksForSession(String sessionId);
097    
098    /**
099     * This method is used to identify who is an admin user for {@link PessimisticLock} objects
100     *
101     * @param user - user to verify as admin
102     * @return true if the given use is an admin user or false if not
103     */
104    public boolean isPessimisticLockAdminUser(Person user);
105
106    /**
107     * This method will release all locks in the given list that are owned by the given user
108     *
109     * @param locks - locks to release if owned by given user
110     * @param user - user to check for lock ownership
111     */
112    public void releaseAllLocksForUser(List<PessimisticLock> locks, Person user);
113
114    /**
115     * This method will release all locks in the given list that are owned by the given user that have a matching lock
116     * descriptor value
117     *
118     * @param locks - locks to release if owned by given user
119     * @param user - user to check for lock ownership
120     * @param lockDescriptor - lock descriptor value to match locks against
121     */
122    public void releaseAllLocksForUser(List<PessimisticLock> locks, Person user, String lockDescriptor);
123
124    /**
125     * This method saves the given lock object
126     *
127     */
128    public PessimisticLock save(PessimisticLock lock);
129
130    /**
131     * Establishes pessimistic locks for {@code user} on the {@code document} based whether the {@code user} can edit
132     * the document.
133     *
134     * <p>
135     * Will only establish a new pessimistic lock if one doesn't exist for the {@code user} and one can be created based
136     * on other pessimistic locks in the system and whether {@code user} can edit the document.  Will return true
137     * if either a new pessimistic lock was established or one already exists for the {@code user}.
138     * </p>
139     *
140     * @param document the document on which the locks will be established
141     * @param user the user for which the locks are being established
142     * @param canEdit whether the user currently can edit the document
143     *
144     * @return true if a pessimistic lock has been established, false otherwise
145     */
146    public boolean establishPessimisticLocks(Document document, Person user, boolean canEdit);
147
148    /**
149     * @param document - the document locks are to be established against or by
150     * @param editMode - the editMode
151     * @param user - the user locks are being established for
152     * @return New map generated by locking logic combined with passed in parameter editMode.  Map contains keys
153     *         AuthorizationConstants.EditMode value (String) which indicates what operations the user is currently
154     *         allowed to take on that document.  This may be a modified list of
155     * @deprecated For KRAD, use @{code establishPessimisticLocks} to generate locks and
156     * {@code calculatePessimisticLockEditModes} to get the edit modes based on the current locks
157     */
158    @Deprecated
159    public Map establishLocks(Document document, Map editMode, Person user);
160
161    /**
162     * @param document - the document to create the lock against and add the lock to
163     */
164    public void establishWorkflowPessimisticLocking(Document document);
165
166    /**
167     * @param document - document to release locks from
168     */
169    public void releaseWorkflowPessimisticLocking(Document document);
170
171    /**
172     * @param document
173     * @param user
174     * @return Set of actions are permitted the given user on the given document
175     * @deprecated KRAD has integrated this functionality into
176     * {@link org.kuali.rice.krad.document.TransactionalDocumentAuthorizerBase}
177     */
178    @Deprecated
179    public Set getDocumentActions(Document document, Person user, Set<String> documentActions);
180
181}
182