コード例 #1
0
ファイル: UGCServiceImpl.java プロジェクト: rart/social
 @Override
 @HasPermission(action = UGC_UPDATE, type = SocialPermission.class)
 public void removeAttachment(
     @SecuredObject final String ugcId, final String contextId, final String attachmentId)
     throws UGCException, FileNotFoundException {
   try {
     UGC ugc = ugcRepository.findUGC(contextId, ugcId);
     if (ugc == null) {
       throw new IllegalUgcException("UGC with given Id does not exist");
     }
     if (!ObjectId.isValid(attachmentId)) {
       throw new IllegalArgumentException("Given Attachment id is not valid");
     }
     ObjectId attachmentOid = new ObjectId(attachmentId);
     FileInfo info = ugcRepository.getFileInfo(attachmentOid);
     if (!info.getStoreName().startsWith(File.separator + contextId)) {
       throw new IllegalSocialQueryException(
           "Given Attachment does not belong to the given context");
     }
     ugc.getAttachments().remove(info);
     ugcRepository.deleteFile(attachmentOid);
     ugcRepository.update(ugcId, ugc);
     reactor.notify(
         UGCEvent.DELETE_ATTACHMENT.getName(),
         Event.wrap(new SocialEvent<>(ugcId, attachmentId, UGCEvent.DELETE_ATTACHMENT)));
   } catch (MongoDataException e) {
     log.error("logging.ugc.attachmentToRemove", e, attachmentId);
     throw new UGCException("Unable to save File to UGC");
   }
 }