Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A class which creates a instance of an IndexEventLog.
4
 *    Copyright: 2013 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Leinfelder
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 2 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
 */
22
package edu.ucsb.nceas.metacat.index.event;
23

    
24
import java.util.ArrayList;
25
import java.util.Date;
26
import java.util.List;
27

    
28
import org.dataone.service.types.v1.Event;
29
import org.dataone.service.types.v1.Identifier;
30

    
31
import edu.ucsb.nceas.metacat.index.DistributedMapsFactory;
32

    
33
/**
34
 * @author leinfelder
35
 *
36
 */
37
public class HazelcastIndexEventLog implements IndexEventLog {
38

    
39
	/* (non-Javadoc)
40
	 * @see edu.ucsb.nceas.metacat.index.event.IndexEventLog#write(edu.ucsb.nceas.metacat.index.event.IndexEvent)
41
	 */
42
	@Override
43
	public void write(IndexEvent event) throws IndexEventLogException {
44
		// write to the map
45
		try {
46
			DistributedMapsFactory.getIndexEventMap().put(event.getIdentifier(), event);
47
		} catch (Exception e) {
48
			throw new IndexEventLogException("Could not write to event map", e);
49
		}
50
	}
51

    
52
	/* (non-Javadoc)
53
	 * @see edu.ucsb.nceas.metacat.index.event.IndexEventLog#remove(java.lang.String)
54
	 */
55
	@Override
56
	public void remove(Identifier identifier) throws IndexEventLogException {
57
		// remove from the map
58
		try {
59
			DistributedMapsFactory.getIndexEventMap().remove(identifier);
60
		} catch (Exception e) {
61
			throw new IndexEventLogException("Could not remove from event map", e);
62
		}
63

    
64
	}
65

    
66
	/* (non-Javadoc)
67
	 * @see edu.ucsb.nceas.metacat.index.event.IndexEventLog#getEvents(int, org.dataone.service.types.v1.Identifier, java.util.Date, java.util.Date)
68
	 */
69
	@Override
70
	public List<IndexEvent> getEvents(Event action, Identifier pid, Date start, Date end) throws IndexEventLogException {
71
		try {
72
			// TODO: query the map using the parameters
73
			return new ArrayList<IndexEvent>(DistributedMapsFactory.getIndexEventMap().values());
74
		} catch (Exception e) {
75
			throw new IndexEventLogException("Could not remove from event map", e);
76
		}
77
	}
78

    
79
	/* (non-Javadoc)
80
	 * @see edu.ucsb.nceas.metacat.index.event.IndexEventLog#getLastProcessDate()
81
	 */
82
	@Override
83
	public Date getLastProcessDate() throws IndexEventLogException {
84
		// TODO Auto-generated method stub
85
		return null;
86
	}
87

    
88
	/* (non-Javadoc)
89
	 * @see edu.ucsb.nceas.metacat.index.event.IndexEventLog#setLastProcessDate(java.util.Date)
90
	 */
91
	@Override
92
	public void setLastProcessDate(Date date) throws IndexEventLogException {
93
		// TODO Auto-generated method stub
94

    
95
	}
96

    
97
}
(2-2/6)