Project

General

Profile

1
package edu.ucsb.nceas.metacat.admin.upgrade;
2
/**
3
 *  '$RCSfile$'
4
 *    Purpose: A Class for upgrading the database to version 1.5
5
 *  Copyright: 2000 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Saurabh Garg
8
 *
9
 *   '$Author: leinfelder $'
10
 *     '$Date: 2011-03-29 18:23:38 +0000 (Tue, 29 Mar 2011) $'
11
 * '$Revision: 6025 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

    
28

    
29
import java.util.List;
30

    
31
import org.apache.commons.logging.Log;
32
import org.apache.commons.logging.LogFactory;
33

    
34
import edu.emory.mathcs.backport.java.util.Collections;
35
import edu.ucsb.nceas.metacat.DBUtil;
36
import edu.ucsb.nceas.metacat.admin.AdminException;
37
import edu.ucsb.nceas.metacat.dataone.SystemMetadataFactory;
38
import edu.ucsb.nceas.metacat.properties.PropertyService;
39
import edu.ucsb.nceas.utilities.SortedProperties;
40

    
41
public class GenerateSystemMetadata implements UpgradeUtilityInterface {
42

    
43
	private static Log log = LogFactory.getLog(GenerateSystemMetadata.class);
44
	
45
    public boolean upgrade() throws AdminException {
46
        boolean success = true;
47
        
48
        // do not include ORE or data, but can generate SystemMetadata for ALL records
49
        boolean includeOre = false;
50
        boolean downloadData = false;
51
        int serverLocation = -1;
52
        
53
        try {
54
        	// get list of ALL docids at ALL server locations
55
            List<String> idList = DBUtil.getAllDocidsByType(null, true, serverLocation);
56
            Collections.sort(idList);
57

    
58
            // generate based on this list
59
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
60
		} catch (Exception e) {
61
			String msg = "Problem generating missing system metadata: " + e.getMessage();
62
			log.error(msg, e);
63
			success = false;
64
			throw new AdminException(msg);
65
		}
66
    	return success;
67
    }
68
    
69
    public static void main(String [] ags){
70

    
71
        try {
72
        	// set up the properties based on the test/deployed configuration of the workspace
73
        	SortedProperties testProperties = 
74
				new SortedProperties("test/test.properties");
75
			testProperties.load();
76
			String metacatContextDir = testProperties.getProperty("metacat.contextDir");
77
			PropertyService.getInstance(metacatContextDir + "/WEB-INF");
78
			// now run it
79
            GenerateSystemMetadata upgrader = new GenerateSystemMetadata();
80
	        upgrader.upgrade();
81
	        
82
        } catch (Exception ex) {
83
            System.out.println("Exception:" + ex.getMessage());
84
            ex.printStackTrace();
85
        }
86
    }
87
}
(2-2/7)