Commit 6cfa95a8 by Jan Hrabal

x

parent 9bab9437
...@@ -19,7 +19,6 @@ public abstract class AbstractHibernateAttachmentService implements AttachmentSe ...@@ -19,7 +19,6 @@ public abstract class AbstractHibernateAttachmentService implements AttachmentSe
protected abstract void saveData(Attachment attachment, InputStream stream); protected abstract void saveData(Attachment attachment, InputStream stream);
@Override @Override
public Attachment saveAttachment(Attachment attachment) { public Attachment saveAttachment(Attachment attachment) {
repository.save(attachment); repository.save(attachment);
...@@ -39,9 +38,15 @@ public abstract class AbstractHibernateAttachmentService implements AttachmentSe ...@@ -39,9 +38,15 @@ public abstract class AbstractHibernateAttachmentService implements AttachmentSe
@Override @Override
public void deleteAttachment(Long attachmentId) { public void deleteAttachment(Long attachmentId) {
throw new UnsupportedOperationException("Not implemented"); Attachment a = repository.findById(attachmentId);
if (a != null) {
repository.delete(a);
deleteData(a);
}
} }
protected abstract void deleteData(Attachment attachment);
@Autowired(required = false) @Autowired(required = false)
public void setRepository(AttachmentRepository repository) { public void setRepository(AttachmentRepository repository) {
......
...@@ -31,7 +31,21 @@ public class FileBasedAttachmentService extends AbstractHibernateAttachmentServi ...@@ -31,7 +31,21 @@ public class FileBasedAttachmentService extends AbstractHibernateAttachmentServi
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Cannot write data", e); throw new RuntimeException("Cannot write data", e);
} }
}
@Override
protected void deleteData(Attachment attachment) {
File file = file(attachment);
if (file.exists()) {
file.delete();
file = file.getParentFile();
if (file.listFiles().length == 0) {
//delete ?
file.delete();
}
}
} }
protected File file(Attachment attachment) { protected File file(Attachment attachment) {
...@@ -51,4 +65,5 @@ public class FileBasedAttachmentService extends AbstractHibernateAttachmentServi ...@@ -51,4 +65,5 @@ public class FileBasedAttachmentService extends AbstractHibernateAttachmentServi
this.dataDirectory = dataDirectory; this.dataDirectory = dataDirectory;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment