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 */ 018 019package org.fcrepo.kernel.impl.observer; 020 021import org.fcrepo.kernel.api.identifiers.FedoraId; 022import org.fcrepo.kernel.api.observer.Event; 023import org.fcrepo.kernel.api.observer.EventType; 024 025import java.net.URI; 026import java.time.Instant; 027import java.util.Set; 028 029import static com.google.common.base.Preconditions.checkNotNull; 030import static java.util.UUID.randomUUID; 031 032/** 033 * An event that describes one or more actions that a user preformed on a resource. 034 * 035 * @author pwinckles 036 */ 037public class EventImpl implements Event { 038 039 private final String eventId; 040 private final FedoraId fedoraId; 041 private final Set<EventType> types; 042 private final Set<String> resourceTypes; 043 private final String userID; 044 private final URI userURI; 045 private final String userAgent; 046 private final String baseUrl; 047 private final Instant date; 048 049 /** 050 * Create a new FedoraEvent 051 * 052 * @param fedoraId the FedoraId of the resource the event is on 053 * @param types a collection of Fedora EventTypes 054 * @param resourceTypes the rdf types of the corresponding resource 055 * @param userID the acting user for this event 056 * @param userURI the uri of the acting user for this event 057 * @param userAgent the user-agent associated with the request 058 * @param baseUrl the originating request's baseUrl 059 * @param date the timestamp for this event 060 */ 061 public EventImpl(final FedoraId fedoraId, final Set<EventType> types, 062 final Set<String> resourceTypes, final String userID, 063 final URI userURI, final String userAgent, final String baseUrl, 064 final Instant date) { 065 this.eventId = "urn:uuid:" + randomUUID().toString(); 066 this.fedoraId = checkNotNull(fedoraId, "fedoraId cannot be null"); 067 this.types = Set.copyOf(checkNotNull(types, "types cannot be null")); 068 this.resourceTypes = Set.copyOf(checkNotNull(resourceTypes, "resourceTypes cannot be null")); 069 this.userID = userID; 070 this.userURI = userURI; 071 this.userAgent = userAgent; 072 checkNotNull(baseUrl, "baseUrl cannot be null"); 073 // baseUrl is expected to not have a trailing slash 074 this.baseUrl = baseUrl.replaceAll("/+$", ""); 075 this.date = checkNotNull(date, "date cannot be null"); 076 } 077 078 @Override 079 public FedoraId getFedoraId() { 080 return fedoraId; 081 } 082 083 @Override 084 public Set<EventType> getTypes() { 085 return types; 086 } 087 088 @Override 089 public Set<String> getResourceTypes() { 090 return resourceTypes; 091 } 092 093 @Override 094 public String getPath() { 095 return fedoraId.getFullIdPath(); 096 } 097 098 @Override 099 public String getUserID() { 100 return userID; 101 } 102 103 @Override 104 public Instant getDate() { 105 return date; 106 } 107 108 @Override 109 public String getEventID() { 110 return eventId; 111 } 112 113 @Override 114 public URI getUserURI() { 115 return userURI; 116 } 117 118 @Override 119 public String getUserAgent() { 120 return userAgent; 121 } 122 123 @Override 124 public String getBaseUrl() { 125 return baseUrl; 126 } 127 128 @Override 129 public String toString() { 130 return "EventImpl{" + 131 "eventId='" + eventId + '\'' + 132 ", fedoraId=" + fedoraId + 133 ", types=" + types + 134 ", resourceTypes=" + resourceTypes + 135 ", userID='" + userID + '\'' + 136 ", userURI=" + userURI + 137 ", userAgent=" + userAgent + 138 ", baseUrl=" + baseUrl + 139 ", date=" + date + 140 '}'; 141 } 142 143}