Project

General

Profile

« Previous | Next » 

Revision 5356

Added by berkley almost 14 years ago

changed the detailCode for DataOne exceptions to a string

View differences:

src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
499 499
        } catch (BaseException e) {
500 500
                serializeException(e, out);
501 501
        } catch (IOException e) {
502
            ServiceFailure sf = new ServiceFailure(1030, e.getMessage());
502
            ServiceFailure sf = new ServiceFailure("1030", e.getMessage());
503 503
            serializeException(sf, out);
504 504
        }
505 505
    }
......
525 525
                IMarshallingContext mctx = bfact.createMarshallingContext();
526 526
                mctx.marshalDocument(sysmeta, "UTF-8", null, out);
527 527
            } catch (JiBXException e) {
528
                throw new ServiceFailure(1190, "Failed to serialize SystemMetadata: " + e.getMessage());
528
                throw new ServiceFailure("1190", "Failed to serialize SystemMetadata: " + e.getMessage());
529 529
            }
530 530
        } catch (BaseException e) {
531 531
                serializeException(e, out);
532 532
        } catch (IOException e) {
533
            ServiceFailure sf = new ServiceFailure(1030, e.getMessage());
533
            ServiceFailure sf = new ServiceFailure("1030", e.getMessage());
534 534
            serializeException(sf, out);
535 535
        } finally {
536 536
            IOUtils.closeQuietly(out);
......
646 646
                    sysmeta = part.getInputStream();
647 647
                    logMetacat.debug("Found sysmeta part, size is: " + part.getSize());
648 648
                } else {
649
                    throw new InvalidRequest(1000, "Request had malformed MIME part with name: " + name);
649
                    throw new InvalidRequest("1000", "Request had malformed MIME part with name: " + name);
650 650
                }
651 651
            }
652 652
            
......
655 655
                // Check if the objectId exists
656 656
                IdentifierManager im = IdentifierManager.getInstance();
657 657
                if (im.identifierExists(guid)) {
658
                    throw new IdentifierNotUnique(1000, "Identifier is already in use: " + guid);
658
                    throw new IdentifierNotUnique("1000", "Identifier is already in use: " + guid);
659 659
                }
660 660

  
661 661
                // TODO: access control -- should be in CrudService et al. I think
......
676 676

  
677 677
                } else {
678 678
                    logMetacat.debug("Unauthorized to create.");
679
                    throw new NotAuthorized(1000, "Permission denied for user " + username);
679
                    throw new NotAuthorized("1000", "Permission denied for user " + username);
680 680
                }
681 681
            } else if (action.equals(FUNCTION_NAME_UPDATE)) { //handle updates
682 682
                IdentifierManager im = IdentifierManager.getInstance();
......
689 689
                //do some checks
690 690
                if(params.get("obsoletedGuid") == null)
691 691
                {
692
                    throw new InvalidRequest(1202, "obsoletedGuid must be contained in the request parameters.");
692
                    throw new InvalidRequest("1202", "obsoletedGuid must be contained in the request parameters.");
693 693
                }
694 694
                //get the obsoletedGuid
695 695
                String[] obsGuidS = params.get("obsoletedGuid");
......
697 697
                
698 698
                if (!im.identifierExists(obsoletedGuid.getValue())) 
699 699
                {
700
                    throw new InvalidRequest(1202, "The guid you are trying to update does not exist.");
700
                    throw new InvalidRequest("1202", "The guid you are trying to update does not exist.");
701 701
                }
702 702
                
703 703
                
......
717 717
                }
718 718
                catch(NotFound e)
719 719
                {
720
                    throw new InvalidRequest(1202, "The guid you are trying to update does not exist.");
720
                    throw new InvalidRequest("1202", "The guid you are trying to update does not exist.");
721 721
                }
722 722
                
723 723
            } else {
724
                throw new InvalidRequest(1000, "Operation must be create or update.");
724
                throw new InvalidRequest("1000", "Operation must be create or update.");
725 725
            }
