Skip to content

Asset Management Java 客户端

简介

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

提示

以下示例中的占位符由尖括号 < > 表示。

Aspect 类型操作

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

客户端名称:AspecttypeClient

列出所有 Aspect 类型

本部分展示两种获得租户所有 aspect 类型的列表的方法。

// Construct the AspecttypeClient object
AspecttypeClient aspect_type_client = AspecttypeClient.builder()
                                        .mindsphereCredentials(<credentials>)
                                        .restClientConfig(<config>)
                                        .build();

AspectTypeListResource aspect_types = null;
try {
  aspect_types = aspect_type_client.listAspectTypes(<page>, <size>, <sort>, <filter>, <ifNoneMatch>);
}catch (MindsphereException e) {
  // Exception handling
}

或者,使用 ListAspectTypesRequest 模型。

// Construct the AspecttypeClient object as shown above
ListAspectTypesRequest request_object = new ListAspectTypesRequest();
request_object.setPage(<page>);
request_object.setSize(<size>);
request_object.setFilter(<filter>);

AspectTypeListResource aspectTypes = null;
try {
  aspect_types = aspect_type_client.listAspectTypes(request_object);
}catch (MindsphereException e) {
  // Exception handling
}

创建 Aspect 类型

本部分展示创建 aspect 类型的两种方法。

// Construct the AspecttypeClient object as shown above
AspectTypeResource aspect_type_resource = null;
try {
  aspect_type_resource = aspect_type_client.saveAspectType(<aspect_type_id>, <aspect_type>, <ifMatch>);
} catch (MindsphereException e) {
  // Exception handling
}

或者,使用 SaveAspectTypeRequest 模型。

// Construct the AspecttypeClient object as shown above
SaveAspectTypeRequest request_object = new SaveAspectTypeRequest();
request_object.setId(<aspect_type_id>);
request_object.setAspecttype(<aspect_type>);

AspectTypeResource aspect_type_resource = null;
try {
  aspect_type_resource = aspect_type_client.saveAspectType(request_object);
}catch (MindsphereException e) {
  // Exception handling
}

更新 Aspect 类型

本部分展示更新现有 aspect 类型的两种选项。 variables 仅可以被添加,不能被删除。

// Construct the AspecttypeClient object as shown above
AspectTypeResource aspect_type_resource = null;

try {
  aspect_type_resource = aspect_type_client.updateAspectType(<ifMatch>, <aspect_type_id>, <aspect_type>);
} catch (MindsphereException e) {
  // Exception handling
}

或者,使用 UpdateAspectTypeRequest 模型。

// Construct the AspecttypeClient object as shown above
UpdateAspectTypeRequest request_object = new UpdateAspectTypeRequest();
request_object.setId(<aspect_type_id>);
request_object.setAspecttype(<aspect_type>);
request_object.setIfMatch(<ifMatch>);

AspectTypeResource aspect_type_resource = null;
try {
  aspect_type_resource = aspect_type_client.updateAspectType(request_object);
}catch (MindsphereException e) {
  // Exception handling
}

读取 Aspect 类型

本部分展示读取 aspect 类型的两种选项。

// Construct the AspecttypeClient object as shown above
AspectTypeResource aspect_type_resource = null;

try {
  aspect_type_resource = aspect_type_client.getAspectType(<aspect_type_id>, <ifNoneMatch>);
} catch (MindsphereException e) {
  // Exception handling
}

或者,使用 GetAspectTypeRequest 模型。

// Construct the AspecttypeClient object as shown above
GetAspectTypeRequest request_object = new GetAspectTypeRequest();
request_object.setId(<aspect_type_id>);

AspectTypeResource aspect_type_resource = null;
try {
  aspect_type_resource = aspect_type_client.getAspectType(request_object);
}catch (MindsphereException e) {
  // Exception handling
}

删除 Aspect 类型

本部分展示删除 aspect 类型的两种选项。只有在没有任何 asset type 使用 aspect 类型时,才能删除 aspect 类型。

