Revision 6259
Added by Chris Jones over 13 years ago
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
84 | 84 |
public class MNodeService extends D1NodeService implements MNAuthorization, |
85 | 85 |
MNCore, MNRead, MNReplication, MNStorage { |
86 | 86 |
|
87 |
/* the instance of the MNodeService object */
|
|
87 |
/* the instance of the MNodeService object */
|
|
88 | 88 |
private static MNodeService instance = null; |
89 | 89 |
|
90 | 90 |
/* the logger instance */ |
... | ... | |
109 | 109 |
* Constructor, private for singleton access |
110 | 110 |
*/ |
111 | 111 |
private MNodeService() { |
112 |
super();
|
|
112 |
super();
|
|
113 | 113 |
logMetacat = Logger.getLogger(MNodeService.class); |
114 | 114 |
|
115 | 115 |
} |
116 | 116 |
|
117 |
/**
|
|
118 |
* Deletes an object from the Member Node, where the object is either a
|
|
119 |
* data object or a science metadata object.
|
|
120 |
*
|
|
121 |
* @param session - the Session object containing the credentials for the Subject
|
|
122 |
* @param pid - The object identifier to be deleted
|
|
123 |
*
|
|
124 |
* @return pid - the identifier of the object used for the deletion
|
|
125 |
*
|
|
126 |
* @throws InvalidToken
|
|
127 |
* @throws ServiceFailure
|
|
128 |
* @throws NotAuthorized
|
|
129 |
* @throws NotFound
|
|
130 |
* @throws NotImplemented
|
|
131 |
* @throws InvalidRequest
|
|
132 |
*/
|
|
117 |
/**
|
|
118 |
* Deletes an object from the Member Node, where the object is either a
|
|
119 |
* data object or a science metadata object.
|
|
120 |
*
|
|
121 |
* @param session - the Session object containing the credentials for the Subject
|
|
122 |
* @param pid - The object identifier to be deleted
|
|
123 |
*
|
|
124 |
* @return pid - the identifier of the object used for the deletion
|
|
125 |
*
|
|
126 |
* @throws InvalidToken
|
|
127 |
* @throws ServiceFailure
|
|
128 |
* @throws NotAuthorized
|
|
129 |
* @throws NotFound
|
|
130 |
* @throws NotImplemented
|
|
131 |
* @throws InvalidRequest
|
|
132 |
*/
|
|
133 | 133 |
@Override |
134 |
public Identifier delete(Session session, Identifier pid)
|
|
134 |
public Identifier delete(Session session, Identifier pid)
|
|
135 | 135 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, |
136 | 136 |
NotImplemented, InvalidRequest { |
137 | 137 |
|
... | ... | |
145 | 145 |
// put the group names into a string array |
146 | 146 |
if( session != null ) { |
147 | 147 |
for ( int i = 0; i > groupList.size(); i++ ) { |
148 |
groups[i] = groupList.get(i).getGroupName();
|
|
149 |
|
|
148 |
groups[i] = groupList.get(i).getGroupName();
|
|
149 |
|
|
150 | 150 |
} |
151 | 151 |
} |
152 | 152 |
|
... | ... | |
166 | 166 |
|
167 | 167 |
// check for the existing identifier |
168 | 168 |
try { |
169 |
localId = im.getLocalId(pid.getValue());
|
|
169 |
localId = im.getLocalId(pid.getValue());
|
|
170 | 170 |
|
171 | 171 |
} catch (McdbDocNotFoundException e) { |
172 | 172 |
throw new InvalidRequest("1322", "The object with the provided " + |
173 |
"identifier was not found.");
|
|
173 |
"identifier was not found.");
|
|
174 | 174 |
|
175 | 175 |
} |
176 | 176 |
|
... | ... | |
180 | 180 |
if ( allowed ) { |
181 | 181 |
try { |
182 | 182 |
// delete the document |
183 |
DocumentImpl.delete(localId, subject.getValue(), groups, null);
|
|
183 |
DocumentImpl.delete(localId, subject.getValue(), groups, null);
|
|
184 | 184 |
EventLog.getInstance().log(metacatUrl, subject.getValue(), localId, "delete"); |
185 | 185 |
|
186 | 186 |
} catch (McdbDocNotFoundException e) { |
... | ... | |
188 | 188 |
|
189 | 189 |
} catch (SQLException e) { |
190 | 190 |
throw new ServiceFailure("1350", "There was a problem deleting the object." + |
191 |
"The error message was: " + e.getMessage());
|
|
191 |
"The error message was: " + e.getMessage());
|
|
192 | 192 |
|
193 | 193 |
} catch (InsufficientKarmaException e) { |
194 | 194 |
throw new NotAuthorized("1320", "The provided identity does not have " + |
... | ... | |
196 | 196 |
|
197 | 197 |
} catch (Exception e) { // for some reason DocumentImpl throws a general Exception |
198 | 198 |
throw new ServiceFailure("1350", "There was a problem deleting the object." + |
199 |
"The error message was: " + e.getMessage());
|
|
199 |
"The error message was: " + e.getMessage());
|
|
200 | 200 |
|
201 | 201 |
} |
202 | 202 |
|
203 | 203 |
} else { |
204 | 204 |
throw new NotAuthorized("1320", "The provided identity does not have " + |
205 | 205 |
"permission to DELETE objects on the Member Node."); |
206 |
|
|
206 |
|
|
207 | 207 |
} |
208 | 208 |
|
209 |
return pid;
|
|
210 |
}
|
|
209 |
return pid;
|
|
210 |
}
|
|
211 | 211 |
|
212 | 212 |
|
213 | 213 |
/** |
... | ... | |
216 | 216 |
* identified by pid through appropriate changes to the SystemMetadata |
217 | 217 |
* of pid and newPid |
218 | 218 |
* |
219 |
* @param session - the Session object containing the credentials for the Subject
|
|
220 |
* @param pid - The identifier of the object to be updated
|
|
221 |
* @param object - the new object bytes
|
|
222 |
* @param sysmeta - the new system metadata describing the object
|
|
223 |
*
|
|
224 |
* @return newPid - the identifier of the new object
|
|
225 |
*
|
|
226 |
* @throws InvalidToken
|
|
227 |
* @throws ServiceFailure
|
|
228 |
* @throws NotAuthorized
|
|
229 |
* @throws NotFound
|
|
230 |
* @throws NotImplemented
|
|
231 |
* @throws IdentifierNotUnique
|
|
232 |
* @throws UnsupportedType
|
|
233 |
* @throws InsufficientResources
|
|
234 |
* @throws InvalidSystemMetadata
|
|
235 |
* @throws InvalidRequest
|
|
219 |
* @param session - the Session object containing the credentials for the Subject
|
|
220 |
* @param pid - The identifier of the object to be updated
|
|
221 |
* @param object - the new object bytes
|
|
222 |
* @param sysmeta - the new system metadata describing the object
|
|
223 |
*
|
|
224 |
* @return newPid - the identifier of the new object
|
|
225 |
*
|
|
226 |
* @throws InvalidToken
|
|
227 |
* @throws ServiceFailure
|
|
228 |
* @throws NotAuthorized
|
|
229 |
* @throws NotFound
|
|
230 |
* @throws NotImplemented
|
|
231 |
* @throws IdentifierNotUnique
|
|
232 |
* @throws UnsupportedType
|
|
233 |
* @throws InsufficientResources
|
|
234 |
* @throws InvalidSystemMetadata
|
|
235 |
* @throws InvalidRequest
|
|
236 | 236 |
*/ |
237 | 237 |
@Override |
238 |
public Identifier update(Session session, Identifier pid, InputStream object,
|
|
239 |
Identifier newPid, SystemMetadata sysmeta)
|
|
238 |
public Identifier update(Session session, Identifier pid, InputStream object,
|
|
239 |
Identifier newPid, SystemMetadata sysmeta)
|
|
240 | 240 |
throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, |
241 | 241 |
UnsupportedType, InsufficientResources, NotFound, InvalidSystemMetadata, |
242 | 242 |
NotImplemented, InvalidRequest { |
243 | 243 |
|
244 |
String localId = null;
|
|
245 |
boolean allowed = false;
|
|
246 |
boolean isScienceMetadata = false;
|
|
247 |
Subject subject = session.getSubject();
|
|
248 |
List<Group> groupList = session.getSubjectList().getGroupList();
|
|
249 |
String[] groups = new String[groupList.size()];
|
|
250 |
IdentifierManager im = IdentifierManager.getInstance();
|
|
244 |
String localId = null;
|
|
245 |
boolean allowed = false;
|
|
246 |
boolean isScienceMetadata = false;
|
|
247 |
Subject subject = session.getSubject();
|
|
248 |
List<Group> groupList = session.getSubjectList().getGroupList();
|
|
249 |
String[] groups = new String[groupList.size()];
|
|
250 |
IdentifierManager im = IdentifierManager.getInstance();
|
|
251 | 251 |
|
252 |
// put the group names into a string array
|
|
253 |
if( session != null ) {
|
|
254 |
for ( int i = 0; i > groupList.size(); i++ ) {
|
|
255 |
groups[i] = groupList.get(i).getGroupName();
|
|
256 |
|
|
257 |
}
|
|
258 |
}
|
|
252 |
// put the group names into a string array
|
|
253 |
if( session != null ) {
|
|
254 |
for ( int i = 0; i > groupList.size(); i++ ) {
|
|
255 |
groups[i] = groupList.get(i).getGroupName();
|
|
256 |
|
|
257 |
}
|
|
258 |
}
|
|
259 | 259 |
|
260 |
// be sure the user is authenticated for update()
|
|
261 |
if (subject.getValue() == null ||
|
|
262 |
subject.getValue().toLowerCase().equals("public") ) {
|
|
263 |
throw new NotAuthorized("1200", "The provided identity does not have " +
|
|
264 |
"permission to UPDATE objects on the Member Node.");
|
|
265 |
|
|
266 |
}
|
|
260 |
// be sure the user is authenticated for update()
|
|
261 |
if (subject.getValue() == null ||
|
|
262 |
subject.getValue().toLowerCase().equals("public") ) {
|
|
263 |
throw new NotAuthorized("1200", "The provided identity does not have " +
|
|
264 |
"permission to UPDATE objects on the Member Node.");
|
|
265 |
|
|
266 |
}
|
|
267 | 267 |
|
268 |
// do we have a valid pid?
|
|
269 |
if ( pid == null || pid.getValue().trim().equals("") ) {
|
|
270 |
throw new InvalidRequest("1202", "The provided identifier was invalid.");
|
|
268 |
// do we have a valid pid?
|
|
269 |
if ( pid == null || pid.getValue().trim().equals("") ) {
|
|
270 |
throw new InvalidRequest("1202", "The provided identifier was invalid.");
|
|
271 | 271 |
|
272 |
}
|
|
272 |
}
|
|
273 | 273 |
|
274 |
// check for the existing identifier
|
|
275 |
try {
|
|
276 |
localId = im.getLocalId(pid.getValue());
|
|
274 |
// check for the existing identifier
|
|
275 |
try {
|
|
276 |
localId = im.getLocalId(pid.getValue());
|
|
277 | 277 |
|
278 |
} catch (McdbDocNotFoundException e) {
|
|
279 |
throw new InvalidRequest("1202", "The object with the provided " +
|
|
280 |
"identifier was not found.");
|
|
278 |
} catch (McdbDocNotFoundException e) {
|
|
279 |
throw new InvalidRequest("1202", "The object with the provided " +
|
|
280 |
"identifier was not found.");
|
|
281 | 281 |
|
282 |
}
|
|
282 |
}
|
|
283 | 283 |
|
284 |
// does the subject have WRITE ( == update) priveleges on the pid?
|
|
285 |
allowed = isAuthorized(session, pid, Permission.WRITE);
|
|
284 |
// does the subject have WRITE ( == update) priveleges on the pid?
|
|
285 |
allowed = isAuthorized(session, pid, Permission.WRITE);
|
|
286 | 286 |
|
287 |
if ( allowed ) {
|
|
288 |
|
|
289 |
// get the existing system metadata for the object
|
|
290 |
SystemMetadata existingSysMeta = getSystemMetadata(session, pid);
|
|
291 |
|
|
292 |
// add the obsoleted pid to the obsoletedBy list
|
|
293 |
List<Identifier> obsoletedList = existingSysMeta.getObsoletedByList();
|
|
294 |
obsoletedList.add(pid);
|
|
295 |
existingSysMeta.setObsoletedByList(obsoletedList);
|
|
296 |
|
|
297 |
// then update the existing system metadata
|
|
298 |
updateSystemMetadata(existingSysMeta);
|
|
299 |
|
|
300 |
// prep the new system metadata, add pid to the obsoletes list
|
|
301 |
sysmeta.addObsolete(pid);
|
|
302 |
|
|
303 |
// and insert the new system metadata
|
|
304 |
insertSystemMetadata(sysmeta);
|
|
305 |
|
|
306 |
isScienceMetadata = isScienceMetadata(sysmeta);
|
|
307 |
|
|
308 |
// do we have XML metadata or a data object?
|
|
309 |
if ( isScienceMetadata ) {
|
|
310 |
|
|
311 |
// update the science metadata XML document
|
|
312 |
// TODO: handle non-XML metadata/data documents (like netCDF)
|
|
313 |
// TODO: don't put objects into memory using stream to string
|
|
314 |
String objectAsXML = "";
|
|
315 |
try {
|
|
316 |
objectAsXML = IOUtils.toString(object, "UTF-8");
|
|
317 |
localId = insertOrUpdateDocument(objectAsXML, newPid, session, "update");
|
|
318 |
// register the newPid and the generated localId
|
|
319 |
if ( newPid != null ) {
|
|
320 |
im.createMapping(newPid.getValue(), localId);
|
|
321 |
|
|
322 |
}
|
|
323 |
|
|
324 |
} catch (IOException e) {
|
|
325 |
String msg = "The Node is unable to create the object. " +
|
|
287 |
if ( allowed ) {
|
|
288 |
|
|
289 |
// get the existing system metadata for the object
|
|
290 |
SystemMetadata existingSysMeta = getSystemMetadata(session, pid);
|
|
291 |
|
|
292 |
// add the obsoleted pid to the obsoletedBy list
|
|
293 |
List<Identifier> obsoletedList = existingSysMeta.getObsoletedByList();
|
|
294 |
obsoletedList.add(pid);
|
|
295 |
existingSysMeta.setObsoletedByList(obsoletedList);
|
|
296 |
|
|
297 |
// then update the existing system metadata
|
|
298 |
updateSystemMetadata(existingSysMeta);
|
|
299 |
|
|
300 |
// prep the new system metadata, add pid to the obsoletes list
|
|
301 |
sysmeta.addObsolete(pid);
|
|
302 |
|
|
303 |
// and insert the new system metadata
|
|
304 |
insertSystemMetadata(sysmeta);
|
|
305 |
|
|
306 |
isScienceMetadata = isScienceMetadata(sysmeta);
|
|
307 |
|
|
308 |
// do we have XML metadata or a data object?
|
|
309 |
if ( isScienceMetadata ) {
|
|
310 |
|
|
311 |
// update the science metadata XML document
|
|
312 |
// TODO: handle non-XML metadata/data documents (like netCDF)
|
|
313 |
// TODO: don't put objects into memory using stream to string
|
|
314 |
String objectAsXML = "";
|
|
315 |
try {
|
|
316 |
objectAsXML = IOUtils.toString(object, "UTF-8");
|
|
317 |
localId = insertOrUpdateDocument(objectAsXML, newPid, session, "update");
|
|
318 |
// register the newPid and the generated localId
|
|
319 |
if ( newPid != null ) {
|
|
320 |
im.createMapping(newPid.getValue(), localId);
|
|
321 |
|
|
322 |
}
|
|
323 |
|
|
324 |
} catch (IOException e) {
|
|
325 |
String msg = "The Node is unable to create the object. " +
|
|
326 | 326 |
"There was a problem converting the object to XML"; |
327 |
logMetacat.info(msg);
|
|
327 |
logMetacat.info(msg);
|
|
328 | 328 |
throw new ServiceFailure("1310", msg + ": " + e.getMessage()); |
329 |
|
|
330 |
}
|
|
331 |
|
|
332 |
} else {
|
|
333 |
|
|
334 |
// update the data object
|
|
335 |
localId = insertDataObject(object, newPid, session);
|
|
336 |
// register the newPid and the generated localId
|
|
337 |
if ( newPid != null ) {
|
|
338 |
im.createMapping(newPid.getValue(), localId);
|
|
339 |
|
|
340 |
}
|
|
341 |
|
|
342 |
}
|
|
343 |
// log the update event
|
|
329 |
|
|
330 |
}
|
|
331 |
|
|
332 |
} else {
|
|
333 |
|
|
334 |
// update the data object
|
|
335 |
localId = insertDataObject(object, newPid, session);
|
|
336 |
// register the newPid and the generated localId
|
|
337 |
if ( newPid != null ) {
|
|
338 |
im.createMapping(newPid.getValue(), localId);
|
|
339 |
|
|
340 |
}
|
|
341 |
|
|
342 |
}
|
|
343 |
// log the update event
|
|
344 | 344 |
EventLog.getInstance().log(metacatUrl, subject.getValue(), localId, "update"); |
345 | 345 |
|
346 |
} else {
|
|
347 |
throw new NotAuthorized("1200", "The provided identity does not have " +
|
|
348 |
"permission to UPDATE the object identified by " +
|
|
349 |
pid.getValue() + " on the Member Node.");
|
|
350 |
|
|
351 |
}
|
|
346 |
} else {
|
|
347 |
throw new NotAuthorized("1200", "The provided identity does not have " +
|
|
348 |
"permission to UPDATE the object identified by " +
|
|
349 |
pid.getValue() + " on the Member Node.");
|
|
350 |
|
|
351 |
}
|
|
352 | 352 |
|
353 |
return pid;
|
|
354 |
}
|
|
353 |
return pid;
|
|
354 |
}
|
|
355 | 355 |
|
356 | 356 |
/** |
357 | 357 |
* Called by a Coordinating Node to request that the Member Node create a |
... | ... | |
359 | 359 |
* Node and storing it locally so that it can be made accessible to |
360 | 360 |
* the DataONE system. |
361 | 361 |
* |
362 |
* @param session - the Session object containing the credentials for the Subject
|
|
363 |
* @param sysmeta - Copy of the CN held system metadata for the object
|
|
364 |
* @param sourceNode - A reference to node from which the content should be
|
|
365 |
* retrieved. The reference should be resolved by
|
|
366 |
* checking the CN node registry.
|
|
367 |
*
|
|
368 |
* @return true if the replication succeeds
|
|
369 |
*
|
|
370 |
* @throws ServiceFailure
|
|
371 |
* @throws NotAuthorized
|
|
372 |
* @throws NotImplemented
|
|
373 |
* @throws UnsupportedType
|
|
374 |
* @throws InsufficientResources
|
|
375 |
* @throws InvalidRequest
|
|
362 |
* @param session - the Session object containing the credentials for the Subject
|
|
363 |
* @param sysmeta - Copy of the CN held system metadata for the object
|
|
364 |
* @param sourceNode - A reference to node from which the content should be
|
|
365 |
* retrieved. The reference should be resolved by
|
|
366 |
* checking the CN node registry.
|
|
367 |
*
|
|
368 |
* @return true if the replication succeeds
|
|
369 |
*
|
|
370 |
* @throws ServiceFailure
|
|
371 |
* @throws NotAuthorized
|
|
372 |
* @throws NotImplemented
|
|
373 |
* @throws UnsupportedType
|
|
374 |
* @throws InsufficientResources
|
|
375 |
* @throws InvalidRequest
|
|
376 | 376 |
*/ |
377 | 377 |
@Override |
378 |
public boolean replicate(Session session, SystemMetadata sysmeta,
|
|
379 |
NodeReference sourceNode)
|
|
380 |
throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest,
|
|
381 |
InsufficientResources, UnsupportedType {
|
|
378 |
public boolean replicate(Session session, SystemMetadata sysmeta,
|
|
379 |
NodeReference sourceNode)
|
|
380 |
throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest,
|
|
381 |
InsufficientResources, UnsupportedType {
|
|
382 | 382 |
|
383 |
return false;
|
|
384 |
}
|
|
383 |
return false;
|
|
384 |
}
|
|
385 | 385 |
|
386 | 386 |
/** |
387 | 387 |
* This method provides a lighter weight mechanism than |
388 | 388 |
* MN_read.getSystemMetadata() for a client to determine basic |
389 | 389 |
* properties of the referenced object. |
390 | 390 |
* |
391 |
* @param session - the Session object containing the credentials for the Subject
|
|
392 |
* @param pid - the identifier of the object to be described
|
|
393 |
*
|
|
394 |
* @return describeResponse - A set of values providing a basic description
|
|
395 |
* of the object.
|
|
396 |
*
|
|
397 |
* @throws InvalidToken
|
|
398 |
* @throws ServiceFailure
|
|
399 |
* @throws NotAuthorized
|
|
400 |
* @throws NotFound
|
|
401 |
* @throws NotImplemented
|
|
402 |
* @throws InvalidRequest
|
|
391 |
* @param session - the Session object containing the credentials for the Subject
|
|
392 |
* @param pid - the identifier of the object to be described
|
|
393 |
*
|
|
394 |
* @return describeResponse - A set of values providing a basic description
|
|
395 |
* of the object.
|
|
396 |
*
|
|
397 |
* @throws InvalidToken
|
|
398 |
* @throws ServiceFailure
|
|
399 |
* @throws NotAuthorized
|
|
400 |
* @throws NotFound
|
|
401 |
* @throws NotImplemented
|
|
402 |
* @throws InvalidRequest
|
|
403 | 403 |
*/ |
404 | 404 |
@Override |
405 |
public DescribeResponse describe(Session session, Identifier pid)
|
|
406 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
|
|
407 |
NotImplemented, InvalidRequest {
|
|
405 |
public DescribeResponse describe(Session session, Identifier pid)
|
|
406 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
|
|
407 |
NotImplemented, InvalidRequest {
|
|
408 | 408 |
|
409 |
if(session == null) {
|
|
409 |
if(session == null) {
|
|
410 | 410 |
throw new InvalidToken("1370", "The session object is null"); |
411 | 411 |
|
412 | 412 |
} |
... | ... | |
420 | 420 |
|
421 | 421 |
SystemMetadata sysmeta = getSystemMetadata(session, pid); |
422 | 422 |
DescribeResponse describeResponse = |
423 |
new DescribeResponse(sysmeta.getObjectFormat(),
|
|
423 |
new DescribeResponse(sysmeta.getObjectFormat(),
|
|
424 | 424 |
sysmeta.getSize(), sysmeta.getDateSysMetadataModified(), sysmeta.getChecksum()); |
425 | 425 |
|
426 | 426 |
return describeResponse; |
427 | 427 |
|
428 |
}
|
|
428 |
}
|
|
429 | 429 |
|
430 |
/**
|
|
431 |
* Return the object identified by the given object identifier
|
|
432 |
*
|
|
433 |
* @param session - the Session object containing the credentials for the Subject
|
|
434 |
* @param pid - the object identifier for the given object
|
|
435 |
*
|
|
436 |
* @return inputStream - the input stream of the given object
|
|
437 |
*
|
|
438 |
* @throws InvalidToken
|
|
439 |
* @throws ServiceFailure
|
|
440 |
* @throws NotAuthorized
|
|
441 |
* @throws InvalidRequest
|
|
442 |
* @throws NotImplemented
|
|
443 |
*/
|
|
430 |
/**
|
|
431 |
* Return the object identified by the given object identifier
|
|
432 |
*
|
|
433 |
* @param session - the Session object containing the credentials for the Subject
|
|
434 |
* @param pid - the object identifier for the given object
|
|
435 |
*
|
|
436 |
* @return inputStream - the input stream of the given object
|
|
437 |
*
|
|
438 |
* @throws InvalidToken
|
|
439 |
* @throws ServiceFailure
|
|
440 |
* @throws NotAuthorized
|
|
441 |
* @throws InvalidRequest
|
|
442 |
* @throws NotImplemented
|
|
443 |
*/
|
|
444 | 444 |
@Override |
445 |
public InputStream get(Session session, Identifier pid)
|
|
446 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
|
|
447 |
NotImplemented, InvalidRequest {
|
|
448 |
|
|
449 |
return super.get(session, pid);
|
|
450 |
|
|
451 |
}
|
|
445 |
public InputStream get(Session session, Identifier pid)
|
|
446 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
|
|
447 |
NotImplemented, InvalidRequest {
|
|
448 |
|
|
449 |
return super.get(session, pid);
|
|
450 |
|
|
451 |
}
|
|
452 | 452 |
|
453 |
/**
|
|
454 |
* Returns a Checksum for the specified object using an accepted hashing algorithm
|
|
455 |
*
|
|
456 |
* @param session - the Session object containing the credentials for the Subject
|
|
457 |
* @param pid - the object identifier for the given object
|
|
458 |
* @param algorithm - the name of an algorithm that will be used to compute
|
|
459 |
* a checksum of the bytes of the object
|
|
460 |
*
|
|
461 |
* @return checksum - the checksum of the given object
|
|
462 |
*
|
|
463 |
* @throws InvalidToken
|
|
464 |
* @throws ServiceFailure
|
|
465 |
* @throws NotAuthorized
|
|
466 |
* @throws NotFound
|
|
467 |
* @throws InvalidRequest
|
|
468 |
* @throws NotImplemented
|
|
469 |
*/
|
|
453 |
/**
|
|
454 |
* Returns a Checksum for the specified object using an accepted hashing algorithm
|
|
455 |
*
|
|
456 |
* @param session - the Session object containing the credentials for the Subject
|
|
457 |
* @param pid - the object identifier for the given object
|
|
458 |
* @param algorithm - the name of an algorithm that will be used to compute
|
|
459 |
* a checksum of the bytes of the object
|
|
460 |
*
|
|
461 |
* @return checksum - the checksum of the given object
|
|
462 |
*
|
|
463 |
* @throws InvalidToken
|
|
464 |
* @throws ServiceFailure
|
|
465 |
* @throws NotAuthorized
|
|
466 |
* @throws NotFound
|
|
467 |
* @throws InvalidRequest
|
|
468 |
* @throws NotImplemented
|
|
469 |
*/
|
|
470 | 470 |
@Override |
471 |
public Checksum getChecksum(Session session, Identifier pid, String algorithm)
|
|
472 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
|
|
473 |
InvalidRequest, NotImplemented {
|
|
471 |
public Checksum getChecksum(Session session, Identifier pid, String algorithm)
|
|
472 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
|
|
473 |
InvalidRequest, NotImplemented {
|
|
474 | 474 |
|
475 |
Checksum checksum = null; |
|
476 |
|
|
477 |
InputStream inputStream = get(session, pid); |
|
478 |
|
|
479 |
try { |
|
480 |
checksum = |
|
481 |
ServiceTypeUtil.checksum(inputStream, ChecksumAlgorithm.convert(algorithm)); |
|
475 |
Checksum checksum = null; |
|
482 | 476 |
|
483 |
} catch (NoSuchAlgorithmException e) { |
|
477 |
InputStream inputStream = get(session, pid); |
|
478 |
|
|
479 |
try { |
|
480 |
checksum = |
|
481 |
ServiceTypeUtil.checksum(inputStream, ChecksumAlgorithm.convert(algorithm)); |
|
482 |
|
|
483 |
} catch (NoSuchAlgorithmException e) { |
|
484 | 484 |
throw new ServiceFailure("1410", "The checksum for the object specified by " + |
485 | 485 |
pid.getValue() + |
486 | 486 |
"could not be returned due to an internal error: " + |
... | ... | |
493 | 493 |
e.getMessage()); |
494 | 494 |
|
495 | 495 |
} |
496 |
|
|
496 |
|
|
497 | 497 |
if ( checksum == null ) { |
498 | 498 |
throw new ServiceFailure("1410", "The checksum for the object specified by " + |
499 | 499 |
pid.getValue() + |
... | ... | |
501 | 501 |
|
502 | 502 |
} |
503 | 503 |
|
504 |
return checksum;
|
|
505 |
}
|
|
504 |
return checksum;
|
|
505 |
}
|
|
506 | 506 |
|
507 |
/**
|
|
508 |
* Return the system metadata for a given object
|
|
509 |
*
|
|
510 |
* @param session - the Session object containing the credentials for the Subject
|
|
511 |
* @param pid - the object identifier for the given object
|
|
512 |
*
|
|
513 |
* @return inputStream - the input stream of the given system metadata object
|
|
514 |
*
|
|
515 |
* @throws InvalidToken
|
|
516 |
* @throws ServiceFailure
|
|
517 |
* @throws NotAuthorized
|
|
518 |
* @throws NotFound
|
|
519 |
* @throws InvalidRequest
|
|
520 |
* @throws NotImplemented
|
|
521 |
*/
|
|
507 |
/**
|
|
508 |
* Return the system metadata for a given object
|
|
509 |
*
|
|
510 |
* @param session - the Session object containing the credentials for the Subject
|
|
511 |
* @param pid - the object identifier for the given object
|
|
512 |
*
|
|
513 |
* @return inputStream - the input stream of the given system metadata object
|
|
514 |
*
|
|
515 |
* @throws InvalidToken
|
|
516 |
* @throws ServiceFailure
|
|
517 |
* @throws NotAuthorized
|
|
518 |
* @throws NotFound
|
|
519 |
* @throws InvalidRequest
|
|
520 |
* @throws NotImplemented
|
|
521 |
*/
|
|
522 | 522 |
@Override |
523 |
public SystemMetadata getSystemMetadata(Session session, Identifier pid)
|
|
524 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
|
|
525 |
InvalidRequest, NotImplemented {
|
|
523 |
public SystemMetadata getSystemMetadata(Session session, Identifier pid)
|
|
524 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
|
|
525 |
InvalidRequest, NotImplemented {
|
|
526 | 526 |
|
527 |
return super.getSystemMetadata(session, pid);
|
|
528 |
}
|
|
527 |
return super.getSystemMetadata(session, pid);
|
|
528 |
}
|
|
529 | 529 |
|
530 |
/**
|
|
531 |
* Retrieve the list of objects present on the MN that match the calling parameters
|
|
532 |
*
|
|
533 |
* @param session - the Session object containing the credentials for the Subject
|
|
534 |
* @param startTime - Specifies the beginning of the time range from which
|
|
535 |
* to return object (>=)
|
|
536 |
* @param endTime - Specifies the beginning of the time range from which
|
|
537 |
* to return object (>=)
|
|
538 |
* @param objectFormat - Restrict results to the specified object format
|
|
539 |
* @param replicaStatus - Indicates if replicated objects should be returned in the list
|
|
540 |
* @param start - The zero-based index of the first value, relative to the
|
|
541 |
* first record of the resultset that matches the parameters.
|
|
542 |
* @param count - The maximum number of entries that should be returned in
|
|
543 |
* the response. The Member Node may return less entries
|
|
544 |
* than specified in this value.
|
|
545 |
*
|
|
546 |
* @return objectList - the list of objects matching the criteria
|
|
547 |
*
|
|
548 |
* @throws InvalidToken
|
|
549 |
* @throws ServiceFailure
|
|
550 |
* @throws NotAuthorized
|
|
551 |
* @throws InvalidRequest
|
|
552 |
* @throws NotImplemented
|
|
553 |
*/
|
|
530 |
/**
|
|
531 |
* Retrieve the list of objects present on the MN that match the calling parameters
|
|
532 |
*
|
|
533 |
* @param session - the Session object containing the credentials for the Subject
|
|
534 |
* @param startTime - Specifies the beginning of the time range from which
|
|
535 |
* to return object (>=)
|
|
536 |
* @param endTime - Specifies the beginning of the time range from which
|
|
537 |
* to return object (>=)
|
|
538 |
* @param objectFormat - Restrict results to the specified object format
|
|
539 |
* @param replicaStatus - Indicates if replicated objects should be returned in the list
|
|
540 |
* @param start - The zero-based index of the first value, relative to the
|
|
541 |
* first record of the resultset that matches the parameters.
|
|
542 |
* @param count - The maximum number of entries that should be returned in
|
|
543 |
* the response. The Member Node may return less entries
|
|
544 |
* than specified in this value.
|
|
545 |
*
|
|
546 |
* @return objectList - the list of objects matching the criteria
|
|
547 |
*
|
|
548 |
* @throws InvalidToken
|
|
549 |
* @throws ServiceFailure
|
|
550 |
* @throws NotAuthorized
|
|
551 |
* @throws InvalidRequest
|
|
552 |
* @throws NotImplemented
|
|
553 |
*/
|
|
554 | 554 |
@Override |
555 |
public ObjectList listObjects(Session session, Date startTime, Date endTime,
|
|
556 |
ObjectFormat objectFormat, Boolean replicaStatus, Integer start, Integer count)
|
|
557 |
throws NotAuthorized, InvalidRequest, NotImplemented, ServiceFailure,
|
|
558 |
InvalidToken {
|
|
555 |
public ObjectList listObjects(Session session, Date startTime, Date endTime,
|
|
556 |
ObjectFormat objectFormat, Boolean replicaStatus, Integer start, Integer count)
|
|
557 |
throws NotAuthorized, InvalidRequest, NotImplemented, ServiceFailure,
|
|
558 |
InvalidToken {
|
|
559 | 559 |
|
560 |
ObjectList objectList = null;
|
|
561 |
|
|
562 |
objectList = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime,
|
|
560 |
ObjectList objectList = null;
|
|
561 |
|
|
562 |
objectList = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime,
|
|
563 | 563 |
objectFormat, replicaStatus, start, count); |
564 |
|
|
565 |
if ( objectList == null ) {
|
|
566 |
throw new ServiceFailure("1580", "The object list was null.");
|
|
567 |
}
|
|
568 |
|
|
569 |
return objectList;
|
|
570 |
}
|
|
564 |
|
|
565 |
if ( objectList == null ) {
|
|
566 |
throw new ServiceFailure("1580", "The object list was null.");
|
|
567 |
}
|
|
568 |
|
|
569 |
return objectList;
|
|
570 |
}
|
|
571 | 571 |
|
572 |
/**
|
|
573 |
* Retrieve the list of objects present on the MN that match the calling parameters
|
|
574 |
*
|
|
575 |
* @return node - the technical capabilities of the Member Node
|
|
576 |
*
|
|
577 |
* @throws ServiceFailure
|
|
578 |
* @throws NotAuthorized
|
|
579 |
* @throws InvalidRequest
|
|
580 |
* @throws NotImplemented
|
|
581 |
*/
|
|
572 |
/**
|
|
573 |
* Retrieve the list of objects present on the MN that match the calling parameters
|
|
574 |
*
|
|
575 |
* @return node - the technical capabilities of the Member Node
|
|
576 |
*
|
|
577 |
* @throws ServiceFailure
|
|
578 |
* @throws NotAuthorized
|
|
579 |
* @throws InvalidRequest
|
|
580 |
* @throws NotImplemented
|
|
581 |
*/
|
|
582 | 582 |
@Override |
583 |
public Node getCapabilities() throws NotImplemented, NotAuthorized,
|
|
584 |
ServiceFailure, InvalidRequest {
|
|
583 |
public Node getCapabilities() throws NotImplemented, NotAuthorized,
|
|
584 |
ServiceFailure, InvalidRequest {
|
|
585 | 585 |
|
586 |
return null;
|
|
587 |
}
|
|
586 |
return null;
|
|
587 |
}
|
|
588 | 588 |
|
589 |
/**
|
|
590 |
* Returns the number of operations that have been serviced by the node
|
|
591 |
* over time periods of one and 24 hours.
|
|
592 |
*
|
|
593 |
* @param session - the Session object containing the credentials for the Subject
|
|
594 |
* @param period - An ISO8601 compatible DateTime range specifying the time
|
|
595 |
* range for which to return operation statistics.
|
|
596 |
* @param requestor - Limit to operations performed by given requestor identity.
|
|
597 |
* @param event - Enumerated value indicating the type of event being examined
|
|
598 |
* @param format - Limit to events involving objects of the specified format
|
|
599 |
*
|
|
600 |
* @return the desired log records
|
|
601 |
*
|
|
602 |
* @throws InvalidToken
|
|
603 |
* @throws ServiceFailure
|
|
604 |
* @throws NotAuthorized
|
|
605 |
* @throws InvalidRequest
|
|
606 |
* @throws NotImplemented
|
|
607 |
*/
|
|
589 |
/**
|
|
590 |
* Returns the number of operations that have been serviced by the node
|
|
591 |
* over time periods of one and 24 hours.
|
|
592 |
*
|
|
593 |
* @param session - the Session object containing the credentials for the Subject
|
|
594 |
* @param period - An ISO8601 compatible DateTime range specifying the time
|
|
595 |
* range for which to return operation statistics.
|
|
596 |
* @param requestor - Limit to operations performed by given requestor identity.
|
|
597 |
* @param event - Enumerated value indicating the type of event being examined
|
|
598 |
* @param format - Limit to events involving objects of the specified format
|
|
599 |
*
|
|
600 |
* @return the desired log records
|
|
601 |
*
|
|
602 |
* @throws InvalidToken
|
|
603 |
* @throws ServiceFailure
|
|
604 |
* @throws NotAuthorized
|
|
605 |
* @throws InvalidRequest
|
|
606 |
* @throws NotImplemented
|
|
607 |
*/
|
|
608 | 608 |
@Override |
609 |
public MonitorList getOperationStatistics(Session session, Integer period,
|
|
610 |
Subject requestor, Event event, ObjectFormat format)
|
|
609 |
public MonitorList getOperationStatistics(Session session, Integer period,
|
|
610 |
Subject requestor, Event event, ObjectFormat format)
|
|
611 | 611 |
throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, |
612 | 612 |
InsufficientResources, UnsupportedType { |
613 | 613 |
|
614 |
return null;
|
|
615 |
}
|
|
614 |
return null;
|
|
615 |
}
|
|
616 | 616 |
|
617 | 617 |
/** |
618 | 618 |
* Low level “are you alive” operation. A valid ping response is |
... | ... | |
620 | 620 |
* |
621 | 621 |
* @return true if the service is alive |
622 | 622 |
* |
623 |
* @throws InvalidToken
|
|
624 |
* @throws ServiceFailure
|
|
625 |
* @throws NotAuthorized
|
|
626 |
* @throws InvalidRequest
|
|
627 |
* @throws NotImplemented
|
|
623 |
* @throws InvalidToken
|
|
624 |
* @throws ServiceFailure
|
|
625 |
* @throws NotAuthorized
|
|
626 |
* @throws InvalidRequest
|
|
627 |
* @throws NotImplemented
|
|
628 | 628 |
*/ |
629 |
@Override
|
|
630 |
public boolean ping()
|
|
631 |
throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest,
|
|
632 |
InsufficientResources, UnsupportedType {
|
|
629 |
@Override
|
|
630 |
public boolean ping()
|
|
631 |
throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest,
|
|
632 |
InsufficientResources, UnsupportedType {
|
|
633 | 633 |
|
634 |
return true;
|
|
635 |
}
|
|
634 |
return true;
|
|
635 |
}
|
|
636 | 636 |
|
637 | 637 |
/** |
638 | 638 |
* A callback method used by a CN to indicate to a MN that it cannot |
... | ... | |
641 | 641 |
* |
642 | 642 |
* @param session |
643 | 643 |
* @param syncFailed |
644 |
*
|
|
645 |
* @throws ServiceFailure
|
|
646 |
* @throws NotAuthorized
|
|
647 |
* @throws InvalidRequest
|
|
648 |
* @throws NotImplemented
|
|
644 |
*
|
|
645 |
* @throws ServiceFailure
|
|
646 |
* @throws NotAuthorized
|
|
647 |
* @throws InvalidRequest
|
|
648 |
* @throws NotImplemented
|
|
649 | 649 |
*/ |
650 |
@Override
|
|
650 |
@Override
|
|
651 | 651 |
public void synchronizationFailed(Session session, SynchronizationFailed syncFailed) |
652 | 652 |
throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest { |
653 | 653 |
|
654 |
String localId;
|
|
655 |
|
|
656 |
try {
|
|
657 |
localId = IdentifierManager.getInstance().getLocalId(syncFailed.getPid().getValue());
|
|
654 |
String localId;
|
|
655 |
|
|
656 |
try {
|
|
657 |
localId = IdentifierManager.getInstance().getLocalId(syncFailed.getPid().getValue());
|
|
658 | 658 |
} catch (McdbDocNotFoundException e) { |
659 | 659 |
throw new ServiceFailure("2161", "The identifier specified by " + |
660 |
syncFailed.getPid().getValue() +
|
|
661 |
" was not found on this node.");
|
|
660 |
syncFailed.getPid().getValue() +
|
|
661 |
" was not found on this node.");
|
|
662 | 662 |
|
663 | 663 |
} |
664 |
// TODO: update the CN URL below when the CNRead.SynchronizationFailed
|
|
664 |
// TODO: update the CN URL below when the CNRead.SynchronizationFailed
|
|
665 | 665 |
// method is changed to include the URL as a parameter |
666 | 666 |
logMetacat.debug("Synchronization for the object identified by " + |
667 |
syncFailed.getPid().getValue() +
|
|
668 |
" failed from " +
|
|
669 |
"CN URL WILL GO HERE." +
|
|
670 |
" Logging the event to the Metacat EventLog as a 'syncFailed' event.");
|
|
667 |
syncFailed.getPid().getValue() +
|
|
668 |
" failed from " +
|
|
669 |
"CN URL WILL GO HERE." +
|
|
670 |
" Logging the event to the Metacat EventLog as a 'syncFailed' event.");
|
|
671 | 671 |
EventLog.getInstance().log("CN URL WILL GO HERE", |
672 |
session.getSubject().getValue(), localId, "syncFailed");
|
|
672 |
session.getSubject().getValue(), localId, "syncFailed");
|
|
673 | 673 |
|
674 | 674 |
} |
675 | 675 |
|
Also available in: Unified diff
Minor housekeeping - tabs to spaces.