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 * Refresh an existing anonymous session using an implementation-defined default 098 * 099 * @param sessionId the Id of the {@link FedoraSession} 100 */ 101 default void refresh(String sessionId) { 102 refresh(sessionId, null); 103 } 104 105 /** 106 * Commit any changes during a {@link FedoraSession} with the given id and username 107 * 108 * @param sessionId the id of the {@link FedoraSession} 109 * @param username the name of the {@link java.security.Principal} 110 */ 111 void commit(String sessionId, String username); 112 113 /** 114 * Commit any changes during a {@link FedoraSession} with the given id for the anonymous user 115 * 116 * @param sessionId the id of the {@link FedoraSession} 117 */ 118 default void commit(String sessionId) { 119 commit(sessionId, null); 120 } 121 122 /** 123 * Roll back any uncommited changes during a {@link FedoraSession} 124 * 125 * @param sessionId the id of the {@link FedoraSession} 126 * @param username the name of the {@link java.security.Principal} 127 */ 128 void abort(String sessionId, String username); 129 130 /** 131 * Roll back any uncommited changes during a {@link FedoraSession} for the anonymous user 132 * 133 * @param sessionId the id of the {@link FedoraSession} 134 */ 135 default void abort(String sessionId) { 136 abort(sessionId, null); 137 } 138}