726 726
        } catch (NotAuthorized e) {
727 727
            serializeException(e, out);
......
742 742
        } catch (InvalidRequest e) {
743 743
            serializeException(e, out);
744 744
        } catch (MessagingException e) {
745
            ServiceFailure sf = new ServiceFailure(1000, e.getMessage());
745
            ServiceFailure sf = new ServiceFailure("1000", e.getMessage());
746 746
            serializeException(sf, out);
747 747
        } catch (IOException e) {
748
            ServiceFailure sf = new ServiceFailure(1000, e.getMessage());
748
            ServiceFailure sf = new ServiceFailure("1000", e.getMessage());
749 749
            serializeException(sf, out);
750 750
        } catch (JiBXException e) {
751 751
            e.printStackTrace(System.out);
752
            InvalidSystemMetadata ism = new InvalidSystemMetadata(1080, e.getMessage());
752
            InvalidSystemMetadata ism = new InvalidSystemMetadata("1080", e.getMessage());
753 753
            serializeException(ism, out);
754 754
        }
755 755
    }
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
194 194
        // verify that guid == SystemMetadata.getIdentifier()
195 195
        logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getValue() + "|" + sysmeta.getIdentifier().getValue());
196 196
        if (!guid.getValue().equals(sysmeta.getIdentifier().getValue())) {
197
            throw new InvalidSystemMetadata(1180, 
197
            throw new InvalidSystemMetadata("1180", 
198 198
                "GUID in method call does not match GUID in system metadata.");
199 199
        }
200 200

  
......
202 202
        // Check that the identifier does not already exist
203 203
        IdentifierManager im = IdentifierManager.getInstance();
204 204
        if (im.identifierExists(guid.getValue())) {
205
            throw new IdentifierNotUnique(1120, 
205
            throw new IdentifierNotUnique("1120", 
206 206
                "GUID is already in use by an existing object.");
207 207
        }
208 208

  
......
217 217
                String msg = "Could not create string from XML stream: " +
218 218
                    " " + e.getMessage();
219 219
                logMetacat.debug(msg);
220
                throw new ServiceFailure(1190, msg);
220
                throw new ServiceFailure("1190", msg);
221 221
            }
222 222

  
223 223
        } else {
......
275 275
        }
276 276
        catch(Exception e)
277 277
        {
278
            throw new ServiceFailure(1030, "Error updating document in CrudService: " + e.getMessage());
278
            throw new ServiceFailure("1030", "Error updating document in CrudService: " + e.getMessage());
279 279
        }
280 280
    }
281 281

  
282 282
    public Identifier delete(AuthToken token, Identifier guid)
283 283
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
284 284
            NotImplemented {
285
        throw new NotImplemented(1000, "This method not yet implemented.");
285
        throw new NotImplemented("1000", "This method not yet implemented.");
286 286
    }
287 287

  
288 288
    public DescribeResponse describe(AuthToken token, Identifier guid)
289 289
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
290 290
            NotImplemented {
291
        throw new NotImplemented(1000, "This method not yet implemented.");
291
        throw new NotImplemented("1000", "This method not yet implemented.");
292 292
    }
293 293
    
294 294
    public InputStream get(AuthToken token, Identifier guid)
......
316 316
                                sessionData.getUserName(), 
317 317
                                sessionData.getGroupNames(), true, params);
318 318
                    } catch (PropertyNotFoundException e) {
319
                        throw new ServiceFailure(1030, e.getMessage());
319
                        throw new ServiceFailure("1030", e.getMessage());
320 320
                    } catch (ClassNotFoundException e) {
321
                        throw new ServiceFailure(1030, e.getMessage());
321
                        throw new ServiceFailure("1030", e.getMessage());
322 322
                    } catch (IOException e) {
323
                        throw new ServiceFailure(1030, e.getMessage());
323
                        throw new ServiceFailure("1030", e.getMessage());
324 324
                    } catch (SQLException e) {
325
                        throw new ServiceFailure(1030, e.getMessage());
325
                        throw new ServiceFailure("1030", e.getMessage());
326 326
                    } catch (McdbException e) {
327
                        throw new ServiceFailure(1030, e.getMessage());
327
                        throw new ServiceFailure("1030", e.getMessage());
328 328
                    } catch (ParseLSIDException e) {
329
                        throw new NotFound(1020, e.getMessage());
329
                        throw new NotFound("1020", e.getMessage());
330 330
                    } catch (InsufficientKarmaException e) {
331
                        throw new NotAuthorized(1000, "Not authorized for get().");
331
                        throw new NotAuthorized("1000", "Not authorized for get().");
332 332
                    }
