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