|
| 1 | +/** |
| 2 | + * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file |
| 3 | + * distributed with this work for additional information regarding copyright ownership. Apereo |
| 4 | + * licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use |
| 5 | + * this file except in compliance with the License. You may obtain a copy of the License at the |
| 6 | + * following location: |
| 7 | + * |
| 8 | + * <p>http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * <p>Unless required by applicable law or agreed to in writing, software distributed under the |
| 11 | + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | +package org.apereo.portal.events.handlers.db; |
| 16 | + |
| 17 | +import java.io.Serializable; |
| 18 | +import javax.persistence.Column; |
| 19 | +import javax.persistence.Entity; |
| 20 | +import javax.persistence.GeneratedValue; |
| 21 | +import javax.persistence.Id; |
| 22 | +import javax.persistence.Inheritance; |
| 23 | +import javax.persistence.InheritanceType; |
| 24 | +import javax.persistence.Lob; |
| 25 | +import javax.persistence.SequenceGenerator; |
| 26 | +import javax.persistence.Table; |
| 27 | +import javax.persistence.TableGenerator; |
| 28 | +import org.apereo.portal.events.PortalEvent; |
| 29 | +import org.hibernate.annotations.Index; |
| 30 | +import org.hibernate.annotations.Type; |
| 31 | +import org.joda.time.DateTime; |
| 32 | + |
| 33 | +/** Persistent wrapper for storing portal events */ |
| 34 | +@Entity |
| 35 | +@Table(name = "UP_ANALYTICS_EVENTS") |
| 36 | +@Inheritance(strategy = InheritanceType.JOINED) |
| 37 | +@SequenceGenerator( |
| 38 | + name = "UP_ANALYTICS_EVENTS_GEN", |
| 39 | + sequenceName = "UP_ANALYTICS_EVENTS_SEQ", |
| 40 | + allocationSize = 1000) |
| 41 | +@TableGenerator( |
| 42 | + name = "UP_ANALYTICS_EVENTS_GEN", |
| 43 | + pkColumnValue = "UP_ANNALYTICS_EVENTS_PROP", |
| 44 | + allocationSize = 1000) |
| 45 | +public class PersistentAnalyticsEvent implements Serializable { |
| 46 | + private static final long serialVersionUID = 1L; |
| 47 | + |
| 48 | + @Id |
| 49 | + @GeneratedValue(generator = "UP_ANALYTICS_EVENTS_GEN") |
| 50 | + @Column(name = "EVENT_ID") |
| 51 | + @SuppressWarnings("unused") |
| 52 | + private final long id; |
| 53 | + |
| 54 | + @Index(name = "IDX_UP_ANALYTICS_EVENTS_TIMESTAMP") |
| 55 | + @Column(name = "TIMESTAMP", nullable = false, updatable = false) |
| 56 | + @Type(type = "dateTime") |
| 57 | + @SuppressWarnings("unused") |
| 58 | + private final DateTime timestamp; |
| 59 | + |
| 60 | + @Index(name = "IDX_UP_ANALYTICS_EVENTS_SERVER_ID") |
| 61 | + @Column(name = "SERVER_ID", length = 200, nullable = false, updatable = false) |
| 62 | + @SuppressWarnings("unused") |
| 63 | + private final String serverId; |
| 64 | + |
| 65 | + @Index(name = "IDX_UP_ANALYTICS_EVENTS_SESSION_ID") |
| 66 | + @Column(name = "SESSION_ID", length = 500, nullable = false, updatable = false) |
| 67 | + @SuppressWarnings("unused") |
| 68 | + private final String eventSessionId; |
| 69 | + |
| 70 | + @Index(name = "IDX_UP_ANALYTICS_EVENTS_USER_NAME") |
| 71 | + @Column(name = "USER_NAME", length = 100, nullable = false, updatable = false) |
| 72 | + @SuppressWarnings("unused") |
| 73 | + private final String userName; |
| 74 | + |
| 75 | + @Column(name = "EVENT_TYPE", length = 200, nullable = false, updatable = false) |
| 76 | + @Type(type = "class") |
| 77 | + private final Class<PortalEvent> eventType; |
| 78 | + |
| 79 | + @Column(name = "EVENT_DATA", nullable = false, updatable = false, length = 10000) |
| 80 | + @Lob |
| 81 | + private final String eventData; |
| 82 | + |
| 83 | + /** no-arg needed by hibernate */ |
| 84 | + @SuppressWarnings("unused") |
| 85 | + private PersistentAnalyticsEvent() { |
| 86 | + this.id = -1; |
| 87 | + this.eventData = null; |
| 88 | + this.timestamp = null; |
| 89 | + this.serverId = null; |
| 90 | + this.eventSessionId = null; |
| 91 | + this.userName = null; |
| 92 | + this.eventType = null; |
| 93 | + } |
| 94 | + |
| 95 | + @SuppressWarnings("unchecked") |
| 96 | + PersistentAnalyticsEvent(PortalEvent portalEvent, String eventData) { |
| 97 | + this.id = -1; |
| 98 | + this.eventData = eventData; |
| 99 | + this.timestamp = new DateTime(portalEvent.getTimestamp()); |
| 100 | + this.serverId = portalEvent.getServerId(); |
| 101 | + this.eventSessionId = portalEvent.getEventSessionId(); |
| 102 | + this.userName = portalEvent.getUserName(); |
| 103 | + this.eventType = (Class<PortalEvent>) portalEvent.getClass(); |
| 104 | + } |
| 105 | + |
| 106 | + public Class<PortalEvent> getEventType() { |
| 107 | + return this.eventType; |
| 108 | + } |
| 109 | + |
| 110 | + /** Rreturn the eventData as a JSON-encoded string */ |
| 111 | + public String getEventData() { |
| 112 | + return this.eventData; |
| 113 | + } |
| 114 | + |
| 115 | + /* (non-Javadoc) |
| 116 | + * @see java.lang.Object#toString() |
| 117 | + */ |
| 118 | + @Override |
| 119 | + public String toString() { |
| 120 | + return this.eventData; |
| 121 | + } |
| 122 | +} |
0 commit comments