333 333

  
334 334
                    return "Completed";
......
337 337
            return objectStream;
338 338

  
339 339
        } catch (McdbDocNotFoundException e) {
340
            throw new NotFound(1020, e.getMessage());
340
            throw new NotFound("1020", e.getMessage());
341 341
        }
342 342
    }
343 343

  
344 344
    public Checksum getChecksum(AuthToken token, Identifier guid)
345 345
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
346 346
            InvalidRequest, NotImplemented {
347
        throw new NotImplemented(1000, "This method not yet implemented.");
347
        throw new NotImplemented("1000", "This method not yet implemented.");
348 348
    }
349 349

  
350 350
    public Checksum getChecksum(AuthToken token, Identifier guid, 
351 351
            String checksumAlgorithm) throws InvalidToken, ServiceFailure, 
352 352
            NotAuthorized, NotFound, InvalidRequest, NotImplemented {
353
        throw new NotImplemented(1000, "This method not yet implemented.");
353
        throw new NotImplemented("1000", "This method not yet implemented.");
354 354
    }
355 355

  
356 356
    public LogRecordSet getLogRecords(AuthToken token, Date fromDate, Date toDate)
357 357
            throws InvalidToken, ServiceFailure, NotAuthorized, InvalidRequest, 
358 358
            NotImplemented {
359
        throw new NotImplemented(1000, "This method not yet implemented.");
359
        throw new NotImplemented("1000", "This method not yet implemented.");
360 360
    }
361 361

  
362 362
    public SystemMetadata getSystemMetadata(AuthToken token, Identifier guid)
......
387 387
                                sessionData.getUserName(), 
388 388
                                sessionData.getGroupNames(), true, params);
389 389
                    } catch (PropertyNotFoundException e) {
390
                        throw new ServiceFailure(1030, e.getMessage());
390
                        throw new ServiceFailure("1030", e.getMessage());
391 391
                    } catch (ClassNotFoundException e) {
392
                        throw new ServiceFailure(1030, e.getMessage());
392
                        throw new ServiceFailure("1030", e.getMessage());
393 393
                    } catch (IOException e) {
394
                        throw new ServiceFailure(1030, e.getMessage());
394
                        throw new ServiceFailure("1030", e.getMessage());
395 395
                    } catch (SQLException e) {
396
                        throw new ServiceFailure(1030, e.getMessage());
396
                        throw new ServiceFailure("1030", e.getMessage());
397 397
                    } catch (McdbException e) {
398
                        throw new ServiceFailure(1030, e.getMessage());
398
                        throw new ServiceFailure("1030", e.getMessage());
399 399
                    } catch (ParseLSIDException e) {
400
                        throw new NotFound(1020, e.getMessage());
400
                        throw new NotFound("1020", e.getMessage());
401 401
                    } catch (InsufficientKarmaException e) {
402
                        throw new NotAuthorized(1000, "Not authorized for get().");
402
                        throw new NotAuthorized("1000", "Not authorized for get().");
403 403
                    }
404 404

  
405 405
                    return "Completed";
......
412 412
            
413 413
        } catch (McdbDocNotFoundException e) {
414 414
            //e.printStackTrace();
415
            throw new NotFound(1000, e.getMessage());
415
            throw new NotFound("1000", e.getMessage());
416 416
        }                
417 417
    }
418 418

  
......
505 505
                        //newFile.delete();
506 506
                        logMetacat.debug("SQLE: " + e.getMessage());
507 507
                        e.printStackTrace(System.out);
508
                        throw new ServiceFailure(1190, "Registration failed: " + e.getMessage());
508
                        throw new ServiceFailure("1190", "Registration failed: " + e.getMessage());
