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; 019 020import java.time.Duration; 021import java.time.Instant; 022import java.util.Collection; 023import java.util.Map; 024import java.util.Optional; 025 026/** 027 * The Fedora Session abstraction 028 * 029 * @author acoburn 030 */ 031public interface FedoraSession { 032 033 /** 034 * Expire the session 035 */ 036 void expire(); 037 038 /** 039 * Commit any batch operations 040 */ 041 void commit(); 042 043 /** 044 * Update the expiry by the provided amount 045 * @param amountToAdd the amount of time to add 046 * @return the new expiration date 047 */ 048 Instant updateExpiry(Duration amountToAdd); 049 050 /** 051 * Get the date this session was created 052 * @return creation date 053 */ 054 Instant getCreated(); 055 056 /** 057 * Get the date this session expires 058 * @return expiration date, if one exists 059 */ 060 Optional<Instant> getExpires(); 061 062 /** 063 * Get the session identifier 064 * @return the session id 065 */ 066 String getId(); 067 068 /** 069 * Get the user identifier associated with this session 070 * @return the user id 071 */ 072 String getUserId(); 073 074 /** 075 * Get a mapping of registered namespaces 076 * @return the namespace mapping 077 */ 078 Map<String, String> getNamespaces(); 079 080 /** 081 * Add session-specific data 082 * @param key the key 083 * @param value the value 084 * 085 * Note: it is up to the particular implementation as to whether multi-valued session data 086 * is allowed. 087 */ 088 void addSessionData(String key, String value); 089 090 /** 091 * Retrieve the session data for a given key 092 * @param key the key 093 * @return the value 094 */ 095 Collection<String> getSessionData(String key); 096 097 /** 098 * Remove a particular session key-value pair 099 * @param key the data key 100 * @param value the data value 101 */ 102 void removeSessionData(String key, String value); 103 104 /** 105 * Remove all session data for a particular key 106 * @param key the data key 107 */ 108 default void removeSessionData(String key) { 109 getSessionData(key).forEach(v -> removeSessionData(key, v)); 110 } 111}