All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bimface.sdk.service.BdfsService Maven / Gradle / Ivy

The newest version!
package com.bimface.sdk.service;

import com.bimface.bdfs.bean.*;
import com.bimface.bdfs.bean.dto.*;
import com.bimface.bdfs.bean.dto.v1.FileItemDTOV1;
import com.bimface.bdfs.bean.dto.v1.multipartupload.*;
import com.bimface.exception.BimfaceException;
import com.bimface.page.PagedList;
import com.bimface.sdk.bean.request.CreateFolderRequest;
import com.bimface.sdk.bean.request.FileItemQueryRequest;
import com.bimface.sdk.bean.request.ProjectCreateRequest;
import com.bimface.sdk.bean.response.FileItemUploadStatusBean;
import com.bimface.sdk.client.BdfsClient;
import com.bimface.sdk.config.Config;
import com.bimface.sdk.config.Endpoint;

import java.io.InputStream;
import java.util.List;

/**
 * Created by tangj-i on 2023/3/27.
 */
public class BdfsService {

    private AccessTokenService accessTokenService;
    private BdfsClient bdfsClient;

    public BdfsService(Endpoint endpoint, AccessTokenService accessTokenService) {
        this(endpoint, null, accessTokenService);
    }

    public BdfsService(Endpoint endpoint, Config config, AccessTokenService accessTokenService) {
        this.bdfsClient = BdfsClient.getBdfsClient(endpoint.getBdfsHost(), config);
        this.accessTokenService = accessTokenService;
    }


    /**
     * 获取hub列表
     *
     * @param name         hub名称
     * @param tenantCode   租户标识
     * @param info         描述信息
     * @param dateTimeFrom 开始时间
     * @param dateTimeTo   结束时间
     * @return
     */
    public List getHubList(String name, String tenantCode, String info, String dateTimeFrom, String dateTimeTo) throws BimfaceException {
        return bdfsClient.getHubList(name, tenantCode, info, dateTimeFrom, dateTimeTo, accessTokenService.getAccessToken());
    }

    /**
     * 获取Hub Meta信息
     *
     * @param hubId hubId
     * @return 单个Hub
     */
    public HubDTO getHubMeta(Long hubId) throws BimfaceException {
        return bdfsClient.getHubMeta(hubId, accessTokenService.getAccessToken());
    }

    /**
     * 创建项目
     *
     * @param hubId
     * @param request 项目目创建请求
     * @return
     */
    public ProjectDTO createProject(String hubId, ProjectCreateRequest request) throws BimfaceException {
        return bdfsClient.createProject(hubId, request, accessTokenService.getAccessToken());
    }

    /**
     * 获取项目列表
     *
     * @param hubId
     * @param name           项目名称
     * @param useFuzzySearch 是否使用模糊查询
     * @return
     */
    public List getProjectList(String hubId, String name, Boolean useFuzzySearch) throws BimfaceException {
        return bdfsClient.getProjectList(hubId, name, useFuzzySearch, accessTokenService.getAccessToken());
    }

    /**
     * 获取项目信息
     *
     * @param hubId     hubId
     * @param projectId 项目Id
     * @return
     */
    public ProjectDTO getProjectMeta(String hubId, String projectId) throws BimfaceException {
        return bdfsClient.getProjectMeta(hubId, projectId, accessTokenService.getAccessToken());
    }

    /**
     * 删除项目
     *
     * @param hubId     hubId
     * @param projectId 项目Id
     * @return
     */
    public ProjectDTO deleteProject(String hubId, String projectId) throws BimfaceException {
        return bdfsClient.deleteProject(hubId, projectId, accessTokenService.getAccessToken());
    }

    /**
     * 更新项目信息
     *
     * @param hubId            hubId
     * @param projectId        项目Id
     * @param updateProjectReq 更新项目信息请求体
     * @return
     */
    public ProjectDTO updateProject(String hubId, String projectId, UpdateProjectRequest updateProjectReq) throws BimfaceException {
        return bdfsClient.updateProject(hubId, projectId, updateProjectReq, accessTokenService.getAccessToken());
    }

