Project

General

Profile

Revision 6610

Added by Chris Jones about 9 years ago

Update methods in MNodeService to reflect they modifications of the MN API with regard to exceptions being raised. Largely removed InvalidRequest from a number of methods, and instead threw an appropriate NotFound or ServiceFailure instead.

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
172 172
     */
173 173
    @Override
174 174
    public Identifier delete(Session session, Identifier pid) 
175
        throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented, InvalidRequest {
175
        throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
176 176

  
177 177
        String localId = null;
178 178
        boolean allowed = false;
......
193 193

  
194 194
        // do we have a valid pid?
195 195
        if (pid == null || pid.getValue().trim().equals("")) {
196
            throw new InvalidRequest("1322", "The provided identifier was invalid.");
196
            throw new ServiceFailure("1350", "The provided identifier was invalid.");
197 197
        }
198 198

  
199 199
        // check for the existing identifier
200 200
        try {
201 201
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
202 202
        } catch (McdbDocNotFoundException e) {
203
            throw new InvalidRequest("1322", "The object with the provided " + "identifier was not found.");
203
            throw new NotFound("1340", "The object with the provided " + "identifier was not found.");
204 204
        }
205 205

  
206 206
        // does the subject have DELETE (a D1 CHANGE_PERMISSION level) priveleges on the pid?
207 207
        allowed = isAuthorized(session, pid, Permission.CHANGE_PERMISSION);
208
            
208 209

  
209 210
        if (allowed) {
210 211
            try {
......
213 214
                EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, Event.DELETE.xmlValue());
214 215

  
215 216
            } catch (McdbDocNotFoundException e) {
216
                throw new InvalidRequest("1322", "The provided identifier was invalid.");
217
                throw new NotFound("1340", "The provided identifier was invalid.");
217 218

  
218 219
            } catch (SQLException e) {
219 220
                throw new ServiceFailure("1350", "There was a problem deleting the object." + "The error message was: " + e.getMessage());
......
488 489
     * @throws InvalidRequest
489 490
     */
490 491
    @Override
491
    public DescribeResponse describe(Session session, Identifier pid) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented,
492
            InvalidRequest {
492
    public DescribeResponse describe(Session session, Identifier pid) 
493
        throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
493 494

  
494 495
      // get system metadata and construct the describe response
495 496
        SystemMetadata sysmeta = getSystemMetadata(session, pid);
......
515 516
     * @throws NotImplemented
516 517
     */
517 518
    @Override
518
    public InputStream get(Session session, Identifier pid) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented, InvalidRequest {
519
    public InputStream get(Session session, Identifier pid) 
520
    throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
519 521

  
520 522
        return super.get(session, pid);
521 523

  
......
539 541
     * @throws NotImplemented
540 542
     */
541 543
    @Override
542
    public Checksum getChecksum(Session session, Identifier pid, String algorithm) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
543
            InvalidRequest, NotImplemented {
544
    public Checksum getChecksum(Session session, Identifier pid, String algorithm) 
545
        throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
546
        InvalidRequest, NotImplemented {
544 547

  
545 548
        Checksum checksum = null;
546 549

  
......
580 583
     * @throws NotImplemented
581 584
     */
582 585
    @Override
583
    public SystemMetadata getSystemMetadata(Session session, Identifier pid) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, InvalidRequest,
584
            NotImplemented {
586
    public SystemMetadata getSystemMetadata(Session session, Identifier pid) 
587
        throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
588
        NotImplemented {
585 589

  
586 590
        return super.getSystemMetadata(session, pid);
587 591
    }
......
636 640
     * @throws NotImplemented
637 641
     */
638 642
    @Override
639
    public Node getCapabilities() throws NotImplemented, NotAuthorized, ServiceFailure, InvalidRequest {
643
    public Node getCapabilities() 
644
        throws NotImplemented, ServiceFailure {
640 645

  
641 646
        String nodeName = null;
642 647
        String nodeId = null;
......
698 703
                canPing.setSuccess(ping());
699 704
            } catch (InsufficientResources e) {
700 705
                e.printStackTrace();
701
            } catch (UnsupportedType e) {
702
                e.printStackTrace();
703 706
            }
707
            
704 708
            node.setPing(canPing);
705 709

  
706 710
            NodeReference identifier = new NodeReference();
......
794 798
     * @throws InvalidRequest
795 799
     * @throws NotImplemented
796 800
     */
797
    @Override
798
    public MonitorList getOperationStatistics(Session session, Date startTime, Date endTime, Subject requestor, Event event, ObjectFormatIdentifier formatId)
799
            throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, InsufficientResources, UnsupportedType {
801
    public MonitorList getOperationStatistics(Session session, Date startTime, 
802
        Date endTime, Subject requestor, Event event, ObjectFormatIdentifier formatId)
803
        throws NotImplemented, ServiceFailure, NotAuthorized, InsufficientResources, UnsupportedType {
800 804

  
801 805
        MonitorList monitorList = new MonitorList();
802 806

  
......
841 845
     * 
842 846
     * @throws InvalidToken
843 847
     * @throws ServiceFailure
844
     * @throws NotAuthorized
845
     * @throws InvalidRequest
846 848
     * @throws NotImplemented
847 849
     */
848 850
    @Override
849
    public boolean ping() throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, InsufficientResources, UnsupportedType {
851
    public boolean ping() 
852
        throws NotImplemented, ServiceFailure, InsufficientResources {
850 853

  
851 854
        // test if we can get a database connection
852 855
        boolean alive = false;
......
876 879
     * 
877 880
     * @throws ServiceFailure
878 881
     * @throws NotAuthorized
879
     * @throws InvalidRequest
880 882
     * @throws NotImplemented
881 883
     */
882 884
    @Override
883
    public void synchronizationFailed(Session session, SynchronizationFailed syncFailed) throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest {
885
    public void synchronizationFailed(Session session, SynchronizationFailed syncFailed) 
886
        throws NotImplemented, ServiceFailure, NotAuthorized {
884 887

  
885 888
        String localId;
886 889

  
887 890
        try {
888 891
            localId = IdentifierManager.getInstance().getLocalId(syncFailed.getPid());
889 892
        } catch (McdbDocNotFoundException e) {
890
            throw new InvalidRequest("2163", "The identifier specified by " + syncFailed.getPid() + " was not found on this node.");
893
            throw new ServiceFailure("2161", "The identifier specified by " + syncFailed.getPid() + " was not found on this node.");
891 894

  
892 895
        }
893 896
        // TODO: update the CN URL below when the CNRead.SynchronizationFailed
......
914 917
     */
915 918
    @Override
916 919
    public InputStream getReplica(Session session, Identifier pid) 
917
        throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented, 
918
        ServiceFailure, NotFound {
920
        throws NotAuthorized, NotImplemented, ServiceFailure {
919 921

  
920 922
        logMetacat.info("MNodeService.getReplica() called.");
921 923

  
......
928 930
        try {
929 931
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
930 932
        } catch (McdbDocNotFoundException e) {
931
            throw new NotFound("1020", "The object specified by " + pid.getValue() + " does not exist at this node.");
933
            throw new ServiceFailure("2181", "The object specified by " + 
934
                    pid.getValue() + " does not exist at this node.");
935
            
932 936
        }
933 937

  
934 938
        Subject targetNodeSubject = session.getSubject();
935 939

  
936 940
        // check for authorization to replicate, null session to act as this source MN
937
        allowed = D1Client.getCN().isNodeAuthorized(null, targetNodeSubject, pid, Permission.REPLICATE);
941
        try {
942
            allowed = D1Client.getCN().isNodeAuthorized(null, targetNodeSubject, pid, Permission.REPLICATE);
943
        } catch (InvalidToken e1) {
944
            throw new ServiceFailure("2181", "Could not determine if node is authorized: " 
945
                + e1.getMessage());
946
            
947
        } catch (NotFound e1) {
948
            throw new ServiceFailure("2181", "Could not determine if node is authorized: " 
949
                    + e1.getMessage());
938 950

  
951
        } catch (InvalidRequest e1) {
952
            throw new ServiceFailure("2181", "Could not determine if node is authorized: " 
953
                    + e1.getMessage());
954

  
955
        }
956

  
939 957
        logMetacat.info("Called D1Client.isNodeAuthorized(). Allowed = " + allowed +
940 958
            " for identifier " + pid.getValue());
941 959

  
......
944 962
            try {
945 963
                inputStream = handler.read(localId);
946 964
            } catch (Exception e) {
947
                throw new ServiceFailure("1020", "The object specified by " + pid.getValue() + "could not be returned due to error: " + e.getMessage());
965
                throw new ServiceFailure("1020", "The object specified by " + 
966
                    pid.getValue() + "could not be returned due to error: " + e.getMessage());
948 967
            }
949 968
        }
950 969

  
951 970
        // if we fail to set the input stream
952 971
        if (inputStream == null) {
953
            throw new NotFound("1020", "The object specified by " + pid.getValue() + "does not exist at this node.");
972
            throw new ServiceFailure("2181", "The object specified by " + 
973
                pid.getValue() + "does not exist at this node.");
954 974
        }
955 975

  
956 976
        // log the replica event

Also available in: Unified diff