Skip to content

Asset Management Java 客户端

简介

Asset Management Java 客户端允许用户通过 Java 对象模型与数字形式的机器或自动化系统进行交互,并借助 MindSphere API 对交互进行抽象化。有关该服务的更多信息,请参见 Asset Management

Aspect 类型操作

Aspect 类型客户端管理静态和动态 aspect 类型,可以列出、创建、更新和读取 aspect 类型。

客户端名称:AspectTypeClient

列出所有 Aspect 类型

获取租户的所有 aspect 类型。

// Construct the AspectTypeClient object
AspectTypeClient aspecttypeClient = AspectTypeClient.builder()
 .mindsphereCredentials(credentials)
 .restClientConfig(config)
 .build();

AspectTypes aspectTypes = null;
try {
 aspectTypes = aspecttypeClient.getAspectTypes(page, size, sort, filter, ifNoneMatch);
}catch (MindsphereException e) {
 // Exception handling
}

创建 Aspect 类型

创建 aspect 类型。可定义 aspect 类型以包含 variables。

//Create client object "aspecttypeClient" as shown above
AspectTypeResource aspectType = null;
try {
 aspectType = aspecttypeClient.createAspectType(id, aspectTypeDto);
} catch (MindsphereException e) {
 // Exception handling
}

更新 Aspect 类型

更新现有 aspect 类型。可定义 aspect 类型以包含 variables。

//Create client object "aspecttypeClient" as shown above
AspectTypeResource aspectType = null;
try {
 aspectType = aspecttypeClient.updateAspectType(id, aspectTypeDto, IfMatch);
} catch (MindsphereException e) {
 // Exception handling
}

读取 Aspect 类型

读取 aspect 类型。

//Create client object "aspecttypeClient" as shown above
AspectTypeResource aspectTypeResource = null;
try {
 aspectTypeResource = aspecttypeClient.getAspectTypeById(id, ifNoneMatch);
} catch (MindsphereException e) {
 // Exception handling
}

删除 Aspect 类型

删除 aspect 类型。只有在没有任何 asset type 使用 aspect 类型时,才能删除 aspect 类型。

//Create client object "aspecttypeClient" as shown above
boolean deleted = false;
try {
 deleted = aspecttypeClient.deleteAspectType(id, ifMatch);
} catch (MindsphereException e) {
 // Exception handling
}

Asset Type 操作

Asset type 客户端管理 asset type。

客户端名称:AssetTypeClient

列出所有 Asset Type

列出租户的所有 asset type。

// Construct the AssetTypeClient object
AssetTypeClient assetTypeClient = AssetTypeClient.builder()
 .mindsphereCredentials(credentials)
 .restClientConfig(config)
 .build();

AssetTypes assetTypes = null;
try {
 assetTypes = assetTypeClient.getAssetTypes(page, size, sort, filter, ifNoneMatch);
} catch (MindsphereException e) {
 // Exception handling
}

创建 Asset Type

//Create client object "assetTypeClient" as shown above
AssetTypeResource assetTypeResource = null;

AssetTypeDto assetTypeDto = new AssetTypeDto();
assetTypeDto.setParentTypeId(assetTypeId);
assetTypeDto.setName(assetTypeName);
assetTypeDto.setScope(assetTypeScope);

try {
 assetTypeResource = assetTypeClient.createAssetType(id, assetTypeDto);
} catch (MindsphereException e) {
 // Exception handling
}

可以通过以下方式将 Aspects 添加到 asset type:

  1. 使用 Aspect 类型名称和 Aspect 类型 id

    //Create Asset Type Dto instance
    AssetTypeDto assetTypeDto = new AssetTypeDto();
    assetTypeDto.setParentTypeId(assetTypeId);
    assetTypeDto.setName(assetTypeName);
    assetTypeDto.setScope(assetTypeScope);
    
    //Add the Aspect Type name and Aspect Type id to AssetTypeDto instance
    assetTypeDTO.addAspectsItem(aspectTypeName, aspectTypeId);
    
  2. 使用 AspectTypeResource 实例

    //Create Asset Type Dto instance as shown above
    
    //Create AspectTypeResource instance
    AspectTypeResource aspectTypeResource = new AspectTypeResource();
    aspectTypeResource.setName(aspectTypeName);
    aspectTypeResource.setId(aspectTypeId);
    
    //Add the AspectTypeResource instance to AssetTypeDto instance
    assetTypeDTO.addAspectsItem(aspect);
    
  3. 使用 AssetTypeDtoAspects 实例

    //Create Asset Type Dto instance as shown above
    
    //Create AssetTypeDtoAspects instance
    AssetTypeDtoAspects assetTypeDtoAspects = new AssetTypeDtoAspects(aspectTypeName, aspectTypeId);
    
    //Add the AssetTypeDtoAspects instance to AssetTypeDto instance
    assetTypeDTO.addAspectsItem(assetTypeDtoAspects);
    
  4. 使用 AspectTypeResource 实例列表

    //Create AssetTypeDto instance as shown above
    
    //Create AspectTypeResource instance
    AspectTypeResource aspectTypeResource = new AspectTypeResource();
    aspectTypeResource.setName(aspectTypeName);
    aspectTypeResource.setId(aspectTypeId);
    
    //Create a List of AspectTypeResource instances and add the AspectTypeResource instance
    List<AspectTypeResource> aspects = new ArrayList<>();
    aspects.add(aspectTypeResource);
    
    //Add the List of AspectTypeResource instances to AssetTypeDto instance
    assetTypeDTO.addAspectsItem(aspects);
    
  5. 使用 AssetTypeDtoAspects 实例列表

    //Create AssetTypeDto instance as shown above
    
    //Create AssetTypeDtoAspects instance
    AssetTypeDtoAspects assetTypeDtoAspects = new AssetTypeDtoAspects(aspectTypeName, aspectTypeId);
    
    //Create a List of AssetTypeDtoAspects instances and add the AssetTypeDtoAspects instance
    List<AssetTypeDtoAspects> aspects = new ArrayList<>();
    aspects.add(assetTypeDtoAspects);
    
    //Add the List of AssetTypeDtoAspects instances to AssetTypeDto instance
    assetTypeDTO.addAspectsItem(aspects);
    

