Project

General

Profile

1
package edu.ucsb.nceas.metacat.admin.upgrade.dataone;
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: 2012-05-18 12:09:33 -0700 (Fri, 18 May 2012) $'
11
 * '$Revision: 7175 $'
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.Collections;
30
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
import edu.ucsb.nceas.metacat.DocumentImpl;
37
import edu.ucsb.nceas.metacat.admin.AdminException;
38
import edu.ucsb.nceas.metacat.admin.upgrade.UpgradeUtilityInterface;
39
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
	private int serverLocation = 1;
48

    
49
    public boolean upgrade() throws AdminException {
50
        boolean success = true;
51
        
52
        // include ORE, data, for this server only
53
        boolean includeOre = true;
54
        boolean downloadData = false;
55

    
56
        try {
57
        	// get only local ids for this server
58
            List<String> idList = null;
59
            
60
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_0_0NAMESPACE, true, serverLocation);
61
            Collections.sort(idList);
62
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
63
            
64
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_0_1NAMESPACE, true, serverLocation);
65
            Collections.sort(idList);
66
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
67
            
68
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_1_0NAMESPACE, true, serverLocation);
69
            Collections.sort(idList);
70
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
71
            
72
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_1_1NAMESPACE, true, serverLocation);
73
            Collections.sort(idList);
74
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
75
            
76
		} 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
    public int getServerLocation() {
86
		return serverLocation;
87
	}
88

    
89
	public void setServerLocation(int serverLocation) {
90
		this.serverLocation = serverLocation;
91
	}
92

    
93
	public static void main(String [] ags){
94

    
95
        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
}
(1-1/2)