Project

General

Profile

« Previous | Next » 

Revision 7170

add "Generate System Metadata" button to the replication server list display. When clicked, we generate SM for records belonging to that source server. This is only enabled when DataONE has been configured.
https://redmine.dataone.org/issues/2762

View differences:

src/edu/ucsb/nceas/metacat/admin/ReplicationAdmin.java
156 156
			out = response.getWriter();
157 157
			out.println("<html><body>\"Get All\" Done</body></html>");
158 158
		} else if (action.equals("servercontrol")) {
159
			ReplicationService.handleServerControlRequest(params, response);
159
			ReplicationService.handleServerControlRequest(params, request, response);
160 160
		} else {
161 161
			// Forward the request to the JSP page
162 162
			RequestUtil.forwardRequest(request, response, "/admin/replication-configuration.jsp", null);
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
49 49
import java.util.Calendar;
50 50
import java.util.Date;
51 51
import java.util.Hashtable;
52
import java.util.List;
53 52
import java.util.Timer;
54 53
import java.util.Vector;
55 54

  
......
81 80
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile;
82 81
import edu.ucsb.nceas.metacat.accesscontrol.PermOrderException;
83 82
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
83
import edu.ucsb.nceas.metacat.admin.upgrade.dataone.GenerateSystemMetadata;
84 84
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
85 85
import edu.ucsb.nceas.metacat.database.DBConnection;
86 86
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
......
280 280
	      //updates this server exactly once
281 281
	      replicationDaemon.schedule(new ReplicationHandler(), 0);
282 282
	}
283

  
283
	
284 284
	/**
285 285
	 * This method can add, delete and list the servers currently included in
286 286
	 * xml_replication.
......
291 291
	 * servercontrol    list
292 292
	 */
