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-02-09 16:11:46 -0800 (Thu, 09 Feb 2012) $'
11
 * '$Revision: 7007 $'
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
    public boolean upgrade() throws AdminException {
48
        boolean success = true;
49
        
50
        // include ORE, data, for this server only
51
        boolean includeOre = true;
52
        boolean downloadData = true;
53
        int serverLocation = 1;
54

    
55
        try {
56
        	// get only local ids for this server
57
            List<String> idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_0_0NAMESPACE, true, serverLocation);
58
            Collections.sort(idList);
59
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
60
            
61
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_0_1NAMESPACE, true, serverLocation);
62
            Collections.sort(idList);
63
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
64
            
65
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_1_0NAMESPACE, true, serverLocation);
66
            Collections.sort(idList);
67
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
68
            
69
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_1_1NAMESPACE, true, serverLocation);
70
            Collections.sort(idList);
71
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
72
            
73
		} catch (Exception e) {
74
			String msg = "Problem generating missing system metadata: " + e.getMessage();
75
			log.error(msg, e);
76
			success = false;
77
			throw new AdminException(msg);
78
		}
79
    	return success;
80
    }
81
    
82
    public static void main(String [] ags){
83

    
84
        try {
85
        	// set up the properties based on the test/deployed configuration of the workspace
86
        	SortedProperties testProperties = 
87
				new SortedProperties("test/test.properties");
88
			testProperties.load();
89
			String metacatContextDir = testProperties.getProperty("metacat.contextDir");
90
			PropertyService.getInstance(metacatContextDir + "/WEB-INF");
91
			// now run it
92
            GenerateORE upgrader = new GenerateORE();
93
	        upgrader.upgrade();
94
	        
95
        } catch (Exception ex) {
96
            System.out.println("Exception:" + ex.getMessage());
97
            ex.printStackTrace();
98
        }
99
    }
100
}
(1-1/2)