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
|
|
24
|
import org.dataone.client.exception.ClientSideException;
|
25
|
import org.dataone.client.v2.impl.MultipartCNode;
|
26
|
import org.dataone.service.exceptions.IdentifierNotUnique;
|
27
|
import org.dataone.service.exceptions.InvalidToken;
|
28
|
import org.dataone.service.exceptions.NotAuthorized;
|
29
|
import org.dataone.service.exceptions.NotFound;
|
30
|
import org.dataone.service.exceptions.NotImplemented;
|
31
|
import org.dataone.service.exceptions.ServiceFailure;
|
32
|
import org.dataone.service.types.v1.Identifier;
|
33
|
import org.dataone.service.types.v1.NodeReference;
|
34
|
import org.dataone.service.types.v1.NodeType;
|
35
|
import org.dataone.service.types.v1.Session;
|
36
|
import org.dataone.service.types.v1.Subject;
|
37
|
import org.dataone.service.types.v2.Node;
|
38
|
import org.dataone.service.types.v2.NodeList;
|
39
|
import org.dataone.service.types.v2.SystemMetadata;
|
40
|
|
41
|
/**
|
42
|
* MockCNode mimics a DataONE Coordinating Node, and should be used only for testing
|
43
|
* when there is a dependency on CN services
|
44
|
*/
|
45
|
public class MockCNode extends MultipartCNode {
|
46
|
|
47
|
/**
|
48
|
* See superclass for documentation
|
49
|
*/
|
50
|
public MockCNode() throws ClientSideException, IOException {
|
51
|
super(null);
|
52
|
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
public NodeList listNodes() throws NotImplemented, ServiceFailure {
|
57
|
NodeList list = new NodeList();
|
58
|
list.addNode(getCapabilities());
|
59
|
return list;
|
60
|
}
|
61
|
|
62
|
@Override
|
63
|
public Node getCapabilities() throws NotImplemented, ServiceFailure {
|
64
|
Node node = new Node();
|
65
|
node.setIdentifier(getNodeId());
|
66
|
Subject subject = new Subject();
|
67
|
subject.setValue("cn=" + getNodeId() + ",dc=dataone,dc=org");
|
68
|
node.addSubject(subject );
|
69
|
node.setType(getNodeType());
|
70
|
return node;
|
71
|
}
|
72
|
|
73
|
@Override
|
74
|
public NodeReference getNodeId() {
|
75
|
NodeReference nodeRef = new NodeReference();
|
76
|
nodeRef.setValue("urn:node:MockCNode");
|
77
|
return nodeRef ;
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public NodeType getNodeType() {
|
82
|
return NodeType.CN;
|
83
|
}
|
84
|
|
85
|
@Override
|
86
|
public String getNodeBaseServiceUrl() {
|
87
|
return "https//:foo.dataone.org";
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* No records exist in the Mock CNode - indicates such
|
92
|
*/
|
93
|
@Override
|
94
|
public SystemMetadata getSystemMetadata(Session session, Identifier pid)
|
95
|
throws InvalidToken, NotImplemented, ServiceFailure, NotAuthorized, NotFound {
|
96
|
throw new NotFound("0000", "MockCNode does not contain any records");
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* Always return true that the reservation exists
|
101
|
*/
|
102
|
@Override
|
103
|
public boolean hasReservation(Session session, Subject subject, Identifier pid)
|
104
|
throws InvalidToken, ServiceFailure, NotFound,
|
105
|
NotAuthorized, IdentifierNotUnique, NotImplemented {
|
106
|
// always return true
|
107
|
return true;
|
108
|
}
|
109
|
|
110
|
}
|