Revision 6258
Added by Chris Jones over 13 years ago
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
30 | 30 |
import java.util.Date; |
31 | 31 |
import java.util.List; |
32 | 32 |
|
33 |
import org.apache.commons.io.IOUtils; |
|
33 | 34 |
import org.apache.log4j.Logger; |
34 | 35 |
import org.dataone.service.exceptions.IdentifierNotUnique; |
35 | 36 |
import org.dataone.service.exceptions.InsufficientResources; |
... | ... | |
180 | 181 |
try { |
181 | 182 |
// delete the document |
182 | 183 |
DocumentImpl.delete(localId, subject.getValue(), groups, null); |
183 |
EventLog.getInstance().log(metacatUrl, subject.getValue(), localId, "create");
|
|
184 |
EventLog.getInstance().log(metacatUrl, subject.getValue(), localId, "delete");
|
|
184 | 185 |
|
185 | 186 |
} catch (McdbDocNotFoundException e) { |
186 | 187 |
throw new InvalidRequest("1322", "The provided identifier was invalid."); |
... | ... | |
240 | 241 |
UnsupportedType, InsufficientResources, NotFound, InvalidSystemMetadata, |
241 | 242 |
NotImplemented, InvalidRequest { |
242 | 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(); |
|
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 |
} |
|
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 |
} |
|
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."); |
|
271 |
|
|
272 |
} |
|
273 |
|
|
274 |
// check for the existing identifier |
|
275 |
try { |
|
276 |
localId = im.getLocalId(pid.getValue()); |
|
277 |
|
|
278 |
} catch (McdbDocNotFoundException e) { |
|
279 |
throw new InvalidRequest("1202", "The object with the provided " + |
|
280 |
"identifier was not found."); |
|
281 |
|
|
282 |
} |
|
283 |
|
|
284 |
// does the subject have WRITE ( == update) priveleges on the pid? |
|
285 |
allowed = isAuthorized(session, pid, Permission.WRITE); |
|
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. " + |
|
326 |
"There was a problem converting the object to XML"; |
|
327 |
logMetacat.info(msg); |
|
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 |
|
344 |
EventLog.getInstance().log(metacatUrl, subject.getValue(), localId, "update"); |
|
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 |
} |
|
243 | 352 |
|
244 | 353 |
return pid; |
245 | 354 |
} |
Also available in: Unified diff
Implement update() in MNodeService. Handle both XML science metadata updates and data object updates. Keep system metadata up to date, and log the update event.