Project

General

Profile

Revision 6635

DataONE MN registration/configuration is now its own configuration page in the admin interface.
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5531

View differences:

lib/metacat.properties
11 11
configutil.skinsConfigured=false
12 12
configutil.databaseConfigured=false
13 13
configutil.geoserverConfigured=false
14
configutil.dataoneConfigured=false
14 15

  
15 16
############### Server Values #################
16 17

  
......
498 499
#dataone.coordinatingNodeBaseURL=https://cn-dev.dataone.org/cn
499 500
dataone.memberNodeId=METACAT1
500 501
dataone.subject=CN=METACAT1, DC=dataone, DC=org
501
dataone.certpath=/etc/dataone/client/certs
502 502
dataone.nodeName=My Metacat Node
503 503
dataone.nodeType=mn
504 504
dataone.nodeDescription=A DataONE member node implemented in Metacat.
lib/admin/dataone-configuration.jsp
1
<%@ page language="java" %>
2
<%@ page import="java.util.Set,java.util.Map,java.util.Vector,edu.ucsb.nceas.utilities.PropertiesMetaData" %>
3
<%@ page import="edu.ucsb.nceas.utilities.MetaDataGroup,edu.ucsb.nceas.utilities.MetaDataProperty" %>
4
<% 
5
/**
6
 *  '$RCSfile$'
7
 *    Copyright: 2008 Regents of the University of California and the
8
 *               National Center for Ecological Analysis and Synthesis
9
 *  For Details: http://www.nceas.ucsb.edu/
10
 *
11
 *   '$Author$'
12
 *     '$Date$'
13
 * '$Revision$'
14
 * 
15
 * This program is free software; you can redistribute it and/or modify
16
 * it under the terms of the GNU General Public License as published by
17
 * the Free Software Foundation; either version 2 of the License, or
18
 * (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
 */
29
%>
30

  
31
<html>
32
<head>
33

  
34
<title>DataONE Configuration</title>
35
<link rel="stylesheet" type="text/css" 
36
        href="<%= request.getContextPath() %>/admin/admin.css"></link>
37
<script language="JavaScript" type="text/JavaScript" src="<%= request.getContextPath() %>/admin/admin.js"></script>
38

  
39
</head>
40
<body>
41
<%@ include file="./header-section.jsp"%>
42

  
43
<img src="<%= request.getContextPath() %>/metacat-logo.png" width="100px" align="right"/> 
44
<h2>DataONE Configuration</h2>
45

  
46
<p>
47
	Configure the Metacat as a DataONE Member Node.
48
</p>
49
<!-- BRL TODO add DataONE instructions and contact info -->
50
<br clear="right"/>
51

  
52
<%@ include file="page-message-section.jsp"%>
53

  
54
<form method="POST" name="configuration_form" action="<%= request.getContextPath() %>/admin" 
55
                                        onsubmit="return submitForm(this);">
56

  
57
	<h3>Member Node Configuration</h3>
58
	<hr class="config-line">
59
	
60
	<div class="form-row">
61
		<img class="question-mark" src="style/images/question-mark.gif" 
62
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#dataone')"/>
63
		<div class="textinput-label">
64
			<label for="dataone.nodeName" title="Node Name">Node Name</label>
65
		</div>
66
		<input class="textinput" 
67
			id="dataone.nodeName" 
68
			name="dataone.nodeName" 	             		    	    	           		    	             			
69
			value="<%= request.getAttribute("dataone.nodeName") %>"/> 
70
	</div>
71
	<div class="form-row">
72
		<img class="question-mark" src="style/images/question-mark.gif" 
73
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#dataone')"/>
74
		<div class="textinput-label">
75
			<label for="dataone.nodeDescription" title="Node Description">Node Description</label>
76
		</div>
77
		<input class="textinput" 
78
			id="dataone.nodeDescription" 
79
			name="dataone.nodeDescription" 	             		    	    	           		    	             			
80
			value="<%= request.getAttribute("dataone.nodeDescription") %>"/> 
81
	</div>
82
	<div class="form-row">
