001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.kernel.api.services; 019 020import org.fcrepo.kernel.api.FedoraSession; 021 022/** 023 * @author acoburn 024 * @since Sept 30, 2016 025 */ 026public interface BatchService { 027 028 /** 029 * Check for expired batch operations and remove them 030 */ 031 void removeExpired(); 032 033 /** 034 * Create a new batch operation with a FedoraSession and add it to the currently open ones 035 * 036 * @param session The session to use for this batch operation 037 * @param username the name of the {@link java.security.Principal} 038 */ 039 void begin(FedoraSession session, String username); 040 041 /** 042 * Create a new batch operation with a FedoraSession for the anonymous user and add it to the currently open ones 043 * 044 * @param session The session to use for this batch operation 045 */ 046 default void begin(FedoraSession session) { 047 begin(session, null); 048 } 049 050 /** 051 * Retrieve an open {@link FedoraSession} for a given user 052 * 053 * @param sessionId the Id of the {@link FedoraSession} 054 * @param username the name of the {@link java.security.Principal} 055 * @return the {@link FedoraSession} with this user 056 */ 057 FedoraSession getSession(String sessionId, String username); 058 059 /** 060 * Retrieve an open {@link FedoraSession} for an anonymous user 061 * 062 * @param sessionId the Id of the {@link FedoraSession} 063 * @return the {@link FedoraSession} 064 */ 065 default FedoraSession getSession(String sessionId) { 066 return getSession(sessionId, null); 067 } 068 069 /** 070 * Check if a FedoraSession exists for a particular user 071 * 072 * @param sessionId the Id of the {@link FedoraSession} 073 * @param username the name of the {@link java.security.Principal} 074 * @return the {@link FedoraSession} object for the defined user 075 */ 076 boolean exists(String sessionId, String username); 077 078 /** 079 * Check if a FedoraSession exists for the anonymous user 080 * 081 * @param sessionId the Id of the {@link FedoraSession} 082 * @return the {@link FedoraSession} object 083 */ 084 default boolean exists(String sessionId) { 085 return exists(sessionId, null); 086 } 087 088 /** 089 * Refresh an existing session using an implementation-defined default 090 * 091 * @param sessionId the Id of the {@link FedoraSession} 092 * @param username the name of the {@link java.security.Principal} 093 */ 094 void refresh(String sessionId, String username); 095 096 /** 097 * Commit any changes during a {@link FedoraSession} with the given id and username 098 * 099 * @param sessionId the id of the {@link FedoraSession} 100 * @param username the name of the {@link java.security.Principal} 101 */ 102 void commit(String sessionId, String username); 103 104 /** 105 * Commit any changes during a {@link FedoraSession} with the given id for the anonymous user 106 * 107 * @param sessionId the id of the {@link FedoraSession} 108 */ 109 default void commit(String sessionId) { 110 commit(sessionId, null); 111 } 112 113 /** 114 * Roll back any uncommited changes during a {@link FedoraSession} 115 * 116 * @param sessionId the id of the {@link FedoraSession} 117 * @param username the name of the {@link java.security.Principal} 118 */ 119 void abort(String sessionId, String username); 120 121 /** 122 * Roll back any uncommited changes during a {@link FedoraSession} for the anonymous user 123 * 124 * @param sessionId the id of the {@link FedoraSession} 125 */ 126 default void abort(String sessionId) { 127 abort(sessionId, null); 128 } 129}