    /**
     * 获取项目根文件夹信息
     *
     * @param hubId     hubId
     * @param projectId 项目Id
     * @return
     */
    public FileItemWithPathDTO getProjectRootFolderInfo(String hubId, String projectId) throws BimfaceException {
        return bdfsClient.getProjectRootFolderInfo(hubId, projectId, accessTokenService.getAccessToken());
    }

    /**
     * 指定目录创建文件夹
     *
     * @param projectId           项目id
     * @param createFolderRequest 文件夹创建请求
     */
    public FileItemDTO createFolder(String projectId, CreateFolderRequest createFolderRequest) throws BimfaceException {
        return bdfsClient.createFolder(projectId, createFolderRequest, accessTokenService.getAccessToken());
    }

    /**
     * 获取文件夹信息
     */
    public FileItemDTO getFolder(String projectId, String folderId, String path) throws BimfaceException {
        return bdfsClient.getFolder(projectId, folderId, path, accessTokenService.getAccessToken());
    }

    /**
     * 获取children列表(不包含itemSource)
     *
     * @param projectId            项目ID
     * @param fileItemQueryRequest
     * @return
     */
    public PagedList getChildrenFileItems(String projectId, FileItemQueryRequest fileItemQueryRequest) throws BimfaceException {
        return bdfsClient.getChildrenFileItems(projectId, fileItemQueryRequest, accessTokenService.getAccessToken());
    }


    /**
     * 根据folderId 获取path
     *
     * @param projectId 项目ID
     * @param folderId  文件夹ID
     * @return
     */
    public String getFolderPathById(String projectId, String folderId) throws BimfaceException {
        return bdfsClient.getFolderPathById(projectId, folderId, accessTokenService.getAccessToken());
    }

    /**
     * 获取父文件夹
     *
     * @param projectId
     * @param folderId
     * @return
     */
    public FileItemDTO getParent(String projectId, String folderId) throws BimfaceException {
        return bdfsClient.getParent(projectId, folderId, accessTokenService.getAccessToken());
    }

    /**
     * 文件夹重命名
     * 根据folderId(path)更新文件夹
     *
     * @param projectId       项目id
     * @param updateFolderReq 更新文件夹请求体
     * @return
     */
    public FileItemDTO updateFolder(String projectId, UpdateFolderRequest updateFolderReq) throws BimfaceException {
        return bdfsClient.updateFolder(projectId, updateFolderReq, accessTokenService.getAccessToken());
    }

    /**
     * 删除文件夹
     * 根据folderId(path)删除文件夹
     *
     * @param projectId 项目id
     * @param folderId  文件夹id(folderId和path,必须二选一填入)
     * @param path      文件夹路径,使用URL编码(UTF-8),最多256个字符(folderId和path,必须二选一填入)
     * @return
     */
    public String deleteFolder(String projectId, String folderId, String path) throws BimfaceException {
        return bdfsClient.deleteFolder(projectId, folderId, path, accessTokenService.getAccessToken());
    }


    /**
     * 上传文件流
     *
     * @param fileIn     文件流
     * @param projectId  项目id
     * @param parentId   父文件夹id
     * @param parentPath 父文件夹路径
     * @param name       文件名称
     * @param length     文件大小
     * @param sourceId   源文件id
     * @return
     */
    public FileItemDTO uploadFileItem(InputStream fileIn, String projectId, String parentId, String parentPath, String name, Long length, String sourceId) throws BimfaceException {
        return bdfsClient.uploadFileItem(fileIn, projectId, parentId, parentPath, name, length, sourceId, accessTokenService.getAccessToken());
    }

