Project

General

Profile

1 6999 leinfelder
package edu.ucsb.nceas.metacat.admin.upgrade.dataone;
2 6912 leinfelder
/**
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$'
10
 *     '$Date$'
11
 * '$Revision$'
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 6993 leinfelder
import java.util.Collections;
30 6912 leinfelder
import java.util.List;
31
32
import org.apache.commons.logging.Log;
33
import org.apache.commons.logging.LogFactory;
34
35
import edu.ucsb.nceas.metacat.DBUtil;
36 7007 leinfelder
import edu.ucsb.nceas.metacat.DocumentImpl;
37 6912 leinfelder
import edu.ucsb.nceas.metacat.admin.AdminException;
38 6999 leinfelder
import edu.ucsb.nceas.metacat.admin.upgrade.UpgradeUtilityInterface;
39 6912 leinfelder
import edu.ucsb.nceas.metacat.dataone.SystemMetadataFactory;
40
import edu.ucsb.nceas.metacat.properties.PropertyService;
41
import edu.ucsb.nceas.utilities.SortedProperties;
42
43
public class GenerateORE implements UpgradeUtilityInterface {
44
45
	private static Log log = LogFactory.getLog(GenerateORE.class);
46
47 7175 leinfelder
	private int serverLocation = 1;
48
49 6912 leinfelder
    public boolean upgrade() throws AdminException {
50
        boolean success = true;
51
52
        // include ORE, data, for this server only
53
        boolean includeOre = true;
54 7124 leinfelder
        boolean downloadData = false;
55 6912 leinfelder
56
        try {
57
        	// get only local ids for this server
58 7121 leinfelder
            List<String> idList = null;
59 7007 leinfelder
60 7174 leinfelder
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_0_0NAMESPACE, true, serverLocation);
61
            Collections.sort(idList);
62
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
63 7007 leinfelder
64 7174 leinfelder
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_0_1NAMESPACE, true, serverLocation);
65
            Collections.sort(idList);
66
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
67
68 7007 leinfelder
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_1_0NAMESPACE, true, serverLocation);
69
            Collections.sort(idList);
70
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
71
72 7174 leinfelder
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_1_1NAMESPACE, true, serverLocation);
73
            Collections.sort(idList);
74
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
75 7007 leinfelder
76 6912 leinfelder
		} catch (Exception e) {
77
			String msg = "Problem generating missing system metadata: " + e.getMessage();
78
			log.error(msg, e);
79
			success = false;
80
			throw new AdminException(msg);
81
		}
82
    	return success;
83
    }
84
85 7175 leinfelder
    public int getServerLocation() {
86
		return serverLocation;
87
	}
88 6912 leinfelder
89 7175 leinfelder
	public void setServerLocation(int serverLocation) {
90
		this.serverLocation = serverLocation;
91
	}
92
93
	public static void main(String [] ags){
94
95 6912 leinfelder
        try {
96
        	// set up the properties based on the test/deployed configuration of the workspace
97
        	SortedProperties testProperties =
98
				new SortedProperties("test/test.properties");
99
			testProperties.load();
100
			String metacatContextDir = testProperties.getProperty("metacat.contextDir");
101
			PropertyService.getInstance(metacatContextDir + "/WEB-INF");
102
			// now run it
103
            GenerateORE upgrader = new GenerateORE();
104
	        upgrader.upgrade();
105
106
        } catch (Exception ex) {
107
            System.out.println("Exception:" + ex.getMessage());
108
            ex.printStackTrace();
109
        }
110
    }
111
}