/** * Retrieve the original name of this attachment. * * @return the original filename, for example {@code MyPhoto.png} */ public String getFilename() { return this.deletedAttachment.getFilename(); }
@Override public DeletedAttachment next() { Long item = this.data.next(); try { DeletedAttachment result = HibernateDeletedAttachmentsReader.this.store.getDeletedAttachment( item, HibernateDeletedAttachmentsReader.this.context.get(), true); HibernateDeletedAttachmentsReader.this.logger.debug("Loaded [{}@{}#{}] from the database trash", result.getDocName(), result.getFilename(), result.getId()); return result; } catch (Exception ex) { HibernateDeletedAttachmentsReader.this.logger.error( "Failed to read deleted attachment from the database store: {}", ex.getMessage(), ex); } return null; }
@Override public DeletedAttachment next() { Long item = this.data.next(); try { DeletedAttachment result = HibernateDeletedAttachmentsReader.this.store.getDeletedAttachment( item, HibernateDeletedAttachmentsReader.this.context.get(), true); HibernateDeletedAttachmentsReader.this.logger.debug("Loaded [{}@{}#{}] from the database trash", result.getDocName(), result.getFilename(), result.getId()); return result; } catch (Exception ex) { HibernateDeletedAttachmentsReader.this.logger.error( "Failed to read deleted attachment from the database store: {}", ex.getMessage(), ex); } return null; }
@Override public boolean discardEntity(DeletedAttachment entity) { boolean transaction = false; try { transaction = ((XWikiHibernateBaseStore) this.store).beginTransaction(this.context.get()); Session session = ((XWikiHibernateBaseStore) this.store).getSession(this.context.get()); session.delete(entity); this.logger.debug("Deleted deleted attachment [{}@{}#{}] from the database trash", entity.getDocName(), entity.getFilename(), entity.getId()); } catch (XWikiException ex) { this.logger.warn("Failed to cleanup attachment from the database trash: {}", ex.getMessage()); return false; } finally { if (transaction) { ((XWikiHibernateBaseStore) this.store).endTransaction(this.context.get(), transaction); } } return true; }
@Override public boolean discardEntity(DeletedAttachment entity) { boolean transaction = false; try { transaction = ((XWikiHibernateBaseStore) this.store).beginTransaction(this.context.get()); Session session = ((XWikiHibernateBaseStore) this.store).getSession(this.context.get()); session.delete(entity); this.logger.debug("Deleted deleted attachment [{}@{}#{}] from the database trash", entity.getDocName(), entity.getFilename(), entity.getId()); } catch (XWikiException ex) { this.logger.warn("Failed to cleanup attachment from the database trash: {}", ex.getMessage()); return false; } finally { if (transaction) { ((XWikiHibernateBaseStore) this.store).endTransaction(this.context.get(), transaction); } } return true; }
@Override public boolean storeEntity(DeletedAttachment entity) { if (entity == null) { return true; } try { XWikiAttachment attachment = entity.restoreAttachment(null, this.context.get()); this.store.saveToRecycleBin(attachment, entity.getDeleter(), entity.getDate(), this.context.get(), false); this.logger.debug("Imported deleted attachment [{}@{}#{}] into the filesystem trash store", entity.getDocName(), entity.getFilename(), entity.getId()); return true; } catch (XWikiException ex) { this.logger.error("Failed to store deleted attachment into the filesystem store: {}", ex.getMessage(), ex); return false; } } }
@Override public boolean storeEntity(DeletedAttachment entity) { if (entity == null) { return true; } try { XWikiAttachment attachment = entity.restoreAttachment(null, this.context.get()); this.store.saveToRecycleBin(attachment, entity.getDeleter(), entity.getDate(), this.context.get(), false); this.logger.debug("Imported deleted attachment [{}@{}#{}] into the filesystem trash store", entity.getDocName(), entity.getFilename(), entity.getId()); return true; } catch (XWikiException ex) { this.logger.error("Failed to store deleted attachment into the filesystem store: {}", ex.getMessage(), ex); return false; } } }
new File(directory.getParentFile(), encode(dbAttachment.getFilename() + "-id" + databaseId)); FileUtils.moveDirectory(directory, newDirectory);