コード例 #1
0
 private boolean canCreate(DMSFile parent) {
   final User user = AuthUtils.getUser();
   final Group group = user.getGroup();
   if (parent.getCreatedBy() == user
       || security.hasRole("role.super")
       || security.hasRole("role.admin")) {
     return true;
   }
   return dmsPermissions
           .all()
           .filter(
               "self.file = :file AND self.permission.canWrite = true AND "
                   + "(self.user = :user OR self.group = :group)")
           .bind("file", parent)
           .bind("user", user)
           .bind("group", group)
           .autoFlush(false)
           .count()
       > 0;
 }
コード例 #2
0
  @Override
  public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    final DMSFile file = findFrom(json);
    if (file == null) {
      return json;
    }

    boolean isFile = file.getIsDirectory() != Boolean.TRUE;
    LocalDateTime dt = file.getUpdatedOn();
    if (dt == null) {
      dt = file.getCreatedOn();
    }

    final User user = AuthUtils.getUser();
    final MetaFile metaFile = file.getMetaFile();

    boolean canShare =
        file.getCreatedBy() == user
            || security.isPermitted(AccessType.CREATE, DMSFile.class, file.getId())
            || dmsPermissions
                    .all()
                    .filter(
                        "self.file = ? AND self.value = 'FULL' AND (self.user = ? OR self.group = ?)",
                        file,
                        user,
                        user.getGroup())
                    .count()
                > 0;

    json.put("typeIcon", isFile ? "fa fa-file" : "fa fa-folder");
    json.put("downloadIcon", "fa fa-download");
    json.put("detailsIcon", "fa fa-info-circle");

    json.put("canShare", canShare);
    json.put("canWrite", canCreate(file));

    if (canOffline(file, user)) {
      json.put("offline", true);
    }

    json.put("lastModified", dt);
    json.put("createdOn", file.getCreatedOn());
    json.put("createdBy", file.getCreatedBy());
    json.put("updatedBy", file.getUpdatedBy());
    json.put("updatedOn", file.getUpdatedOn());

    if ("html".equals(file.getContentType())) {
      json.put("fileType", "text/html");
      json.put("contentType", "html");
      json.put("typeIcon", "fa fa-file-text-o");
      json.remove("downloadIcon");
    }
    if ("spreadsheet".equals(file.getContentType())) {
      json.put("fileType", "text/json");
      json.put("contentType", "spreadsheet");
      json.put("typeIcon", "fa fa-file-excel-o");
      json.remove("downloadIcon");
    }

    if (metaFile != null) {

      String fileType = metaFile.getFileType();
      String fileIcon = "fa-file-o";

      switch (fileType) {
        case "application/msword":
        case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
        case "application/vnd.oasis.opendocument.text":
          fileIcon = "fa-file-word-o";
          break;
        case "application/vnd.ms-excel":
        case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
        case "application/vnd.oasis.opendocument.spreadsheet":
          fileIcon = "fa-file-excel-o";
          break;
        case "application/pdf":
          fileIcon = "fa-file-pdf-o";
          break;
        case "application/zip":
        case "application/gzip":
          fileIcon = "fa-file-archive-o";
          break;
        default:
          String type = metaFile.getFileType();
          if (type != null) {
            if (type.startsWith("text")) fileIcon = "fa-file-text-o";
            if (type.startsWith("image")) fileIcon = "fa-file-image-o";
            if (type.startsWith("video")) fileIcon = "fa-file-video-o";
          }
          break;
      }

      json.put("fileType", fileType);
      json.put("typeIcon", "fa " + fileIcon);
    }

    if (file.getTags() != null) {
      final List<Object> tags = new ArrayList<>();
      for (DMSFileTag tag : file.getTags()) {
        tags.add(Resource.toMap(tag, "id", "code", "name", "style"));
      }
      json.put("tags", tags);
    }

    return json;
  }