509 509
                    } catch (AccessionNumberException e) {
510 510
                        //newFile.delete();
511 511
                        logMetacat.debug("ANE: " + e.getMessage());
512 512
                        e.printStackTrace(System.out);
513
                        throw new ServiceFailure(1190, "Registration failed: " + e.getMessage());
513
                        throw new ServiceFailure("1190", "Registration failed: " + e.getMessage());
514 514
                    } catch (Exception e) {
515 515
                        //newFile.delete();
516 516
                        logMetacat.debug("Exception: " + e.getMessage());
517 517
                        e.printStackTrace(System.out);
518
                        throw new ServiceFailure(1190, "Registration failed: " + e.getMessage());
518
                        throw new ServiceFailure("1190", "Registration failed: " + e.getMessage());
519 519
                    }
520 520
    
521 521
                    logMetacat.debug("Logging the creation event.");
......
528 528
                            localId, "insert", false, null);
529 529
    
530 530
                } catch (PropertyNotFoundException e) {
531
                    throw new ServiceFailure(1190, "Could not lock file for writing:" + e.getMessage());
531
                    throw new ServiceFailure("1190", "Could not lock file for writing:" + e.getMessage());
532 532
                }
533 533
    
534 534
            }
535 535
        } catch (Exception e) {
536 536
            // Could not get a lock on the document, so we can not update the file now
537
            throw new ServiceFailure(1190, "Failed to lock file: " + e.getMessage());
537
            throw new ServiceFailure("1190", "Failed to lock file: " + e.getMessage());
538 538
        }
539 539
    }
540 540

  
......
553 553
                os.close();
554 554
            } else {
555 555
                logMetacat.debug("File creation failed, or file already exists.");
556
                throw new ServiceFailure(1190, "File already exists: " + fileName);
556
                throw new ServiceFailure("1190", "File already exists: " + fileName);
557 557
            }
558 558
        } catch (FileNotFoundException e) {
559 559
            logMetacat.debug("FNF: " + e.getMessage());
560
            throw new ServiceFailure(1190, "File not found: " + fileName + " " 
560
            throw new ServiceFailure("1190", "File not found: " + fileName + " " 
561 561
                    + e.getMessage());
562 562
        } catch (IOException e) {
563 563
            logMetacat.debug("IOE: " + e.getMessage());
564
            throw new ServiceFailure(1190, "File was not written: " + fileName 
564
            throw new ServiceFailure("1190", "File was not written: " + fileName 
565 565
                    + " " + e.getMessage());
566 566
        }
567 567

  
......
605 605
        }
606 606
        catch(Exception e)
607 607
        {
608
            throw new ServiceFailure(1030, "Error updating system metadata: " + e.getMessage());
608
            throw new ServiceFailure("1030", "Error updating system metadata: " + e.getMessage());
609 609
        }
610 610
    }
611 611
    
......
689 689
            }
690 690
            catch(McdbDocNotFoundException e)
691 691
            {
692
                throw new ServiceFailure(1030, "CrudService.insertOrUpdateDocument(): " +
692
                throw new ServiceFailure("1030", "CrudService.insertOrUpdateDocument(): " +
693 693
                    "guid " + guid.getValue() + " should have been in the identifier table, but it wasn't: " + e.getMessage());
694 694
            }
695 695
        }
......
733 733
            sysmetaOut = new ByteArrayOutputStream();
734 734
            mctx.marshalDocument(sysmeta, "UTF-8", null, sysmetaOut);
735 735
        } catch (JiBXException e) {
736
            throw new ServiceFailure(1190, "Failed to serialize and insert SystemMetadata: " + e.getMessage());
736
            throw new ServiceFailure("1190", "Failed to serialize and insert SystemMetadata: " + e.getMessage());
737 737
        }
738 738
        
739 739
        return sysmetaOut;
......
747 747
            SystemMetadata sysmeta = (SystemMetadata) uctx.unmarshalDocument(xml, null);
748 748
            return sysmeta;
749 749
        } catch (JiBXException e) {
750
            throw new ServiceFailure(1190, "Failed to serialize and insert SystemMetadata: " + e.getMessage());
750
            throw new ServiceFailure("1190", "Failed to serialize and insert SystemMetadata: " + e.getMessage());
751 751
        }    
752 752
    }
753 753
}

Also available in: Unified diff