Project

General

Profile

« Previous | Next » 

Revision 7924

Added by Jing Tao over 11 years ago

Add a method to write ids which will be indexed into a file.

View differences:

metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/IndexGenerator.java
26 26
 */
27 27
package edu.ucsb.nceas.metacat.index;
28 28

  
29
import java.io.File;
29 30
import java.io.FileInputStream;
30 31
import java.io.FileNotFoundException;
31 32
import java.io.IOException;
32 33
import java.io.InputStream;
34
import java.text.SimpleDateFormat;
33 35
import java.util.ArrayList;
34 36
import java.util.Calendar;
35 37
import java.util.Collections;
......
40 42
import javax.xml.parsers.ParserConfigurationException;
41 43
import javax.xml.xpath.XPathExpressionException;
42 44

  
45
import org.apache.commons.io.FileUtils;
43 46
import org.apache.commons.logging.Log;
44 47
import org.apache.commons.logging.LogFactory;
45 48
import org.apache.solr.client.solrj.SolrServerException;
......
60 63
import com.hazelcast.core.IMap;
61 64
import com.hazelcast.core.ISet;
62 65

  
66
import edu.ucsb.nceas.metacat.common.SolrServerFactory;
63 67
import edu.ucsb.nceas.metacat.common.index.event.IndexEvent;
64 68
import edu.ucsb.nceas.metacat.index.event.EventlogFactory;
65 69
import edu.ucsb.nceas.metacat.index.event.IndexEventLogException;
......
310 314
        }*/
311 315
        
312 316
        log.info("the metacat ids (except the resource map ids)-----------------------------"+otherMetacatIds);
317
        logFile(otherMetacatIds);
313 318
        log.info("the deleted metacat ids (except the resource map ids)-----------------------------"+otherDeletedMetacatIds);
314 319
        log.info("the metacat resroucemap ids -----------------------------"+resourceMapIds);
320
        logFile(resourceMapIds);
315 321
        log.info("the deleted metacat resroucemap ids -----------------------------"+resourceMapDeletedIds);
316 322
        index(otherMetacatIds);
317 323
        removeIndex(otherDeletedMetacatIds);
......
326 332
    }
327 333
    
328 334
    /*
335
     * Write the docids which will be indexed into a file. 
336
     */
337
    private void logFile(List<String> ids) throws IOException {
338
        if(ids != null) {
339
            String solrHomeDir = Settings.getConfiguration().getString(SolrServerFactory.SOLR_HOME_PROPERTY_NAME);
340
            File idsForIndex = new File(solrHomeDir, "ids-for-timed-indexing-log");
341
            if(!idsForIndex.exists()) {
342
                idsForIndex.createNewFile();
343
            }
344
            Date date = Calendar.getInstance().getTime();
345
            SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z");
346
            String dateStr = format.format(date);
347
            List<String> dateList = new ArrayList<String>();
348
            dateList.add(dateStr);
349
            Boolean append = true;
350
            FileUtils.writeLines(idsForIndex, dateList, append);//write time string
351
            FileUtils.writeLines(idsForIndex, ids, append);
352
        }
353
    }
354
    /*
329 355
     * Doing index
330 356
     */
331 357
    private void index(List<String> metacatIds) {

Also available in: Unified diff