use of org.obiba.mica.file.Attachment in project mica2 by obiba.
the class FileSystemService method copy.
/**
* Make a copy of the latest {@link Attachment} (and associated raw file) and optionally delete
* the {@link AttachmentState} source.
*
* @param state
* @param newPath
* @param newName
* @param delete
*/
public void copy(AttachmentState state, String newPath, String newName, boolean delete) {
if (state.getPath().equals(newPath) && state.getName().equals(newName))
return;
if (hasAttachmentState(newPath, newName, false))
throw new IllegalArgumentException("A file with name '" + newName + "' already exists at path: " + newPath);
Attachment attachment = state.getAttachment();
Attachment newAttachment = new Attachment();
BeanUtils.copyProperties(attachment, newAttachment, "id", "version", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate");
newAttachment.setPath(newPath);
newAttachment.setName(newName);
save(newAttachment);
fileStoreService.save(newAttachment.getFileReference(), fileStoreService.getFile(attachment.getFileReference()));
if (delete)
updateStatus(state, RevisionStatus.DELETED);
}
Aggregations