Project

General

Profile

« Previous | Next » 

Revision 4674

Added by Jing Tao over 15 years ago

Add method to save transforming message into files.

View differences:

src/edu/ucsb/nceas/metacat/util/EMLVersionsTransformer.java
28 28
import java.sql.PreparedStatement;
29 29
import java.sql.ResultSet;
30 30
import java.sql.SQLException;
31
import java.text.SimpleDateFormat;
31 32
import java.util.Enumeration;
32 33
import java.util.Hashtable;
33 34
import java.util.Vector;
......
56 57
 */
57 58
public class EMLVersionsTransformer {
58 59
	
59
	private static Logger logMetacat = Logger.getLogger(EMLVersionsTransformer.class);
60
	private static org.apache.log4j.Logger logMetacat = Logger.getLogger(EMLVersionsTransformer.class);
60 61
	private static String eml210StyleFile = null;
61 62
	static{
62 63
		try
......
70 71
		}
71 72
	}
72 73
	private static String DOT = ".";
74
	private static int CAP = 100000; // How many documents you want to transform.
73 75

  
74 76
    /**
75 77
     * Public constructor because all methods are static and do not need 
......
96 98
    	Vector list = getEML2DocList();
97 99
    	if(list != null)
98 100
    	{
99
    		for(int i=0; i<list.size(); i++)
101
    		// Choose the smaller value between the size of vector and CAP
102
    		int size = list.size();
103
    		if (size > CAP)
100 104
    		{
105
    			size = CAP;
106
    		}
107
    		for(int i=0; i<size; i++)
108
    		{
101 109
    			OwnerAndDocid pair = (OwnerAndDocid)list.elementAt(i);
102 110
    			String docid = pair.getDocid();
103 111
    			String owner = pair.getOwner();
104 112
    			try
105 113
    			{
106 114
    				handleSingleEML200Document(docid, owner);
115
    				try
116
    				{
117
    					Thread.sleep(5000);
118
    				}
119
    				catch(Exception e)
120
    				{
121
    					logMetacat.warn("Couldn't sleep 5 seconds");
122
    				}
107 123
    			}
108 124
    			catch(Exception e)
109 125
    			{
110 126
    				logMetacat.warn("The docid "+docid+" with owner "+owner+" couldn't be transformed to eml-2.1.0 since "+e.getMessage());
127
    				transformErrorLog("The docid "+docid+" with owner "+owner+" couldn't be transformed to eml-2.1.0 since "+e.getMessage());
111 128
    			}
112 129
    		}
113 130
    	}
......
149 166
                  serialNumber = dbconn.getCheckOutSerialNumber();
150 167
                  documentWrapper.write(dbconn, xml, pub, dtd,
151 168
                          doAction, newId, owner, groups);
152
                  logMetacat.warn("Doc "+docidWithRev+"was transformed to eml210 with new id "+newId);
169
                  logMetacat.warn("Doc "+docidWithRev+" was transformed to eml210 with new id "+newId);
170
                  transformLog("Doc "+docidWithRev+" was transformed to eml210 with new id "+newId);
153 171
             }
154 172
             catch(Exception e)
155 173
             {
......
299 317
    	return newid;
300 318
    }
301 319
    
320
    
302 321
    /*
322
	 * Method for writing transformation messages to a log file specified in
323
	 * metacat.properties
324
	 */
325
	private static void transformLog(String message) {
326
		try {
327
			FileOutputStream fos = 
328
				new FileOutputStream(PropertyService.getProperty("replication.logdir")
329
					+ "/transform.log", true);
330
			PrintWriter pw = new PrintWriter(fos);
331
			SimpleDateFormat formatter = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
332
			java.util.Date localtime = new java.util.Date();
333
			String dateString = formatter.format(localtime);
334
			dateString += " :: " + message;
335
			// time stamp each entry
336
			pw.println(dateString);
337
			pw.flush();
338
		} catch (Exception e) {
339
			logMetacat.warn("error writing to transform log from "
340
					+ "EMLVersionTransformer.transformlLog: " + e.getMessage());
341
			// e.printStackTrace(System.out);
342
		}
343
	}
344

  
345
  /*
346
	 * Method for writing transform messages to a log file specified in
347
	 * metacat.properties
348
	 */
349
  private static void transformErrorLog(String message)
350
  {
351
    try
352
    {
353
    	FileOutputStream fos = 
354
			new FileOutputStream(PropertyService.getProperty("replication.logdir")
355
				+ "/transformerror.log", true);
356
      PrintWriter pw = new PrintWriter(fos);
357
      SimpleDateFormat formatter = new SimpleDateFormat ("yy-MM-dd HH:mm:ss");
358
      java.util.Date localtime = new java.util.Date();
359
      String dateString = formatter.format(localtime);
360
      dateString += " :: " + message;
361
      //time stamp each entry
362
      pw.println(dateString);
363
      pw.flush();
364
    }
365
    catch(Exception e)
366
    {
367
      logMetacat.warn("error writing to transforming error log from " +
368
                         "EMLVersionTransformer.transformErrorLog: " + e.getMessage());
369
      //e.printStackTrace(System.out);
370
    }
371
  }
372
    
373
    /*
303 374
     * Class reprents a document's docid and its owner 
304 375
     * @author tao
305 376
     *

Also available in: Unified diff