293 293
	public static void handleServerControlRequest(
294
			Hashtable<String, String[]> params, HttpServletResponse response) {
294
			Hashtable<String, String[]> params, HttpServletRequest request, HttpServletResponse response) {
295 295
		String subaction = ((String[]) params.get("subaction"))[0];
296 296
		DBConnection dbConn = null;
297 297
		int serialNumber = -1;
......
301 301
		String dataReplicate = null;
302 302
		String hub = null;
303 303
		Writer out = null;
304
		boolean showGenerateSystemMetadata = false;
304 305
		try {
305 306
			response.setContentType("text/xml");
306 307
			out = response.getWriter();
......
345 346
				pstmt.close();
346 347
				dbConn.commit();
347 348
				out.write("Server " + server + " added");
348
				response.setContentType("text/html");
349
				out.write("<html><body><table border=\"1\">");
350
				out.write("<tr><td><b>server</b></td>");
351
				out.write("<td><b>last_checked</b></td>");
352
				out.write("<td><b>replicate</b></td>");
353
				out.write("<td><b>datareplicate</b></td>");
354
				out.write("<td><b>hub</b></td></tr>");
355
				pstmt = dbConn.prepareStatement("SELECT serverid, server, last_checked, replicate, datareplicate, hub FROM xml_replication");
356
				//increase dbconnection usage
357
				dbConn.increaseUsageCount(1);
358

  
359
				pstmt.execute();
360
				ResultSet rs = pstmt.getResultSet();
361
				boolean tablehasrows = rs.next();
362
				while (tablehasrows) {
363
					out.write("<tr><td>" + rs.getString(2) + "</td><td>");
364
					out.write(rs.getString(3) + "</td><td>");
365
					out.write(rs.getString(4) + "</td><td>");
366
					out.write(rs.getString(5) + "</td><td>");
367
					out.write(rs.getString(6) + "</td></tr>");
368

  
369
					tablehasrows = rs.next();
370
				}
371
				out.write("</table></body></html>");
372

  
349
				
350
				
373 351
				// delete server from server list
374 352
			} else if (subaction.equals("delete")) {
375 353
				server = ((String[]) params.get("server"))[0];
......
380 358
				pstmt.close();
381 359
				dbConn.commit();
382 360
				out.write("Server " + server + " deleted");
383
				response.setContentType("text/html");
384
				out.write("<html><body><table border=\"1\">");
385
				out.write("<tr><td><b>server</b></td>");
386
				out.write("<td><b>last_checked</b></td>");
387
				out.write("<td><b>replicate</b></td>");
388
				out.write("<td><b>datareplicate</b></td>");
389
				out.write("<td><b>hub</b></td></tr>");
390

  
391
				pstmt = dbConn.prepareStatement("SELECT serverid, server, last_checked, replicate, datareplicate, hub FROM xml_replication");
392
				//increase dbconnection usage
393
				dbConn.increaseUsageCount(1);
394
				pstmt.execute();
395
				ResultSet rs = pstmt.getResultSet();
396
				boolean tablehasrows = rs.next();
397
				while (tablehasrows) {
398
					out.write("<tr><td>" + rs.getString(2) + "</td><td>");
399
					out.write(rs.getString(3) + "</td><td>");
400
					out.write(rs.getString(4) + "</td><td>");
401
					out.write(rs.getString(5) + "</td><td>");
402
					out.write(rs.getString(6) + "</td></tr>");
403
					tablehasrows = rs.next();
404
				}
405
				out.write("</table></body></html>");
406

  
407
				// list servers in server list
408 361
			} else if (subaction.equals("list")) {
409
				response.setContentType("text/html");
410
				out.write("<html><body><table border=\"1\">");
411
				out.write("<tr><td><b>server</b></td>");
412
				out.write("<td><b>last_checked</b></td>");
413
				out.write("<td><b>replicate</b></td>");
414
				out.write("<td><b>datareplicate</b></td>");
415
				out.write("<td><b>hub</b></td></tr>");
416
				pstmt = dbConn.prepareStatement("SELECT serverid, server, last_checked, replicate, datareplicate, hub FROM xml_replication");
417
				pstmt.execute();
418
				ResultSet rs = pstmt.getResultSet();
419
				boolean tablehasrows = rs.next();
420
				while (tablehasrows) {
421
					out.write("<tr><td>" + rs.getString(2) + "</td><td>");
422
					out.write(rs.getString(3) + "</td><td>");
423
					out.write(rs.getString(4) + "</td><td>");
424
					out.write(rs.getString(5) + "</td><td>");
425
					out.write(rs.getString(6) + "</td></tr>");
362
				// nothing special - it's the default behavior
426 363

  
427
					tablehasrows = rs.next();
428
				}
429
				out.write("</table></body></html>");
364
			} else if (subaction.equals("generatesystemmetadata")) {
365
				GenerateSystemMetadata gsm = new GenerateSystemMetadata();
366
				int serverLocation = -1;
367
				String serverid = ((String[]) params.get("serverid"))[0];
368
				serverLocation = Integer.parseInt(serverid);
369
				gsm.setServerLocation(serverLocation );
370
				gsm.multiThreadUpgrade();
371
				out.write("System Metadata generated for server " + serverid);
372
				
430 373
			} else {
431

  
374
			
432 375
				out.write("<error>Unkonwn subaction</error>");
376
				return;
377
			}
378
			
379
			// show SM generate button?
380
			String dataoneConfigured = PropertyService.getProperty("configutil.dataoneConfigured");
381
			if (dataoneConfigured != null) {
382
				showGenerateSystemMetadata = Boolean.parseBoolean(dataoneConfigured);
383
			}
384
			
385
			// always list them after processing
386
			response.setContentType("text/html");
387
			out.write("<html><body><table border=\"1\">");
388
			out.write("<tr><td><b>server</b></td>");
389
			out.write("<td><b>last_checked</b></td>");
390
			out.write("<td><b>replicate</b></td>");
391
			out.write("<td><b>datareplicate</b></td>");
392
			out.write("<td><b>hub</b></td>");
393
			if (showGenerateSystemMetadata) {
394
				out.write("<td><b>Action</b></td>");
395
			}
396
			out.write("</tr>");
433 397

  
398
			pstmt = dbConn.prepareStatement("SELECT serverid, server, last_checked, replicate, datareplicate, hub FROM xml_replication");
399
			pstmt.execute();
400
			ResultSet rs = pstmt.getResultSet();
401
			boolean tablehasrows = rs.next();
402
			while (tablehasrows) {
403
				out.write("<tr><td>" + rs.getString(2) + "</td><td>");
404
				out.write(rs.getString(3) + "</td><td>");
405
				out.write(rs.getString(4) + "</td><td>");
406
				out.write(rs.getString(5) + "</td><td>");
407
				out.write(rs.getString(6) + "</td>");
408
				if (showGenerateSystemMetadata) {
409
					//request.getContextPath() %>/admin?configureType=replication&action=servercontrol&subaction=list"
410
					out.write("<td><form action='" + request.getContextPath() + "/admin'>");
411
					out.write("<input name='serverid' type='hidden' value='" + rs.getString(1) + "'/>");
412
					out.write("<input name='configureType' type='hidden' value='replication'/>");
413
					out.write("<input name='action' type='hidden' value='servercontrol'/>");
414
					out.write("<input name='subaction' type='hidden' value='generatesystemmetadata'/>");
415
					out.write("<input type='submit' value='Generate System Metadata'/>");
416
					out.write("</form></td>");
417
				}
418
				out.write("</tr>");
419

  
420
				tablehasrows = rs.next();
434 421
			}
422
			out.write("</table></body></html>");
423
			
424
			
435 425
			pstmt.close();
436 426
			//conn.close();
437 427

  

Also available in: Unified diff