Project

General

Profile

« Previous | Next » 

Revision 7097

Added by Chris Jones over 12 years ago

Modify deleteReplica() to use parameters parsed from the mime multipart entity rather than the request params. Need to check that the unit test uses MMP params. This partially addresses https://redmine.dataone.org/issues/2526.

View differences:

src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
1425 1425

  
1426 1426
    }
1427 1427
    
1428
    public boolean deleteReplica(String pid) throws NotImplemented, NotFound,
1429
			NotAuthorized, ServiceFailure, InvalidRequest, InvalidToken,
1430
			IOException, InstantiationException, IllegalAccessException,
1431
			JiBXException, VersionMismatch {
1428
    /**
1429
     * Delete the replica entry with the given nodeId for the given pid
1430
     * 
1431
     * @param pid
1432
     * @return
1433
     * @throws NotImplemented
1434
     * @throws NotFound
1435
     * @throws NotAuthorized
1436
     * @throws ServiceFailure
1437
     * @throws InvalidRequest
1438
     * @throws InvalidToken
1439
     * @throws InstantiationException
1440
     * @throws IllegalAccessException
1441
     * @throws VersionMismatch
1442
     */
1443
    public boolean deleteReplica(String pid) 
1444
        throws NotImplemented, NotFound, NotAuthorized, ServiceFailure, 
1445
        InvalidRequest, InvalidToken, InstantiationException, 
1446
        IllegalAccessException, VersionMismatch {
1432 1447

  
1433
		boolean result = false;
1434
		long serialVersion = 0L;
1435
		String serialVersionStr = null;
1448
        boolean result = false;
1449
        long serialVersion = 0L;
1450
        String serialVersionStr = null;
1436 1451

  
1437
		Identifier identifier = new Identifier();
1438
		identifier.setValue(pid);
1452
        Identifier identifier = new Identifier();
1453
        identifier.setValue(pid);
1439 1454

  
1440
		NodeReference nodeId = null;
1441
		try {
1442
			String nodeIdString = params.get("nodeId")[0];
1443
			nodeId = new NodeReference();
1444
			nodeId.setValue(nodeIdString);
1445
		} catch (NullPointerException e) {
1446
			String msg = "The 'nodeId' must be provided as a parameter and was not.";
1447
			logMetacat.error(msg);
1448
			throw new InvalidRequest("4883", msg);
1449
		}
1455
        NodeReference nodeId = null;
1456
        
1457
        // Parse the params out of the multipart form data
1458
        // Read the incoming data from its Mime Multipart encoding
1459
        logMetacat.debug("Parsing delete replica parameters from the mime multipart entity");
1460
        try {
1461
            collectMultipartParams();
1462
            
1463
        } catch (FileUploadException e1) {
1464
            String msg = "FileUploadException: Couldn't parse the mime multipart information: " +
1465
            e1.getMessage();
1466
            logMetacat.debug(msg);
1467
            throw new ServiceFailure("4951", msg);
1450 1468

  
1451
		// get the serialVersion
1452
		try {
1453
			serialVersionStr = params.get("serialVersion")[0];
1454
			serialVersion = new Long(serialVersionStr).longValue();
1469
        } catch (IOException e1) {
1470
            String msg = "IOException: Couldn't parse the mime multipart information: " +
1471
            e1.getMessage();
1472
            logMetacat.debug(msg);
1473
            throw new ServiceFailure("4951", msg);
1474
        
1475
        } catch (Exception e1) {
1476
            String msg = "Exception: Couldn't parse the mime multipart information: " +
1477
            e1.getMessage();
1478
            logMetacat.debug(msg);
1479
            throw new ServiceFailure("4951", msg);
1455 1480

  
1456
		} catch (NullPointerException e) {
1457
			String msg = "The 'serialVersion' must be provided as a parameter and was not.";
1458
			logMetacat.error(msg);
1459
			throw new InvalidRequest("4883", msg);
1481
        }
1482
        
1483
        // get the nodeId param
1484
        try {
1485
            String nodeIdString = multipartparams.get("nodeId").get(0);
1486
            nodeId = new NodeReference();
1487
            nodeId.setValue(nodeIdString);
1488
            
1489
        } catch (NullPointerException e) {
1490
            String msg = "The 'nodeId' must be provided as a parameter and was not.";
1491
            logMetacat.error(msg);
1492
            throw new InvalidRequest("4952", msg);
1493
        }
1460 1494

  
1461
		}
1462
		result = CNodeService.getInstance(request).deleteReplicationMetadata(session, identifier, nodeId, serialVersion);
1463
		response.setStatus(200);
1464
		response.setContentType("text/xml");
1465
		return result;
1495
        // get the serialVersion
1496
        try {
1497
            serialVersionStr = multipartparams.get("serialVersion").get(0);
1498
            serialVersion = new Long(serialVersionStr).longValue();
1499
            
1500
        } catch (NumberFormatException nfe) {
1501
            String msg = "The 'serialVersion' must be provided as a positive integer and was not.";
1502
            logMetacat.error(msg);
1503
            throw new InvalidRequest("4952", msg);
1504
                        
1505
        } catch (NullPointerException e) {
1506
            String msg = "The 'serialVersion' must be provided as a parameter and was not.";
1507
            logMetacat.error(msg);
1508
            throw new InvalidRequest("4952", msg);
1509
            
1510
        }
1511
        result = CNodeService.getInstance(request).deleteReplicationMetadata(
1512
                session, identifier, nodeId, serialVersion);
1513
        response.setStatus(200);
1514
        response.setContentType("text/xml");
1515
        return result;
1466 1516

  
1467
	}
1517
    }
1468 1518

  
1469 1519
    /**
1470 1520
     * Pass the request to set the replication status to CNodeService

Also available in: Unified diff