Project

General

Profile

« Previous | Next » 

Revision 9044

Added by Jing Tao over 9 years ago

Enforce the sid requirement in the update method.

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
286 286
        UnsupportedType, InsufficientResources, NotFound, 
287 287
        InvalidSystemMetadata, NotImplemented, InvalidRequest {
288 288

  
289
        //transform a sid to a pid if it is applicable
290
        String serviceFailureCode = "1310";
291
        Identifier sid = getPIDForSID(pid, serviceFailureCode);
292
        if(sid != null) {
293
            pid = sid;
294
        }
295
        
289 296
        String localId = null;
290 297
        boolean allowed = false;
291 298
        boolean isScienceMetadata = false;
......
299 306
        if (!isValidIdentifier(pid)) {
300 307
        	throw new InvalidRequest("1202", "The provided identifier is invalid.");
301 308
        }
309
        
310
        // verify the new pid is valid format
311
        if (!isValidIdentifier(newPid)) {
312
            throw new InvalidRequest("1202", "The provided identifier is invalid.");
313
        }
314
        
315
        // make sure that the newPid doesn't exists
316
        boolean idExists = true;
317
        try {
318
            idExists = IdentifierManager.getInstance().identifierExists(newPid.getValue());
319
        } catch (SQLException e) {
320
            throw new ServiceFailure("1310", 
321
                                    "The requested identifier " + newPid.getValue() +
322
                                    " couldn't be determined if it is unique since : "+e.getMessage());
323
        }
324
        if (idExists) {
325
                throw new IdentifierNotUnique("1220", 
326
                          "The requested identifier " + newPid.getValue() +
327
                          " is already used by another object and" +
328
                          "therefore can not be used for this object. Clients should choose" +
329
                          "a new identifier that is unique and retry the operation or " +
330
                          "use CN.reserveIdentifier() to reserve one.");
331
            
332
        }
333
        
334
       
302 335

  
303 336
        // check for the existing identifier
304 337
        try {
......
353 386
            	throw new InvalidRequest("1202", 
354 387
            			"The previous identifier has already been made obsolete by: " + existingObsoletedBy.getValue());
355 388
            }
389
            //check the sid in the system metadata. If it exists, it should be non-exist or match the old sid in the previous system metadata.
390
            Identifier sidInSys = sysmeta.getSeriesId();
391
            if(sidInSys != null) {
392
                Identifier previousSid = existingSysMeta.getSeriesId();
393
                if(previousSid != null) {
394
                    // there is a previous sid, if the new sid doesn't match it, the new sid should be non-existing.
395
                    if(!sidInSys.getValue().equals(previousSid)) {
396
                        try {
397
                            idExists = IdentifierManager.getInstance().identifierExists(sidInSys.getValue());
398
                        } catch (SQLException e) {
399
                            throw new ServiceFailure("1310", 
400
                                                    "The requested identifier " + sidInSys.getValue() +
401
                                                    " couldn't be determined if it is unique since : "+e.getMessage());
402
                        }
403
                        if(idExists) {
404
                            throw new InvalidSystemMetadata("1300", "The series id "+sidInSys.getValue()+" in the system metadata doesn't match the previous series id "
405
                                                            +previousSid.getValue()+", so it should NOT exist. However, it was used by another object.");
406
                        }
407
                    }
408
                } else {
409
                    // there is no previous sid, the new sid should be non-existing.
410
                    try {
411
                        idExists = IdentifierManager.getInstance().identifierExists(sidInSys.getValue());
412
                    } catch (SQLException e) {
413
                        throw new ServiceFailure("1310", 
414
                                                "The requested identifier " + sidInSys.getValue() +
415
                                                " couldn't be determined if it is unique since : "+e.getMessage());
416
                    }
417
                    if(idExists) {
418
                        throw new InvalidSystemMetadata("1300", "The series id "+sidInSys.getValue()+" in the system metadata should NOT exist since the previous series id is null."
419
                                                        +"However, it was used by another object.");
420
                    }
421
                }
422
                
423
            }
356 424

  
357 425
            isScienceMetadata = isScienceMetadata(sysmeta);
358 426

  

Also available in: Unified diff