Removed Event class
parent
88863f4910
commit
d4fbb4f599
|
@ -1,90 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2013 The MITRE Corporation
|
||||
* and the MIT Kerberos and Internet Trust Consortium
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
package org.mitre.openid.connect.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
|
||||
/**
|
||||
* Class to contain a logged event in the system.
|
||||
*
|
||||
* @author jricher
|
||||
*
|
||||
*/
|
||||
|
||||
@Entity
|
||||
@Table(name="event")
|
||||
public class Event {
|
||||
|
||||
public static enum EventType { LOGIN, AUTHORIZATION, ACCESS }
|
||||
|
||||
private Long id;
|
||||
private EventType type;
|
||||
private Date timestamp;
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public EventType getType() {
|
||||
return type;
|
||||
}
|
||||
/**
|
||||
* @param type the type to set
|
||||
*/
|
||||
public void setType(EventType type) {
|
||||
this.type = type;
|
||||
}
|
||||
/**
|
||||
* @return the timestamp
|
||||
*/
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
@Column(name = "timestamp")
|
||||
public Date getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
/**
|
||||
* @param timestamp the timestamp to set
|
||||
*/
|
||||
public void setTimestamp(Date timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2013 The MITRE Corporation
|
||||
* and the MIT Kerberos and Internet Trust Consortium
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
package org.mitre.openid.connect.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
import org.mitre.openid.connect.model.Event;
|
||||
|
||||
/**
|
||||
* Event repository interface
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
public interface EventRepository {
|
||||
|
||||
/**
|
||||
* Returns the Event for the given id
|
||||
*
|
||||
* @param id
|
||||
* id the id of the Event
|
||||
* @return a valid Event if it exists, null otherwise
|
||||
*/
|
||||
public Event getById(Long id);
|
||||
|
||||
/**
|
||||
* Returns the Events for a given Date range
|
||||
*
|
||||
* @param start
|
||||
* the Date to start from
|
||||
* @param end
|
||||
* the Date to end at
|
||||
* @param startChunk
|
||||
* the start chuck of a list you desire
|
||||
* @param chunkSize
|
||||
* the size of the chunk you desire
|
||||
*
|
||||
* @return a Collection of Events
|
||||
*/
|
||||
public Collection<Event> getEventsDuringPeriod(Date start, Date end, int startChunk, int chunkSize);
|
||||
|
||||
/**
|
||||
* Removes the given Event from the repository
|
||||
*
|
||||
* @param event
|
||||
* the Event object to remove
|
||||
*/
|
||||
public void remove(Event event);
|
||||
|
||||
/**
|
||||
* Removes an Event from the repository
|
||||
*
|
||||
* @param id
|
||||
* the id of the Event to remove
|
||||
*/
|
||||
public void removeById(Long id);
|
||||
|
||||
/**
|
||||
* Persists a Event
|
||||
*
|
||||
* @param event
|
||||
* the Event to be saved
|
||||
* @return
|
||||
*/
|
||||
public Event save(Event event);
|
||||
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2013 The MITRE Corporation
|
||||
* and the MIT Kerberos and Internet Trust Consortium
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
package org.mitre.openid.connect.repository.impl;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.mitre.openid.connect.model.Event;
|
||||
import org.mitre.openid.connect.repository.EventRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
|
||||
/**
|
||||
* JPA Event repository implementation
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public class JpaEventRepository implements EventRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager manager;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Event getById(Long id) {
|
||||
return manager.find(Event.class, id);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<Event> getEventsDuringPeriod(Date start, Date end, int startChunk, int chunkSize) {
|
||||
|
||||
Query query = manager.createQuery("SELECT e FROM Event e WHERE e.timestamp BETWEEN :start AND :end");
|
||||
|
||||
query = query.setParameter("start", start, TemporalType.DATE);
|
||||
query = query.setParameter("end", end, TemporalType.DATE);
|
||||
query = query.setFirstResult(startChunk);
|
||||
query = query.setMaxResults(chunkSize);
|
||||
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void remove(Event event) {
|
||||
Event found = manager.find(Event.class, event.getId());
|
||||
|
||||
if (found != null) {
|
||||
manager.remove(event);
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeById(Long id) {
|
||||
Event found = getById(id);
|
||||
|
||||
manager.remove(found);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Event save(Event event) {
|
||||
return saveOrUpdate(event.getId(), manager, event);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue