1 |
6253
|
leinfelder
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Copyright: 2011 Regents of the University of California and the
|
4 |
|
|
* National Center for Ecological Analysis and Synthesis
|
5 |
|
|
*
|
6 |
|
|
* '$Author$'
|
7 |
|
|
* '$Date$'
|
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 |
8810
|
leinfelder
|
package edu.ucsb.nceas.metacat.restservice.v2;
|
24 |
6253
|
leinfelder
|
|
25 |
|
|
import java.io.File;
|
26 |
|
|
import java.io.FileInputStream;
|
27 |
9123
|
tao
|
import java.io.FileNotFoundException;
|
28 |
6253
|
leinfelder
|
import java.io.IOException;
|
29 |
|
|
import java.io.InputStream;
|
30 |
|
|
import java.io.OutputStream;
|
31 |
|
|
import java.util.Date;
|
32 |
6622
|
leinfelder
|
import java.util.Enumeration;
|
33 |
6253
|
leinfelder
|
import java.util.Map;
|
34 |
|
|
|
35 |
|
|
import javax.servlet.ServletContext;
|
36 |
|
|
import javax.servlet.http.HttpServletRequest;
|
37 |
|
|
import javax.servlet.http.HttpServletResponse;
|
38 |
6514
|
leinfelder
|
import javax.xml.parsers.ParserConfigurationException;
|
39 |
6253
|
leinfelder
|
|
40 |
6269
|
leinfelder
|
import org.apache.commons.fileupload.FileUploadException;
|
41 |
6253
|
leinfelder
|
import org.apache.commons.io.IOUtils;
|
42 |
|
|
import org.apache.log4j.Logger;
|
43 |
8810
|
leinfelder
|
import org.dataone.client.v2.formats.ObjectFormatInfo;
|
44 |
6253
|
leinfelder
|
import org.dataone.service.exceptions.BaseException;
|
45 |
|
|
import org.dataone.service.exceptions.IdentifierNotUnique;
|
46 |
|
|
import org.dataone.service.exceptions.InsufficientResources;
|
47 |
|
|
import org.dataone.service.exceptions.InvalidRequest;
|
48 |
|
|
import org.dataone.service.exceptions.InvalidSystemMetadata;
|
49 |
|
|
import org.dataone.service.exceptions.InvalidToken;
|
50 |
|
|
import org.dataone.service.exceptions.NotAuthorized;
|
51 |
|
|
import org.dataone.service.exceptions.NotFound;
|
52 |
|
|
import org.dataone.service.exceptions.NotImplemented;
|
53 |
|
|
import org.dataone.service.exceptions.ServiceFailure;
|
54 |
|
|
import org.dataone.service.exceptions.UnsupportedType;
|
55 |
6869
|
cjones
|
import org.dataone.service.exceptions.VersionMismatch;
|
56 |
6366
|
leinfelder
|
import org.dataone.service.types.v1.AccessPolicy;
|
57 |
|
|
import org.dataone.service.types.v1.Checksum;
|
58 |
6803
|
leinfelder
|
import org.dataone.service.types.v1.ChecksumAlgorithmList;
|
59 |
|
|
import org.dataone.service.types.v1.DescribeResponse;
|
60 |
6366
|
leinfelder
|
import org.dataone.service.types.v1.Event;
|
61 |
|
|
import org.dataone.service.types.v1.Identifier;
|
62 |
8810
|
leinfelder
|
import org.dataone.service.types.v2.Log;
|
63 |
9148
|
tao
|
import org.dataone.service.types.v2.OptionList;
|
64 |
6592
|
cjones
|
import org.dataone.service.types.v1.NodeReference;
|
65 |
8810
|
leinfelder
|
import org.dataone.service.types.v2.ObjectFormat;
|
66 |
6366
|
leinfelder
|
import org.dataone.service.types.v1.ObjectFormatIdentifier;
|
67 |
8810
|
leinfelder
|
import org.dataone.service.types.v2.ObjectFormatList;
|
68 |
6622
|
leinfelder
|
import org.dataone.service.types.v1.ObjectList;
|
69 |
6366
|
leinfelder
|
import org.dataone.service.types.v1.ObjectLocationList;
|
70 |
|
|
import org.dataone.service.types.v1.Permission;
|
71 |
6592
|
cjones
|
import org.dataone.service.types.v1.Replica;
|
72 |
|
|
import org.dataone.service.types.v1.ReplicationPolicy;
|
73 |
|
|
import org.dataone.service.types.v1.ReplicationStatus;
|
74 |
6366
|
leinfelder
|
import org.dataone.service.types.v1.Subject;
|
75 |
8810
|
leinfelder
|
import org.dataone.service.types.v2.SystemMetadata;
|
76 |
6803
|
leinfelder
|
import org.dataone.service.util.Constants;
|
77 |
6469
|
leinfelder
|
import org.dataone.service.util.DateTimeMarshaller;
|
78 |
7048
|
leinfelder
|
import org.dataone.service.util.EncodingUtilities;
|
79 |
8810
|
leinfelder
|
import org.dataone.service.util.ExceptionHandler;
|
80 |
6367
|
leinfelder
|
import org.dataone.service.util.TypeMarshaller;
|
81 |
6253
|
leinfelder
|
import org.jibx.runtime.JiBXException;
|
82 |
6514
|
leinfelder
|
import org.xml.sax.SAXException;
|
83 |
6253
|
leinfelder
|
|
84 |
9148
|
tao
|
import edu.ucsb.nceas.metacat.common.query.stream.ContentTypeInputStream;
|
85 |
6253
|
leinfelder
|
import edu.ucsb.nceas.metacat.dataone.CNodeService;
|
86 |
6639
|
leinfelder
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
87 |
8810
|
leinfelder
|
import edu.ucsb.nceas.metacat.restservice.D1ResourceHandler;
|
88 |
6639
|
leinfelder
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
89 |
6253
|
leinfelder
|
|
90 |
|
|
/**
|
91 |
|
|
* CN REST service implementation handler
|
92 |
|
|
*
|
93 |
6756
|
cjones
|
* ****************** CNCore -- DONE create() - POST /d1/cn/object/PID
|
94 |
|
|
* listFormats() - GET /d1/cn/formats getFormat() - GET /d1/cn/formats/FMTID
|
95 |
|
|
* getLogRecords - GET /d1/cn/log reserveIdentifier() - POST /d1/cn/reserve
|
96 |
|
|
* listNodes() - Not implemented registerSystemMetadata() - POST /d1/meta/PID
|
97 |
|
|
*
|
98 |
|
|
* CNRead -- DONE get() - GET /d1/cn/object/PID getSystemMetadata() - GET
|
99 |
|
|
* /d1/cn/meta/PID resolve() - GET /d1/cn/resolve/PID assertRelation() - GET
|
100 |
|
|
* /d1/cn/assertRelation/PID getChecksum() - GET /d1/cn/checksum search() - Not
|
101 |
|
|
* implemented in Metacat
|
102 |
|
|
*
|
103 |
|
|
* CNAuthorization setOwner() - PUT /d1/cn/owner/PID isAuthorized() - GET
|
104 |
|
|
* /d1/cn/isAuthorized/PID setAccessPolicy() - POST /d1/cn/accessRules
|
105 |
|
|
*
|
106 |
|
|
* CNIdentity - not implemented at all on Metacat
|
107 |
|
|
*
|
108 |
|
|
* CNReplication setReplicationStatus() - PUT /replicaNotifications/PID
|
109 |
|
|
* updateReplicationMetadata() - PUT /replicaMetadata/PID setReplicationPolicy()
|
110 |
|
|
* - PUT /replicaPolicies/PID isNodeAuthorized() - GET
|
111 |
|
|
* /replicaAuthorizations/PID
|
112 |
|
|
*
|
113 |
|
|
* CNRegister -- not implemented at all in Metacat ******************
|
114 |
|
|
*
|
115 |
6253
|
leinfelder
|
* @author leinfelder
|
116 |
6756
|
cjones
|
*
|
117 |
6253
|
leinfelder
|
*/
|
118 |
6267
|
leinfelder
|
public class CNResourceHandler extends D1ResourceHandler {
|
119 |
6253
|
leinfelder
|
|
120 |
6756
|
cjones
|
/** CN-specific operations **/
|
121 |
6253
|
leinfelder
|
protected static final String RESOURCE_RESERVE = "reserve";
|
122 |
6271
|
leinfelder
|
protected static final String RESOURCE_FORMATS = "formats";
|
123 |
6253
|
leinfelder
|
protected static final String RESOURCE_RESOLVE = "resolve";
|
124 |
|
|
protected static final String RESOURCE_OWNER = "owner";
|
125 |
6592
|
cjones
|
protected static final String RESOURCE_REPLICATION_POLICY = "replicaPolicies";
|
126 |
|
|
protected static final String RESOURCE_REPLICATION_META = "replicaMetadata";
|
127 |
|
|
protected static final String RESOURCE_REPLICATION_AUTHORIZED = "replicaAuthorizations";
|
128 |
|
|
protected static final String RESOURCE_REPLICATION_NOTIFY = "replicaNotifications";
|
129 |
6756
|
cjones
|
|
130 |
6253
|
leinfelder
|
public CNResourceHandler(ServletContext servletContext,
|
131 |
6756
|
cjones
|
HttpServletRequest request, HttpServletResponse response) {
|
132 |
|
|
super(servletContext, request, response);
|
133 |
6253
|
leinfelder
|
logMetacat = Logger.getLogger(CNResourceHandler.class);
|
134 |
6756
|
cjones
|
}
|
135 |
6253
|
leinfelder
|
|
136 |
6756
|
cjones
|
/**
|
137 |
|
|
* This function is called from REST API servlet and handles each request to
|
138 |
|
|
* the servlet
|
139 |
6253
|
leinfelder
|
*
|
140 |
6756
|
cjones
|
* @param httpVerb
|
141 |
|
|
* (GET, POST, PUT or DELETE)
|
142 |
6253
|
leinfelder
|
*/
|
143 |
6271
|
leinfelder
|
@Override
|
144 |
6253
|
leinfelder
|
public void handle(byte httpVerb) {
|
145 |
6756
|
cjones
|
// prepare the handler
|
146 |
|
|
super.handle(httpVerb);
|
147 |
|
|
|
148 |
6253
|
leinfelder
|
try {
|
149 |
6282
|
leinfelder
|
|
150 |
6994
|
leinfelder
|
// only service requests if we have D1 configured
|
151 |
|
|
if (!isD1Enabled()) {
|
152 |
|
|
ServiceFailure se = new ServiceFailure("0000", "DataONE services are not enabled on this node");
|
153 |
|
|
serializeException(se, response.getOutputStream());
|
154 |
|
|
return;
|
155 |
|
|
}
|
156 |
|
|
|
157 |
6756
|
cjones
|
// get the resource
|
158 |
6282
|
leinfelder
|
String resource = request.getPathInfo();
|
159 |
|
|
resource = resource.substring(resource.indexOf("/") + 1);
|
160 |
6756
|
cjones
|
|
161 |
6396
|
leinfelder
|
// for the rest of the resouce
|
162 |
6282
|
leinfelder
|
String extra = null;
|
163 |
6756
|
cjones
|
|
164 |
|
|
logMetacat.debug("handling verb " + httpVerb
|
165 |
|
|
+ " request with resource '" + resource + "'");
|
166 |
6253
|
leinfelder
|
boolean status = false;
|
167 |
6271
|
leinfelder
|
|
168 |
6253
|
leinfelder
|
if (resource != null) {
|
169 |
|
|
|
170 |
6756
|
cjones
|
if (resource.startsWith(RESOURCE_ACCESS_RULES)
|
171 |
|
|
&& httpVerb == PUT) {
|
172 |
6253
|
leinfelder
|
logMetacat.debug("Setting access policy");
|
173 |
6514
|
leinfelder
|
// after the command
|
174 |
|
|
extra = parseTrailing(resource, RESOURCE_ACCESS_RULES);
|
175 |
9299
|
tao
|
extra = decode(extra);
|
176 |
6514
|
leinfelder
|
setAccess(extra);
|
177 |
6253
|
leinfelder
|
status = true;
|
178 |
|
|
logMetacat.debug("done setting access");
|
179 |
6756
|
cjones
|
|
180 |
6282
|
leinfelder
|
} else if (resource.startsWith(RESOURCE_META)) {
|
181 |
6253
|
leinfelder
|
logMetacat.debug("Using resource: " + RESOURCE_META);
|
182 |
6756
|
cjones
|
|
183 |
6396
|
leinfelder
|
// after the command
|
184 |
|
|
extra = parseTrailing(resource, RESOURCE_META);
|
185 |
9299
|
tao
|
extra = decode(extra);
|
186 |
6253
|
leinfelder
|
// get
|
187 |
|
|
if (httpVerb == GET) {
|
188 |
6282
|
leinfelder
|
getSystemMetadataObject(extra);
|
189 |
6253
|
leinfelder
|
status = true;
|
190 |
|
|
}
|
191 |
|
|
// post to register system metadata
|
192 |
|
|
if (httpVerb == POST) {
|
193 |
6974
|
leinfelder
|
registerSystemMetadata();
|
194 |
6756
|
cjones
|
status = true;
|
195 |
6253
|
leinfelder
|
}
|
196 |
9123
|
tao
|
else if (httpVerb == PUT) {
|
197 |
|
|
logMetacat.debug("Using resource 'meta' for PUT");
|
198 |
|
|
updateSystemMetadata();
|
199 |
|
|
status = true;
|
200 |
|
|
}
|
201 |
6253
|
leinfelder
|
|
202 |
6282
|
leinfelder
|
} else if (resource.startsWith(RESOURCE_RESERVE)) {
|
203 |
6253
|
leinfelder
|
// reserve the ID (in params)
|
204 |
|
|
if (httpVerb == POST) {
|
205 |
6756
|
cjones
|
reserve();
|
206 |
|
|
status = true;
|
207 |
6253
|
leinfelder
|
}
|
208 |
6282
|
leinfelder
|
} else if (resource.startsWith(RESOURCE_RESOLVE)) {
|
209 |
6756
|
cjones
|
|
210 |
|
|
// after the command
|
211 |
6396
|
leinfelder
|
extra = parseTrailing(resource, RESOURCE_RESOLVE);
|
212 |
9299
|
tao
|
extra = decode(extra);
|
213 |
6253
|
leinfelder
|
// resolve the object location
|
214 |
|
|
if (httpVerb == GET) {
|
215 |
6756
|
cjones
|
resolve(extra);
|
216 |
|
|
status = true;
|
217 |
6253
|
leinfelder
|
}
|
218 |
6282
|
leinfelder
|
} else if (resource.startsWith(RESOURCE_OWNER)) {
|
219 |
6756
|
cjones
|
|
220 |
|
|
// after the command
|
221 |
6396
|
leinfelder
|
extra = parseTrailing(resource, RESOURCE_OWNER);
|
222 |
9299
|
tao
|
extra = decode(extra);
|
223 |
6253
|
leinfelder
|
// set the owner
|
224 |
|
|
if (httpVerb == PUT) {
|
225 |
6756
|
cjones
|
owner(extra);
|
226 |
|
|
status = true;
|
227 |
|
|
}
|
228 |
6282
|
leinfelder
|
} else if (resource.startsWith(RESOURCE_IS_AUTHORIZED)) {
|
229 |
6756
|
cjones
|
|
230 |
|
|
// after the command
|
231 |
6396
|
leinfelder
|
extra = parseTrailing(resource, RESOURCE_IS_AUTHORIZED);
|
232 |
9299
|
tao
|
extra = decode(extra);
|
233 |
6253
|
leinfelder
|
// authorized?
|
234 |
|
|
if (httpVerb == GET) {
|
235 |
6756
|
cjones
|
isAuthorized(extra);
|
236 |
|
|
status = true;
|
237 |
|
|
}
|
238 |
6282
|
leinfelder
|
} else if (resource.startsWith(RESOURCE_OBJECTS)) {
|
239 |
6253
|
leinfelder
|
logMetacat.debug("Using resource 'object'");
|
240 |
6756
|
cjones
|
logMetacat
|
241 |
|
|
.debug("D1 Rest: Starting resource processing...");
|
242 |
|
|
|
243 |
6396
|
leinfelder
|
// after the command
|
244 |
|
|
extra = parseTrailing(resource, RESOURCE_OBJECTS);
|
245 |
9299
|
tao
|
extra = decode(extra);
|
246 |
6282
|
leinfelder
|
logMetacat.debug("objectId: " + extra);
|
247 |
6253
|
leinfelder
|
logMetacat.debug("verb:" + httpVerb);
|
248 |
|
|
|
249 |
|
|
if (httpVerb == GET) {
|
250 |
6756
|
cjones
|
if (extra != null) {
|
251 |
|
|
getObject(extra);
|
252 |
|
|
} else {
|
253 |
|
|
listObjects();
|
254 |
|
|
}
|
255 |
6253
|
leinfelder
|
status = true;
|
256 |
|
|
} else if (httpVerb == POST) {
|
257 |
6973
|
leinfelder
|
putObject(FUNCTION_NAME_INSERT);
|
258 |
6253
|
leinfelder
|
status = true;
|
259 |
6803
|
leinfelder
|
} else if (httpVerb == HEAD) {
|
260 |
|
|
describeObject(extra);
|
261 |
|
|
status = true;
|
262 |
7077
|
leinfelder
|
} else if (httpVerb == DELETE) {
|
263 |
|
|
deleteObject(extra);
|
264 |
|
|
status = true;
|
265 |
|
|
}
|
266 |
6756
|
cjones
|
|
267 |
6282
|
leinfelder
|
} else if (resource.startsWith(RESOURCE_FORMATS)) {
|
268 |
6756
|
cjones
|
logMetacat.debug("Using resource: " + RESOURCE_FORMATS);
|
269 |
|
|
|
270 |
|
|
// after the command
|
271 |
|
|
extra = parseTrailing(resource, RESOURCE_FORMATS);
|
272 |
9299
|
tao
|
extra = decode(extra);
|
273 |
6756
|
cjones
|
// handle each verb
|
274 |
|
|
if (httpVerb == GET) {
|
275 |
|
|
if (extra == null) {
|
276 |
|
|
// list the formats collection
|
277 |
|
|
listFormats();
|
278 |
|
|
} else {
|
279 |
|
|
// get the specified format
|
280 |
|
|
getFormat(extra);
|
281 |
|
|
}
|
282 |
|
|
status = true;
|
283 |
9189
|
tao
|
} else if (httpVerb == PUT) {
|
284 |
|
|
addFormat(extra);
|
285 |
6756
|
cjones
|
}
|
286 |
|
|
|
287 |
6282
|
leinfelder
|
} else if (resource.startsWith(RESOURCE_LOG)) {
|
288 |
6253
|
leinfelder
|
logMetacat.debug("Using resource: " + RESOURCE_LOG);
|
289 |
6756
|
cjones
|
// handle log events
|
290 |
6253
|
leinfelder
|
if (httpVerb == GET) {
|
291 |
|
|
getLog();
|
292 |
|
|
status = true;
|
293 |
|
|
}
|
294 |
|
|
|
295 |
7155
|
leinfelder
|
} else if (resource.startsWith(Constants.RESOURCE_ARCHIVE)) {
|
296 |
|
|
logMetacat.debug("Using resource " + Constants.RESOURCE_ARCHIVE);
|
297 |
|
|
// handle archive events
|
298 |
|
|
if (httpVerb == PUT) {
|
299 |
|
|
extra = parseTrailing(resource, Constants.RESOURCE_ARCHIVE);
|
300 |
9299
|
tao
|
extra = decode(extra);
|
301 |
7155
|
leinfelder
|
archive(extra);
|
302 |
|
|
status = true;
|
303 |
|
|
}
|
304 |
7019
|
leinfelder
|
} else if (resource.startsWith(Constants.RESOURCE_CHECKSUM)) {
|
305 |
|
|
logMetacat.debug("Using resource: " + Constants.RESOURCE_CHECKSUM);
|
306 |
6756
|
cjones
|
|
307 |
6396
|
leinfelder
|
// after the command
|
308 |
7019
|
leinfelder
|
extra = parseTrailing(resource, Constants.RESOURCE_CHECKSUM);
|
309 |
9299
|
tao
|
extra = decode(extra);
|
310 |
6756
|
cjones
|
// handle checksum requests
|
311 |
6253
|
leinfelder
|
if (httpVerb == GET) {
|
312 |
6756
|
cjones
|
|
313 |
7019
|
leinfelder
|
if (extra != null && extra.length() > 0) {
|
314 |
|
|
checksum(extra);
|
315 |
|
|
status = true;
|
316 |
|
|
} else {
|
317 |
|
|
listChecksumAlgorithms();
|
318 |
|
|
status = true;
|
319 |
|
|
}
|
320 |
6756
|
cjones
|
|
321 |
6253
|
leinfelder
|
}
|
322 |
6756
|
cjones
|
|
323 |
|
|
} else if (resource.startsWith(RESOURCE_REPLICATION_POLICY)
|
324 |
|
|
&& httpVerb == PUT) {
|
325 |
|
|
|
326 |
|
|
logMetacat.debug("Using resource: "
|
327 |
|
|
+ RESOURCE_REPLICATION_POLICY);
|
328 |
6592
|
cjones
|
// get the trailing pid
|
329 |
|
|
extra = parseTrailing(resource, RESOURCE_REPLICATION_POLICY);
|
330 |
9299
|
tao
|
extra = decode(extra);
|
331 |
6592
|
cjones
|
setReplicationPolicy(extra);
|
332 |
|
|
status = true;
|
333 |
|
|
|
334 |
6756
|
cjones
|
} else if (resource.startsWith(RESOURCE_REPLICATION_META)
|
335 |
|
|
&& httpVerb == PUT) {
|
336 |
|
|
|
337 |
|
|
logMetacat.debug("Using resource: "
|
338 |
|
|
+ RESOURCE_REPLICATION_META);
|
339 |
6592
|
cjones
|
// get the trailing pid
|
340 |
|
|
extra = parseTrailing(resource, RESOURCE_REPLICATION_META);
|
341 |
9299
|
tao
|
extra = decode(extra);
|
342 |
6592
|
cjones
|
updateReplicationMetadata(extra);
|
343 |
|
|
status = true;
|
344 |
|
|
|
345 |
6756
|
cjones
|
} else if (resource.startsWith(RESOURCE_REPLICATION_NOTIFY)
|
346 |
|
|
&& httpVerb == PUT) {
|
347 |
|
|
|
348 |
|
|
logMetacat.debug("Using resource: "
|
349 |
|
|
+ RESOURCE_REPLICATION_NOTIFY);
|
350 |
6592
|
cjones
|
// get the trailing pid
|
351 |
|
|
extra = parseTrailing(resource, RESOURCE_REPLICATION_NOTIFY);
|
352 |
9299
|
tao
|
extra = decode(extra);
|
353 |
6592
|
cjones
|
setReplicationStatus(extra);
|
354 |
|
|
status = true;
|
355 |
6756
|
cjones
|
|
356 |
|
|
} else if (resource.startsWith(RESOURCE_REPLICATION_AUTHORIZED)
|
357 |
6592
|
cjones
|
&& httpVerb == GET) {
|
358 |
6756
|
cjones
|
|
359 |
|
|
logMetacat.debug("Using resource: "
|
360 |
|
|
+ RESOURCE_REPLICATION_AUTHORIZED);
|
361 |
6592
|
cjones
|
// get the trailing pid
|
362 |
6756
|
cjones
|
extra = parseTrailing(resource,
|
363 |
|
|
RESOURCE_REPLICATION_AUTHORIZED);
|
364 |
9299
|
tao
|
extra = decode(extra);
|
365 |
6592
|
cjones
|
isNodeAuthorized(extra);
|
366 |
|
|
status = true;
|
367 |
6756
|
cjones
|
|
368 |
6803
|
leinfelder
|
} else if (resource.startsWith(Constants.RESOURCE_MONITOR_PING)) {
|
369 |
|
|
if (httpVerb == GET) {
|
370 |
|
|
// after the command
|
371 |
|
|
extra = parseTrailing(resource, Constants.RESOURCE_MONITOR_PING);
|
372 |
9299
|
tao
|
extra = decode(extra);
|
373 |
6803
|
leinfelder
|
logMetacat.debug("processing ping request");
|
374 |
|
|
Date result = CNodeService.getInstance(request).ping();
|
375 |
|
|
// TODO: send to output
|
376 |
|
|
status = true;
|
377 |
|
|
}
|
378 |
6890
|
leinfelder
|
} else if (resource.startsWith(Constants.RESOURCE_META_OBSOLETEDBY)
|
379 |
|
|
&& httpVerb == PUT) {
|
380 |
|
|
|
381 |
|
|
logMetacat.debug("Using resource: "
|
382 |
|
|
+ Constants.RESOURCE_META_OBSOLETEDBY);
|
383 |
|
|
// get the trailing pid
|
384 |
|
|
extra = parseTrailing(resource, Constants.RESOURCE_META_OBSOLETEDBY);
|
385 |
9299
|
tao
|
extra = decode(extra);
|
386 |
6890
|
leinfelder
|
setObsoletedBy(extra);
|
387 |
|
|
status = true;
|
388 |
6891
|
leinfelder
|
} else if (resource.startsWith(Constants.RESOURCE_REPLICATION_DELETE_REPLICA)
|
389 |
|
|
&& httpVerb == PUT) {
|
390 |
6890
|
leinfelder
|
|
391 |
6891
|
leinfelder
|
logMetacat.debug("Using resource: "
|
392 |
|
|
+ Constants.RESOURCE_REPLICATION_DELETE_REPLICA);
|
393 |
|
|
// get the trailing pid
|
394 |
|
|
extra = parseTrailing(resource, Constants.RESOURCE_REPLICATION_DELETE_REPLICA);
|
395 |
9299
|
tao
|
extra = decode(extra);
|
396 |
7026
|
leinfelder
|
deleteReplica(extra);
|
397 |
6891
|
leinfelder
|
status = true;
|
398 |
9148
|
tao
|
} else if (resource.startsWith(RESOURCE_VIEWS)) {
|
399 |
9245
|
tao
|
logMetacat.info("Using resource " + RESOURCE_VIEWS);
|
400 |
9148
|
tao
|
// after the command
|
401 |
|
|
extra = parseTrailing(resource, RESOURCE_VIEWS);
|
402 |
9245
|
tao
|
logMetacat.info("view extra: " + extra);
|
403 |
6756
|
cjones
|
|
404 |
9148
|
tao
|
String format = null;
|
405 |
|
|
String pid = null;
|
406 |
|
|
|
407 |
|
|
if (extra != null) {
|
408 |
|
|
// get the format
|
409 |
|
|
int formatIndex = extra.length();
|
410 |
|
|
if (extra.indexOf("/") > -1) {
|
411 |
|
|
formatIndex = extra.indexOf("/");
|
412 |
9245
|
tao
|
format = extra.substring(0, formatIndex);
|
413 |
|
|
} else {
|
414 |
|
|
throw new InvalidRequest("2853", "The request doesn't specify the name of theme.");
|
415 |
9148
|
tao
|
}
|
416 |
9299
|
tao
|
format = decode(format);
|
417 |
9245
|
tao
|
logMetacat.info("view format: " + format);
|
418 |
9148
|
tao
|
|
419 |
|
|
// get the pid if it is there
|
420 |
|
|
pid = extra.substring(formatIndex, extra.length());
|
421 |
|
|
if (pid != null && pid.length() == 0) {
|
422 |
|
|
pid = null;
|
423 |
|
|
} else {
|
424 |
|
|
if (pid.startsWith("/")) {
|
425 |
|
|
pid = pid.substring(1);
|
426 |
|
|
}
|
427 |
|
|
}
|
428 |
9299
|
tao
|
pid=decode(pid);
|
429 |
9148
|
tao
|
logMetacat.debug("pid: " + pid);
|
430 |
|
|
|
431 |
|
|
}
|
432 |
|
|
logMetacat.debug("verb:" + httpVerb);
|
433 |
|
|
if (httpVerb == GET) {
|
434 |
|
|
doViews(format, pid);
|
435 |
|
|
status = true;
|
436 |
|
|
}
|
437 |
|
|
}
|
438 |
|
|
|
439 |
6253
|
leinfelder
|
if (!status) {
|
440 |
6756
|
cjones
|
throw new ServiceFailure("0000", "Unknown error, status = "
|
441 |
|
|
+ status);
|
442 |
6253
|
leinfelder
|
}
|
443 |
|
|
} else {
|
444 |
6756
|
cjones
|
throw new InvalidRequest("0000", "No resource matched for "
|
445 |
|
|
+ resource);
|
446 |
6253
|
leinfelder
|
}
|
447 |
|
|
} catch (BaseException be) {
|
448 |
6756
|
cjones
|
// report Exceptions as clearly and generically as possible
|
449 |
|
|
OutputStream out = null;
|
450 |
|
|
try {
|
451 |
|
|
out = response.getOutputStream();
|
452 |
|
|
} catch (IOException ioe) {
|
453 |
|
|
logMetacat.error("Could not get output stream from response",
|
454 |
|
|
ioe);
|
455 |
|
|
}
|
456 |
6253
|
leinfelder
|
serializeException(be, out);
|
457 |
|
|
} catch (Exception e) {
|
458 |
6270
|
leinfelder
|
// report Exceptions as clearly and generically as possible
|
459 |
6253
|
leinfelder
|
logMetacat.error(e.getClass() + ": " + e.getMessage(), e);
|
460 |
6756
|
cjones
|
OutputStream out = null;
|
461 |
|
|
try {
|
462 |
|
|
out = response.getOutputStream();
|
463 |
|
|
} catch (IOException ioe) {
|
464 |
|
|
logMetacat.error("Could not get output stream from response",
|
465 |
|
|
ioe);
|
466 |
|
|
}
|
467 |
|
|
ServiceFailure se = new ServiceFailure("0000", e.getMessage());
|
468 |
6270
|
leinfelder
|
serializeException(se, out);
|
469 |
6253
|
leinfelder
|
}
|
470 |
|
|
}
|
471 |
6756
|
cjones
|
|
472 |
6270
|
leinfelder
|
/**
|
473 |
|
|
* Get the checksum for the given guid
|
474 |
|
|
*
|
475 |
|
|
* @param guid
|
476 |
6756
|
cjones
|
* @throws NotImplemented
|
477 |
|
|
* @throws InvalidRequest
|
478 |
|
|
* @throws NotFound
|
479 |
|
|
* @throws NotAuthorized
|
480 |
|
|
* @throws ServiceFailure
|
481 |
|
|
* @throws InvalidToken
|
482 |
|
|
* @throws IOException
|
483 |
|
|
* @throws JiBXException
|
484 |
6270
|
leinfelder
|
*/
|
485 |
6756
|
cjones
|
private void checksum(String guid) throws InvalidToken, ServiceFailure,
|
486 |
|
|
NotAuthorized, NotFound, InvalidRequest, NotImplemented,
|
487 |
|
|
JiBXException, IOException {
|
488 |
|
|
Identifier guidid = new Identifier();
|
489 |
6270
|
leinfelder
|
guidid.setValue(guid);
|
490 |
|
|
logMetacat.debug("getting checksum for object " + guid);
|
491 |
6756
|
cjones
|
Checksum c = CNodeService.getInstance(request).getChecksum(session,
|
492 |
|
|
guidid);
|
493 |
6270
|
leinfelder
|
logMetacat.debug("got checksum " + c.getValue());
|
494 |
|
|
response.setStatus(200);
|
495 |
|
|
logMetacat.debug("serializing response");
|
496 |
6367
|
leinfelder
|
TypeMarshaller.marshalTypeToOutputStream(c, response.getOutputStream());
|
497 |
6270
|
leinfelder
|
logMetacat.debug("done serializing response.");
|
498 |
6756
|
cjones
|
|
499 |
6270
|
leinfelder
|
}
|
500 |
6756
|
cjones
|
|
501 |
|
|
/**
|
502 |
|
|
* get the logs based on passed params. Available params are token,
|
503 |
|
|
* fromDate, toDate, event. See
|
504 |
|
|
* http://mule1.dataone.org/ArchitectureDocs/mn_api_crud
|
505 |
|
|
* .html#MN_crud.getLogRecords for more info
|
506 |
|
|
*
|
507 |
|
|
* @throws NotImplemented
|
508 |
|
|
* @throws InvalidRequest
|
509 |
|
|
* @throws NotAuthorized
|
510 |
|
|
* @throws ServiceFailure
|
511 |
|
|
* @throws InvalidToken
|
512 |
|
|
* @throws IOException
|
513 |
|
|
* @throws JiBXException
|
514 |
6253
|
leinfelder
|
*/
|
515 |
6756
|
cjones
|
private void getLog() throws InvalidToken, ServiceFailure, NotAuthorized,
|
516 |
|
|
InvalidRequest, NotImplemented, IOException, JiBXException {
|
517 |
|
|
|
518 |
6270
|
leinfelder
|
Date fromDate = null;
|
519 |
|
|
Date toDate = null;
|
520 |
8810
|
leinfelder
|
String event = null;
|
521 |
6270
|
leinfelder
|
Integer start = null;
|
522 |
|
|
Integer count = null;
|
523 |
7099
|
leinfelder
|
String pidFilter = null;
|
524 |
6756
|
cjones
|
|
525 |
6270
|
leinfelder
|
try {
|
526 |
6756
|
cjones
|
String fromDateS = params.get("fromDate")[0];
|
527 |
6272
|
leinfelder
|
logMetacat.debug("param fromDateS: " + fromDateS);
|
528 |
6469
|
leinfelder
|
fromDate = DateTimeMarshaller.deserializeDateToUTC(fromDateS);
|
529 |
6270
|
leinfelder
|
} catch (Exception e) {
|
530 |
6756
|
cjones
|
logMetacat.warn("Could not parse fromDate: " + e.getMessage());
|
531 |
6253
|
leinfelder
|
}
|
532 |
6270
|
leinfelder
|
try {
|
533 |
6756
|
cjones
|
String toDateS = params.get("toDate")[0];
|
534 |
6272
|
leinfelder
|
logMetacat.debug("param toDateS: " + toDateS);
|
535 |
6469
|
leinfelder
|
toDate = DateTimeMarshaller.deserializeDateToUTC(toDateS);
|
536 |
6270
|
leinfelder
|
} catch (Exception e) {
|
537 |
6756
|
cjones
|
logMetacat.warn("Could not parse toDate: " + e.getMessage());
|
538 |
|
|
}
|
539 |
6270
|
leinfelder
|
try {
|
540 |
8810
|
leinfelder
|
event = params.get("event")[0];
|
541 |
6270
|
leinfelder
|
} catch (Exception e) {
|
542 |
6756
|
cjones
|
logMetacat.warn("Could not parse event: " + e.getMessage());
|
543 |
|
|
}
|
544 |
6272
|
leinfelder
|
logMetacat.debug("fromDate: " + fromDate + " toDate: " + toDate);
|
545 |
6756
|
cjones
|
|
546 |
6270
|
leinfelder
|
try {
|
547 |
6756
|
cjones
|
start = Integer.parseInt(params.get("start")[0]);
|
548 |
6270
|
leinfelder
|
} catch (Exception e) {
|
549 |
6756
|
cjones
|
logMetacat.warn("Could not parse start: " + e.getMessage());
|
550 |
|
|
}
|
551 |
6270
|
leinfelder
|
try {
|
552 |
6756
|
cjones
|
count = Integer.parseInt(params.get("count")[0]);
|
553 |
6270
|
leinfelder
|
} catch (Exception e) {
|
554 |
6756
|
cjones
|
logMetacat.warn("Could not parse count: " + e.getMessage());
|
555 |
|
|
}
|
556 |
|
|
|
557 |
7099
|
leinfelder
|
try {
|
558 |
|
|
pidFilter = params.get("pidFilter")[0];
|
559 |
|
|
} catch (Exception e) {
|
560 |
|
|
logMetacat.warn("Could not parse pidFilter: " + e.getMessage());
|
561 |
|
|
}
|
562 |
|
|
|
563 |
6272
|
leinfelder
|
logMetacat.debug("calling getLogRecords");
|
564 |
6756
|
cjones
|
Log log = CNodeService.getInstance(request).getLogRecords(session,
|
565 |
7101
|
leinfelder
|
fromDate, toDate, event, pidFilter, start, count);
|
566 |
6756
|
cjones
|
|
567 |
6270
|
leinfelder
|
OutputStream out = response.getOutputStream();
|
568 |
|
|
response.setStatus(200);
|
569 |
|
|
response.setContentType("text/xml");
|
570 |
6756
|
cjones
|
|
571 |
6367
|
leinfelder
|
TypeMarshaller.marshalTypeToOutputStream(log, out);
|
572 |
6756
|
cjones
|
|
573 |
6253
|
leinfelder
|
}
|
574 |
|
|
|
575 |
|
|
/**
|
576 |
|
|
* Implements REST version of DataONE CRUD API --> get
|
577 |
6756
|
cjones
|
*
|
578 |
|
|
* @param guid
|
579 |
|
|
* ID of data object to be read
|
580 |
|
|
* @throws NotImplemented
|
581 |
|
|
* @throws InvalidRequest
|
582 |
|
|
* @throws NotFound
|
583 |
|
|
* @throws NotAuthorized
|
584 |
|
|
* @throws ServiceFailure
|
585 |
|
|
* @throws InvalidToken
|
586 |
|
|
* @throws IOException
|
587 |
6253
|
leinfelder
|
*/
|
588 |
6756
|
cjones
|
protected void getObject(String guid) throws InvalidToken, ServiceFailure,
|
589 |
|
|
NotAuthorized, NotFound, InvalidRequest, NotImplemented,
|
590 |
|
|
IOException {
|
591 |
6270
|
leinfelder
|
|
592 |
6280
|
leinfelder
|
Identifier id = new Identifier();
|
593 |
|
|
id.setValue(guid);
|
594 |
6756
|
cjones
|
|
595 |
|
|
SystemMetadata sm = CNodeService.getInstance(request)
|
596 |
|
|
.getSystemMetadata(session, id);
|
597 |
|
|
|
598 |
7412
|
leinfelder
|
// set the headers for the content
|
599 |
|
|
String mimeType = ObjectFormatInfo.instance().getMimeType(sm.getFormatId().getValue());
|
600 |
|
|
if (mimeType == null) {
|
601 |
|
|
mimeType = "application/octet-stream";
|
602 |
6280
|
leinfelder
|
}
|
603 |
7412
|
leinfelder
|
String extension = ObjectFormatInfo.instance().getExtension(sm.getFormatId().getValue());
|
604 |
|
|
String filename = id.getValue();
|
605 |
|
|
if (extension != null) {
|
606 |
|
|
filename = id.getValue() + extension;
|
607 |
|
|
}
|
608 |
|
|
response.setContentType(mimeType);
|
609 |
|
|
response.setHeader("Content-Disposition", "inline; filename=" + filename);
|
610 |
6756
|
cjones
|
|
611 |
6542
|
leinfelder
|
InputStream data = CNodeService.getInstance(request).get(session, id);
|
612 |
6756
|
cjones
|
|
613 |
6280
|
leinfelder
|
OutputStream out = response.getOutputStream();
|
614 |
|
|
response.setStatus(200);
|
615 |
|
|
IOUtils.copyLarge(data, out);
|
616 |
6756
|
cjones
|
|
617 |
6253
|
leinfelder
|
}
|
618 |
|
|
|
619 |
|
|
/**
|
620 |
|
|
* Implements REST version of DataONE CRUD API --> getSystemMetadata
|
621 |
6756
|
cjones
|
*
|
622 |
|
|
* @param guid
|
623 |
|
|
* ID of data object to be read
|
624 |
|
|
* @throws NotImplemented
|
625 |
|
|
* @throws InvalidRequest
|
626 |
|
|
* @throws NotFound
|
627 |
|
|
* @throws NotAuthorized
|
628 |
|
|
* @throws ServiceFailure
|
629 |
|
|
* @throws InvalidToken
|
630 |
|
|
* @throws IOException
|
631 |
|
|
* @throws JiBXException
|
632 |
6253
|
leinfelder
|
*/
|
633 |
6756
|
cjones
|
protected void getSystemMetadataObject(String guid) throws InvalidToken,
|
634 |
|
|
ServiceFailure, NotAuthorized, NotFound, InvalidRequest,
|
635 |
|
|
NotImplemented, IOException, JiBXException {
|
636 |
6270
|
leinfelder
|
|
637 |
|
|
Identifier id = new Identifier();
|
638 |
|
|
id.setValue(guid);
|
639 |
6756
|
cjones
|
SystemMetadata sysmeta = CNodeService.getInstance(request)
|
640 |
|
|
.getSystemMetadata(session, id);
|
641 |
|
|
|
642 |
6270
|
leinfelder
|
response.setContentType("text/xml");
|
643 |
|
|
response.setStatus(200);
|
644 |
|
|
OutputStream out = response.getOutputStream();
|
645 |
6756
|
cjones
|
|
646 |
6270
|
leinfelder
|
// Serialize and write it to the output stream
|
647 |
6367
|
leinfelder
|
TypeMarshaller.marshalTypeToOutputStream(sysmeta, out);
|
648 |
6756
|
cjones
|
}
|
649 |
|
|
|
650 |
6253
|
leinfelder
|
/**
|
651 |
6756
|
cjones
|
* Earthgrid API > Put Service >Put Function : calls MetacatHandler >
|
652 |
|
|
* handleInsertOrUpdateAction
|
653 |
6253
|
leinfelder
|
*
|
654 |
6756
|
cjones
|
* @param guid
|
655 |
|
|
* - ID of data object to be inserted or updated. If action is
|
656 |
|
|
* update, the pid is the existing pid. If insert, the pid is the
|
657 |
|
|
* new one
|
658 |
|
|
* @throws InvalidRequest
|
659 |
|
|
* @throws ServiceFailure
|
660 |
|
|
* @throws IdentifierNotUnique
|
661 |
|
|
* @throws JiBXException
|
662 |
|
|
* @throws NotImplemented
|
663 |
|
|
* @throws InvalidSystemMetadata
|
664 |
|
|
* @throws InsufficientResources
|
665 |
|
|
* @throws UnsupportedType
|
666 |
|
|
* @throws NotAuthorized
|
667 |
|
|
* @throws InvalidToken
|
668 |
|
|
* @throws IOException
|
669 |
|
|
* @throws IllegalAccessException
|
670 |
|
|
* @throws InstantiationException
|
671 |
6253
|
leinfelder
|
*/
|
672 |
6973
|
leinfelder
|
protected void putObject(String action) throws ServiceFailure,
|
673 |
6756
|
cjones
|
InvalidRequest, IdentifierNotUnique, JiBXException, InvalidToken,
|
674 |
|
|
NotAuthorized, UnsupportedType, InsufficientResources,
|
675 |
|
|
InvalidSystemMetadata, NotImplemented, IOException,
|
676 |
|
|
InstantiationException, IllegalAccessException {
|
677 |
6973
|
leinfelder
|
|
678 |
6269
|
leinfelder
|
// Read the incoming data from its Mime Multipart encoding
|
679 |
6756
|
cjones
|
Map<String, File> files = collectMultipartFiles();
|
680 |
6973
|
leinfelder
|
|
681 |
6974
|
leinfelder
|
// get the encoded pid string from the body and make the object
|
682 |
6975
|
leinfelder
|
String pidString = multipartparams.get("pid").get(0);
|
683 |
|
|
Identifier pid = new Identifier();
|
684 |
|
|
pid.setValue(pidString);
|
685 |
6973
|
leinfelder
|
|
686 |
|
|
logMetacat.debug("putObject: " + pid.getValue() + "/" + action);
|
687 |
|
|
|
688 |
6269
|
leinfelder
|
InputStream object = null;
|
689 |
|
|
InputStream sysmeta = null;
|
690 |
6253
|
leinfelder
|
|
691 |
6269
|
leinfelder
|
File smFile = files.get("sysmeta");
|
692 |
|
|
sysmeta = new FileInputStream(smFile);
|
693 |
|
|
File objFile = files.get("object");
|
694 |
|
|
object = new FileInputStream(objFile);
|
695 |
6253
|
leinfelder
|
|
696 |
6756
|
cjones
|
if (action.equals(FUNCTION_NAME_INSERT)) { // handle inserts
|
697 |
|
|
|
698 |
6269
|
leinfelder
|
logMetacat.debug("Commence creation...");
|
699 |
6756
|
cjones
|
SystemMetadata smd = TypeMarshaller.unmarshalTypeFromStream(
|
700 |
|
|
SystemMetadata.class, sysmeta);
|
701 |
6253
|
leinfelder
|
|
702 |
6973
|
leinfelder
|
|
703 |
|
|
logMetacat.debug("creating object with pid " + pid.getValue());
|
704 |
|
|
Identifier rId = CNodeService.getInstance(request).create(session, pid, object, smd);
|
705 |
6756
|
cjones
|
|
706 |
6269
|
leinfelder
|
OutputStream out = response.getOutputStream();
|
707 |
|
|
response.setStatus(200);
|
708 |
|
|
response.setContentType("text/xml");
|
709 |
6756
|
cjones
|
|
710 |
6367
|
leinfelder
|
TypeMarshaller.marshalTypeToOutputStream(rId, out);
|
711 |
6756
|
cjones
|
|
712 |
6269
|
leinfelder
|
} else {
|
713 |
|
|
throw new InvalidRequest("1000", "Operation must be create.");
|
714 |
6253
|
leinfelder
|
}
|
715 |
|
|
}
|
716 |
|
|
|
717 |
|
|
/**
|
718 |
|
|
* List the object formats registered with the system
|
719 |
6756
|
cjones
|
*
|
720 |
|
|
* @throws NotImplemented
|
721 |
|
|
* @throws InsufficientResources
|
722 |
|
|
* @throws NotFound
|
723 |
|
|
* @throws ServiceFailure
|
724 |
|
|
* @throws InvalidRequest
|
725 |
|
|
* @throws IOException
|
726 |
|
|
* @throws JiBXException
|
727 |
6253
|
leinfelder
|
*/
|
728 |
6756
|
cjones
|
private void listFormats() throws InvalidRequest, ServiceFailure, NotFound,
|
729 |
|
|
InsufficientResources, NotImplemented, IOException, JiBXException {
|
730 |
|
|
logMetacat.debug("Entering listFormats()");
|
731 |
6270
|
leinfelder
|
|
732 |
6756
|
cjones
|
ObjectFormatList objectFormatList = CNodeService.getInstance(request)
|
733 |
|
|
.listFormats();
|
734 |
|
|
// get the response output stream
|
735 |
|
|
OutputStream out = response.getOutputStream();
|
736 |
|
|
response.setStatus(200);
|
737 |
|
|
response.setContentType("text/xml");
|
738 |
|
|
|
739 |
|
|
// style the object with a processing directive
|
740 |
|
|
String stylesheet = null;
|
741 |
|
|
try {
|
742 |
9237
|
leinfelder
|
stylesheet = PropertyService.getProperty("dataone.types.xsl.v2");
|
743 |
6756
|
cjones
|
} catch (PropertyNotFoundException e) {
|
744 |
|
|
logMetacat.warn("Could not locate DataONE types XSLT: "
|
745 |
|
|
+ e.getMessage());
|
746 |
|
|
}
|
747 |
|
|
|
748 |
|
|
TypeMarshaller.marshalTypeToOutputStream(objectFormatList, out,
|
749 |
|
|
stylesheet);
|
750 |
|
|
|
751 |
6253
|
leinfelder
|
}
|
752 |
6803
|
leinfelder
|
|
753 |
|
|
private void listChecksumAlgorithms() throws IOException, ServiceFailure,
|
754 |
|
|
NotImplemented, JiBXException {
|
755 |
|
|
logMetacat.debug("Entering listFormats()");
|
756 |
6253
|
leinfelder
|
|
757 |
6803
|
leinfelder
|
ChecksumAlgorithmList result = CNodeService.getInstance(request).listChecksumAlgorithms();
|
758 |
|
|
|
759 |
|
|
// get the response output stream
|
760 |
|
|
OutputStream out = response.getOutputStream();
|
761 |
|
|
response.setStatus(200);
|
762 |
|
|
response.setContentType("text/xml");
|
763 |
|
|
|
764 |
7034
|
leinfelder
|
TypeMarshaller.marshalTypeToOutputStream(result, out);
|
765 |
6803
|
leinfelder
|
|
766 |
|
|
}
|
767 |
|
|
|
768 |
6756
|
cjones
|
/**
|
769 |
6803
|
leinfelder
|
* http://mule1.dataone.org/ArchitectureDocs-current/apis/CN_APIs.html#CNRead.describe
|
770 |
|
|
* @param pid
|
771 |
|
|
* @throws InvalidToken
|
772 |
|
|
* @throws ServiceFailure
|
773 |
|
|
* @throws NotAuthorized
|
774 |
|
|
* @throws NotFound
|
775 |
|
|
* @throws NotImplemented
|
776 |
|
|
* @throws InvalidRequest
|
777 |
|
|
*/
|
778 |
|
|
private void describeObject(String pid) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented, InvalidRequest
|
779 |
|
|
{
|
780 |
|
|
response.setContentType("text/xml");
|
781 |
|
|
|
782 |
|
|
Identifier id = new Identifier();
|
783 |
|
|
id.setValue(pid);
|
784 |
7043
|
leinfelder
|
|
785 |
|
|
DescribeResponse dr = null;
|
786 |
|
|
try {
|
787 |
|
|
dr = CNodeService.getInstance(request).describe(session, id);
|
788 |
|
|
} catch (BaseException e) {
|
789 |
|
|
response.setStatus(e.getCode());
|
790 |
|
|
response.addHeader("DataONE-Exception-Name", e.getClass().getName());
|
791 |
|
|
response.addHeader("DataONE-Exception-DetailCode", e.getDetail_code());
|
792 |
|
|
response.addHeader("DataONE-Exception-Description", e.getDescription());
|
793 |
|
|
response.addHeader("DataONE-Exception-PID", id.getValue());
|
794 |
|
|
return;
|
795 |
|
|
}
|
796 |
|
|
|
797 |
|
|
response.setStatus(200);
|
798 |
6803
|
leinfelder
|
//response.addHeader("pid", pid);
|
799 |
|
|
response.addHeader("DataONE-Checksum", dr.getDataONE_Checksum().getAlgorithm() + "," + dr.getDataONE_Checksum().getValue());
|
800 |
|
|
response.addHeader("Content-Length", dr.getContent_Length() + "");
|
801 |
|
|
response.addHeader("Last-Modified", DateTimeMarshaller.serializeDateToUTC(dr.getLast_Modified()));
|
802 |
|
|
response.addHeader("DataONE-ObjectFormat", dr.getDataONE_ObjectFormatIdentifier().getValue());
|
803 |
|
|
response.addHeader("DataONE-SerialVersion", dr.getSerialVersion().toString());
|
804 |
|
|
|
805 |
|
|
}
|
806 |
7077
|
leinfelder
|
|
807 |
|
|
/**
|
808 |
|
|
* Handle delete
|
809 |
|
|
* @param pid ID of data object to be deleted
|
810 |
|
|
* @throws IOException
|
811 |
|
|
* @throws InvalidRequest
|
812 |
|
|
* @throws NotImplemented
|
813 |
|
|
* @throws NotFound
|
814 |
|
|
* @throws NotAuthorized
|
815 |
|
|
* @throws ServiceFailure
|
816 |
|
|
* @throws InvalidToken
|
817 |
|
|
* @throws JiBXException
|
818 |
|
|
*/
|
819 |
|
|
private void deleteObject(String pid) throws IOException, InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented, InvalidRequest, JiBXException
|
820 |
|
|
{
|
821 |
6803
|
leinfelder
|
|
822 |
7077
|
leinfelder
|
OutputStream out = response.getOutputStream();
|
823 |
|
|
response.setStatus(200);
|
824 |
|
|
response.setContentType("text/xml");
|
825 |
|
|
|
826 |
|
|
Identifier id = new Identifier();
|
827 |
|
|
id.setValue(pid);
|
828 |
|
|
|
829 |
7090
|
cjones
|
logMetacat.debug("Calling delete for identifier " + pid);
|
830 |
7077
|
leinfelder
|
CNodeService.getInstance(request).delete(session, id);
|
831 |
|
|
TypeMarshaller.marshalTypeToOutputStream(id, out);
|
832 |
|
|
|
833 |
|
|
}
|
834 |
7155
|
leinfelder
|
|
835 |
|
|
/**
|
836 |
|
|
* Archives the given pid
|
837 |
|
|
* @param pid
|
838 |
|
|
* @throws InvalidToken
|
839 |
|
|
* @throws ServiceFailure
|
840 |
|
|
* @throws NotAuthorized
|
841 |
|
|
* @throws NotFound
|
842 |
|
|
* @throws NotImplemented
|
843 |
|
|
* @throws IOException
|
844 |
|
|
* @throws JiBXException
|
845 |
|
|
*/
|
846 |
|
|
private void archive(String pid) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented, IOException, JiBXException {
|
847 |
7077
|
leinfelder
|
|
848 |
7155
|
leinfelder
|
OutputStream out = response.getOutputStream();
|
849 |
|
|
response.setStatus(200);
|
850 |
|
|
response.setContentType("text/xml");
|
851 |
|
|
|
852 |
|
|
Identifier id = new Identifier();
|
853 |
|
|
id.setValue(pid);
|
854 |
|
|
|
855 |
|
|
logMetacat.debug("Calling archive");
|
856 |
|
|
CNodeService.getInstance(request).archive(session, id);
|
857 |
|
|
|
858 |
|
|
TypeMarshaller.marshalTypeToOutputStream(id, out);
|
859 |
|
|
|
860 |
|
|
}
|
861 |
|
|
|
862 |
6803
|
leinfelder
|
/**
|
863 |
6253
|
leinfelder
|
* Return the requested object format
|
864 |
|
|
*
|
865 |
6756
|
cjones
|
* @param fmtidStr
|
866 |
|
|
* the requested format identifier as a string
|
867 |
|
|
* @throws NotImplemented
|
868 |
|
|
* @throws InsufficientResources
|
869 |
|
|
* @throws NotFound
|
870 |
|
|
* @throws ServiceFailure
|
871 |
|
|
* @throws InvalidRequest
|
872 |
|
|
* @throws IOException
|
873 |
|
|
* @throws JiBXException
|
874 |
6253
|
leinfelder
|
*/
|
875 |
6756
|
cjones
|
private void getFormat(String fmtidStr) throws InvalidRequest,
|
876 |
|
|
ServiceFailure, NotFound, InsufficientResources, NotImplemented,
|
877 |
|
|
IOException, JiBXException {
|
878 |
|
|
logMetacat.debug("Entering listFormats()");
|
879 |
|
|
|
880 |
|
|
ObjectFormatIdentifier fmtid = new ObjectFormatIdentifier();
|
881 |
|
|
fmtid.setValue(fmtidStr);
|
882 |
|
|
|
883 |
|
|
// get the specified object format
|
884 |
|
|
ObjectFormat objectFormat = CNodeService.getInstance(request)
|
885 |
|
|
.getFormat(fmtid);
|
886 |
|
|
|
887 |
|
|
OutputStream out = response.getOutputStream();
|
888 |
|
|
response.setStatus(200);
|
889 |
|
|
response.setContentType("text/xml");
|
890 |
|
|
|
891 |
|
|
TypeMarshaller.marshalTypeToOutputStream(objectFormat, out);
|
892 |
|
|
|
893 |
6253
|
leinfelder
|
}
|
894 |
6756
|
cjones
|
|
895 |
6253
|
leinfelder
|
/**
|
896 |
9189
|
tao
|
* Adds a new {@link ObjectFormat} to the object format list.
|
897 |
|
|
*
|
898 |
|
|
* @param formatIdStr the format identifier
|
899 |
|
|
*
|
900 |
|
|
* @throws NotImplemented
|
901 |
|
|
* @throws InvalidRequest
|
902 |
|
|
* @throws ServiceFailure
|
903 |
|
|
* @throws JiBXException
|
904 |
|
|
* @throws IOException
|
905 |
|
|
* @throws IllegalAccessException
|
906 |
|
|
* @throws InstantiationException
|
907 |
|
|
* @throws NotFound
|
908 |
|
|
* @throws NotAuthorized
|
909 |
|
|
* @throws InvalidToken
|
910 |
|
|
*/
|
911 |
|
|
private void addFormat(String formatIdStr)
|
912 |
|
|
throws NotImplemented, ServiceFailure, InvalidRequest, InstantiationException,
|
913 |
|
|
IllegalAccessException, IOException, JiBXException, NotFound, NotAuthorized, InvalidToken {
|
914 |
|
|
|
915 |
|
|
logMetacat.debug("addFormat: " + formatIdStr);
|
916 |
|
|
|
917 |
|
|
Map<String, File> files = collectMultipartFiles();
|
918 |
|
|
File formatFile = files.get("format");
|
919 |
|
|
FileInputStream formatStream = new FileInputStream(formatFile);
|
920 |
|
|
ObjectFormat objectFormat = TypeMarshaller.unmarshalTypeFromStream(ObjectFormat.class, formatStream);
|
921 |
|
|
ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
|
922 |
|
|
formatId.setValue(formatIdStr);
|
923 |
|
|
|
924 |
|
|
ObjectFormatIdentifier formatID = CNodeService.getInstance(request).addFormat(session, formatId, objectFormat);
|
925 |
|
|
|
926 |
|
|
OutputStream out = response.getOutputStream();
|
927 |
|
|
response.setStatus(200);
|
928 |
|
|
response.setContentType("text/xml");
|
929 |
|
|
TypeMarshaller.marshalTypeToOutputStream(formatID, out);
|
930 |
|
|
}
|
931 |
|
|
|
932 |
|
|
/**
|
933 |
6253
|
leinfelder
|
* Reserve the given Identifier
|
934 |
6756
|
cjones
|
*
|
935 |
6253
|
leinfelder
|
* @throws InvalidToken
|
936 |
|
|
* @throws ServiceFailure
|
937 |
|
|
* @throws NotAuthorized
|
938 |
|
|
* @throws IdentifierNotUnique
|
939 |
|
|
* @throws NotImplemented
|
940 |
|
|
* @throws InvalidRequest
|
941 |
|
|
*/
|
942 |
7095
|
cjones
|
private void reserve()
|
943 |
|
|
throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique,
|
944 |
|
|
NotImplemented, InvalidRequest {
|
945 |
6756
|
cjones
|
Identifier pid = null;
|
946 |
|
|
String scope = null;
|
947 |
|
|
String format = null;
|
948 |
7095
|
cjones
|
|
949 |
|
|
// Parse the params out of the multipart form data
|
950 |
|
|
logMetacat.debug("Parsing reserve parameters from the mime multipart entity");
|
951 |
|
|
try {
|
952 |
|
|
collectMultipartParams();
|
953 |
|
|
|
954 |
|
|
} catch (FileUploadException e1) {
|
955 |
|
|
String msg = "FileUploadException: Couldn't parse the mime multipart information: " +
|
956 |
|
|
e1.getMessage();
|
957 |
|
|
logMetacat.debug(msg);
|
958 |
|
|
throw new ServiceFailure("4210", msg);
|
959 |
|
|
|
960 |
|
|
} catch (IOException e1) {
|
961 |
|
|
String msg = "IOException: Couldn't parse the mime multipart information: " +
|
962 |
|
|
e1.getMessage();
|
963 |
|
|
logMetacat.debug(msg);
|
964 |
|
|
throw new ServiceFailure("4210", msg);
|
965 |
|
|
|
966 |
|
|
} catch (Exception e1) {
|
967 |
|
|
String msg = "Exception: Couldn't parse the mime multipart information: " +
|
968 |
|
|
e1.getMessage();
|
969 |
|
|
logMetacat.debug(msg);
|
970 |
|
|
throw new ServiceFailure("4210", msg);
|
971 |
|
|
|
972 |
|
|
}
|
973 |
|
|
|
974 |
6756
|
cjones
|
// gather the params
|
975 |
|
|
try {
|
976 |
7095
|
cjones
|
String id = multipartparams.get("pid").get(0);
|
977 |
6756
|
cjones
|
pid = new Identifier();
|
978 |
|
|
pid.setValue(id);
|
979 |
7095
|
cjones
|
|
980 |
|
|
} catch (NullPointerException e) {
|
981 |
|
|
String msg = "The 'pid' must be provided as a parameter and was not.";
|
982 |
|
|
logMetacat.error(msg);
|
983 |
|
|
throw new InvalidRequest("4200", msg);
|
984 |
|
|
|
985 |
6756
|
cjones
|
}
|
986 |
7095
|
cjones
|
|
987 |
|
|
// call the implementation
|
988 |
6756
|
cjones
|
try {
|
989 |
7095
|
cjones
|
Identifier resultPid = CNodeService.getInstance(request).reserveIdentifier(session, pid);
|
990 |
|
|
OutputStream out = response.getOutputStream();
|
991 |
|
|
response.setStatus(200);
|
992 |
|
|
response.setContentType("text/xml");
|
993 |
|
|
// send back the reserved pid
|
994 |
|
|
TypeMarshaller.marshalTypeToOutputStream(resultPid, out);
|
995 |
|
|
|
996 |
|
|
} catch (IOException e) {
|
997 |
|
|
String msg = "Couldn't write the identifier to the response output stream: " +
|
998 |
|
|
e.getMessage();
|
999 |
|
|
logMetacat.debug(msg);
|
1000 |
|
|
throw new ServiceFailure("4210", msg);
|
1001 |
|
|
|
1002 |
|
|
} catch (JiBXException e) {
|
1003 |
|
|
String msg = "Couldn't marshall the identifier to the response output stream: " +
|
1004 |
|
|
e.getMessage();
|
1005 |
|
|
logMetacat.debug(msg);
|
1006 |
|
|
throw new ServiceFailure("4210", msg);
|
1007 |
|
|
|
1008 |
6756
|
cjones
|
}
|
1009 |
6253
|
leinfelder
|
}
|
1010 |
6756
|
cjones
|
|
1011 |
6270
|
leinfelder
|
/**
|
1012 |
|
|
*
|
1013 |
|
|
* @param id
|
1014 |
|
|
* @throws InvalidRequest
|
1015 |
|
|
* @throws InvalidToken
|
1016 |
|
|
* @throws ServiceFailure
|
1017 |
|
|
* @throws NotAuthorized
|
1018 |
|
|
* @throws NotFound
|
1019 |
|
|
* @throws NotImplemented
|
1020 |
|
|
* @throws IOException
|
1021 |
6756
|
cjones
|
* @throws JiBXException
|
1022 |
6270
|
leinfelder
|
*/
|
1023 |
6756
|
cjones
|
private void resolve(String id) throws InvalidRequest, InvalidToken,
|
1024 |
|
|
ServiceFailure, NotAuthorized, NotFound, NotImplemented,
|
1025 |
|
|
IOException, JiBXException {
|
1026 |
|
|
Identifier pid = new Identifier();
|
1027 |
|
|
pid.setValue(id);
|
1028 |
|
|
ObjectLocationList locationList = CNodeService.getInstance(request)
|
1029 |
|
|
.resolve(session, pid);
|
1030 |
|
|
OutputStream out = response.getOutputStream();
|
1031 |
|
|
response.setStatus(200);
|
1032 |
|
|
response.setContentType("text/xml");
|
1033 |
|
|
TypeMarshaller.marshalTypeToOutputStream(locationList, out);
|
1034 |
|
|
|
1035 |
6253
|
leinfelder
|
}
|
1036 |
|
|
|
1037 |
6270
|
leinfelder
|
/**
|
1038 |
|
|
* Set the owner of a resource
|
1039 |
6756
|
cjones
|
*
|
1040 |
6270
|
leinfelder
|
* @param id
|
1041 |
|
|
* @throws InvalidToken
|
1042 |
|
|
* @throws ServiceFailure
|
1043 |
|
|
* @throws NotFound
|
1044 |
|
|
* @throws NotAuthorized
|
1045 |
|
|
* @throws NotImplemented
|
1046 |
|
|
* @throws InvalidRequest
|
1047 |
6756
|
cjones
|
* @throws IllegalAccessException
|
1048 |
|
|
* @throws InstantiationException
|
1049 |
6869
|
cjones
|
* @throws VersionMismatch
|
1050 |
6270
|
leinfelder
|
*/
|
1051 |
7093
|
cjones
|
private void owner(String id)
|
1052 |
7094
|
cjones
|
throws InvalidToken, ServiceFailure, NotFound, NotAuthorized,
|
1053 |
|
|
NotImplemented, InvalidRequest, InstantiationException,
|
1054 |
7093
|
cjones
|
IllegalAccessException, VersionMismatch {
|
1055 |
6756
|
cjones
|
|
1056 |
6592
|
cjones
|
Identifier pid = new Identifier();
|
1057 |
6756
|
cjones
|
pid.setValue(id);
|
1058 |
6592
|
cjones
|
|
1059 |
|
|
long serialVersion = 0L;
|
1060 |
|
|
String serialVersionStr = null;
|
1061 |
7093
|
cjones
|
String userIdStr = null;
|
1062 |
|
|
Subject userId = null;
|
1063 |
|
|
|
1064 |
|
|
// Parse the params out of the multipart form data
|
1065 |
|
|
// Read the incoming data from its Mime Multipart encoding
|
1066 |
|
|
logMetacat.debug("Parsing rights holder parameters from the mime multipart entity");
|
1067 |
|
|
try {
|
1068 |
|
|
collectMultipartParams();
|
1069 |
|
|
|
1070 |
|
|
} catch (FileUploadException e1) {
|
1071 |
|
|
String msg = "FileUploadException: Couldn't parse the mime multipart information: " +
|
1072 |
|
|
e1.getMessage();
|
1073 |
|
|
logMetacat.debug(msg);
|
1074 |
|
|
throw new ServiceFailure("4490", msg);
|
1075 |
6756
|
cjones
|
|
1076 |
7093
|
cjones
|
} catch (IOException e1) {
|
1077 |
|
|
String msg = "IOException: Couldn't parse the mime multipart information: " +
|
1078 |
|
|
e1.getMessage();
|
1079 |
|
|
logMetacat.debug(msg);
|
1080 |
|
|
throw new ServiceFailure("4490", msg);
|
1081 |
|
|
|
1082 |
|
|
} catch (Exception e1) {
|
1083 |
|
|
String msg = "Exception: Couldn't parse the mime multipart information: " +
|
1084 |
|
|
e1.getMessage();
|
1085 |
|
|
logMetacat.debug(msg);
|
1086 |
|
|
throw new ServiceFailure("4490", msg);
|
1087 |
|
|
|
1088 |
|
|
}
|
1089 |
|
|
|
1090 |
6592
|
cjones
|
// get the serialVersion
|
1091 |
|
|
try {
|
1092 |
7093
|
cjones
|
serialVersionStr = multipartparams.get("serialVersion").get(0);
|
1093 |
6592
|
cjones
|
serialVersion = new Long(serialVersionStr).longValue();
|
1094 |
7093
|
cjones
|
|
1095 |
|
|
} catch (NumberFormatException nfe) {
|
1096 |
|
|
String msg = "The 'serialVersion' must be provided as a positive integer and was not.";
|
1097 |
|
|
logMetacat.error(msg);
|
1098 |
|
|
throw new InvalidRequest("4442", msg);
|
1099 |
|
|
|
1100 |
|
|
} catch (NullPointerException e) {
|
1101 |
|
|
String msg = "The 'serialVersion' must be provided as a parameter and was not.";
|
1102 |
|
|
logMetacat.error(msg);
|
1103 |
|
|
throw new InvalidRequest("4442", msg);
|
1104 |
|
|
|
1105 |
|
|
}
|
1106 |
6756
|
cjones
|
|
1107 |
7093
|
cjones
|
// get the subject userId that will become the rights holder
|
1108 |
|
|
try {
|
1109 |
|
|
userIdStr = multipartparams.get("userId").get(0);
|
1110 |
|
|
userId = new Subject();
|
1111 |
|
|
userId.setValue(userIdStr);
|
1112 |
|
|
|
1113 |
6592
|
cjones
|
} catch (NullPointerException e) {
|
1114 |
|
|
String msg = "The 'serialVersion' must be provided as a parameter and was not.";
|
1115 |
|
|
logMetacat.error(msg);
|
1116 |
|
|
throw new InvalidRequest("4442", msg);
|
1117 |
7093
|
cjones
|
|
1118 |
|
|
}
|
1119 |
6756
|
cjones
|
|
1120 |
7093
|
cjones
|
// set the rights holder
|
1121 |
|
|
Identifier retPid = CNodeService.getInstance(request).setRightsHolder(session, pid, userId, serialVersion);
|
1122 |
|
|
|
1123 |
|
|
try {
|
1124 |
|
|
OutputStream out = response.getOutputStream();
|
1125 |
|
|
response.setStatus(200);
|
1126 |
|
|
response.setContentType("text/xml");
|
1127 |
|
|
TypeMarshaller.marshalTypeToOutputStream(retPid, out);
|
1128 |
|
|
|
1129 |
|
|
} catch (IOException e) {
|
1130 |
|
|
String msg = "Couldn't write the identifier to the response output stream: " +
|
1131 |
|
|
e.getMessage();
|
1132 |
|
|
logMetacat.debug(msg);
|
1133 |
|
|
throw new ServiceFailure("4490", msg);
|
1134 |
7094
|
cjones
|
|
1135 |
|
|
} catch (JiBXException e) {
|
1136 |
|
|
String msg = "Couldn't marshall the identifier to the response output stream: " +
|
1137 |
|
|
e.getMessage();
|
1138 |
|
|
logMetacat.debug(msg);
|
1139 |
|
|
throw new ServiceFailure("4490", msg);
|
1140 |
|
|
|
1141 |
6756
|
cjones
|
}
|
1142 |
6253
|
leinfelder
|
}
|
1143 |
6756
|
cjones
|
|
1144 |
6270
|
leinfelder
|
/**
|
1145 |
|
|
* Processes the authorization check for given id
|
1146 |
6756
|
cjones
|
*
|
1147 |
6270
|
leinfelder
|
* @param id
|
1148 |
|
|
* @return
|
1149 |
|
|
* @throws ServiceFailure
|
1150 |
|
|
* @throws InvalidToken
|
1151 |
|
|
* @throws NotFound
|
1152 |
|
|
* @throws NotAuthorized
|
1153 |
|
|
* @throws NotImplemented
|
1154 |
|
|
* @throws InvalidRequest
|
1155 |
|
|
*/
|
1156 |
6756
|
cjones
|
private boolean isAuthorized(String id) throws ServiceFailure,
|
1157 |
|
|
InvalidToken, NotFound, NotAuthorized, NotImplemented,
|
1158 |
|
|
InvalidRequest {
|
1159 |
|
|
Identifier pid = new Identifier();
|
1160 |
|
|
pid.setValue(id);
|
1161 |
|
|
String permission = params.get("action")[0];
|
1162 |
|
|
boolean result = CNodeService.getInstance(request).isAuthorized(
|
1163 |
|
|
session, pid, Permission.convert(permission));
|
1164 |
|
|
response.setStatus(200);
|
1165 |
|
|
response.setContentType("text/xml");
|
1166 |
|
|
return result;
|
1167 |
6253
|
leinfelder
|
}
|
1168 |
6756
|
cjones
|
|
1169 |
6253
|
leinfelder
|
/**
|
1170 |
|
|
* Register System Metadata without data or metadata object
|
1171 |
6756
|
cjones
|
*
|
1172 |
|
|
* @param pid
|
1173 |
|
|
* identifier for System Metadata entry
|
1174 |
|
|
* @throws JiBXException
|
1175 |
|
|
* @throws FileUploadException
|
1176 |
|
|
* @throws IOException
|
1177 |
|
|
* @throws InvalidRequest
|
1178 |
|
|
* @throws ServiceFailure
|
1179 |
|
|
* @throws InvalidSystemMetadata
|
1180 |
|
|
* @throws NotAuthorized
|
1181 |
|
|
* @throws NotImplemented
|
1182 |
|
|
* @throws IllegalAccessException
|
1183 |
|
|
* @throws InstantiationException
|
1184 |
6253
|
leinfelder
|
*/
|
1185 |
6974
|
leinfelder
|
protected void registerSystemMetadata()
|
1186 |
6756
|
cjones
|
throws ServiceFailure, InvalidRequest, IOException,
|
1187 |
|
|
FileUploadException, JiBXException, NotImplemented, NotAuthorized,
|
1188 |
|
|
InvalidSystemMetadata, InstantiationException,
|
1189 |
|
|
IllegalAccessException {
|
1190 |
6974
|
leinfelder
|
|
1191 |
|
|
// Read the incoming data from its Mime Multipart encoding
|
1192 |
|
|
Map<String, File> files = collectMultipartFiles();
|
1193 |
|
|
|
1194 |
|
|
// get the encoded pid string from the body and make the object
|
1195 |
6975
|
leinfelder
|
String pidString = multipartparams.get("pid").get(0);
|
1196 |
|
|
Identifier pid = new Identifier();
|
1197 |
|
|
pid.setValue(pidString);
|
1198 |
6974
|
leinfelder
|
|
1199 |
|
|
logMetacat.debug("registerSystemMetadata: " + pid);
|
1200 |
6253
|
leinfelder
|
|
1201 |
6756
|
cjones
|
// get the system metadata from the request
|
1202 |
6974
|
leinfelder
|
File smFile = files.get("sysmeta");
|
1203 |
|
|
FileInputStream sysmeta = new FileInputStream(smFile);
|
1204 |
|
|
SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromStream(SystemMetadata.class, sysmeta);
|
1205 |
6253
|
leinfelder
|
|
1206 |
6974
|
leinfelder
|
logMetacat.debug("registering system metadata with pid " + pid.getValue());
|
1207 |
|
|
Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, pid, systemMetadata);
|
1208 |
6756
|
cjones
|
|
1209 |
6880
|
leinfelder
|
OutputStream out = response.getOutputStream();
|
1210 |
6756
|
cjones
|
response.setStatus(200);
|
1211 |
|
|
response.setContentType("text/xml");
|
1212 |
6880
|
leinfelder
|
|
1213 |
|
|
TypeMarshaller.marshalTypeToOutputStream(retGuid, out);
|
1214 |
6756
|
cjones
|
|
1215 |
|
|
}
|
1216 |
|
|
|
1217 |
6268
|
leinfelder
|
/**
|
1218 |
|
|
* set the access perms on a document
|
1219 |
6756
|
cjones
|
*
|
1220 |
|
|
* @throws JiBXException
|
1221 |
|
|
* @throws InvalidRequest
|
1222 |
|
|
* @throws NotImplemented
|
1223 |
|
|
* @throws NotAuthorized
|
1224 |
|
|
* @throws NotFound
|
1225 |
|
|
* @throws ServiceFailure
|
1226 |
|
|
* @throws InvalidToken
|
1227 |
|
|
* @throws IllegalAccessException
|
1228 |
|
|
* @throws InstantiationException
|
1229 |
|
|
* @throws IOException
|
1230 |
|
|
* @throws SAXException
|
1231 |
|
|
* @throws ParserConfigurationException
|
1232 |
6869
|
cjones
|
* @throws VersionMismatch
|
1233 |
6268
|
leinfelder
|
*/
|
1234 |
6756
|
cjones
|
protected void setAccess(String pid) throws JiBXException, InvalidToken,
|
1235 |
|
|
ServiceFailure, NotFound, NotAuthorized, NotImplemented,
|
1236 |
|
|
InvalidRequest, IOException, InstantiationException,
|
1237 |
6869
|
cjones
|
IllegalAccessException, ParserConfigurationException, SAXException, VersionMismatch {
|
1238 |
6270
|
leinfelder
|
|
1239 |
6592
|
cjones
|
long serialVersion = 0L;
|
1240 |
|
|
String serialVersionStr = null;
|
1241 |
8810
|
leinfelder
|
|
1242 |
|
|
// parse the accessPolicy
|
1243 |
|
|
Map<String, File> files = collectMultipartFiles();
|
1244 |
|
|
AccessPolicy accessPolicy = TypeMarshaller.unmarshalTypeFromFile(AccessPolicy.class, files.get("accessPolicy"));;
|
1245 |
6756
|
cjones
|
|
1246 |
6592
|
cjones
|
// get the serialVersion
|
1247 |
|
|
try {
|
1248 |
7090
|
cjones
|
serialVersionStr = multipartparams.get("serialVersion").get(0);
|
1249 |
6592
|
cjones
|
serialVersion = new Long(serialVersionStr).longValue();
|
1250 |
6756
|
cjones
|
|
1251 |
7090
|
cjones
|
} catch (NumberFormatException nfe) {
|
1252 |
|
|
String msg = "The 'serialVersion' must be provided as a positive integer and was not.";
|
1253 |
|
|
logMetacat.error(msg);
|
1254 |
|
|
throw new InvalidRequest("4402", msg);
|
1255 |
|
|
|
1256 |
6592
|
cjones
|
} catch (NullPointerException e) {
|
1257 |
|
|
String msg = "The 'serialVersion' must be provided as a parameter and was not.";
|
1258 |
|
|
logMetacat.error(msg);
|
1259 |
|
|
throw new InvalidRequest("4402", msg);
|
1260 |
6756
|
cjones
|
|
1261 |
6592
|
cjones
|
}
|
1262 |
6756
|
cjones
|
|
1263 |
6270
|
leinfelder
|
Identifier id = new Identifier();
|
1264 |
6514
|
leinfelder
|
id.setValue(pid);
|
1265 |
6756
|
cjones
|
|
1266 |
|
|
CNodeService.getInstance(request).setAccessPolicy(session, id,
|
1267 |
|
|
accessPolicy, serialVersion);
|
1268 |
6270
|
leinfelder
|
|
1269 |
6268
|
leinfelder
|
}
|
1270 |
6756
|
cjones
|
|
1271 |
6268
|
leinfelder
|
/**
|
1272 |
6756
|
cjones
|
* List the objects
|
1273 |
|
|
*
|
1274 |
|
|
* @throws NotImplemented
|
1275 |
|
|
* @throws InvalidRequest
|
1276 |
|
|
* @throws NotAuthorized
|
1277 |
|
|
* @throws ServiceFailure
|
1278 |
|
|
* @throws InvalidToken
|
1279 |
|
|
* @throws NotFound
|
1280 |
|
|
* @throws IOException
|
1281 |
6622
|
leinfelder
|
* @throws JiBXException
|
1282 |
6268
|
leinfelder
|
* @throws Exception
|
1283 |
|
|
*/
|
1284 |
6756
|
cjones
|
private void listObjects() throws InvalidToken, ServiceFailure,
|
1285 |
|
|
NotAuthorized, InvalidRequest, NotImplemented, NotFound,
|
1286 |
|
|
IOException, JiBXException {
|
1287 |
6622
|
leinfelder
|
|
1288 |
6756
|
cjones
|
Date startTime = null;
|
1289 |
|
|
Date endTime = null;
|
1290 |
7100
|
leinfelder
|
ObjectFormatIdentifier formatId = null;
|
1291 |
8810
|
leinfelder
|
Identifier identifier = null;
|
1292 |
9249
|
tao
|
//boolean replicaStatus = true;
|
1293 |
|
|
NodeReference nodeId = null;
|
1294 |
6756
|
cjones
|
int start = 0;
|
1295 |
7471
|
leinfelder
|
int count = 1000;
|
1296 |
6756
|
cjones
|
Enumeration<String> paramlist = request.getParameterNames();
|
1297 |
|
|
while (paramlist.hasMoreElements()) {
|
1298 |
|
|
// parse the params and make the call
|
1299 |
|
|
String name = paramlist.nextElement();
|
1300 |
7048
|
leinfelder
|
String[] values = request.getParameterValues(name);
|
1301 |
|
|
String value = null;
|
1302 |
|
|
if (values != null && values.length > 0) {
|
1303 |
|
|
value = values[0];
|
1304 |
|
|
value = EncodingUtilities.decodeString(value);
|
1305 |
|
|
}
|
1306 |
6622
|
leinfelder
|
|
1307 |
7046
|
cjones
|
if (name.equals("fromDate") && value != null) {
|
1308 |
6756
|
cjones
|
try {
|
1309 |
7048
|
leinfelder
|
startTime = DateTimeMarshaller.deserializeDateToUTC(value);
|
1310 |
6756
|
cjones
|
} catch (Exception e) {
|
1311 |
|
|
// if we can't parse it, just don't use the startTime param
|
1312 |
7048
|
leinfelder
|
logMetacat.warn("Could not parse fromDate: " + value);
|
1313 |
6756
|
cjones
|
startTime = null;
|
1314 |
|
|
}
|
1315 |
7046
|
cjones
|
} else if (name.equals("toDate") && value != null) {
|
1316 |
6756
|
cjones
|
try {
|
1317 |
7048
|
leinfelder
|
endTime = DateTimeMarshaller.deserializeDateToUTC(value);
|
1318 |
6756
|
cjones
|
} catch (Exception e) {
|
1319 |
|
|
// if we can't parse it, just don't use the endTime param
|
1320 |
7048
|
leinfelder
|
logMetacat.warn("Could not parse toDate: " + value);
|
1321 |
6756
|
cjones
|
endTime = null;
|
1322 |
|
|
}
|
1323 |
7100
|
leinfelder
|
} else if (name.equals("formatId") && value != null) {
|
1324 |
|
|
formatId = new ObjectFormatIdentifier();
|
1325 |
|
|
formatId.setValue(value);
|
1326 |
8810
|
leinfelder
|
} else if (name.equals("identifier") && value != null) {
|
1327 |
|
|
identifier = new Identifier();
|
1328 |
|
|
identifier.setValue(value);
|
1329 |
9249
|
tao
|
/*} else if (name.equals("replicaStatus") && value != null) {
|
1330 |
|
|
replicaStatus = Boolean.parseBoolean(value);*/
|
1331 |
|
|
} else if (name.equals("nodeId") && value != null) {
|
1332 |
|
|
nodeId = new NodeReference();
|
1333 |
|
|
nodeId.setValue(value);
|
1334 |
|
|
logMetacat.debug("the nodeId value is "+nodeId.getValue());
|
1335 |
6756
|
cjones
|
} else if (name.equals("start") && value != null) {
|
1336 |
7048
|
leinfelder
|
start = Integer.valueOf(value);
|
1337 |
6756
|
cjones
|
} else if (name.equals("count") && value != null) {
|
1338 |
7048
|
leinfelder
|
count = Integer.valueOf(value);
|
1339 |
6756
|
cjones
|
}
|
1340 |
|
|
}
|
1341 |
|
|
// make the call
|
1342 |
7046
|
cjones
|
logMetacat.debug("session: " + session + " fromDate: " + startTime
|
1343 |
7100
|
leinfelder
|
+ " toDate: " + endTime + " formatId: " + formatId
|
1344 |
9249
|
tao
|
+ " start: " + start
|
1345 |
7048
|
leinfelder
|
+ " count: " + count);
|
1346 |
6622
|
leinfelder
|
|
1347 |
6756
|
cjones
|
// get the list
|
1348 |
|
|
ObjectList ol = CNodeService.getInstance(request).listObjects(session,
|
1349 |
9249
|
tao
|
startTime, endTime, formatId, identifier, nodeId, start, count);
|
1350 |
6756
|
cjones
|
|
1351 |
|
|
// send it
|
1352 |
|
|
OutputStream out = response.getOutputStream();
|
1353 |
|
|
response.setStatus(200);
|
1354 |
|
|
response.setContentType("text/xml");
|
1355 |
|
|
|
1356 |
|
|
// style the object with a processing directive
|
1357 |
|
|
String stylesheet = null;
|
1358 |
|
|
try {
|
1359 |
9237
|
leinfelder
|
stylesheet = PropertyService.getProperty("dataone.types.xsl.v2");
|
1360 |
6756
|
cjones
|
} catch (PropertyNotFoundException e) {
|
1361 |
|
|
logMetacat.warn("Could not locate DataONE types XSLT: "
|
1362 |
|
|
+ e.getMessage());
|
1363 |
|
|
}
|
1364 |
|
|
|
1365 |
|
|
// Serialize and write it to the output stream
|
1366 |
|
|
TypeMarshaller.marshalTypeToOutputStream(ol, out, stylesheet);
|
1367 |
|
|
}
|
1368 |
|
|
|
1369 |
6592
|
cjones
|
/**
|
1370 |
|
|
* Pass the request to get node replication authorization to CNodeService
|
1371 |
|
|
*
|
1372 |
6756
|
cjones
|
* @param pid
|
1373 |
|
|
* the identifier of the object to get authorization to replicate
|
1374 |
6592
|
cjones
|
*
|
1375 |
|
|
* @throws NotImplemented
|
1376 |
|
|
* @throws NotAuthorized
|
1377 |
|
|
* @throws InvalidToken
|
1378 |
|
|
* @throws ServiceFailure
|
1379 |
|
|
* @throws NotFound
|
1380 |
|
|
* @throws InvalidRequest
|
1381 |
|
|
*/
|
1382 |
6756
|
cjones
|
public boolean isNodeAuthorized(String pid) throws NotImplemented,
|
1383 |
|
|
NotAuthorized, InvalidToken, ServiceFailure, NotFound,
|
1384 |
|
|
InvalidRequest {
|
1385 |
|
|
|
1386 |
6592
|
cjones
|
boolean result = false;
|
1387 |
|
|
Subject targetNodeSubject = new Subject();
|
1388 |
|
|
String nodeSubject = null;
|
1389 |
|
|
String replPermission = null;
|
1390 |
6756
|
cjones
|
|
1391 |
6592
|
cjones
|
// get the pid
|
1392 |
|
|
Identifier identifier = new Identifier();
|
1393 |
|
|
identifier.setValue(pid);
|
1394 |
6756
|
cjones
|
|
1395 |
6592
|
cjones
|
// get the target node subject
|
1396 |
|
|
try {
|
1397 |
|
|
nodeSubject = params.get("targetNodeSubject")[0];
|
1398 |
|
|
targetNodeSubject.setValue(nodeSubject);
|
1399 |
6756
|
cjones
|
|
1400 |
6592
|
cjones
|
} catch (NullPointerException e) {
|
1401 |
|
|
String msg = "The 'targetNodeSubject' must be provided as a parameter and was not.";
|
1402 |
|
|
logMetacat.error(msg);
|
1403 |
|
|
throw new InvalidRequest("4873", msg);
|
1404 |
6756
|
cjones
|
|
1405 |
6592
|
cjones
|
}
|
1406 |
6756
|
cjones
|
|
1407 |
6777
|
leinfelder
|
result = CNodeService.getInstance(request).isNodeAuthorized(session, targetNodeSubject, identifier);
|
1408 |
6268
|
leinfelder
|
|
1409 |
6592
|
cjones
|
response.setStatus(200);
|
1410 |
|
|
response.setContentType("text/xml");
|
1411 |
|
|
return result;
|
1412 |
6756
|
cjones
|
|
1413 |
6592
|
cjones
|
}
|
1414 |
6756
|
cjones
|
|
1415 |
6592
|
cjones
|
/**
|
1416 |
|
|
* Pass the request to set the replication policy to CNodeService
|
1417 |
|
|
*
|
1418 |
6756
|
cjones
|
* @param pid
|
1419 |
|
|
* the identifier of the object to set the replication policy on
|
1420 |
6592
|
cjones
|
*
|
1421 |
|
|
* @throws NotImplemented
|
1422 |
|
|
* @throws NotFound
|
1423 |
|
|
* @throws NotAuthorized
|
1424 |
|
|
* @throws ServiceFailure
|
1425 |
|
|
* @throws InvalidRequest
|
1426 |
|
|
* @throws InvalidToken
|
1427 |
|
|
* @throws IOException
|
1428 |
|
|
* @throws InstantiationException
|
1429 |
|
|
* @throws IllegalAccessException
|
1430 |
|
|
* @throws JiBXException
|
1431 |
6869
|
cjones
|
* @throws VersionMismatch
|
1432 |
6592
|
cjones
|
*/
|
1433 |
6756
|
cjones
|
public boolean setReplicationPolicy(String pid) throws NotImplemented,
|
1434 |
|
|
NotFound, NotAuthorized, ServiceFailure, InvalidRequest,
|
1435 |
|
|
InvalidToken, IOException, InstantiationException,
|
1436 |
6869
|
cjones
|
IllegalAccessException, JiBXException, VersionMismatch {
|
1437 |
6756
|
cjones
|
|
1438 |
6592
|
cjones
|
boolean result = false;
|
1439 |
|
|
long serialVersion = 0L;
|
1440 |
|
|
String serialVersionStr = null;
|
1441 |
6756
|
cjones
|
|
1442 |
6592
|
cjones
|
Identifier identifier = new Identifier();
|
1443 |
|
|
identifier.setValue(pid);
|
1444 |
6756
|
cjones
|
|
1445 |
8810
|
leinfelder
|
// parse the policy
|
1446 |
|
|
Map<String, File> files = collectMultipartFiles();
|
1447 |
|
|
ReplicationPolicy policy = TypeMarshaller.unmarshalTypeFromFile(ReplicationPolicy.class, files.get("policy"));
|
1448 |
6634
|
cjones
|
|
1449 |
6592
|
cjones
|
// get the serialVersion
|
1450 |
|
|
try {
|
1451 |
6603
|
cjones
|
serialVersionStr = multipartparams.get("serialVersion").get(0);
|
1452 |
6592
|
cjones
|
serialVersion = new Long(serialVersionStr).longValue();
|
1453 |
6756
|
cjones
|
|
1454 |
6592
|
cjones
|
} catch (NullPointerException e) {
|
1455 |
|
|
String msg = "The 'serialVersion' must be provided as a parameter and was not.";
|
1456 |
|
|
logMetacat.error(msg);
|
1457 |
|
|
throw new InvalidRequest("4883", msg);
|
1458 |
6756
|
cjones
|
|
1459 |
6592
|
cjones
|
}
|
1460 |
6756
|
cjones
|
result = CNodeService.getInstance(request).setReplicationPolicy(
|
1461 |
|
|
session, identifier, policy, serialVersion);
|
1462 |
6592
|
cjones
|
response.setStatus(200);
|
1463 |
|
|
response.setContentType("text/xml");
|
1464 |
|
|
return result;
|
1465 |
6756
|
cjones
|
|
1466 |
6592
|
cjones
|
}
|
1467 |
6890
|
leinfelder
|
|
1468 |
7096
|
cjones
|
/**
|
1469 |
|
|
* Update the system metadata for a given pid, setting it to be obsoleted
|
1470 |
|
|
* by the obsoletedByPid
|
1471 |
|
|
*
|
1472 |
|
|
* @param pid
|
1473 |
|
|
* @return
|
1474 |
|
|
* @throws NotImplemented
|
1475 |
|
|
* @throws NotFound
|
1476 |
|
|
* @throws NotAuthorized
|
1477 |
|
|
* @throws ServiceFailure
|
1478 |
|
|
* @throws InvalidRequest
|
1479 |
|
|
* @throws InvalidToken
|
1480 |
|
|
* @throws InstantiationException
|
1481 |
|
|
* @throws IllegalAccessException
|
1482 |
|
|
* @throws VersionMismatch
|
1483 |
|
|
*/
|
1484 |
|
|
public boolean setObsoletedBy(String pid)
|
1485 |
|
|
throws NotImplemented, NotFound, NotAuthorized, ServiceFailure,
|
1486 |
|
|
InvalidRequest, InvalidToken, InstantiationException,
|
1487 |
|
|
IllegalAccessException, VersionMismatch {
|
1488 |
|
|
|
1489 |
|
|
boolean result = false;
|
1490 |
|
|
long serialVersion = 0L;
|
1491 |
|
|
String serialVersionStr = null;
|
1492 |
|
|
|
1493 |
|
|
Identifier identifier = new Identifier();
|
1494 |
|
|
identifier.setValue(pid);
|
1495 |
|
|
String obsoletedByPidString = null;
|
1496 |
|
|
Identifier obsoletedByPid = null;
|
1497 |
|
|
|
1498 |
|
|
// Parse the params out of the multipart form data
|
1499 |
|
|
// Read the incoming data from its Mime Multipart encoding
|
1500 |
|
|
logMetacat.debug("Parsing rights holder parameters from the mime multipart entity");
|
1501 |
|
|
try {
|
1502 |
|
|
collectMultipartParams();
|
1503 |
|
|
|
1504 |
|
|
} catch (FileUploadException e1) {
|
1505 |
|
|
String msg = "FileUploadException: Couldn't parse the mime multipart information: " +
|
1506 |
|
|
e1.getMessage();
|
1507 |
|
|
logMetacat.debug(msg);
|
1508 |
|
|
throw new ServiceFailure("4941", msg);
|
1509 |
|
|
|
1510 |
|
|
} catch (IOException e1) {
|
1511 |
|
|
String msg = "IOException: Couldn't parse the mime multipart information: " +
|
1512 |
|
|
e1.getMessage();
|
1513 |
|
|
logMetacat.debug(msg);
|
1514 |
|
|
throw new ServiceFailure("4941", msg);
|
1515 |
|
|
|
1516 |
|
|
} catch (Exception e1) {
|
1517 |
|
|
String msg = "Exception: Couldn't parse the mime multipart information: " +
|
1518 |
|
|
e1.getMessage();
|
1519 |
|
|
logMetacat.debug(msg);
|
1520 |
|
|
throw new ServiceFailure("4941", msg);
|
1521 |
|
|
|
1522 |
|
|
}
|
1523 |
|
|
|
1524 |
|
|
// get the obsoletedByPid
|
1525 |
|
|
try {
|
1526 |
|
|
obsoletedByPidString = multipartparams.get("obsoletedByPid").get(0);
|
1527 |
|
|
obsoletedByPid = new Identifier();
|
1528 |
|
|
obsoletedByPid.setValue(obsoletedByPidString);
|
1529 |
|
|
} catch (NullPointerException e) {
|
1530 |
|
|
String msg = "The 'obsoletedByPid' must be provided as a parameter and was not.";
|
1531 |
|
|
logMetacat.error(msg);
|
1532 |
|
|
throw new InvalidRequest("4883", msg);
|
1533 |
|
|
}
|
1534 |
|
|
|
1535 |
|
|
// get the serialVersion
|
1536 |
|
|
try {
|
1537 |
|
|
serialVersionStr = multipartparams.get("serialVersion").get(0);
|
1538 |
|
|
serialVersion = new Long(serialVersionStr).longValue();
|
1539 |
|
|
|
1540 |
|
|
} catch (NumberFormatException nfe) {
|
1541 |
|
|
String msg = "The 'serialVersion' must be provided as a positive integer and was not.";
|
1542 |
|
|
logMetacat.error(msg);
|
1543 |
|
|
throw new InvalidRequest("4942", msg);
|
1544 |
|
|
|
1545 |
|
|
} catch (NullPointerException e) {
|
1546 |
|
|
String msg = "The 'serialVersion' must be provided as a parameter and was not.";
|
1547 |
|
|
logMetacat.error(msg);
|
1548 |
|
|
throw new InvalidRequest("4942", msg);
|
1549 |
|
|
|
1550 |
|
|
}
|
1551 |
|
|
result = CNodeService.getInstance(request).setObsoletedBy(session,
|
1552 |
|
|
identifier, obsoletedByPid, serialVersion);
|
1553 |
|
|
response.setStatus(200);
|
1554 |
|
|
response.setContentType("text/xml");
|
1555 |
|
|
return result;
|
1556 |
|
|
|
1557 |
|
|
}
|
1558 |
6891
|
leinfelder
|
|
1559 |
7097
|
cjones
|
/**
|
1560 |
|
|
* Delete the replica entry with the given nodeId for the given pid
|
1561 |
|
|
*
|
1562 |
|
|
* @param pid
|
1563 |
|
|
* @return
|
1564 |
|
|
* @throws NotImplemented
|
1565 |
|
|
* @throws NotFound
|
1566 |
|
|
* @throws NotAuthorized
|
1567 |
|
|
* @throws ServiceFailure
|
1568 |
|
|
* @throws InvalidRequest
|
1569 |
|
|
* @throws InvalidToken
|
1570 |
|
|
* @throws InstantiationException
|
1571 |
|
|
* @throws IllegalAccessException
|
1572 |
|
|
* @throws VersionMismatch
|
1573 |
|
|
*/
|
1574 |
|
|
public boolean deleteReplica(String pid)
|
1575 |
|
|
throws NotImplemented, NotFound, NotAuthorized, ServiceFailure,
|
1576 |
|
|
InvalidRequest, InvalidToken, InstantiationException,
|
1577 |
|
|
IllegalAccessException, VersionMismatch {
|
1578 |
6891
|
leinfelder
|
|
1579 |
7097
|
cjones
|
boolean result = false;
|
1580 |
|
|
long serialVersion = 0L;
|
1581 |
|
|
String serialVersionStr = null;
|
1582 |
6891
|
leinfelder
|
|
1583 |
7097
|
cjones
|
Identifier identifier = new Identifier();
|
1584 |
|
|
identifier.setValue(pid);
|
1585 |
6891
|
leinfelder
|
|
1586 |
7097
|
cjones
|
NodeReference nodeId = null;
|
1587 |
|
|
|
1588 |
|
|
// Parse the params out of the multipart form data
|
1589 |
|
|
// Read the incoming data from its Mime Multipart encoding
|
1590 |
|
|
logMetacat.debug("Parsing delete replica parameters from the mime multipart entity");
|
1591 |
|
|
try {
|
1592 |
|
|
collectMultipartParams();
|
1593 |
|
|
|
1594 |
|
|
} catch (FileUploadException e1) {
|
1595 |
|
|
String msg = "FileUploadException: Couldn't parse the mime multipart information: " +
|
1596 |
|
|
e1.getMessage();
|
1597 |
|
|
logMetacat.debug(msg);
|
1598 |
|
|
throw new ServiceFailure("4951", msg);
|
1599 |
6891
|
leinfelder
|
|
1600 |
7097
|
cjones
|
} catch (IOException e1) {
|
1601 |
|
|
String msg = "IOException: Couldn't parse the mime multipart information: " +
|
1602 |
|
|
e1.getMessage();
|
1603 |
|
|
logMetacat.debug(msg);
|
1604 |
|
|
throw new ServiceFailure("4951", msg);
|
1605 |
|
|
|
1606 |
|
|
} catch (Exception e1) {
|
1607 |
|
|
String msg = "Exception: Couldn't parse the mime multipart information: " +
|
1608 |
|
|
e1.getMessage();
|
1609 |
|
|
logMetacat.debug(msg);
|
1610 |
|
|
throw new ServiceFailure("4951", msg);
|
1611 |
6891
|
leinfelder
|
|
1612 |
7097
|
cjones
|
}
|
1613 |
|
|
|
1614 |
|
|
// get the nodeId param
|
1615 |
|
|
try {
|
1616 |
|
|
String nodeIdString = multipartparams.get("nodeId").get(0);
|
1617 |
|
|
nodeId = new NodeReference();
|
1618 |
|
|
nodeId.setValue(nodeIdString);
|
1619 |
|
|
|
1620 |
|
|
} catch (NullPointerException e) {
|
1621 |
|
|
String msg = "The 'nodeId' must be provided as a parameter and was not.";
|
1622 |
|
|
logMetacat.error(msg);
|
1623 |
|
|
throw new InvalidRequest("4952", msg);
|
1624 |
|
|
}
|
1625 |
6891
|
leinfelder
|
|
1626 |
7097
|
cjones
|
// get the serialVersion
|
1627 |
|
|
try {
|
1628 |
|
|
serialVersionStr = multipartparams.get("serialVersion").get(0);
|
1629 |
|
|
serialVersion = new Long(serialVersionStr).longValue();
|
1630 |
|
|
|
1631 |
|
|
} catch (NumberFormatException nfe) {
|
1632 |
|
|
String msg = "The 'serialVersion' must be provided as a positive integer and was not.";
|
1633 |
|
|
logMetacat.error(msg);
|
1634 |
|
|
throw new InvalidRequest("4952", msg);
|
1635 |
|
|
|
1636 |
|
|
} catch (NullPointerException e) {
|
1637 |
|
|
String msg = "The 'serialVersion' must be provided as a parameter and was not.";
|
1638 |
|
|
logMetacat.error(msg);
|
1639 |
|
|
throw new InvalidRequest("4952", msg);
|
1640 |
|
|
|
1641 |
|
|
}
|
1642 |
|
|
result = CNodeService.getInstance(request).deleteReplicationMetadata(
|
1643 |
|
|
session, identifier, nodeId, serialVersion);
|
1644 |
|
|
response.setStatus(200);
|
1645 |
|
|
response.setContentType("text/xml");
|
1646 |
|
|
return result;
|
1647 |
6891
|
leinfelder
|
|
1648 |
7097
|
cjones
|
}
|
1649 |
6756
|
cjones
|
|
1650 |
6592
|
cjones
|
/**
|
1651 |
|
|
* Pass the request to set the replication status to CNodeService
|
1652 |
|
|
*
|
1653 |
6756
|
cjones
|
* @param pid
|
1654 |
|
|
* the identifier of the object to set the replication status on
|
1655 |
6592
|
cjones
|
*
|
1656 |
|
|
* @throws ServiceFailure
|
1657 |
|
|
* @throws NotImplemented
|
1658 |
|
|
* @throws InvalidToken
|
1659 |
|
|
* @throws NotAuthorized
|
1660 |
|
|
* @throws InvalidRequest
|
1661 |
|
|
* @throws NotFound
|
1662 |
6794
|
cjones
|
* @throws JiBXException
|
1663 |
|
|
* @throws IllegalAccessException
|
1664 |
|
|
* @throws InstantiationException
|
1665 |
|
|
* @throws IOException
|
1666 |
6592
|
cjones
|
*/
|
1667 |
6756
|
cjones
|
public boolean setReplicationStatus(String pid) throws ServiceFailure,
|
1668 |
|
|
NotImplemented, InvalidToken, NotAuthorized, InvalidRequest,
|
1669 |
|
|
NotFound {
|
1670 |
6794
|
cjones
|
|
1671 |
6592
|
cjones
|
boolean result = false;
|
1672 |
|
|
Identifier identifier = new Identifier();
|
1673 |
|
|
identifier.setValue(pid);
|
1674 |
6794
|
cjones
|
BaseException failure = null;
|
1675 |
6592
|
cjones
|
ReplicationStatus status = null;
|
1676 |
|
|
String replicationStatus = null;
|
1677 |
|
|
NodeReference targetNodeRef = null;
|
1678 |
|
|
String targetNode = null;
|
1679 |
6756
|
cjones
|
|
1680 |
6634
|
cjones
|
// Parse the params out of the multipart form data
|
1681 |
|
|
// Read the incoming data from its Mime Multipart encoding
|
1682 |
6794
|
cjones
|
logMetacat.debug("Parsing ReplicaStatus from the mime multipart entity");
|
1683 |
6634
|
cjones
|
|
1684 |
|
|
try {
|
1685 |
9269
|
leinfelder
|
// parse the failure, if we have it
|
1686 |
8810
|
leinfelder
|
Map<String, File> files = collectMultipartFiles();
|
1687 |
9269
|
leinfelder
|
if (files.containsKey("failure")) {
|
1688 |
|
|
failure = ExceptionHandler.deserializeXml(new FileInputStream(files.get("failure")),
|
1689 |
|
|
"Replication failed for an unknown reason.");
|
1690 |
|
|
}
|
1691 |
6794
|
cjones
|
|
1692 |
8810
|
leinfelder
|
} catch (Exception e2) {
|
1693 |
6794
|
cjones
|
throw new ServiceFailure("4700", "Couldn't resolve the multipart request: " +
|
1694 |
|
|
e2.getMessage());
|
1695 |
|
|
|
1696 |
6634
|
cjones
|
}
|
1697 |
6794
|
cjones
|
|
1698 |
6592
|
cjones
|
// get the replication status param
|
1699 |
|
|
try {
|
1700 |
6643
|
cjones
|
replicationStatus = multipartparams.get("status").get(0);
|
1701 |
6592
|
cjones
|
status = ReplicationStatus.convert(replicationStatus);
|
1702 |
6677
|
cjones
|
|
1703 |
6642
|
cjones
|
} catch (NullPointerException npe) {
|
1704 |
|
|
|
1705 |
6756
|
cjones
|
logMetacat.debug("The 'status' parameter was not found in the "
|
1706 |
|
|
+ "multipartparams map. Trying the params map.");
|
1707 |
|
|
|
1708 |
6642
|
cjones
|
try {
|
1709 |
6643
|
cjones
|
replicationStatus = params.get("status")[0];
|
1710 |
6756
|
cjones
|
status = ReplicationStatus.convert(replicationStatus
|
1711 |
|
|
.toLowerCase());
|
1712 |
|
|
|
1713 |
6642
|
cjones
|
} catch (Exception e) {
|
1714 |
6643
|
cjones
|
String msg = "The 'status' must be provided as a parameter and was not.";
|
1715 |
6642
|
cjones
|
logMetacat.error(msg);
|
1716 |
|
|
throw new InvalidRequest("4730", msg);
|
1717 |
6756
|
cjones
|
|
1718 |
6642
|
cjones
|
}
|
1719 |
6756
|
cjones
|
|
1720 |
6592
|
cjones
|
}
|
1721 |
6756
|
cjones
|
|
1722 |
6592
|
cjones
|
// get the target node reference param
|
1723 |
6642
|
cjones
|
try {
|
1724 |
|
|
targetNode = multipartparams.get("nodeRef").get(0);
|
1725 |
|
|
targetNodeRef = new NodeReference();
|
1726 |
|
|
targetNodeRef.setValue(targetNode);
|
1727 |
6756
|
cjones
|
|
1728 |
6642
|
cjones
|
} catch (NullPointerException e) {
|
1729 |
6756
|
cjones
|
logMetacat.debug("The 'nodeRef' parameter was not found in the "
|
1730 |
|
|
+ "multipartparams map. Trying the params map.");
|
1731 |
|
|
|
1732 |
6642
|
cjones
|
try {
|
1733 |
|
|
targetNode = params.get("nodeRef")[0];
|
1734 |
|
|
targetNodeRef = new NodeReference();
|
1735 |
|
|
targetNodeRef.setValue(targetNode);
|
1736 |
6756
|
cjones
|
|
1737 |
6642
|
cjones
|
} catch (Exception e1) {
|
1738 |
|
|
String msg = "The 'nodeRef' must be provided as a parameter and was not.";
|
1739 |
|
|
logMetacat.error(msg);
|
1740 |
|
|
throw new InvalidRequest("4730", msg);
|
1741 |
6756
|
cjones
|
|
1742 |
6642
|
cjones
|
}
|
1743 |
6756
|
cjones
|
|
1744 |
6642
|
cjones
|
}
|
1745 |
6756
|
cjones
|
|
1746 |
|
|
result = CNodeService.getInstance(request).setReplicationStatus(
|
1747 |
6794
|
cjones
|
session, identifier, targetNodeRef, status, failure);
|
1748 |
6592
|
cjones
|
response.setStatus(200);
|
1749 |
|
|
response.setContentType("text/xml");
|
1750 |
|
|
return result;
|
1751 |
6756
|
cjones
|
|
1752 |
6592
|
cjones
|
}
|
1753 |
6756
|
cjones
|
|
1754 |
6592
|
cjones
|
/**
|
1755 |
|
|
* Pass the request to update the replication metadata to CNodeService
|
1756 |
|
|
*
|
1757 |
6756
|
cjones
|
* @param pid
|
1758 |
|
|
* the identifier of the object to update the replication
|
1759 |
|
|
* metadata on
|
1760 |
6592
|
cjones
|
*
|
1761 |
|
|
* @throws ServiceFailure
|
1762 |
|
|
* @throws NotImplemented
|
1763 |
|
|
* @throws InvalidToken
|
1764 |
|
|
* @throws NotAuthorized
|
1765 |
|
|
* @throws InvalidRequest
|
1766 |
|
|
* @throws NotFound
|
1767 |
6869
|
cjones
|
* @throws VersionMismatch
|
1768 |
8810
|
leinfelder
|
* @throws JiBXException
|
1769 |
|
|
* @throws IOException
|
1770 |
|
|
* @throws IllegalAccessException
|
1771 |
|
|
* @throws InstantiationException
|
1772 |
6592
|
cjones
|
*/
|
1773 |
6756
|
cjones
|
public boolean updateReplicationMetadata(String pid) throws ServiceFailure,
|
1774 |
|
|
NotImplemented, InvalidToken, NotAuthorized, InvalidRequest,
|
1775 |
8810
|
leinfelder
|
NotFound, VersionMismatch, InstantiationException, IllegalAccessException, IOException, JiBXException {
|
1776 |
6592
|
cjones
|
|
1777 |
|
|
boolean result = false;
|
1778 |
|
|
long serialVersion = 0L;
|
1779 |
|
|
String serialVersionStr = null;
|
1780 |
|
|
Identifier identifier = new Identifier();
|
1781 |
|
|
identifier.setValue(pid);
|
1782 |
|
|
|
1783 |
8810
|
leinfelder
|
// parse the replica
|
1784 |
|
|
Map<String, File> files = collectMultipartFiles();
|
1785 |
|
|
Replica replica = TypeMarshaller.unmarshalTypeFromFile(Replica.class, files.get("replicaMetadata"));
|
1786 |
6756
|
cjones
|
|
1787 |
6592
|
cjones
|
// get the serialVersion
|
1788 |
|
|
try {
|
1789 |
6603
|
cjones
|
serialVersionStr = multipartparams.get("serialVersion").get(0);
|
1790 |
6592
|
cjones
|
serialVersion = new Long(serialVersionStr).longValue();
|
1791 |
6756
|
cjones
|
|
1792 |
6592
|
cjones
|
} catch (NullPointerException e) {
|
1793 |
|
|
String msg = "The 'serialVersion' must be provided as a parameter and was not.";
|
1794 |
|
|
logMetacat.error(msg);
|
1795 |
|
|
throw new InvalidRequest("4853", msg);
|
1796 |
6756
|
cjones
|
|
1797 |
6592
|
cjones
|
}
|
1798 |
|
|
|
1799 |
6756
|
cjones
|
result = CNodeService.getInstance(request).updateReplicationMetadata(
|
1800 |
|
|
session, identifier, replica, serialVersion);
|
1801 |
6592
|
cjones
|
response.setStatus(200);
|
1802 |
|
|
response.setContentType("text/xml");
|
1803 |
|
|
return result;
|
1804 |
|
|
|
1805 |
|
|
}
|
1806 |
9123
|
tao
|
|
1807 |
|
|
/**
|
1808 |
|
|
* Update the system metadata for a specified pid
|
1809 |
|
|
* @throws ServiceFailure
|
1810 |
|
|
* @throws InvalidRequest
|
1811 |
|
|
* @throws InstantiationException
|
1812 |
|
|
* @throws IllegalAccessException
|
1813 |
|
|
* @throws IOException
|
1814 |
|
|
* @throws JiBXException
|
1815 |
|
|
* @throws NotImplemented
|
1816 |
|
|
* @throws NotAuthorized
|
1817 |
|
|
* @throws InvalidSystemMetadata
|
1818 |
|
|
* @throws InvalidToken
|
1819 |
|
|
*/
|
1820 |
|
|
protected void updateSystemMetadata() throws ServiceFailure, InvalidRequest, InstantiationException,
|
1821 |
|
|
IllegalAccessException, IOException, JiBXException, NotImplemented, NotAuthorized, InvalidSystemMetadata, InvalidToken {
|
1822 |
|
|
// Read the incoming data from its Mime Multipart encoding
|
1823 |
|
|
Map<String, File> files = collectMultipartFiles();
|
1824 |
|
|
|
1825 |
|
|
// get the encoded pid string from the body and make the object
|
1826 |
|
|
String pidString = multipartparams.get("pid").get(0);
|
1827 |
|
|
Identifier pid = new Identifier();
|
1828 |
|
|
pid.setValue(pidString);
|
1829 |
|
|
|
1830 |
|
|
logMetacat.debug("updateSystemMetadata: " + pid);
|
1831 |
6592
|
cjones
|
|
1832 |
9123
|
tao
|
// get the system metadata from the request
|
1833 |
|
|
File smFile = files.get("sysmeta");
|
1834 |
|
|
FileInputStream sysmeta = new FileInputStream(smFile);
|
1835 |
|
|
SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromStream(SystemMetadata.class, sysmeta);
|
1836 |
|
|
|
1837 |
|
|
logMetacat.debug("updating system metadata with pid " + pid.getValue());
|
1838 |
|
|
|
1839 |
|
|
CNodeService.getInstance(request).updateSystemMetadata(session, pid, systemMetadata);
|
1840 |
|
|
}
|
1841 |
9148
|
tao
|
|
1842 |
|
|
private void doViews(String format, String pid) {
|
1843 |
|
|
|
1844 |
|
|
OutputStream out = null;
|
1845 |
|
|
CNodeService cnode = CNodeService.getInstance(request);
|
1846 |
9123
|
tao
|
|
1847 |
9148
|
tao
|
try {
|
1848 |
|
|
// get a list of views
|
1849 |
|
|
if (pid != null) {
|
1850 |
|
|
Identifier identifier = new Identifier();
|
1851 |
|
|
identifier.setValue(pid);
|
1852 |
|
|
InputStream stream = cnode.view(session, format, identifier);
|
1853 |
|
|
|
1854 |
|
|
// set the content-type if we have it from the implementation
|
1855 |
|
|
if (stream instanceof ContentTypeInputStream) {
|
1856 |
|
|
response.setContentType(((ContentTypeInputStream) stream).getContentType());
|
1857 |
|
|
}
|
1858 |
|
|
response.setStatus(200);
|
1859 |
|
|
out = response.getOutputStream();
|
1860 |
|
|
// write the results to the output stream
|
1861 |
|
|
IOUtils.copyLarge(stream, out);
|
1862 |
|
|
return;
|
1863 |
|
|
} else {
|
1864 |
|
|
// TODO: list the registered views
|
1865 |
|
|
//BaseException ni = new NotImplemented("9999", "MN.listViews() is not implemented at this node");
|
1866 |
|
|
//throw ni;
|
1867 |
|
|
OptionList list = cnode.listViews(session);
|
1868 |
|
|
|
1869 |
|
|
response.setContentType("text/xml");
|
1870 |
|
|
response.setStatus(200);
|
1871 |
|
|
TypeMarshaller.marshalTypeToOutputStream(list, response.getOutputStream());
|
1872 |
|
|
}
|
1873 |
|
|
|
1874 |
|
|
|
1875 |
|
|
} catch (BaseException be) {
|
1876 |
|
|
// report Exceptions as clearly as possible
|
1877 |
|
|
try {
|
1878 |
|
|
out = response.getOutputStream();
|
1879 |
|
|
} catch (IOException e) {
|
1880 |
|
|
logMetacat.error("Could not get output stream from response", e);
|
1881 |
|
|
}
|
1882 |
|
|
serializeException(be, out);
|
1883 |
|
|
} catch (Exception e) {
|
1884 |
|
|
// report Exceptions as clearly and generically as possible
|
1885 |
|
|
logMetacat.error(e.getClass() + ": " + e.getMessage(), e);
|
1886 |
|
|
try {
|
1887 |
|
|
out = response.getOutputStream();
|
1888 |
|
|
} catch (IOException ioe) {
|
1889 |
|
|
logMetacat.error("Could not get output stream from response", ioe);
|
1890 |
|
|
}
|
1891 |
|
|
ServiceFailure se = new ServiceFailure("0000", e.getMessage());
|
1892 |
|
|
serializeException(se, out);
|
1893 |
|
|
}
|
1894 |
|
|
}
|
1895 |
|
|
|
1896 |
6253
|
leinfelder
|
}
|