更新 Asset Type

//Create client object "assetTypeClient" as shown above
AssetTypeResource assetTypeResource = null;
try {
 assetTypeResource = assetTypeClient.updateAssetType(id, assetTypeDto, ifMatch);
} catch (MindsphereException e) {
 // Exception handling
}

读取 Asset Type

//Create client object "assetTypeClient" as shown above
AssetTypeResource assetTypeResource = null;
try {
 assetTypeResource = assetTypeClient.getAssetTypeById(id, ifNoneMatch, exploded);
} catch (MindsphereException e) {
 // Exception handling
}

删除 Asset Type

删除 asset type。仅当 asset type 不具有子类型,并且没有 asset 将其实例化时,才可以删除 asset type。

//Create client object "assetTypeClient" as shown above
boolean deleted = false;
try {
 deleted = assetTypeClient.deleteAssetType(id, ifMatch);
} catch (MindsphereException e) {
 // Exception handling
}

为 Asset Type 分配文件

//Create client object "assetTypeClient" as shown above

//Create FileAssignmentDto instance with required parameters.
FileAssignmentDto fileAssignment = new FileAssignmentDto();
assignment.setFileId("fileId");

// Invoke the AssetTypeClient#updateFileAssignment method to assign a file to the asset type
AssetTypeResource assetTypeResource = null;
try {
 assetTypeResource = assetTypeClient.updateFileAssignment(assetTypeId, fileName, fileAssignment, ifMatch);
} catch (MindsphereException e) {
 // Exception handling
}

从 Asset Type 删除文件

//Create client object "assetTypeClient" as shown above

// Invoke the AssetTypeClient#deleteFileAssignment method to remove a file from the asset type
AssetTypeResource assetTypeResource = null;
try {
 assetTypeResource = assetTypeClient.deleteFileAssignment(assetTypeId, fileName, ifMatch);
} catch (MindsphereException e) {
 // Exception handling
}

Asset 操作

Asset 客户端管理用户的 asset 及其位置。仅可创建三种不同类型的 assets:设备类型、代理类型和层级结构类型。

客户端名称:AssetClient

列出所有 Asset Type

列出经过身份验证的用户的所有可用 asset。

// Construct the AssetClient object
AssetClient assetClient = AssetClient.builder()
 .mindsphereCredentials(credentials)
 .restClientConfig(config)
 .build();

Assets assets = null;
try{
 assets = assetClient.getAssets(page, size, sort, filter, ifNoneMatch);
} catch (MindsphereException e) {
 // Exception handling
}

创建 Asset Type

用所提供的内容创建新 asset。

//Create client object "assetClient" as shown above
AssetResource assetResource = null;
try{
 assetResource = assetClient.createAsset(assetDto);
} catch (MindsphereException e) {
 // Exception handling
}

读取 Asset

读取asset。将返回 asset 的所有静态属性。

//Create client object "assetClient" as shown above
AssetResource assetResource = null;
try{
 assetResource = assetClient.getAssetById(id, ifNoneMatch);
} catch (MindsphereException e) {
 // Exception handling
}

更新 Asset

用所提供的内容更新现有 asset。仅可修改值,asset 结构不能修改。Asset 结构可以在 asset type 中进行修改。

//Create client object "assetClient" as shown above
AssetResource assetResource = null;
try{
 AssetResource assetResource = assetClient.updateAsset(id, assetDto, ifMatch);
} catch (MindsphereException e) {
 // Exception handling
}

删除 Asset

删除现有 asset。删除后,只有具备管理员角色的用户才可读取 asset,但不能再进行修改。无法删除含有子项的 asset。

//Create client object "assetClient" as shown above
Boolean deleted = false;
try{
 deleted = assetClient.deleteAsset(id, ifMatch);
} catch (MindsphereException e) {
 // Exception handling
}

移动 Asset

移动实例层级结构中的现有 asset 及其所有子项。