    /**
     * 指定外部文件url方式上传
     *
     * @param projectId  项目ID
     * @param parentId   父文件夹Id
     * @param parentPath 父文件夹路径
     * @param name       文件名称
     * @param sourceId   调用方的文件源ID,不能重复
     * @param url        sourceUrl
     * @param etag       文件etag
     * @param maxLength  maxLength
     * @return
     */
    public FileItemDTO uploadByUrl(String projectId, String parentId, String parentPath, String name, String sourceId, String url, String etag, Long maxLength) throws BimfaceException {
        return bdfsClient.uploadByUrl(projectId, parentId, parentPath, name, sourceId, url, etag, maxLength, accessTokenService.getAccessToken());
    }

    /**
     * 创建追加文件
     *
     * @param projectId  项目ID
     * @param parentId   父文件夹Id
     * @param parentPath 父文件夹路径
     * @param name       文件名称
     * @param length     文件流的长度
     * @param sourceId   调用方的文件源ID,不能重复
     * @return
     */
    public FileItemAppendFileDTO createAppendFile(String projectId, String parentId, String parentPath, String name, Long length, String sourceId) throws BimfaceException {
        return bdfsClient.createAppendFile(projectId, parentId, parentPath, name, length, sourceId, accessTokenService.getAccessToken());
    }

    /**
     * 获取追加文件信息
     * 获取FileItemAppendFile
     *
     * @param projectId    项目ID
     * @param appendFileId 追加上传ID
     * @return
     */
    public FileItemAppendFileDTO getAppendFile(String projectId, String appendFileId) throws BimfaceException {
        return bdfsClient.getAppendFile(projectId, appendFileId, accessTokenService.getAccessToken());
    }

    /**
     * 追加上传文件
     *
     * @param projectId    项目ID
     * @param appendFileId 父文件夹Id
     * @param position     父文件夹路径
     * @return
     */
    public FileItemAppendFileDTO appendUpload(InputStream fileIn, String projectId, String appendFileId, String position) throws BimfaceException {
        return bdfsClient.appendUpload(fileIn, projectId, appendFileId, position, accessTokenService.getAccessToken());
    }

    /**
     * 复制文件
     *
     * @param projectId       项目ID
     * @param copyFileRequest 复制文件请求体
     * @return
     */
    public List copyFile(String projectId, CopyFileRequest copyFileRequest) throws BimfaceException {
        return bdfsClient.copyFile(projectId, copyFileRequest, accessTokenService.getAccessToken());
    }

    /**
     * 获取文件直传的policy凭证
     * 获取上传file的policy
     *
     * @param projectId  项目ID
     * @param parentId   父文件ID
     * @param parentPath 父文件路径
     * @param name       文件名称
     * @param sourceId   调用方的文件源ID
     * @param maxLength  文件流的长度
     * @return
     */
    public UploadPolicyResponse getFileItemPolicy(String projectId, String parentId, String parentPath, String name, String sourceId, Long maxLength) throws BimfaceException {
        return bdfsClient.getFileItemPolicy(projectId, parentId, parentPath, name, sourceId, maxLength, accessTokenService.getAccessToken());
    }

    /**
     * 获取文件信息(不包含itemSource信息)
     *
     * @param projectId      项目id
     * @param fileItemId     文件id
     * @param path           文件路径
     * @param withItemSource 是否携带fileItemSource信息
     * @return
     */
    public FileItemDTO getFileItemMeta(String projectId, String fileItemId, String path, Boolean withItemSource) throws BimfaceException {
        return bdfsClient.getFileItemMeta(projectId, fileItemId, path, withItemSource, accessTokenService.getAccessToken());
    }


    /**
     * 获取文件状态
     *
     * @param projectId  项目id
     * @param fileItemId 文件id
     * @param path       文件路径
     * @return
     */
    public FileItemUploadStatusBean getFileItemStatus(String projectId, String fileItemId, String path) throws BimfaceException {
        return bdfsClient.getFileItemStatus(projectId, fileItemId, path, accessTokenService.getAccessToken());
    }