83
		<img class="question-mark" src="style/images/question-mark.gif" 
84
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#dataone')"/>
85
		<div class="textinput-label">
86
			<label for="dataone.memberNodeId" title="Node Identifier">Node Identifier</label>
87
		</div>
88
		<input class="textinput" 
89
			id="dataone.memberNodeId" 
90
			name="dataone.memberNodeId" 	             		    	    	           		    	             			
91
			value="<%= request.getAttribute("dataone.memberNodeId") %>"/> 
92
	</div>
93
	<div class="form-row">
94
		<img class="question-mark" src="style/images/question-mark.gif" 
95
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#dataone')"/>
96
		<div class="textinput-label">
97
			<label for="dataone.subject" title="Node Subject">Node Subject</label>
98
		</div>
99
		<input class="textinput" 
100
			id="dataone.subject" 
101
			name="dataone.subject" 	             		    	    	           		    	             			
102
			value="<%= request.getAttribute("dataone.subject") %>"/> 
103
	</div>
104
	<div class="form-row">
105
		<img class="question-mark" src="style/images/question-mark.gif" 
106
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#dataone')"/>
107
		<div class="textinput-label">
108
			<label for="D1Client.certificate.file" title="Node Certificate Path">Node Certificate Path</label>
109
		</div>
110
		<input class="textinput" 
111
			id="D1Client.certificate.file" 
112
			name="D1Client.certificate.file" 	             		    	    	           		    	             			
113
			value="<%= request.getAttribute("D1Client.certificate.file") %>"/> 
114
	</div>
115
	<hr class="config-line">
116
	<div class="form-row">
117
		<img class="question-mark" src="style/images/question-mark.gif" 
118
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#dataone')"/>
119
		<div class="textinput-label"><label for="dataone.nodeSynchronize" title="Synchronize">Synchronize</label></div>
120

  
121
		<%
122
		boolean synchronize = (Boolean) request.getAttribute("dataone.nodeSynchronize");
123
		if (synchronize) { 
124
		%>
125
		<input type="checkbox" 
126
				class="textinput" 
127
				id="dataone.nodeSynchronize" 
128
				name="dataone.nodeSynchronize" 	             		    	    	           		    	             			
129
				value="true"
130
				checked="checked"/>
131
		<% } else {%>
132
		<input type="checkbox" 
133
				class="textinput" 
134
				id="dataone.nodeSynchronize" 
135
				name="dataone.nodeSynchronize" 	             		    	    	           		    	             			
136
				value="true"/>
137
		<% } %>
138

  
139
	</div>
140
	<div class="form-row">
141
		<img class="question-mark" src="style/images/question-mark.gif" 
142
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#dataone')"/>
143
		<div class="textinput-label"><label for="dataone.nodeReplicate" title="Replicate">Replicate</label></div>
144

  
145
		<%
146
		boolean replicate = (Boolean) request.getAttribute("dataone.nodeReplicate");
147
		if (replicate) { 
148
		%>
149
		<input type="checkbox" 
150
				class="textinput" 
151
				id="dataone.nodeReplicate" 
152
				name="dataone.nodeReplicate" 	             		    	    	           		    	             			
153
				value="true"
154
				checked="checked"/>
155
		<% } else {%>
156
		<input type="checkbox" 
157
				class="textinput" 
158
				id="dataone.nodeReplicate" 
159
				name="dataone.nodeReplicate" 	             		    	    	           		    	             			
160
				value="true"/>
161
		<% } %>
162

  
163
	</div>
164

  
165
	<input type="hidden" name="configureType" value="dataone"/>
166
	<input type="hidden" name="processForm" value="true"/>
167
	<input class=button type="submit" value="Update"/>
168
	<input class=button type="button" value="Bypass" onClick="forward('./admin?configureType=dataone&bypass=true&processForm=true')">
169
	<input class=button type="button" value="Cancel" onClick="forward('./admin')"> 
170

  
171
</form>
172

  
173
<%@ include file="./footer-section.jsp"%>
174

  
175
</body>
176
</html>
0 177

  
lib/admin/metacat-configuration.jsp
37 37
    Boolean authConfigured = (Boolean)request.getAttribute("authConfigured");	