// Construct the AspecttypeClient object as shown above
try {
  aspect_type_client.deleteAspectType(<ifMatch>, <aspect_type_id>);
} catch (MindsphereException e) {
  // Exception handling
}

或者,使用 DeleteAspectTypeRequest 模型。

// Construct the AspecttypeClient object as shown above
DeleteAspectTypeRequest request_object = new DeleteAspectTypeRequest();
request_object.setId(<aspect_type_id>);
request_object.setIfMatch(<ifMatch>);

try {
  aspect_type_client.deleteAspectType(request_object);
}catch (MindsphereException e) {
  // Exception handling
}

使用过滤获取 aspect 类型

获取带有特定参数的 aspect 类型

此代码示例使用 filter - equals 功能来获取名称或租户 ID 等于输入值的所有 aspect 类型。

// Construct the AspecttypeClient object as shown above
AspectTypeListResource aspect_types = null;
try {
  aspect_types = aspect_type_client.getAspectTypesEqualTo(FieldTypeEnum.NAME, <filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

从列表中获取带有参数的 aspect 类型

使用 filter - in 功能来获取名称或租户 ID 匹配数组值中任何值的所有 aspect 类型。

// Construct the AspecttypeClient object as shown above
AspectTypeListResource aspect_types = null;
try {
  aspect_types = aspect_type_client.getAspectTypesLike(FieldTypeEnum.NAME, <filter_value_1>, <filter_value_2>);
}catch (MindsphereException e) {
  // Exception handling
}

获取参数以特定值开头的 aspect 类型

使用 filter - startsWith 功能来获取名称或租户 ID 以输入值开头的所有 aspect 类型。

// Construct the AspecttypeClient object as shown above
AspectTypeListResource aspect_types = null;
try {
  aspect_types = aspect_type_client.getAspectTypesStartsWith(FieldTypeEnum.NAME, <filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

获取参数以特定值结尾的 aspect 类型

使用 filter - endsWith 功能来获取名称或租户 ID 以输入值结尾的所有 aspect 类型。

// Construct the AspecttypeClient object as shown above
AspectTypeListResource aspect_types = null;
try {
  aspect_types = aspect_type_client.getAspectTypesEndsWith(FieldTypeEnum.NAME, <filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

获取含有特定值的参数的 aspect 类型

使用 Asset management 的 filter - contains 功能来获取名称或租户 ID 包含输入值的所有 aspect 类型。

// Construct the AspecttypeClient object as shown above
AspectTypeListResource aspect_types = null;
try {
  aspect_types = aspect_type_client.getAspectTypesContains(FieldTypeEnum.NAME, <filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

Asset Type 操作

Asset type 客户端管理 asset type。可以列出、创建、更新、读取和删除 asset type。还可用于添加和删除 asset type 的文件分配。

客户端名称:AssettypeClient

列出所有 Asset Type

本部分展示列出租户的所有 asset type 的两种选项。

// Construct the AssettypeClient object
AssettypeClient asset_type_client = AssettypeClient.builder()
                                      .mindsphereCredentials(<credentials>)
                                      .restClientConfig(<config>)
                                      .build();

AssetTypeListResource asset_types = null;
try {
    asset_types = asset_type_client.listAssetTypes(<page>, <size>, <sort>, <filter>, <ifNoneMatch>, <exploded>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 ListAssetTypesRequest 模型。

// Construct the AssettypeClient object as shown above
ListAssetTypesRequest request_object = new ListAssetTypesRequest();
request_object.setPage(<page>);
request_object.setSize(<size>);

AssetTypeListResource asset_types = null;
try {
    asset_types = asset_type_client.listAssetTypes(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

创建 Asset Type

本部分展示创建 asset type 的两种选项。

// Construct the AssettypeClient object as shown above
AssetTypeResource asset_type_resource = null

try {
    asset_type_resource = asset_type_client.saveAssetType(<asset_type_id>, <asset_type>, <ifMatch>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 SaveAssetTypeRequest 模型。

// Construct the AssettypeClient object as shown above
SaveAssetTypeRequest request_object = new SaveAssetTypeRequest();
request_object.setId(<asset_type_id>);
request_object.setAssettype(<asset_type>);

AssetTypeResource asset_type_resource = null

try {
    asset_type_resource = asset_type_client.saveAssetType(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

更新 Asset Type

本部分展示更新现有 asset type 的两种选项。

// Construct the AssettypeClient object as shown above
AssetTypeResource asset_type_resource = null;

try {
    asset_type_resource = asset_type_client.updateAssetType(<ifMatch>, <asset_type_id>, <asset_type>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 UpdateAssetTypeRequest 模型。

// Construct the AssettypeClient object as shown above
UpdateAssetTypeRequest request_object = new UpdateAssetTypeRequest();
request_object.setId(<asset_type_id>);
request_object.setAssettype(<asset_type>);
request_object.setIfMatch(<ifMatch>);

AssetTypeResource asset_type_resource = null;

try {
    asset_type_resource = asset_type_client.updateAssetType(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

读取 Asset Type

本部分展示读取 asset type 的两种选项。

// Construct the AssettypeClient object as shown above
AssetTypeResource asset_type_resource = null;

try {
    asset_type_resource = asset_type_client.getAssetType(<asset_type_id>, <ifNoneMatch>, <exploded>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 GetAssetTypeRequest 模型。

// Construct the AssettypeClient object as shown above
GetAssetTypeRequest request_object = new GetAssetTypeRequest();
request_object.setId(<asset_type_id>);

AssetTypeResource asset_type_resource = null;

try {
    asset_type_resource = asset_type_client.getAssetType(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

删除 Asset Type

本部分展示删除 asset type 的两种选项。仅当 asset type 不具有子类型,并且没有 asset 将其实例化时,才可以删除 asset type。

// Construct the AssettypeClient object as shown above
try {
    asset_type_client.deleteAssetType(<ifMatch>, <asset_type_id>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 DeleteAssetTypeRequest 模型。

// Construct the AssettypeClient object as shown above
DeleteAssetTypeRequest request_object = new DeleteAssetTypeRequest();
request_object.setId(<asset_type_id>);
request_object.setIfMatch(<ifMatch>);

try {
    asset_type_client.deleteAssetType(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

为 Asset Type 添加新文件分配任务

本部分展示为 asset type 添加新文件分配任务的两种选项。默认情况下,该文件分配到扩展此类型的 asset type 和从该类型实例化的 assets。

// Construct the AssettypeClient object as shown above
AssetTypeResource asset_type_resource = null;
try {
    asset_type_resource = asset_type_client.saveAssetTypeFileAssignment(<ifMatch>, <asset_type_id>, <key>, <assignment>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 SaveAssetTypeFileAssignmentRequest 模型。

// Construct the AssettypeClient object as shown above
SaveAssetTypeFileAssignmentRequest request_object = new SaveAssetTypeFileAssignmentRequest();
request_object.setId(<asset_type_id>);
request_object.setKey(<key>);
request_object.setAssignment(<assignment>);
request_object.setIfMatch(<ifMatch>);

AssetTypeResource asset_type_resource = null;
try {
    asset_type_resource = asset_type_client.saveAssetTypeFileAssignment(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

从 Asset Type 删除文件分配

本部分展示从 asset type 删除文件分配的两种选项。如果文件分配到 asset type 的父类,则该密钥将显示在继承的值字段中。

// Construct the AssettypeClient object as shown above
AssetTypeResource asset_type_resource = null;

try {
    asset_type_resource = asset_type_client.deleteAssetTypeFileAssignment(<asset_type_id>, <key>, <ifMatch>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 DeleteAssetTypeFileAssignmentRequest 模型。

// Construct the AssettypeClient object as shown above
DeleteAssetTypeFileAssignmentRequest request_object = new DeleteAssetTypeFileAssignmentRequest();
request_object.setId(<asset_type_id>);
request_object.setKey(<key>);
request_object.setIfMatch(<ifMatch>);

AssetTypeResource asset_type_resource = null;
try {
    asset_type_resource = asset_type_client.deleteAssetTypeFileAssignment(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

使用过滤获取 asset types

获取带有特定参数的 asset types

使用 filter - equals 功能来获取名称或租户 ID 或父类类型 ID 等于输入值的所有 asset types。

// Construct the AssettypeClient object as shown above
AssetTypeListResource asset_types = null;
try {
  asset_types = asset_type_client.getAssetTypesEqualTo(FieldTypeEnum.NAME, <filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

从列表中获取带有参数的 asset types

使用 filter - in 功能来获取名称或租户 ID 或父类类型 ID 匹配数组值中任何值的所有 asset types。

// Construct the AssettypeClient object as shown above
AssetTypeListResource asset_types = null;
try {
  asset_types = asset_type_client.getAssetTypesLike(FieldTypeEnum.NAME, <filter_value_1>, <filter_value_2>);
}catch (MindsphereException e) {
  // Exception handling
}

获取参数以特定值开头的 asset types

使用 filter - startsWith 功能来获取名称或租户 ID 或父类类型 ID 以输入值开头的所有 asset types。

// Construct the AssettypeClient object as shown above
AssetTypeListResource asset_types = null;
try {
  asset_types = asset_type_client.getAssetTypesStartsWith(FieldTypeEnum.NAME, <filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

获取参数以特定值结尾的 asset types

使用 filter - endsWith 功能来获取名称或租户 ID 或父类类型 ID 以输入值结尾的所有 asset types。

// Construct the AssettypeClient object as shown above
AssetTypeListResource asset_types = null;
try {
  asset_types = asset_type_client.getAssetTypesEndsWith(FieldTypeEnum.NAME, <filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

获取含有特定值的参数的 asset types

使用 filter - contains 功能来获取名称或租户 ID 或父类类型 ID 包含输入值的所有 aspect 类型。

// Construct the AssettypeClient object as shown above
AssetTypeListResource asset_types = null;
try {
  asset_types = asset_type_client.getAssetTypesContains(FieldTypeEnum.NAME, <filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

Asset 操作

Asset 客户端管理用户的 asset 及其位置。可创建三种不同类型的 asset:设备类型、代理类型和层级结构类型。Asset 客户端可以列出、创建、更新、读取、删除、移动和替换 asset,还可用来添加和删除 asset 的文件分配。

客户端名称:AssetsClient

列出所有 Asset

本部分展示列出经过身份验证的用户的所有可用 assets 的两种选项。

// Construct the AssetClient object
AssetsClient asset_client = AssetsClient.builder()
                              .mindsphereCredentials(<credentials>)
                              .restClientConfig(<config>)
                              .build();

AssetListResource assets = null;
try{
    assets = asset_client.listAssets(<page>, <size>, <sort>, <filter>, <ifNoneMatch>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 ListAssetsRequest 模型。

// Construct the AssetClient object as shown above
ListAssetsRequest request_object = new ListAssetsRequest();
request_object.setPage(<page>);
request_object.setSize(<size>);

AssetListResource assets = null;
try{
    assets = asset_client.listAssets(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

创建 Asset

本部分展示用所提供的内容创建新 asset 的两种选项。

// Construct the AssetClient object as shown above
AssetResourceWithHierarchyPath asset_resource = null;

try{
    asset_resource = asset_client.addAsset(<asset>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 AddAssetRequest 模型。

// Construct the AssetClient object as shown above
AddAssetRequest request_object = new AddAssetRequest();
request_object.setAsset(<asset>);

AssetResourceWithHierarchyPath asset_resource = null;
try{
    asset_resource = asset_client.addAsset(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

读取 Asset

本部分展示了读取单个 asset 的两种选项。将返回 asset 的所有静态属性。

// Construct the AssetClient object as shown above
AssetResourceWithHierarchyPath asset_resource = null;

try{
    asset_resource = asset_client.getAsset(<asst_id>, <ifNoneMatch>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 GetAssetRequest 模型。

// Construct the AssetClient object as shown above
GetAssetRequest request_object = new GetAssetRequest();
request_object.setId(<asst_id>);

AssetResourceWithHierarchyPath asset_resource = null;
try{
    asset_resource = asset_client.getAsset(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

更新 Asset

本部分展示了用所提供的内容更新现有 asset 的两种选项。仅可修改值,asset 结构不能修改。Asset 结构只能在 asset type 中进行修改。

// Construct the AssetClient object as shown above
AssetResourceWithHierarchyPath asset_resource = null;
try{
    asset_resource = asset_client.updateAsset(<ifMatch>, <asst_id>, <asset_update>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 UpdateAssetRequest 模型。

// Construct the AssetClient object as shown above
UpdateAssetRequest request_object = new UpdateAssetRequest();
request_object.setId(<asst_id>);
request_object.setAsset(<asset_update>);
request_object.setIfMatch(<ifMatch>);

AssetResourceWithHierarchyPath asset_resource = null;
try{
    asset_resource = asset_client.updateAsset(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

删除 Asset

本部分展示了删除现有 asset 的两种选项。删除后,具备管理员角色的用户仍可读取 asset,但不能再进行修改。无法删除含有子项的 asset。

// Construct the AssetClient object as shown above
try{
    asset_client.deleteAsset(<ifMatch>, <asst_id>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 DeleteAssetRequest 模型。

// Construct the AssetClient object as shown above
DeleteAssetRequest request_object = new DeleteAssetRequest();
request_object.setId(<asst_id>);
request_object.setIfMatch(<ifMatch>);

try{
    asset_client.deleteAsset(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

移动 Asset

本部分展示了移动实例层级结构中的现有 asset 及其所有子项的两种选项。

// Construct the AssetClient object as shown above
AssetResourceWithHierarchyPath asset_resource = null;

try{
    asset_resource = asset_client.moveAsset(<ifMatch>, <asset_id>, <asset_move>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 MoveAssetRequest 模型。

// Construct the AssetClient object as shown above
MoveAssetRequest request_object = new MoveAssetRequest();
request_object.setId(<asset_id>);
request_object.setMoveParameters(<asset_move>);
request_object.setIfMatch(<ifMatch>);

AssetResourceWithHierarchyPath asset_resource = null;
try{
    asset_resource = asset_client.moveAsset(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

替换 Asset

本部分展示用所提供的内容更新 asset 的两种选项。

// Construct the AssetClient object as shown above
AssetResourceWithHierarchyPath asset_resource = null;

try{
    asset_resource = asset_client.replaceAsset(<ifMatch>, <asset_id>, <asset_update>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 ReplaceAssetRequest 模型。

// Construct the AssetClient object as shown above
ReplaceAssetRequest request_object = new ReplaceAssetRequest();
request_object.setId(<asset_id>);
request_object.setAsset(<asset_update>);
request_object.setIfMatch(<ifMatch>);

AssetResourceWithHierarchyPath asset_resource = null;
try{
    asset_resource = asset_client.replaceAsset(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

获取用户的根 Asset

本部分展示了读取用户的根 asset 的两种选项,从这里可以重建整个 asset 层级结构。

// Construct the AssetClient object as shown above
RootAssetResource root_asset_resource = null;
try{
    root_asset_resource = asset_client.getRootAsset(<ifNoneMatch>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 GetRootAssetRequest 模型。

// Construct the AssetClient object as shown above
GetRootAssetRequest request_object = new GetRootAssetRequest();
request_object.setIfNoneMatch(<ifNoneMatch>);

RootAssetResource root_asset_resource = null;
try{
    root_asset_resource = asset_client.getRootAsset(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

为 Asset 添加新的文件分配

本部分展示了为 asset 添加新的文件分配的两种选项。默认情况下,该文件也分配到所有 asset 的所有子项。

// Construct the AssetClient object as shown above
AssetResourceWithHierarchyPath asset_resource = null;
try {
    asset_resource = asset_client.saveAssetFileAssignment(<asset_id>, <key>, <ifMatch>, <assignment>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 SaveAssetFileAssignmentRequest 模型。

// Construct the AssetClient object as shown above
SaveAssetFileAssignmentRequest request_object = new SaveAssetFileAssignmentRequest();
request_object.setId(<asset_id>);
request_object.setKey(<key>);
request_object.setAssignment(<assignment>);
request_object.setIfMatch(<ifMatc>h);

AssetResourceWithHierarchyPath asset_resource = null;
try {
    asset_resource = asset_client.saveAssetFileAssignment(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

从 Asset 删除文件分配

本部分展示了从 asset 删除文件分配的两种选项。

// Construct the AssetClient object as shown above
AssetResourceWithHierarchyPath asset_resource = null;

try {
    asset_resource = asset_client.deleteAssetFileAssigment(<asset_id>, <key>, <ifMatch>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 DeleteAssetFileAssigmentRequest 模型。

// Construct the AssetClient object as shown above
DeleteAssetFileAssigmentRequest request_object = new DeleteAssetFileAssigmentRequest();
request_object.setId(response.getAssetId());
request_object.setKey(<key>);
request_object.setIfMatch(<ifMatch>);

AssetResourceWithHierarchyPath asset_resource = null;
try {
    asset_resource = asset_client.deleteAssetFileAssigment(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

使用过滤获取 assets

获取带有特定参数的 assets

使用 filter - equals 方程来获取类似名称、租户 ID、asset ID、外部 ID、子租户等属性和输入值相同的所有 assets。

// Construct the AssetClient object as shown above
AssetListResource assets = null;
try {
  assets = asset_client.getAssetsEqualTo(FieldTypeEnum.NAME, <filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

从列表中获取带有参数的 assets

使用 filter - in 功能来获取类似名称、租户 ID、asset ID、外部 ID、子租户等属性匹配数组值中任何值的所有 assets。

// Construct the AssetClient object as shown above
AssetListResource assets = null;
try {
  assets = asset_client.getAssetsLike(FieldTypeEnum.NAME, <filter_value_1>, <filter_value_2>);
}catch (MindsphereException e) {
  // Exception handling
}

获取参数以特定值开头的 assets

使用 filter - startsWith 功能来获取名称或租户 ID 或 父类 ID 以输入值开头的所有 assets。

// Construct the AssetClient object as shown above
AssetListResource assets = null;
try {
  assets = asset_client.getAssetsStartsWith(FieldTypeEnum.NAME, <filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

获取参数以特定值结尾的 assets

使用 filter - endsWith 功能来获取名称或租户 ID 或父类 ID 以输入值结尾的所有 assets。

// Construct the AssetClient object as shown above
AssetListResource assets = null;
try {
  assets = asset_client.getAssetsEndsWith(FieldTypeEnum.NAME, <filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

获取含有特定值的参数的 assets

使用 filter - contains 功能来获取名称或租户 ID 或父类 ID 包含输入值的所有 assets。

// Construct the AssetClient object as shown above
AssetListResource assets = null;
try {
  assets = asset_client.getAssetsContains(FieldTypeEnum.NAME, <filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

获取特定 type 的 assets

使用 filter - hasType 功能来获取特定类型的所有 assets。

// Construct the AssetClient object as shown above
AssetListResource assets = null;
try {
  assets = asset_client.getAssetsOfType(<filter_value>);
}catch (MindsphereException e) {
  // Exception handling
}

结构操作

结构客户端用于列出 asset 的 aspects 和 variables。

客户端名称:StructureClient

获取 Asset 的 Variables

本部分展示了获取 asset 的所有 variables 的两种选项。

// Construct the StructureClient object
StructureClient structure_client = StructureClient.builder()
                                                .mindsphereCredentials(<credentials>)
                                                .restClientConfig(<config>)
                                                .build();

VariableListResource structure_variables = null;
try{
    structure_variables = structure_client.listAssetVariables(<asset_id>, <page>, <size>, <sort>, <filter>, <ifNoneMatch>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 ListAssetVariablesRequest 模型。

// Construct the StructureClient object as shown above
ListAssetVariablesRequest request_object = new ListAssetVariablesRequest();
request_object.setId(assetId());

VariableListResource structure_variables = null;
try{
    structure_variables = structure_client.listAssetVariables(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

获取 Asset 的所有 Aspects

本部分描述了获取指定 asset 的所有静态和动态 aspects 的两种选项。

// Construct the StructureClient object as shown above
AspectListResource structure_aspects = null;

try{
    structure_aspects = structure_client.listAssetAspects(<asset_id>, <page>, <size>, <sort>, <filter>, <ifNoneMatch>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 ListAssetAspectsRequest 模型。

// Construct the StructureClient object as shown above

ListAssetAspectsRequest request_object = new ListAssetAspectsRequest();
request_object.setId(assetId());

AspectListResource structure_aspects = null;
try{
    structure_aspects = structure_client.listAssetAspects(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

位置操作

位置客户端管理 asset 的位置。其可用于创建、更新和删除 asset 的位置。

客户端名称:LocationsClient

创建或更新 Asset 的位置

本部分展示了创建或更新分配给 asset 的位置的两种操作。如果尚未为 asset 定义任何位置,则会创建一个新位置。否则,会更新位置。

// Construct the AssetLocationClient object
LocationsClient locations_client = LocationsClient.builder()
                                              .mindsphereCredentials(<credentials>)
                                              .restClientConfig(<config>)
                                              .build();

try{
    locations_client.saveAssetLocation(<ifMatch>, <asset_id>, <location>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 SaveAssetLocationRequest 模型。

// Construct the AssetLocationClient object as shown above
SaveAssetLocationRequest request_object = new SaveAssetLocationRequest();
request_object.setId(<asset_id>);
request_object.setIfMatch(<ifMatch>);
request_object.setLocation(<location>);

try{
    locations_client.saveAssetLocation(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

删除 Asset 的位置

本部分展示了从 asset 中删除位置的两种选项。

// Construct the AssetLocationClient object as shown above
AssetResourceWithHierarchyPath asset_resource = null;

try{
    asset_resource = locations_client.deleteAssetLocation(<ifMatch>, <asset_id>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 DeleteAssetLocationRequest 模型。

// Construct the AssetLocationClient object as shown above
DeleteAssetLocationRequest request_object = new DeleteAssetLocationRequest();
request_object.setId(<asset_id>);
request_object.setIfMatch(<ifMatch>);

AssetResourceWithHierarchyPath asset_resource = null;
try{
    asset_resource = locations_client.deleteAssetLocation(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

告示牌操作

告示牌客户端可用于列出所有可用资源。

客户端名称:BillboardClient

列出所有可用资源

列出可用资源的所有链接

// Construct the BillboardClient object
BillboardClient billboard_client = BillboardClient.builder()
                                              .mindsphereCredentials(<credentials>)
                                              .restClientConfig(<config>)
                                              .build();

BillboardResource billboard_resource = null;
try{
    billboard_resource = billboard_client.getBillboard();
} catch (MindsphereException e) {
    // Exception handling
}

文件操作

文件客户端管理可以分配给资源的文件,可用于列出、读取、上传、删除、替换和下载文件。

客户端名称:FilesClient

列出所有文件

本部分展示了获取上传文件的元数据的两种选项。

// Construct the FilesClient object
FilesClient files_client = FilesClient.builder()
                                      .mindsphereCredentials(<credentials>)
                                      .restClientConfig(<config>)
                                      .build();

FileMetadataListResource file_metadata_list_resource = null;

try{
    file_metadata_list_resource = files_client.listFiles(<page>, <size>, <sort>, <filter>, <ifNoneMatch>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 ListFilesRequest 模型。

// Construct the FilesClient object as shown above
ListFilesRequest request_object = new ListFilesRequest();
request_object.setPage(<page>);
request_object.setSize(<size>);

FileMetadataListResource file_metadata_list_resource = null;
try{
    file_metadata_list_resource = files_client.listFiles(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

获取文件

本部分展示了获取带有用户定义 ID 的文件的元数据的两种选项。

// Construct the FilesClient object as shown above
FileMetadataResource file_metadata_resource = null;

try{
    file_metadata_resource = files_client.getFile(<file_id>, <ifNoneMatch>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 GetFileRequest 模型。

// Construct the FilesClient object as shown above
GetFileRequest request_object = new GetFileRequest();
request_object.setFileId(<file_id>);

FileMetadataResource file_metadata_resource = null;
try{
    file_metadata_resource = files_client.getFile(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

下载文件

本部分展示了按文件 id 返回文件的两种选项。

// Construct the FilesClient object as shown above
byte[] file_contents = null;

try{
    file_contents = files_client.downloadFile(<file_id>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 DownloadFileRequest 模型。

// Construct the FilesClient object as shown above
DownloadFileRequest request_object = new DownloadFileRequest();
request_object.setFileId(<file_id>);

byte[] file_contents = null;
try{
    file_contents = files_client.downloadFile(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

替换文件

本部分展示了更新以前上传的文件的两种选项。最大文件大小为 5 MB。

// Construct the FilesClient object as shown above
FileMetadataResource file_metadata_resource = null;
try{
    file_metadata_resource = files_client.replaceFile(<ifMatch>, <file_id>, <file>, <name>, <scope>, <description>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 ReplaceFileRequest 模型。

// Construct the FilesClient object as shown above
ReplaceFileRequest request_object = new ReplaceFileRequest();
request_object.setIfMatch(<ifMatch>);
request_object.setFileId(<file_id>);
request_object.setFile(<file>);
request_object.setName(<name>);
request_object.setScope(<scope>);

FileMetadataResource file_metadata_resource = null;
try{
    file_metadata_resource = files_client.replaceFile(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

上传文件

本部分展示了上传要在 Asset Management 中使用的文件的两种选项。

// Construct the FilesClient object as shown above
FileMetadataResource file_metadata_resource = null;
try{
    file_metadata_resource = files_client.uploadFile(<file>, <name>, <scope>, <description>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 UploadFileRequest 模型。

// Construct the FilesClient object as shown above
UploadFileRequest request_object = new UploadFileRequest();
request_object.setFile(<file>);
request_object.setName(<name>);

FileMetadataResource file_metadata_resource = null;
try{
    file_metadata_resource = files_client.uploadFile(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

删除文件

本部分展示了删除文件的两种选项。

// Construct the FilesClient object as shown above
try{
    deleteFile(<ifMatch>, <file_id>);
} catch (MindsphereException e) {
    // Exception handling
}

或者,使用 DeleteFileRequest 模型。

// Construct the FilesClient object as shown above
DeleteFileRequest request_object = new DeleteFileRequest();
request_object.setIfMatch(<ifMatch>);
request_object.setFileId(<file_id>);

try{
    deleteFile(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

页面迭代器

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

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

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

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

try {
    // Construct the AssetsClient object
    AssetsClient asset_client =  AssetsClient.builder()
                                    .mindsphereCredentials(<credentials>)
                                    .restClientConfig(<config>)
                                    .build();

    // Create Asset Page Iterator
    AssetPageIterator asset_page_iterator = new AssetPageIterator(asset_client, <page_size>);

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

还有问题?

向社区提问


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


Last update: July 21, 2020