Revision 5353
Added by berkley almost 14 years ago
CrudService.java | ||
---|---|---|
232 | 232 |
logMetacat.debug("Returning from CrudService.create()"); |
233 | 233 |
return guid; |
234 | 234 |
} |
235 |
|
|
236 |
/** |
|
237 |
* update an existing object with a new object. Change the system metadata |
|
238 |
* to reflect the changes and update it as well. |
|
239 |
*/ |
|
240 |
public Identifier update(AuthToken token, Identifier guid, |
|
241 |
InputStream object, Identifier obsoletedGuid, SystemMetadata sysmeta) |
|
242 |
throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, |
|
243 |
UnsupportedType, InsufficientResources, NotFound, InvalidSystemMetadata, |
|
244 |
NotImplemented { |
|
245 |
try |
|
246 |
{ |
|
247 |
SessionData sessionData = getSessionData(token); |
|
248 |
|
|
249 |
//find the old systemmetadata (sm.old) document id (the one linked to obsoletedGuid) |
|
250 |
SystemMetadata sm = getSystemMetadata(token, obsoletedGuid); |
|
251 |
//change sm.old's obsoletedBy field |
|
252 |
List l = sm.getObsoletedByList(); |
|
253 |
l.add(guid); |
|
254 |
sm.setObsoletedByList(l); |
|
255 |
//update sm.old |
|
256 |
updateSystemMetadata(sm, sessionData); |
|
257 |
|
|
258 |
//change the obsoletes field of the new systemMetadata (sm.new) to point to the id of the old one |
|
259 |
sysmeta.addObsolete(obsoletedGuid); |
|
260 |
//insert sm.new |
|
261 |
insertSystemMetadata(sysmeta, sessionData); |
|
262 |
|
|
263 |
boolean isScienceMetadata = isScienceMetadata(sysmeta); |
|
264 |
if(isScienceMetadata) |
|
265 |
{ |
|
266 |
//update the doc |
|
267 |
updateDocument(object, obsoletedGuid, guid, sessionData); |
|
268 |
} |
|
269 |
else |
|
270 |
{ |
|
271 |
//update a data file, not xml |
|
272 |
insertDataObject(object, guid, sessionData); |
|
273 |
} |
|
274 |
return guid; |
|
275 |
} |
|
276 |
catch(Exception e) |
|
277 |
{ |
|
278 |
throw new ServiceFailure(1030, "Error updating document in CrudService: " + e.getMessage()); |
|
279 |
} |
|
280 |
} |
|
235 | 281 |
|
236 | 282 |
public Identifier delete(AuthToken token, Identifier guid) |
237 | 283 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, |
... | ... | |
370 | 416 |
} |
371 | 417 |
} |
372 | 418 |
|
373 |
/** |
|
374 |
* update an existing object with a new object. Change the system metadata |
|
375 |
* to reflect the changes and update it as well. |
|
376 |
*/ |
|
377 |
public Identifier update(AuthToken token, Identifier guid, |
|
378 |
InputStream object, Identifier obsoletedGuid, SystemMetadata sysmeta) |
|
379 |
throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, |
|
380 |
UnsupportedType, InsufficientResources, NotFound, InvalidSystemMetadata, |
|
381 |
NotImplemented { |
|
382 |
try |
|
383 |
{ |
|
384 |
SessionData sessionData = getSessionData(token); |
|
385 |
|
|
386 |
//find the old systemmetadata (sm.old) document id (the one linked to obsoletedGuid) |
|
387 |
SystemMetadata sm = getSystemMetadata(token, obsoletedGuid); |
|
388 |
//change sm.old's obsoletedBy field |
|
389 |
List l = sm.getObsoletedByList(); |
|
390 |
l.add(guid); |
|
391 |
sm.setObsoletedByList(l); |
|
392 |
//update sm.old |
|
393 |
updateSystemMetadata(sm, sessionData); |
|
394 |
|
|
395 |
//change the obsoletes field of the new systemMetadata (sm.new) to point to the id of the old one |
|
396 |
sysmeta.addObsolete(obsoletedGuid); |
|
397 |
//insert sm.new |
|
398 |
insertSystemMetadata(sysmeta, sessionData); |
|
399 |
|
|
400 |
//update the doc |
|
401 |
updateDocument(object, obsoletedGuid, guid, sessionData); |
|
402 |
return guid; |
|
403 |
} |
|
404 |
catch(Exception e) |
|
405 |
{ |
|
406 |
throw new ServiceFailure(1030, "Error updating document in CrudService: " + e.getMessage()); |
|
407 |
} |
|
408 |
} |
|
409 |
|
|
410 | 419 |
/* |
411 | 420 |
* Look up the information on the session using the token provided in |
412 | 421 |
* the AuthToken. The Session should have all relevant user information. |
... | ... | |
488 | 497 |
// if the localId is not acceptable or other untoward things happen |
489 | 498 |
try { |
490 | 499 |
logMetacat.debug("Registering document..."); |
500 |
System.out.println("inserting data object: localId: " + localId); |
|
491 | 501 |
DocumentImpl.registerDocument(localId, "BIN", localId, |
492 | 502 |
username, groups); |
493 | 503 |
logMetacat.debug("Registration step completed."); |
Also available in: Unified diff
implemented update in ResourceHandler and fixed a bug in CrudService where data files were not handled correctly on update