Project

General

Profile

« Previous | Next » 

Revision 7836

Added by Jing Tao almost 11 years ago

Add code to get and set the last process date.

View differences:

HazelcastIndexEventLog.java
21 21
 */
22 22
package edu.ucsb.nceas.metacat.index.event;
23 23

  
24
import java.io.File;
25
import java.io.IOException;
26
import java.text.ParseException;
27
import java.text.SimpleDateFormat;
24 28
import java.util.ArrayList;
25 29
import java.util.Date;
26 30
import java.util.List;
27 31

  
32
import org.apache.commons.io.FileUtils;
33
import org.dataone.configuration.Settings;
28 34
import org.dataone.service.types.v1.Event;
29 35
import org.dataone.service.types.v1.Identifier;
30 36

  
......
36 42
 *
37 43
 */
38 44
public class HazelcastIndexEventLog implements IndexEventLog {
45
    
46
    private static final String LASTPROCESSEDDATEFILENAME = "solr-last-proccessed-date";
47
    private File lastProcessedDateFile = null;
48
    private SimpleDateFormat format = new SimpleDateFormat();
49
    
50
    /**
51
     * Constructor
52
     * @throws IOException
53
     */
54
    public HazelcastIndexEventLog() throws IOException {
55
        String path = Settings.getConfiguration().getString("solr.homeDir");
56
        if(path == null || path.trim().equals("")) {
57
            path = System.getProperty("user.home");
58
        }
59
        File pathDir = new File(path);
60
        lastProcessedDateFile = new File(pathDir, LASTPROCESSEDDATEFILENAME);
61
        if(!lastProcessedDateFile.exists()) {
62
            lastProcessedDateFile.createNewFile();
63
        }
64
    }
39 65

  
40 66
	/* (non-Javadoc)
41 67
	 * @see edu.ucsb.nceas.metacat.index.event.IndexEventLog#write(edu.ucsb.nceas.metacat.index.event.IndexEvent)
......
82 108
	 */
83 109
	@Override
84 110
	public Date getLastProcessDate() throws IndexEventLogException {
85
		// TODO Auto-generated method stub
86
		return null;
111
	    Date date = null;
112
        try {
113
            String dateStr = FileUtils.readFileToString(lastProcessedDateFile, "UTF-8");
114
            if(dateStr != null && !dateStr.trim().equals("")) {
115
                date = format.parse(dateStr);
116
            }
117
        } catch (IOException e) {
118
            throw new IndexEventLogException("HazelcastIndexEventLog.getLastProcessedDate - couldn't read the last processed date :", e);
119
        } catch (ParseException e) {
120
            // TODO Auto-generated catch block
121
            throw new IndexEventLogException("HazelcastIndexEventLog.getLastProcessedDate - couldn't read the last processed date since the content of file is not date :", e);
122
        }
123
        return date;
87 124
	}
88 125

  
89 126
	/* (non-Javadoc)
......
91 128
	 */
92 129
	@Override
93 130
	public void setLastProcessDate(Date date) throws IndexEventLogException {
94
		// TODO Auto-generated method stub
131
	    String dateStr = format.format(date);
132
        try {
133
            FileUtils.writeStringToFile(lastProcessedDateFile, dateStr, "UTF-8");
134
        } catch (IOException e) {
135
            // TODO Auto-generated catch block
136
           throw new IndexEventLogException("HazelcastIndexEventLog.setLastProcessedDate - couldn't set the last processed date :", e);
137
        }
95 138

  
96 139
	}
97 140

  

Also available in: Unified diff