}
}
public void removeBinaryResource(final Txn transaction, final DBBroker broker, final DocumentImpl doc) throws PermissionDeniedException, LockException, TriggerException {
if(!getPermissionsNoLock().validate(broker.getSubject(), Permission.WRITE)) {
throw new PermissionDeniedException("Permission denied to write collection: " + path);
}
if(doc == null) {
return; //TODO should throw an exception!!! Otherwise we dont know if the document was removed
}
try {
broker.getBrokerPool().getProcessMonitor().startJob(ProcessMonitor.ACTION_REMOVE_BINARY, doc.getFileURI());
getLock().acquire(Lock.WRITE_LOCK);
if(doc.getResourceType() != DocumentImpl.BINARY_FILE) {
throw new PermissionDeniedException("document " + doc.getFileURI() + " is not a binary object");
}
if(doc.isLockedForWrite()) {
throw new PermissionDeniedException("Document " + doc.getFileURI() + " is locked for write");
}
doc.getUpdateLock().acquire(Lock.WRITE_LOCK);
DocumentTriggers trigger = new DocumentTriggers(broker, null, this, isTriggersEnabled() ? getConfiguration(broker) : null);
trigger.beforeDeleteDocument(broker, transaction, doc);
try {
broker.removeBinaryResource(transaction, (BinaryDocument) doc);
} catch (final IOException ex) {
throw new PermissionDeniedException("Cannot delete file: " + doc.getURI().toString() + ": " + ex.getMessage(), ex);
}
documents.remove(doc.getFileURI().getRawCollectionPath());
trigger.afterDeleteDocument(broker, transaction, doc.getURI());