Project

General

Profile

1
/**
2
 * This work was created by participants in the DataONE project, and is
3
 * jointly copyrighted by participating institutions in DataONE. For
4
 * more information on DataONE, see our web site at http://dataone.org.
5
 *
6
 *   Copyright ${year}
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
package edu.ucsb.nceas.metacat.dataone;
21

    
22
import java.io.IOException;
23
import java.io.InputStream;
24

    
25
import org.dataone.client.exception.ClientSideException;
26
import org.dataone.client.utils.ExceptionUtils;
27
import org.dataone.client.v2.impl.MultipartCNode;
28
import org.dataone.service.exceptions.BaseException;
29
import org.dataone.service.exceptions.IdentifierNotUnique;
30
import org.dataone.service.exceptions.InvalidRequest;
31
import org.dataone.service.exceptions.InvalidToken;
32
import org.dataone.service.exceptions.NotAuthorized;
33
import org.dataone.service.exceptions.NotFound;
34
import org.dataone.service.exceptions.NotImplemented;
35
import org.dataone.service.exceptions.ServiceFailure;
36
//import org.dataone.service.exceptions.IdentifierNotUnique;
37
import org.dataone.service.types.v1.Identifier;
38
import org.dataone.service.types.v1.NodeReference;
39
import org.dataone.service.types.v1.NodeType;
40
import org.dataone.service.types.v1.Session;
41
import org.dataone.service.types.v1.Subject;
42
import org.dataone.service.types.v1.SubjectInfo;
43
import org.dataone.service.types.v2.Node;
44
import org.dataone.service.types.v2.NodeList;
45
import org.dataone.service.types.v2.SystemMetadata;
46
import org.dataone.service.util.Constants;
47
import org.dataone.service.util.D1Url;
48

    
49
/**
50
 * MockCNode mimics a DataONE Coordinating Node, and should be used only for testing
51
 * when there is a dependency on CN services
52
 */
53
public class MockCNode extends MultipartCNode {
54

    
55
    /**
56
     * See superclass for documentation
57
     */
58
    public MockCNode() throws ClientSideException, IOException {
59
        super(null);
60
        
61
    }
62
    
63
    @Override
64
	public NodeList listNodes() throws NotImplemented, ServiceFailure {
65
		NodeList list = new NodeList();
66
		list.addNode(getCapabilities());
67
		list.addNode(getTestMN());
68
		return list;
69
	}
70
    
71
    @Override
72
	public Node getCapabilities() throws NotImplemented, ServiceFailure {
73
		Node node = new Node();
74
		node.setIdentifier(getNodeId());
75
		Subject subject = new Subject();
76
		subject.setValue("cn=" + getNodeId() + ",dc=dataone,dc=org");
77
		node.addSubject(subject );
78
		node.setType(getNodeType());
79
		return node;
80
	}
81
    
82
    @Override
83
	public NodeReference getNodeId() {
84
		NodeReference nodeRef = new NodeReference();
85
		nodeRef.setValue("urn:node:MockCNode");
86
		return nodeRef ;
87
	}
88
    
89
    @Override
90
	public NodeType getNodeType() {
91
		return NodeType.CN;
92
	}
93
    
94
    @Override
95
	public String getNodeBaseServiceUrl() {
96
		return "https//:foo.dataone.org";
97
	}
98
    
99
    /**
100
     * No records exist in the Mock CNode - indicates such
101
     */
102
    @Override
103
    public SystemMetadata getSystemMetadata(Session session, Identifier pid)
104
        throws InvalidToken, NotImplemented, ServiceFailure, NotAuthorized, NotFound {
105
        throw new NotFound("0000", "MockCNode does not contain any records");
106
    }
107
    
108
    /**
109
     * Always return true that the reservation exists
110
     */
111
    @Override
112
    public boolean hasReservation(Session session, Subject subject, Identifier pid) 
113
    	throws InvalidToken, ServiceFailure, NotFound,
114
        NotAuthorized, NotImplemented {
115
    	// always return true
116
        return true;
117
    }
118
    
119
    
120
    @Override
121
    public SubjectInfo getSubjectInfo(Session session, Subject subject)
122
    throws ServiceFailure, NotAuthorized, NotImplemented, NotFound, InvalidToken {
123
        
124
        return null;
125
    }
126

    
127

    
128
    /* (non-Javadoc)
129
     * @see org.dataone.client.CNode#listSubjects(org.dataone.service.types.v1.Session, String, String, Integer, Integer)
130
     */
131
    @Override
132
    public SubjectInfo listSubjects(Session session, String query, String status, Integer start,
133
            Integer count) throws InvalidRequest, ServiceFailure, InvalidToken, NotAuthorized,
134
            NotImplemented {
135
       
136
        return null;
137
    }
138
    
139
    /*
140
     * Create a test mn in this env.
141
     */
142
    private Node getTestMN() {
143
        Node node = new Node();
144
        NodeReference nodeRef = new NodeReference();
145
        nodeRef.setValue("urn:node:test_MN-12346");
146
        node.setIdentifier(nodeRef);
147
        Subject subject = new Subject();
148
        subject.setValue("cn=" + getNodeId() + ",dc=dataone,dc=org");
149
        node.addSubject(subject );
150
        node.setType(NodeType.MN);
151
        return node;
152
    }
153
    
154
}
(5-5/8)