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