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 org.dataone.client.v2.impl.MultipartCNode;
23
import org.dataone.service.exceptions.IdentifierNotUnique;
24
import org.dataone.service.exceptions.InvalidToken;
25
import org.dataone.service.exceptions.NotAuthorized;
26
import org.dataone.service.exceptions.NotFound;
27
import org.dataone.service.exceptions.NotImplemented;
28
import org.dataone.service.exceptions.ServiceFailure;
29
import org.dataone.service.types.v1.Identifier;
30
import org.dataone.service.types.v1.NodeReference;
31
import org.dataone.service.types.v1.NodeType;
32
import org.dataone.service.types.v1.Session;
33
import org.dataone.service.types.v1.Subject;
34
import org.dataone.service.types.v2.Node;
35
import org.dataone.service.types.v2.NodeList;
36
import org.dataone.service.types.v2.SystemMetadata;
37

    
38
/**
39
 * MockCNode mimics a DataONE Coordinating Node, and should be used only for testing
40
 * when there is a dependency on CN services
41
 */
42
public class MockCNode extends MultipartCNode {
43

    
44
    /**
45
     * See superclass for documentation
46
     */
47
    public MockCNode() {
48
    	super(null);
49
    }
50
    
51
    @Override
52
	public NodeList listNodes() throws NotImplemented, ServiceFailure {
53
		NodeList list = new NodeList();
54
		list.addNode(getCapabilities());
55
		return list;
56
	}
57
    
58
    @Override
59
	public Node getCapabilities() throws NotImplemented, ServiceFailure {
60
		Node node = new Node();
61
		node.setIdentifier(getNodeId());
62
		Subject subject = new Subject();
63
		subject.setValue("cn=" + getNodeId() + ",dc=dataone,dc=org");
64
		node.addSubject(subject );
65
		node.setType(getNodeType());
66
		return node;
67
	}
68
    
69
    @Override
70
	public NodeReference getNodeId() {
71
		NodeReference nodeRef = new NodeReference();
72
		nodeRef.setValue("urn:node:MockCNode");
73
		return nodeRef ;
74
	}
75
    
76
    @Override
77
	public NodeType getNodeType() {
78
		return NodeType.CN;
79
	}
80
    
81
    @Override
82
	public String getNodeBaseServiceUrl() {
83
		return "https//:foo.dataone.org";
84
	}
85
    
86
    /**
87
     * No records exist in the Mock CNode - indicates such
88
     */
89
    @Override
90
    public SystemMetadata getSystemMetadata(Session session, Identifier pid)
91
        throws InvalidToken, NotImplemented, ServiceFailure, NotAuthorized, NotFound {
92
        throw new NotFound("0000", "MockCNode does not contain any records");
93
    }
94
    
95
    /**
96
     * Always return true that the reservation exists
97
     */
98
    @Override
99
    public boolean hasReservation(Session session, Subject subject, Identifier pid) 
100
    	throws InvalidToken, ServiceFailure, NotFound,
101
        NotAuthorized, IdentifierNotUnique, NotImplemented {
102
    	// always return true
103
        return true;
104
    }
105
    
106
}
(5-5/8)