コード例 #1
0
ファイル: DiskService.java プロジェクト: bolatu836125/lemon
  /** 删除. */
  public String remove(Long id) {
    DiskInfo diskInfo = diskInfoManager.get(id);

    if (diskInfo == null) {
      return "";
    }

    diskInfo.setStatus("trash");
    diskInfoManager.save(diskInfo);

    return diskInfo.getParentPath();
  }
コード例 #2
0
ファイル: DiskService.java プロジェクト: bolatu836125/lemon
  /** 上传文件,或新建文件夹. */
  public DiskInfo createDiskInfo(
      String userId,
      String name,
      long size,
      String ref,
      String type,
      int dirType,
      String parentPath) {
    if (name == null) {
      logger.info("name cannot be null");

      return null;
    }

    name = name.trim();

    if (name.length() == 0) {
      logger.info("name cannot be empty");

      return null;
    }

    if (parentPath == null) {
      parentPath = "";
    } else {
      parentPath = parentPath.trim();
    }

    if (parentPath.length() != 0) {
      if (!parentPath.startsWith("/")) {
        parentPath = "/" + parentPath;
      }

      int index = parentPath.lastIndexOf("/");
      String targetParentPath = parentPath.substring(0, index);
      String targetName = parentPath.substring(index + 1);
      String hql = "from DiskInfo where parentPath=? and name=?";
      DiskInfo parent = diskInfoManager.findUnique(hql, targetParentPath, targetName);

      if (parent == null) {
        logger.info("cannot find : {} {} {}", parentPath, targetParentPath, targetName);

        return null;
      }
    }

    String hql = "select name from DiskInfo where creator=? and parentPath=?";
    List<String> currentNames = diskInfoManager.find(hql, userId, parentPath);
    String targetName = FileUtils.calculateName(name, currentNames);

    Date now = new Date();
    DiskInfo diskInfo = new DiskInfo();
    diskInfo.setName(targetName);
    diskInfo.setType(type);
    diskInfo.setFileSize(size);
    diskInfo.setCreator(userId);
    diskInfo.setCreateTime(now);
    diskInfo.setLastModifier(userId);
    diskInfo.setLastModifiedTime(now);
    diskInfo.setDirType(dirType);
    diskInfo.setRef(ref);
    diskInfo.setStatus("active");
    diskInfo.setParentPath(parentPath);
    diskInfoManager.save(diskInfo);

    return diskInfo;
  }