38 38
    Boolean skinsConfigured = (Boolean)request.getAttribute("skinsConfigured");	
39 39
    Boolean dbConfigured = (Boolean)request.getAttribute("dbConfigured");
40
    Boolean replicationConfigured = (Boolean)request.getAttribute("replicationConfigured");
41
    String dataoneConfigured = (String)request.getAttribute("dataoneConfigured");
40 42
    String geoserverConfigured = (String)request.getAttribute("geoserverConfigured");
41 43
    Boolean metacatConfigured = (Boolean)request.getAttribute("metacatConfigured");
42 44
    Boolean metacatServletInitialized = (Boolean)request.getAttribute("metcatServletInitialized");
......
200 202
	}
201 203
%>
202 204

  
205
<%
206

  
207
    if (dataoneConfigured != null && dataoneConfigured.equals(PropertyService.CONFIGURED)) {
208
%>
209
    	<tr>
210
    	<td class="configured-tag">[configured] </td>
211
    	<td class="property-title"> Dataone Configuration </td> 
212
		<td class="configure-link"> <a href="<%= request.getContextPath() %>/admin?configureType=dataone">Reconfigure Now</a> </td>   		
213
    	</tr>
214
<%
215
	} else if (dataoneConfigured != null && dataoneConfigured.equals(PropertyService.BYPASSED)){
216
%>    		
217
    	<tr>
218
    	<td class="configured-tag">[bypassed] </td>  
219
		<td class="property-title"> Dataone Configuration </td>  
220
<%
221
		if (propsConfigured != null && propsConfigured) {
222
%>
223
        	
224
		<td class="configure-link"> <a href="<%= request.getContextPath() %>/admin?configureType=dataone">Reconfigure Now</a> </td>			       	
225
<%
226
		} else {
227
%> 
228
		<td class="configure-link"> Configure Global Properties First </td>
229
<%
230
		}
231
			%>     	
232
    	</tr>
233
<%
234
	} else {
235
%>    		
236
    	<tr>
237
    	<td class="unconfigured-tag">[unconfigured] </td>  
238
    	<td class="property-title"> Dataone Configuration </td>   
239
<%
240
		if (propsConfigured != null && propsConfigured) {
241
%>
242
        	
243
		<td class="configure-link"> <a href="<%= request.getContextPath() %>/admin?configureType=dataone">Configure Now</a> </td>			
244
        	
245
<%
246
		} else {
247
%> 
248
		<td class="configure-link"> Configure Global Properties First </td>
249
<%
250
		}
251
%>     	
252
    	</tr>
253
<%
254
	}
255
%>
256

  
203 257
</table>
204 258

  
205 259
<%
src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java
263 263
					logMetacat.error(errorString);
264 264
					validationErrors.add(errorString);
265 265
				}
266

  
267
		        // Register as a DataONE Member Node
268
				registerDataONEMemberNode();
269 266
				
270 267
				// write the backup properties to a location outside the 
271 268
				// application directories so they will be available after
......
348 345
		return errorVector;
349 346
	}
350 347
	
351
	/**
352
	 * Register as a member node on the DataONE network.  The node description is
353
	 * retrieved from the getCapabilities() service, and so this should only be called
354
	 * after the properties have been properly set up in Metacat.
355
	 */
