Project

General

Profile

« Previous | Next » 

Revision 8747

forgot to check in the actual class: first pass at allowing admins to update DOI registration. This only acts on EML objects at the moment and is meant to illustrate one mechanism for updating the DOIs. https://projects.ecoinformatics.org/ecoinfo/issues/6530

View differences:

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

  
25
package edu.ucsb.nceas.metacat.admin.upgrade;
26

  
27
import java.util.Collections;
28
import java.util.List;
29

  
30
import org.apache.commons.logging.Log;
31
import org.apache.commons.logging.LogFactory;
32
import org.dataone.service.types.v1.Identifier;
33
import org.dataone.service.types.v1.SystemMetadata;
34

  
35
import edu.ucsb.nceas.metacat.DBUtil;
36
import edu.ucsb.nceas.metacat.DocumentImpl;
37
import edu.ucsb.nceas.metacat.IdentifierManager;
38
import edu.ucsb.nceas.metacat.admin.AdminException;
39
import edu.ucsb.nceas.metacat.dataone.DOIService;
40
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
41
import edu.ucsb.nceas.metacat.util.DocumentUtil;
42

  
43

  
44

  
45
/**
46
 * Updates existing DOI registrations for EML versions
47
 * @author leinfelder
48
 *
49
 */
50
public class UpdateDOI implements UpgradeUtilityInterface {
51
    
52
	private static Log log = LogFactory.getLog(UpdateDOI.class);
53

  
54
	private int serverLocation = 1;
55

  
56
	public int getServerLocation() {
57
		return serverLocation;
58
	}
59

  
60
	public void setServerLocation(int serverLocation) {
61
		this.serverLocation = serverLocation;
62
	}
63
	
64
	private void updateDOIRegistration(List<String> identifiers) {
65
		for (String pid: identifiers) {
66
			try {
67

  
68
				String docid = DocumentUtil.getDocIdFromAccessionNumber(pid);
69
				int rev = DocumentUtil.getRevisionFromAccessionNumber(pid);
70
				String guid = IdentifierManager.getInstance().getGUID(docid, rev);
71
				Identifier identifier = new Identifier();
72
				identifier.setValue(guid);
73
				SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
74
				DOIService.getInstance().registerDOI(sysMeta);
75
			} catch (Exception e) {
76
				// what to do? nothing
77
				e.printStackTrace();
78
				continue;
79
			}
80
			
81
		}
82
	}
83
	
84
    public boolean upgrade() throws AdminException {
85
        boolean success = true;
86
        
87
        try {
88
        	// get only local ids for this server
89
            List<String> idList = null;
90
            
91
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_0_0NAMESPACE, true, serverLocation);
92
            Collections.sort(idList);
93
            updateDOIRegistration(idList);
94
            
95
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_0_1NAMESPACE, true, serverLocation);
96
            Collections.sort(idList);
97
            updateDOIRegistration(idList);
98
            
99
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_1_0NAMESPACE, true, serverLocation);
100
            Collections.sort(idList);
101
            updateDOIRegistration(idList);
102
            
103
            idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_1_1NAMESPACE, true, serverLocation);
104
            Collections.sort(idList);
105
            updateDOIRegistration(idList);
106
            
107
		} catch (Exception e) {
108
			String msg = "Problem updating DOIs: " + e.getMessage();
109
			log.error(msg, e);
110
			success = false;
111
			throw new AdminException(msg);
112
		}
113
        
114
        
115
        return success;
116
    }
117
    
118
}
0 119

  

Also available in: Unified diff