    /**
     * 获取文件下载签名URL
     *
     * @param projectId  项目id
     * @param fileItemId 文件id
     * @param path       文件路径
     * @param expireTime 过期时间
     * @return
     */
    public String getDownloadURl(String projectId, String fileItemId, String path, Integer expireTime) throws BimfaceException {
        return bdfsClient.getDownloadURl(projectId, fileItemId, path, expireTime, accessTokenService.getAccessToken());
    }

    /**
     * 获取文件路径
     * 根据fileItemId获取fileItemPath
     *
     * @param projectId  项目ID
     * @param fileItemId 文件ID
     * @return
     */
    public String getFileItemPathById(String projectId, String fileItemId) throws BimfaceException {
        return bdfsClient.getFileItemPathById(projectId, fileItemId, accessTokenService.getAccessToken());
    }

    /**
     * 打包下载压缩文件
     *
     * @param projectId   项目ID
     * @param fileItemIds 文件ID
     * @return
     */
    public String downloadFiles(String projectId, List fileItemIds) throws BimfaceException {
        return bdfsClient.downloadFiles(projectId, fileItemIds, accessTokenService.getAccessToken());
    }

    /**
     * 移动文件位置
     *
     * @param projectId       项目ID
     * @param moveFileRequest 移动文件请求体
     * @return
     */
    public List moveFile(String projectId, MoveFileRequest moveFileRequest) throws BimfaceException {
        return bdfsClient.moveFile(projectId, moveFileRequest, accessTokenService.getAccessToken());
    }

    /**
     * 文件重命名
     *
     * @param projectId         项目ID
     * @param updateFileRequest 更新文件请求体
     * @return
     */
    public FileItemDTO fileRename(String projectId, UpdateFileRequest updateFileRequest) throws BimfaceException {
        return bdfsClient.fileRename(projectId, updateFileRequest, accessTokenService.getAccessToken());
    }

    /**
     * 批量删除文件
     *
     * @param projectId   项目id
     * @param fileItemIds 文件id集合
     */
    public void batchDeleteFileItems(String projectId, List fileItemIds) throws BimfaceException {
        bdfsClient.batchDeleteFileItems(projectId, fileItemIds, accessTokenService.getAccessToken());
    }

    /**
     * 创建分片上传任务
     *
     * @param projectId                  项目id
     * @param initMultipartUploadRequest 初始化分片上传的请求体
     * @throws BimfaceException {@link BimfaceException}
     */
    public InitMultipartUploadDTO initMultipartUpload(String projectId, InitMultipartUploadRequest initMultipartUploadRequest) throws BimfaceException {
        return bdfsClient.initMultipartUpload(projectId, initMultipartUploadRequest, accessTokenService.getAccessToken());
    }

    /**
     * 获取分片上传url
     *
     * @param projectId                 项目 id
     * @param multipartSignedUrlRequest 获取分片的 signedUrl的请求体
     * @return 生成的 signed url
     */
    public String getMultipartSignedUrl(String projectId, MultipartSignedUrlRequest multipartSignedUrlRequest) throws BimfaceException {
        return bdfsClient.getMultipartSignedUrl(projectId, multipartSignedUrlRequest, accessTokenService.getAccessToken());
    }

    /**
     * 合并分片生成文件
     *
     * @param projectId                      项目 id
     * @param completeMultipartUploadRequest 完成分片上传的请求体
     * @return 返回生成的 FileItem
     */
    public FileItemDTOV1 completeMultiPartUpload(String projectId,
                                                 CompleteMultipartUploadRequest completeMultipartUploadRequest) throws BimfaceException {
        return bdfsClient.completeMultiPartUpload(projectId, completeMultipartUploadRequest, accessTokenService.getAccessToken());
    }


