com.bimface.sdk.BimfaceClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-sdk Show documentation
Show all versions of api-sdk Show documentation
Bimface provide the required call java sdk.
The newest version!
package com.bimface.sdk;
import java.util.List;
import com.bimface.sdk.authorization.Credential;
import com.bimface.sdk.bean.request.FileTransferRequest;
import com.bimface.sdk.bean.request.FileUploadRequest;
import com.bimface.sdk.bean.response.FileBean;
import com.bimface.sdk.bean.response.TransferBean;
import com.bimface.sdk.config.ClientConfiguration;
import com.bimface.sdk.exception.BimfaceException;
import com.bimface.sdk.http.HttpClient;
import com.bimface.sdk.http.HttpRequestClient;
import com.bimface.sdk.service.AccessTokenService;
import com.bimface.sdk.service.SupportFileService;
import com.bimface.sdk.service.SignatureService;
import com.bimface.sdk.service.TransferService;
import com.bimface.sdk.service.UploadService;
import com.bimface.sdk.service.ViewTokenService;
/**
* 访问bimface服务的入口类。
*/
public class BimfaceClient {
private AccessTokenService accessTokenService;
private SupportFileService supportFileService;
private UploadService uploadFileService;
private TransferService transferService;
private ViewTokenService viewTokenService;
private SignatureService validateSignatureService;
private HttpClient httpClient;
/**
* 使用指定的bimface颁发的AppKey/AppSecret构造一个新的{@link BimfaceClient}对象。
*
* @param appKey bimface颁发的AppKey。
* @param appSecret bimface颁发的AppSecret。
*/
public BimfaceClient(String appKey, String appSecret) {
this(appKey, appSecret, new ClientConfiguration());
}
/**
* 使用指定的bimface颁发的AppKey/AppSecret构造一个新的{@link BimfaceClient}对象。
*
* @param appKey bimface颁发的AppKey。
* @param appSecret bimface颁发的AppSecret。
* @param config 客户端配置 {@link ClientConfiguration}。 如果为null则会使用默认配置。
*/
public BimfaceClient(String appKey, String appSecret, ClientConfiguration config) {
this(new Credential(appKey, appSecret), config);
}
/**
* 使用指定的bimface颁发的AppKey/AppSecret构造一个新的{@link BimfaceClient}对象。
*
* @param credential {@link Credential}。
* @param config 客户端配置 {@link ClientConfiguration}。 如果为null则会使用默认配置。
*/
public BimfaceClient(Credential credential, ClientConfiguration config) {
init(credential, config);
}
/**
* 初始化
*
* @param credential {@link Credential} App证书
* @param config {@link ClientConfiguration} 配置信息
*/
private void init(Credential credential, ClientConfiguration config) {
httpClient = new HttpRequestClient(config == null ? new ClientConfiguration() : config);
accessTokenService = new AccessTokenService(httpClient, credential);
uploadFileService = new UploadService(httpClient);
transferService = new TransferService(httpClient);
viewTokenService = new ViewTokenService(httpClient);
validateSignatureService = new SignatureService();
}
/**
* httpClient客户端
*
* @return 返回httpClient
*/
protected HttpClient httpClient() {
return httpClient;
}
/**
* httpClient客户端
*
* @param config {@link ClientConfiguration}
* @return 返回httpClient
*/
protected HttpClient httpClient(ClientConfiguration config) {
return new HttpRequestClient(config == null ? new ClientConfiguration() : config);
}
/**
* 获取token
*
* @return accessToken AccessToken
* @throws BimfaceException {@link BimfaceException}异常
*/
protected String getToken() throws BimfaceException {
return accessTokenService.getToken();
}
/**
* 获取支持上传且转换的文件格式
*
* @return 文件后缀名数组
* @throws BimfaceException {@link BimfaceException}异常
*/
public List getSupportFile() throws BimfaceException {
return supportFileService.getSupportFile(getToken());
}
/**
* 上传文件
*
* @param fileUploadRequest {@link FileUploadRequest}上传文件请求对象
* @return {@link FileBean} 文件对象
* @throws BimfaceException {@link BimfaceException}异常
*/
public FileBean upload(FileUploadRequest fileUploadRequest) throws BimfaceException {
return uploadFileService.upload(getToken(), getSupportFile(), fileUploadRequest);
}
/**
* 文件转换
*
* @param fileTransferRequest {@link FileTransferRequest}文件转换请求对象
* @return {@link TransferBean} 转换对象
* @throws BimfaceException {@link BimfaceException}异常
*/
public TransferBean transfer(FileTransferRequest fileTransferRequest) throws BimfaceException {
return transferService.transfer(getToken(), fileTransferRequest);
}
/**
* 获取viewToken, 用于模型预览的凭证
*
* @param viewId {@link String}文件转换时返回的viewId,即transferId
* @return {@link String} viewToken
* @throws BimfaceException {@link BimfaceException}异常
*/
public String viewToken(String viewId) throws BimfaceException {
return viewTokenService.grantViewToken(getToken(), viewId);
}
/**
* 校验签名方法,针对于回调函数验证是否为bimface发起
*
* @param signature 回调时带的签名
* @param viewId 转换时返回的预览ID
* @param status 转换状态(success || failed)
* @return true: 验证成功, false: 校验失败
* @throws BimfaceException {@link BimfaceException}异常
*/
public boolean validateSignature(String signature, String viewId, String status) throws BimfaceException {
return validateSignatureService.validateSignature(signature, accessTokenService.getCredential().getAppKey(),
accessTokenService.getCredential().getAppSecret(), viewId,
status);
}
}