//Create client object "assetClient" as shown above
AssetResource assetResource = null;
try{
 assetResource = assetClient.moveAsset(id, assetMoveDto, ifMatch);
} catch (MindsphereException e) {
 // Exception handling
}

读取用户的根 Asset

读取用户的根 asset,从这里可以重建整个 asset 层级结构。

//Create client object "assetClient" as shown above
AssetResource assetResource = null;
try{
 assetResource = assetClient.getRootAsset(ifNoneMatch);
} catch (MindsphereException e) {
 // Exception handling
}

为 Asset 分配文件

//Create client object "assetClient" as shown above

//Create FileAssignmentDto instance with required parameters.
FileAssignmentDto fileAssignment = new FileAssignmentDto();
assignment.setFileId("fileId");

// Invoke the AssetClient#updateFileAssignment method to assign a file to the asset
AssetResource assetResource = null;
try {
 assetResource = assetClient.updateFileAssignment(assetId, fileName, fileAssignment, ifMatch);
} catch (MindsphereException e) {
 // Exception handling
}

从 Asset 删除文件

//Create client object "assetClient" as shown above

// Invoke the AssetClient#deleteFileAssignment method to remove a file from the asset
AssetResource assetResource = null;
try {
 assetResource = assetClient.deleteFileAssignment(assetId, fileName, ifMatch);
} catch (MindsphereException e) {
 // Exception handling
}

Asset 结构操作

客户端名称:AssetStructureClient

读取 Asset 的 Variables

获取 asset 的所有 variables。

// Construct the AssetStructureClient object
AssetStructureClient assetStructureClient = AssetStructureClient.builder()
 .mindsphereCredentials(credentials)
 .restClientConfig(config)
 .build();

StructureVariables structureVariables = null;
try{
 structureVariables = assetStructureClient.getVariables(id, page, size, sort, filter, ifNoneMatch);
} catch (MindsphereException e) {
 // Exception handling
}

读取 Asset 的所有 Aspects

获取 asset 的所有静态和动态 aspects。

//Create client object "assetStructureClient" as shown above
StructureAspects structureAspects = null;
try{
 structureAspects = assetStructureClient.getAspects(id, page, size, sort, filter, ifNoneMatch);
} catch (MindsphereException e) {
 // Exception handling
}

Asset 位置操作

客户端名称:AssetLocationClient

创建或更新位置

创建或更新分配给 asset 的位置。

// Construct the AssetLocationClient object
AssetLocationClient assetLocationClient = AssetLocationClient.builder()
 .mindsphereCredentials(credentials)
 .restClientConfig(config)
 .build();

try{
 assetLocationClient.createOrUpdateAssetLocation(id, location, ifMatch);
} catch (MindsphereException e) {
 // Exception handling
}

删除分配给 Asset 的位置

//Create client object "assetLocationClient" as shown above
AssetResource assetResource = null;
try{
 assetResource = assetLocationClient.deleteAssetLocation(id, ifMatch);
} catch (MindsphereException e) {
 // Exception handling
}

Asset 文件操作

客户端名称:AssetFileClient

上传文件

上传需要关联 asset type 或 asset 的文件。

// Construct the AssetFileClient instance
AssetFileClient assetFileClient = AssetFileClient.builder()
 .mindsphereCredentials(credentials)
 .restClientConfig(config)
 .build();

FileMetadataResource resource = null;
try{
 resource = assetFileClient.uploadAssetFiles(file, fileName, description);
} catch (MindsphereException e) {
 // Exception handling
}

列出所有文件

列出所有上传文件的元数据。

// Construct the AssetFileClient instance as shown above

AssetFiles assetFiles = null;
try{
 assetFiles = assetFileClient.getAssetFiles();
} catch (MindsphereException e) {
 // Exception handling
}

读取文件的元数据

使用用户定义的 ID 读取文件的元数据。

// Construct the AssetFileClient instance as shown above

AssetFiles assetFiles = null;
try{
 assetFiles = assetFileClient.getFileMetadataById(fileId, ifNoneMatch);
} catch (MindsphereException e) {
 // Exception handling
}

读取文件的内容

使用用户定义的 ID 读取文件的内容。

// Construct the AssetFileClient instance as shown above

String fileContents = null;
try{
 fileContents = assetFileClient.getFileContentById(fileId, ifNoneMatch);
} catch (MindsphereException e) {
 // Exception handling
}

页面迭代器

Asset Management API 客户端的页面迭代器可用于获取特定的数据页、下一页数据或上一页数据。

页面迭代器目前支持以下操作:

  • getPage(Integer pageNumber);
  • next();
  • previous();

为 Asset Management 中的不同控制器提供以下迭代器:

try {
 // Create Asset Client
 AssetClient assetClient = AssetClient.builder()
 .mindsphereCredentials(credentials)
 .restClientConfig(config)
 .build();

 // Create Asset Page Iterator
 AssetPageIterator assetPageIterator = new AssetPageIterator(assetClient, pageSize);

 Assets assets = assetPageIterator.getPage(10);
} catch (MindsphereException e) {
 // Exception handling
}

还有问题?

向社区提问


除非另行声明,该网站内容遵循MindSphere开发许可协议.


Last update: June 26, 2019