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

    
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.exceptions.IdentifierNotUnique;
33
import org.dataone.service.types.v1.Identifier;
34
import org.dataone.service.types.v1.NodeReference;
35
import org.dataone.service.types.v1.NodeType;
36
import org.dataone.service.types.v1.Session;
37
import org.dataone.service.types.v1.Subject;
38
import org.dataone.service.types.v2.Node;
39
import org.dataone.service.types.v2.NodeList;
40
import org.dataone.service.types.v2.SystemMetadata;
41

    
42
/**
43
 * MockCNode mimics a DataONE Coordinating Node, and should be used only for testing
44
 * when there is a dependency on CN services
45
 */
46
public class MockCNode extends MultipartCNode {
47

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