356
	private void registerDataONEMemberNode() {
357
        CNode cn;
358
        try {
359
            logMetacat.debug("Get the Node description.");
360
            Node node = MNodeService.getInstance(null).getCapabilities();
361
            logMetacat.debug("Setting client certificate location.");
362
            String certificatePath = PropertyService.getProperty("dataone.certpath");
363
            if (!certificatePath.endsWith(File.separator)) {
364
                certificatePath = certificatePath + File.separator;
365
            }
366
            String mnCertificatePath = certificatePath + node.getIdentifier().getValue() + ".pem";
367
            CertificateManager.getInstance().setCertificateLocation(mnCertificatePath);
368
            cn = D1Client.getCN();
369
            logMetacat.debug("Registering node with DataONE. " + cn.getNodeBaseServiceUrl());
370
            // Session is null, because the libclient code automatically sets up an
371
            // SSL session for us using the client certificate provided
372
            Session session = null;
373
            NodeReference mnode = cn.register(session, node);
374
        } catch (ServiceFailure e) {
375
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
376
        } catch (NotImplemented e) {
377
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
378
        } catch (NotAuthorized e) {
379
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
380
        } catch (InvalidRequest e) {
381
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
382
        } catch (IdentifierNotUnique e) {
383
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
384
        } catch (PropertyNotFoundException e) {
385
            logMetacat.warn("Could not find the location for client certificates: " + e.getMessage());
386
        }
387
	}
348

  
388 349
}
src/edu/ucsb/nceas/metacat/admin/MetacatAdminServlet.java
141 141
			    request.setAttribute("metacatConfigured", new Boolean(ConfigurationUtil.isMetacatConfigured()));	
142 142
			    request.setAttribute("geoserverConfigured", 
143 143
			    		PropertyService.getProperty("configutil.geoserverConfigured"));
144
			    request.setAttribute("dataoneConfigured", 
145
			    		PropertyService.getProperty("configutil.dataoneConfigured"));
144 146
			    request.setAttribute("metcatServletInitialized", MetaCatServlet.isFullyInitialized());
