Commit 6cfa95a8 by Jan Hrabal

x

parent 9bab9437
......@@ -19,7 +19,6 @@ public abstract class AbstractHibernateAttachmentService implements AttachmentSe
protected abstract void saveData(Attachment attachment, InputStream stream);
@Override
public Attachment saveAttachment(Attachment attachment) {
repository.save(attachment);
......@@ -39,9 +38,15 @@ public abstract class AbstractHibernateAttachmentService implements AttachmentSe
@Override
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)
public void setRepository(AttachmentRepository repository) {
......
......@@ -31,7 +31,21 @@ public class FileBasedAttachmentService extends AbstractHibernateAttachmentServi
} catch (Exception 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) {
......@@ -51,4 +65,5 @@ public class FileBasedAttachmentService extends AbstractHibernateAttachmentServi
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