1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2000 Regents of the University of California and the
|
4
|
* National Center for Ecological Analysis and Synthesis
|
5
|
*
|
6
|
* '$Author: leinfelder $'
|
7
|
* '$Date: 2011-06-06 12:08:02 -0700 (Mon, 06 Jun 2011) $'
|
8
|
*
|
9
|
* This program is free software; you can redistribute it and/or modify
|
10
|
* it under the terms of the GNU General Public License as published by
|
11
|
* the Free Software Foundation; either version 2 of the License, or
|
12
|
* (at your option) any later version.
|
13
|
*
|
14
|
* This program is distributed in the hope that it will be useful,
|
15
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
* GNU General Public License for more details.
|
18
|
*
|
19
|
* You should have received a copy of the GNU General Public License
|
20
|
* along with this program; if not, write to the Free Software
|
21
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
22
|
*/
|
23
|
package edu.ucsb.nceas.metacat.dataone;
|
24
|
|
25
|
import java.util.Date;
|
26
|
import java.util.Hashtable;
|
27
|
import java.util.Timer;
|
28
|
|
29
|
import org.apache.log4j.Logger;
|
30
|
import org.dataone.service.cn.tier1.CNCore;
|
31
|
import org.dataone.service.exceptions.IdentifierNotUnique;
|
32
|
import org.dataone.service.exceptions.InsufficientResources;
|
33
|
import org.dataone.service.exceptions.InvalidRequest;
|
34
|
import org.dataone.service.exceptions.InvalidSystemMetadata;
|
35
|
import org.dataone.service.exceptions.InvalidToken;
|
36
|
import org.dataone.service.exceptions.NotAuthorized;
|
37
|
import org.dataone.service.exceptions.NotFound;
|
38
|
import org.dataone.service.exceptions.NotImplemented;
|
39
|
import org.dataone.service.exceptions.ServiceFailure;
|
40
|
import org.dataone.service.exceptions.UnsupportedType;
|
41
|
import org.dataone.service.types.Event;
|
42
|
import org.dataone.service.types.Identifier;
|
43
|
import org.dataone.service.types.Log;
|
44
|
import org.dataone.service.types.NodeList;
|
45
|
import org.dataone.service.types.ObjectFormat;
|
46
|
import org.dataone.service.types.Session;
|
47
|
import org.dataone.service.types.SystemMetadata;
|
48
|
import org.joda.time.DateTime;
|
49
|
|
50
|
import edu.ucsb.nceas.metacat.EventLog;
|
51
|
import edu.ucsb.nceas.metacat.IdentifierManager;
|
52
|
|
53
|
/**
|
54
|
*
|
55
|
* Implements DataONE MemberNode CRUD API for Metacat.
|
56
|
*
|
57
|
* @author Matthew Jones
|
58
|
*/
|
59
|
public class CNCoreImpl implements CNCore
|
60
|
{
|
61
|
private static CNCoreImpl instance = null;
|
62
|
|
63
|
private Logger logMetacat = null;
|
64
|
|
65
|
/**
|
66
|
* singleton accessor
|
67
|
*/
|
68
|
public static CNCoreImpl getInstance()
|
69
|
{
|
70
|
if (instance == null) {
|
71
|
instance = new CNCoreImpl();
|
72
|
}
|
73
|
|
74
|
return instance;
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* Constructor, private for singleton access
|
79
|
*/
|
80
|
private CNCoreImpl() {
|
81
|
logMetacat = Logger.getLogger(CNCoreImpl.class);
|
82
|
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* register System Metadata
|
87
|
*/
|
88
|
public boolean registerSystemMetaData(Session session, Identifier guid,
|
89
|
SystemMetadata sysmeta) throws NotImplemented, NotAuthorized,
|
90
|
ServiceFailure, InvalidRequest {
|
91
|
logMetacat.debug("Starting CrudService.create()...");
|
92
|
|
93
|
// TODO: control who can call this?
|
94
|
if (session == null) {
|
95
|
//TODO: many of the thrown exceptions do not use the correct error codes
|
96
|
//check these against the docs and correct them
|
97
|
throw new NotAuthorized("4861", "No Session - could not authorize to registration." +
|
98
|
" If you are not logged in, please do so and retry the request.");
|
99
|
}
|
100
|
|
101
|
// verify that guid == SystemMetadata.getIdentifier()
|
102
|
logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getValue() + "|" + sysmeta.getIdentifier().getValue());
|
103
|
if (!guid.getValue().equals(sysmeta.getIdentifier().getValue())) {
|
104
|
throw new InvalidRequest("4863",
|
105
|
"GUID in method call (" + guid.getValue() + ") does not match GUID in system metadata (" +
|
106
|
sysmeta.getIdentifier().getValue() + ").");
|
107
|
}
|
108
|
|
109
|
logMetacat.debug("Checking if identifier exists...");
|
110
|
// Check that the identifier does not already exist
|
111
|
IdentifierManager im = IdentifierManager.getInstance();
|
112
|
if (im.identifierExists(guid.getValue())) {
|
113
|
throw new InvalidRequest("4863",
|
114
|
"GUID is already in use by an existing object.");
|
115
|
}
|
116
|
|
117
|
// insert the system metadata into the object store
|
118
|
logMetacat.debug("Starting to insert SystemMetadata...");
|
119
|
sysmeta.setDateSysMetadataModified(new Date());
|
120
|
try {
|
121
|
IdentifierManager.getInstance().createSystemMetadata(sysmeta);
|
122
|
IdentifierManager.getInstance().updateSystemMetadata(sysmeta);
|
123
|
} catch (Exception e) {
|
124
|
throw new ServiceFailure("4862", "Error inserting system metadata: " + e.getClass() + ": " + e.getMessage());
|
125
|
}
|
126
|
|
127
|
logMetacat.debug("Returning from registerSystemMetadata");
|
128
|
EventLog.getInstance().log(null, session.getSubject().getValue(), guid.getValue(), "registerSystemMetadata");
|
129
|
return true;
|
130
|
}
|
131
|
|
132
|
@Override
|
133
|
public ObjectFormat getFormat(Identifier arg0) throws InvalidRequest,
|
134
|
ServiceFailure, NotFound, InsufficientResources, NotImplemented {
|
135
|
// TODO Auto-generated method stub
|
136
|
return null;
|
137
|
}
|
138
|
|
139
|
@Override
|
140
|
public Log getLogRecords(DateTime arg0, DateTime arg1, Event arg2)
|
141
|
throws InvalidToken, InvalidRequest, ServiceFailure, NotAuthorized,
|
142
|
NotImplemented {
|
143
|
// TODO Auto-generated method stub
|
144
|
return null;
|
145
|
}
|
146
|
|
147
|
@Override
|
148
|
public NodeList listNodes() throws NotImplemented, ServiceFailure {
|
149
|
// TODO Auto-generated method stub
|
150
|
return null;
|
151
|
}
|
152
|
|
153
|
}
|
154
|
|