Project

General

Profile

« Previous | Next » 

Revision 7096

Added by Chris Jones over 12 years ago

Modify CN.setObsoletedBy() 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
1334 1334

  
1335 1335
    }
1336 1336
    
1337
    public boolean setObsoletedBy(String pid) throws NotImplemented,
1338
	    NotFound, NotAuthorized, ServiceFailure, InvalidRequest,
1339
	    InvalidToken, IOException, InstantiationException,
1340
	    IllegalAccessException, JiBXException, VersionMismatch {
1341
	
1342
		boolean result = false;
1343
		long serialVersion = 0L;
1344
		String serialVersionStr = null;
1345
		
1346
		Identifier identifier = new Identifier();
1347
		identifier.setValue(pid);
1348
		
1349
		Identifier obsoletedByPid = null;
1350
		try {
1351
			String obsoletedByPidString = params.get("obsoletedByPid")[0];
1352
			obsoletedByPid = new Identifier();
1353
			obsoletedByPid.setValue(obsoletedByPidString);
1354
		} catch (NullPointerException e) {
1355
		    String msg = "The 'obsoletedByPid' must be provided as a parameter and was not.";
1356
		    logMetacat.error(msg);
1357
		    throw new InvalidRequest("4883", msg);
1358
		}
1359
		
1360
		// get the serialVersion
1361
		try {
1362
		    serialVersionStr = params.get("serialVersion")[0];
1363
		    serialVersion = new Long(serialVersionStr).longValue();
1364
		
1365
		} catch (NullPointerException e) {
1366
		    String msg = "The 'serialVersion' must be provided as a parameter and was not.";
1367
		    logMetacat.error(msg);
1368
		    throw new InvalidRequest("4883", msg);
1369
		
1370
		}
1371
		result = CNodeService.getInstance(request).setObsoletedBy(
1372
		        session, identifier, obsoletedByPid, serialVersion);
1373
		response.setStatus(200);
1374
		response.setContentType("text/xml");
1375
		return result;
1376
	
1377
	}
1337
    /**
1338
     * Update the system metadata for a given pid, setting it to be obsoleted
1339
     * by the obsoletedByPid
1340
     *  
1341
     * @param pid
1342
     * @return
1343
     * @throws NotImplemented
1344
     * @throws NotFound
1345
     * @throws NotAuthorized
1346
     * @throws ServiceFailure
1347
     * @throws InvalidRequest
1348
     * @throws InvalidToken
1349
     * @throws InstantiationException
1350
     * @throws IllegalAccessException
1351
     * @throws VersionMismatch
1352
     */
1353
    public boolean setObsoletedBy(String pid) 
1354
        throws NotImplemented, NotFound, NotAuthorized, ServiceFailure, 
1355
        InvalidRequest, InvalidToken, InstantiationException, 
1356
        IllegalAccessException, VersionMismatch {
1357

  
1358
        boolean result = false;
1359
        long serialVersion = 0L;
1360
        String serialVersionStr = null;
1361

  
1362
        Identifier identifier = new Identifier();
1363
        identifier.setValue(pid);
1364
        String obsoletedByPidString = null;
1365
        Identifier obsoletedByPid = null;
1366

  
1367
        // Parse the params out of the multipart form data
1368
        // Read the incoming data from its Mime Multipart encoding
1369
        logMetacat.debug("Parsing rights holder parameters from the mime multipart entity");
1370
        try {
1371
            collectMultipartParams();
1372
            
1373
        } catch (FileUploadException e1) {
1374
            String msg = "FileUploadException: Couldn't parse the mime multipart information: " +
1375
            e1.getMessage();
1376
            logMetacat.debug(msg);
1377
            throw new ServiceFailure("4941", msg);
1378

  
1379
        } catch (IOException e1) {
1380
            String msg = "IOException: Couldn't parse the mime multipart information: " +
1381
            e1.getMessage();
1382
            logMetacat.debug(msg);
1383
            throw new ServiceFailure("4941", msg);
1384
        
1385
        } catch (Exception e1) {
1386
            String msg = "Exception: Couldn't parse the mime multipart information: " +
1387
            e1.getMessage();
1388
            logMetacat.debug(msg);
1389
            throw new ServiceFailure("4941", msg);
1390

  
1391
        }
1392

  
1393
        // get the obsoletedByPid
1394
        try {
1395
            obsoletedByPidString = multipartparams.get("obsoletedByPid").get(0);
1396
            obsoletedByPid = new Identifier();
1397
            obsoletedByPid.setValue(obsoletedByPidString);
1398
        } catch (NullPointerException e) {
1399
            String msg = "The 'obsoletedByPid' must be provided as a parameter and was not.";
1400
            logMetacat.error(msg);
1401
            throw new InvalidRequest("4883", msg);
1402
        }
1403

  
1404
        // get the serialVersion
1405
        try {
1406
            serialVersionStr = multipartparams.get("serialVersion").get(0);
1407
            serialVersion = new Long(serialVersionStr).longValue();
1408
            
1409
        } catch (NumberFormatException nfe) {
1410
            String msg = "The 'serialVersion' must be provided as a positive integer and was not.";
1411
            logMetacat.error(msg);
1412
            throw new InvalidRequest("4942", msg);
1413
                        
1414
        } catch (NullPointerException e) {
1415
            String msg = "The 'serialVersion' must be provided as a parameter and was not.";
1416
            logMetacat.error(msg);
1417
            throw new InvalidRequest("4942", msg);
1418
            
1419
        }
1420
        result = CNodeService.getInstance(request).setObsoletedBy(session,
1421
            identifier, obsoletedByPid, serialVersion);
1422
        response.setStatus(200);
1423
        response.setContentType("text/xml");
1424
        return result;
1425

  
1426
    }
1378 1427
    
1379 1428
    public boolean deleteReplica(String pid) throws NotImplemented, NotFound,
1380 1429
			NotAuthorized, ServiceFailure, InvalidRequest, InvalidToken,

Also available in: Unified diff