145 147
			    if (PropertyService.arePropertiesConfigured()) {
146 148
					request.setAttribute("databaseVersion", 
......
179 181
				// process geoserver password change
180 182
				GeoserverAdmin.getInstance().configureGeoserver(request, response);
181 183
				return;
184
			} else if (action.equals("dataone")) {
185
				// process dataone config
186
				D1Admin.getInstance().configureDataONE(request, response);
187
				return;
182 188
			} else {
183 189
				String errorMessage = "MetacatAdminServlet.handleGetOrPost - Invalid action in configuration request: " + action;
184 190
				logMetacat.error(errorMessage);
src/edu/ucsb/nceas/metacat/admin/D1Admin.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that implements database configuration methods
4
 *  Copyright: 2008 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Michael Daigle
7
 * 
8
 *   '$Author$'
9
 *     '$Date$'
10
 * '$Revision$'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

  
27
package edu.ucsb.nceas.metacat.admin;
28

  
29
import java.io.File;
30
import java.util.Vector;
31

  
32
import javax.servlet.http.HttpServletRequest;
33
import javax.servlet.http.HttpServletResponse;
34

  
35
import org.apache.log4j.Logger;
36
import org.dataone.client.CNode;
37
import org.dataone.client.D1Client;
38
import org.dataone.client.auth.CertificateManager;
39
import org.dataone.service.exceptions.IdentifierNotUnique;
40
import org.dataone.service.exceptions.InvalidRequest;
41
import org.dataone.service.exceptions.NotAuthorized;
42
import org.dataone.service.exceptions.NotFound;
43
import org.dataone.service.exceptions.NotImplemented;
44
import org.dataone.service.exceptions.ServiceFailure;
45
import org.dataone.service.types.v1.Node;
46
import org.dataone.service.types.v1.NodeList;
47
import org.dataone.service.types.v1.NodeReference;
48
import org.dataone.service.types.v1.Session;
49

  
50
import edu.ucsb.nceas.metacat.dataone.MNodeService;
51
import edu.ucsb.nceas.metacat.properties.PropertyService;
52
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
53
import edu.ucsb.nceas.metacat.util.RequestUtil;
54
import edu.ucsb.nceas.metacat.util.SystemUtil;
55
import edu.ucsb.nceas.utilities.FileUtil;
56
import edu.ucsb.nceas.utilities.GeneralPropertyException;
57
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
58

  
59
/**
60
 * Control the display of the database configuration page and the processing
61
 * of the configuration values.
62
 */
63
public class D1Admin extends MetacatAdmin {
64

  
65
	private static D1Admin instance = null;
66
	private Logger logMetacat = Logger.getLogger(D1Admin.class);
67

  
68
	/**
69
	 * private constructor since this is a singleton
70
	 */
71
	private D1Admin() throws AdminException {
72

  
73
	}
74

  
75
	/**
76
	 * Get the single instance of D1Admin.
77
	 * 
78
	 * @return the single instance of D1Admin
79
	 */
80
	public static D1Admin getInstance() throws AdminException {
81
		if (instance == null) {
82
			instance = new D1Admin();
83
		}
84
		return instance;
85
	}
86

  
87
	/**
88
	 * Handle configuration of the database the first time that Metacat starts
89
	 * or when it is explicitly called. Collect necessary update information
90
	 * from the administrator.
91
	 * 
92
	 * @param request
93
	 *            the http request information
94
	 * @param response
95
	 *            the http response to be sent back to the client
96
	 */
97
	public void configureDataONE(HttpServletRequest request,
98
			HttpServletResponse response) throws AdminException {
99

  
100
		String processForm = request.getParameter("processForm");
101
		String bypass = request.getParameter("bypass");
102
		String formErrors = (String) request.getAttribute("formErrors");
103

  
104
		if (processForm == null || !processForm.equals("true") || formErrors != null) {
105
			// The servlet configuration parameters have not been set, or there
106
			// were form errors on the last attempt to configure, so redirect to
107
			// the web form for configuring metacat
108

  
109
			try {
110
				
111
				// get the current configuration values
112
				String nodeName = PropertyService.getProperty("dataone.nodeName");
113
				String nodeDescription = PropertyService.getProperty("dataone.nodeDescription");
114
				String memberNodeId = PropertyService.getProperty("dataone.memberNodeId");
115
				String nodeSynchronize = PropertyService.getProperty("dataone.nodeSynchronize");
116
				String nodeReplicate = PropertyService.getProperty("dataone.nodeReplicate");
117
				String subject = PropertyService.getProperty("dataone.subject");
118
				String certpath = PropertyService.getProperty("D1Client.certificate.file");
119
				
120
				boolean synchronize = false;
121
				if (nodeSynchronize != null) {
122
					synchronize = Boolean.parseBoolean(nodeSynchronize);
123
				}
124
				boolean replicate = false;
125
				if (nodeReplicate != null) {
126
					replicate = Boolean.parseBoolean(nodeReplicate);
127
				}
128
				
129
				request.setAttribute("dataone.nodeName", nodeName);
130
				request.setAttribute("dataone.nodeDescription", nodeDescription);
131
				request.setAttribute("dataone.memberNodeId", memberNodeId);
132
				request.setAttribute("dataone.nodeSynchronize", synchronize);
133
				request.setAttribute("dataone.nodeReplicate", replicate);
134
				request.setAttribute("dataone.subject", subject);
135
				request.setAttribute("D1Client.certificate.file", certpath);
136

  
137
				// Forward the request to the JSP page
138
				RequestUtil.forwardRequest(request, response, "/admin/dataone-configuration.jsp", null);
139
			} catch (GeneralPropertyException gpe) {
140
				throw new AdminException("D1Admin.configureDataONE - Problem getting or " + 
141
						"setting property while initializing system properties page: " + gpe.getMessage());
142
			} catch (MetacatUtilException mue) {
143
				throw new AdminException("D1Admin.configureDataONE - utility problem while initializing "
144
						+ "system properties page:" + mue.getMessage());
145
			} 
146
		} else if (bypass != null && bypass.equals("true")) {
147
			Vector<String> processingErrors = new Vector<String>();
148
			Vector<String> processingSuccess = new Vector<String>();
149
			
150
			// Bypass the D1 configuration. 
151
			// This will keep Metacat running
152
			try {
153
				PropertyService.setProperty("configutil.dataoneConfigured", PropertyService.BYPASSED);
154
				
155
			} catch (GeneralPropertyException gpe) {
156
				String errorMessage = "D1Admin.configureDataONE - Problem getting or setting property while "
157
					+ "processing system properties page: " + gpe.getMessage();
158
				logMetacat.error(errorMessage);
159
				processingErrors.add(errorMessage);
160
			}
161
			try {
162
				if (processingErrors.size() > 0) {
163
					RequestUtil.clearRequestMessages(request);
164
					RequestUtil.setRequestErrors(request, processingErrors);
165
					RequestUtil.forwardRequest(request, response, "/admin", null);
166
				} else {			
167
					// Reload the main metacat configuration page
168
					processingSuccess.add("DataONE configuration successfully bypassed");
169
					RequestUtil.clearRequestMessages(request);
170
					RequestUtil.setRequestSuccess(request, processingSuccess);
171
					RequestUtil.forwardRequest(request, response, 
172
							"/admin?configureType=configure&processForm=false", null);
173
				}
174
			} catch (MetacatUtilException mue) {
175
				throw new AdminException("D1Admin.configureDataONE - utility problem while processing dataone page: "
176
						+ mue.getMessage());
177
			} 
178
		
179
		} else {
180
			// The configuration form is being submitted and needs to be
181
			// processed, setting the properties in the configuration file
182
			// then restart metacat
183

  
184
			// The configuration form is being submitted and needs to be
185
			// processed.
186
			Vector<String> validationErrors = new Vector<String>();
187
			Vector<String> processingErrors = new Vector<String>();
188
			Vector<String> processingSuccess = new Vector<String>();
189

  
190
			try {
191
				// Validate that the options provided are legitimate. Note that
192
				// we've allowed them to persist their entries. As of this point
193
				// there is no other easy way to go back to the configure form
194
				// and preserve their entries.
195
				validationErrors.addAll(validateOptions(request));
196
				
197
				String nodeName = (String)request.getParameter("dataone.nodeName");
198
				String nodeDescription = (String)request.getParameter("dataone.nodeDescription");
199
				String memberNodeId = (String)request.getParameter("dataone.memberNodeId");
200
				String nodeSynchronize = (String)request.getParameter("dataone.nodeSynchronize");
201
				String nodeReplicate = (String)request.getParameter("dataone.nodeReplicate");
202
				String subject = (String)request.getParameter("dataone.subject");
203
				String certpath = (String)request.getParameter("D1Client.certificate.file");
204
				
205
				boolean synchronize = false;
206
				if (nodeSynchronize != null) {
207
					synchronize = Boolean.parseBoolean(nodeSynchronize);
208
				}
209
				boolean replicate = false;
210
				if (nodeReplicate != null) {
211
					replicate = Boolean.parseBoolean(nodeReplicate);
212
				}
213
				
214
				// process the values, checking for nulls etc..
215
				if (nodeName == null ) {
216
					validationErrors.add("nodeName cannot be null");
217
				} else {
218
					
219
					PropertyService.setPropertyNoPersist("dataone.nodeName", nodeName);
220
					PropertyService.setPropertyNoPersist("dataone.nodeDescription", nodeDescription);
221
					PropertyService.setPropertyNoPersist("dataone.memberNodeId", memberNodeId);
222
					PropertyService.setPropertyNoPersist("dataone.nodeSynchronize", Boolean.toString(synchronize));
223
					PropertyService.setPropertyNoPersist("dataone.nodeReplicate", Boolean.toString(replicate));
224
					PropertyService.setPropertyNoPersist("dataone.subject", subject);
225
					PropertyService.setPropertyNoPersist("D1Client.certificate.file", certpath);
226
					
227
					PropertyService.persistProperties();
228

  
229
					// write the backup properties to a location outside the
230
					// application directories so they will be available after
231
					// the next upgrade
232
					PropertyService.persistMainBackupProperties();
233
					
234
			        // Register as a DataONE Member Node
235
					if (replicate) {
236
						registerDataONEMemberNode();
237
					}
238
				}
239
			} catch (GeneralPropertyException gpe) {
240
				String errorMessage = "D1Admin.configureDataONE - Problem getting or setting property while "
241
						+ "processing system properties page: " + gpe.getMessage();
242
				logMetacat.error(errorMessage);
243
				processingErrors.add(errorMessage);
244
			}
245

  
246
			try {
247
				if (validationErrors.size() > 0 || processingErrors.size() > 0) {
248
					RequestUtil.clearRequestMessages(request);
249
					RequestUtil.setRequestFormErrors(request, validationErrors);
250
					RequestUtil.setRequestErrors(request, processingErrors);
251
					RequestUtil.forwardRequest(request, response, "/admin", null);
252
				} else {
253
					// Now that the options have been set, change the
254
					// 'dataoneConfigured' option to 'true'
255
					PropertyService.setProperty("configutil.dataoneConfigured",
256
							PropertyService.CONFIGURED);
257
					
258
					// Reload the main metacat configuration page
259
					processingSuccess.add("DataONE successfully configured");
260
					RequestUtil.clearRequestMessages(request);
261
					RequestUtil.setRequestSuccess(request, processingSuccess);
262
					RequestUtil.forwardRequest(request, response, 
263
							"/admin?configureType=configure&processForm=false", null);
264
				}
265
			} catch (MetacatUtilException mue) {
266
				throw new AdminException("D1Admin.configureDataONE - utility problem while processing geoservices "
267
						+ "geoservices page: " + mue.getMessage());
268
			} catch (GeneralPropertyException gpe) {
269
				throw new AdminException("D1Admin.configureDataONE - problem with properties while "
270
						+ "processing geoservices configuration page: " + gpe.getMessage());
271
			}
272
		}
273
	}
274
	
275
	/**
276
	 * Register as a member node on the DataONE network.  The node description is
277
	 * retrieved from the getCapabilities() service, and so this should only be called
278
	 * after the properties have been properly set up in Metacat.
279
	 */
280
	private void registerDataONEMemberNode() {
281
        CNode cn;
282
        try {
283
            logMetacat.debug("Get the Node description.");
284
            Node node = MNodeService.getInstance(null).getCapabilities();
285
            logMetacat.debug("Setting client certificate location.");
286
            String mnCertificatePath = PropertyService.getProperty("D1Client.certificate.file");
287
            CertificateManager.getInstance().setCertificateLocation(mnCertificatePath);
288
            cn = D1Client.getCN();
289
            // check if this is new or an update
290
            boolean update = false;
291
            NodeList nodes = cn.listNodes();
292
            for (Node n: nodes.getNodeList()) {
293
            	if (n.getIdentifier().getValue().equals(node.getIdentifier().getValue())) {
294
            		update = true;
295
            		break;
296
            	}
297
            }
298
            // Session is null, because the libclient code automatically sets up an
299
            // SSL session for us using the client certificate provided
300
            Session session = null;
301
            if (update) {
302
            	logMetacat.debug("Updating node with DataONE. " + cn.getNodeBaseServiceUrl());
303
	            boolean result = cn.updateNodeCapabilities(session, node.getIdentifier(), node);
304
            } else {
305
	            logMetacat.debug("Registering node with DataONE. " + cn.getNodeBaseServiceUrl());
306
	            NodeReference mnode = cn.register(session, node);
307
            }
308
        } catch (ServiceFailure e) {
309
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
310
        } catch (NotFound e) {
311
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
312
        } catch (NotImplemented e) {
313
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
314
        } catch (NotAuthorized e) {
315
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
316
        } catch (InvalidRequest e) {
317
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
318
        } catch (IdentifierNotUnique e) {
319
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
320
        } catch (PropertyNotFoundException e) {
321
            logMetacat.warn("Could not find the location for client certificates: " + e.getMessage());
322
        }
323
	}
324

  
325
	/**
326
	 * Validate the most important configuration options submitted by the user.
327
	 * 
328
	 * @return a vector holding error message for any fields that fail
329
	 *         validation.
330
	 */
331
	protected Vector<String> validateOptions(HttpServletRequest request) {
332
		Vector<String> errorVector = new Vector<String>();
333

  
334
		// TODO MCD validate options.
335

  
336
		return errorVector;
337
	}
338
}
0 339

  

Also available in: Unified diff