Beispiel #1
0
  /** 重命名. */
  public String rename(String userId, Long id, String name) {
    DiskInfo diskInfo = diskInfoManager.get(id);
    String parentPath = diskInfo.getParentPath();
    String type = FileUtils.getSuffix(name);
    String hql = "select name from DiskInfo where creator=? and parentPath=? and id!=?";
    List<String> currentNames = diskInfoManager.find(hql, userId, parentPath, id);
    String targetName = FileUtils.calculateName(name, currentNames);
    diskInfo.setName(targetName);
    diskInfo.setType(type);
    diskInfoManager.save(diskInfo);

    return parentPath;
  }
Beispiel #2
0
  /** 上传文件,或新建文件夹. */
  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;
  }