    /**
     * 终止分片上传任务
     *
     * @param projectId                   项目 id
     * @param abortMultipartUploadRequest 终止分片上传的请求体
     * @return 提示信息
     */
    public String abortMultiPartUpload(String projectId,
                                       AbortMultipartUploadRequest abortMultipartUploadRequest) throws BimfaceException {

        return bdfsClient.abortMultiPartUpload(projectId, abortMultipartUploadRequest, accessTokenService.getAccessToken());
    }

    /**
     * 获取所有版本文件信息
     *
     * @param projectId  项目ID
     * @param fileItemId 文件Id
     * @param path       文件路径
     * @param pageNo     开始页码
     * @param pageSize   每页大小
     * @return PagedList
     */
    public PagedList getAllVersions(String projectId,
                                                 String fileItemId,
                                                 String path,
                                                 Integer pageNo,
                                                 Integer pageSize) throws BimfaceException {
        return bdfsClient.getAllVersions(projectId, fileItemId, path, pageNo, pageSize, accessTokenService.getAccessToken());
    }

    /**
     * 上传版本文件
     *
     * @param fileIn     文件流
     * @param projectId  项目ID
     * @param fileItemId 文件Id
     * @param path       文件路径
     * @param name       文件名称
     * @param length     文件长度
     * @param sourceId   调用方的文件源ID,不能重复
     * @return FileItemDTO
     */
    public FileItemDTO createVersion(InputStream fileIn,
                                     String projectId,
                                     String fileItemId,
                                     String path,
                                     String name,
                                     Long length,
                                     String sourceId) throws BimfaceException {
        return bdfsClient.createVersion(fileIn, projectId, fileItemId, path, name, length, sourceId, accessTokenService.getAccessToken());
    }

    /**
     * 获取新版本直传的policy凭证
     *
     * @param projectId  项目ID
     * @param fileItemId 文件Id
     * @param path       文件路径
     * @param name       文件名称
     * @param sourceId   调用方的文件源ID,不能重复
     * @param maxLength  文件流的长度
     * @return UploadPolicyResponse
     */
    public UploadPolicyResponse getFilePolicy(String projectId,
                                              String fileItemId,
                                              String path,
                                              String name,
                                              String sourceId,
                                              Long maxLength) throws BimfaceException {
        return bdfsClient.getFilePolicy(projectId, fileItemId, path, name, sourceId, maxLength, accessTokenService.getAccessToken());
    }

    /**
     * 获取指定版本文件信息
     *
     * @param projectId      项目ID
     * @param fileId         文件版本Id
     * @param withFileSource 是否携带itemSource
     * @return FileItemDTO
     */
    public FileItemDTO getVersion(String projectId,
                                  String fileId,
                                  Boolean withFileSource) throws BimfaceException {
        return bdfsClient.getVersion(projectId, fileId, withFileSource, accessTokenService.getAccessToken());
    }

    /**
     * 下载指定版本文件
     *
     * @param projectId  项目ID
     * @param fileId     文件版本Id
     * @param expireTime 有限期,默认3600s
     * @return String
     */
    public String getVersionSignedUrl(String projectId,
                                      String fileId,
                                      Integer expireTime) throws BimfaceException {
        return bdfsClient.getVersionSignedUrl(projectId, fileId, expireTime, accessTokenService.getAccessToken());
    }

    /**
     * 删除指定版本文件
     *
     * @param projectId 项目ID
     * @param fileIds   文件版本Id
     * @return String
     */
    public String deleteVersion(String projectId,
                                List fileIds) throws BimfaceException {
        return bdfsClient.deleteVersion(projectId, fileIds, accessTokenService.getAccessToken());
    }

    /**
     * 获取成功上传的分片列表
     * @param projectId 项目ID
     * @param id 分片上传ID
     * @return 成功上传的分片列表
     */
    public MultipartUploadSuccessPartListDTO getSuccessUploadParts(String projectId, String id) throws BimfaceException {
        return bdfsClient.getSuccessUploadParts(projectId, id, accessTokenService.getAccessToken());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy