Пример #1
0
 /**
  * {@code from}에 첨부된 모든 첨부 파일을 {@code to}로 옮긴다.
  *
  * <p>when: 업로드 직후 일시적으로 사용자에게 첨부되었던 첨부 파일들을, 특정 리소스(이슈, 게시물 등)으로 옮기려 할 때
  *
  * @param from 첨부 파일이 원래 있었던 리소스
  * @param to 첨부 파일이 새로 옮겨질 리소스
  * @return
  */
 public static int moveAll(Resource from, Resource to) {
   List<Attachment> attachments = Attachment.findByContainer(from);
   for (Attachment attachment : attachments) {
     attachment.moveTo(to);
   }
   return attachments.size();
 }
Пример #2
0
 /**
  * {@code from}에 첨부된 파일중 파일 아이디가{@code selectedFileIds}에 해당하는 첨부 파일을 {@code to}로 옮긴다.
  *
  * <p>when: 업로드 직후 일시적으로 사용자에게 첨부되었던 첨부 파일들을, 특정 리소스(이슈, 게시물 등)으로 옮기려 할 때
  *
  * @param from 첨부 파일이 원래 있었던 리소스
  * @param to 첨부 파일이 새로 옮겨질 리소스
  * @return
  */
 public static int moveOnlySelected(Resource from, Resource to, String[] selectedFileIds) {
   if (selectedFileIds.length == 0) {
     return NOTHING_TO_ATTACH;
   }
   List<Attachment> attachments =
       Attachment.find.where().idIn(Arrays.asList(selectedFileIds)).findList();
   for (Attachment attachment : attachments) {
     if (attachment.containerId.equals(from.getId())
         && attachment.containerType == from.getType()) {
       attachment.moveTo(to);
     }
   }
   return attachments.size();
 }