Skip to content

Node.js 的 Asset Management Client

简介

Asset Management Node.js 客户端允许您与机器或自动化系统的数字进行交互。有关此服务的更多信息请参考Asset Management

提示

下面示例中的占位符用尖括号 < > 表示。

Aspect 类型操作

Aspect 类型客户端管理静态和动态 aspect 类型。它列出、创建、更新和删除 aspect 类型。

客户端名称: AspecttypeClient

列出所有 Aspect 类型

获得租户的所有 aspect 类型:

// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;

// Require AspecttypeClient from assetmanagement-sdk module
const AspecttypeClient = require('assetmanagement-sdk').AspecttypeClient;

// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();

// Construct the AspecttypeClient object
let aspect_type_client = new AspecttypeClient(config, credentials);

let aspect_types = null;
try {
  let request_object = {
      page: <page>,
      size: <size>,
      sort: <sort>,
      filter: <filter>,
      ifNoneMatch: <ifNoneMatch>
    };

  aspect_types = await aspect_type_client.listAspectTypes(request_object);
}catch (ex) {
  // Exception handling
}

创建 Aspect 类型

创建 Aspect 类型。

// Construct the AspecttypeClient object as shown above

let aspect_type_input = {
  name: <aspect_name>,
  category: 'dynamic',
  scope: 'private',
  description: '<Aspect Type description>',
  variables: [
    {
      name: 'Temperature',
      dataType: 'STRING',
      unit: 'C',
      searchable: true,
      length: 3,
      qualityCode: true
    }
  ]
};

let aspect_type = null;
try {

  const request_object = {
    id: <id>,
    aspecttype: aspect_type_input
  };
  aspectType = await aspect_type_client.saveAspectType(request_object);
} catch (ex) {
  // Exception handling
}

更新 Aspect 类型

更新现有的 aspect 类型。变量可以被添加,但不能被移除或重命名。

// Construct the AspecttypeClient object as shown above

let aspect_type = null;
try {

  const request_object = {
    id: <id>,
    aspecttype: <updated_aspect_type>,
    ifMatch: <ifMatch>
  };

  aspect_type = await aspect_type_client.saveAspectType(request_object);
} catch (ex) {
  // Exception handling
}

读取 Aspect 类型

使用用户定义的 aspect 类型 ID读取 aspect 类型。

// Construct the AspecttypeClient object as shown above

let aspect_type_resource = null;
try {

  let request_object = {
    id: <id>,
    ifNoneMatch: <ifNoneMatch>
  };

  aspect_type_resource = await aspect_type_client.getAspectType(request_object);
} catch (ex) {
  // Exception handling
}

删除 Aspect 类型

删除 aspect 类型。只有在没有 asset type 使用它的时候,aspect 类型可以被删除。

// Construct the AspecttypeClient object as shown above

try {

  let request_object = {
    id: <id>,
    ifMatch: <ifMatch>
  };

  await aspect_type_client.deleteAspectType(request_object);
} catch (ex) {
  // Exception handling
}

Asset Type 操作

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

租户名称:AssettypeClient

列出所有 Asset Type

列出租户的所有 Asset type。

// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;

// Require AssettypeClient from assetmanagement-sdk module
const AssettypeClient = require('assetmanagement-sdk').AssettypeClient;

// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();

// Construct the AssettypeClient object
let asset_type_client = new AssettypeClient(config, credentials);

let asset_types = null;
try {
  const request_object = {
    page: <page>,
    size: <size>,
    sort: <sort>,
    filter: <filter>,
    ifNoneMatch: <ifNoneMatch>,
    exploded: <exploded>
  };

  asset_types = await asset_type_client.listAssetTypes(request_object);
} catch (ex) {
  // Exception handling
}

创建 Asset Type

创建 Asset type。

// Construct the AssettypeClient object as shown above

let asset_type_resource = null;
try {

  const request_object = {
    id: <id>,
    assettype: <asset_type>
  };

  asset_type_resource = await asset_type_client.saveAssetType(request_object);
} catch (ex) {
  // Exception handling
}

更新 Asset Type

更新现有的 Asset type。

// Construct the AssettypeClient object as shown above

let asset_type_resource = null;
try {
  const request_object = {
    id: <id>,
    assettype: <asset_type>,
    ifMatch: <ifMatch>
  };

  asset_type_resource = await asset_type_client.updateAssetType(request_object);
} catch (ex) {
  // Exception handling
}

读取 Asset Type

读取 Asset type。

// Construct the AssettypeClient object as shown above

let asset_type_resource = null;
try {

  const request_object = {
    id: <id>,
    ifNoneMatch: <ifNoneMatch>,
    exploded: <exploded>
  };

  asset_type_resource = await asset_type_client.getAssetType(request_object);
} catch (ex) {
  // Exception handling
}

删除 Asset Type

删除 Asset type。只有在没有子元素且没有 asset 实例化 asset type 时,才可以删除 asset type。

// Construct the AssettypeClient object as shown above

try {

  const request_object = {
    id: <id>,
    ifMatch: <ifMatch>
  };

  await asset_type_client.deleteAssetType(request_object);
} catch (ex) {
  // Exception handling
}

添加新的文件分配到 Asset Type

默认情况下,该文件被分配给扩展该类型的 asset types 和从中实例化的 asset types。

// Construct the AssettypeClient object as shown above

let asset_type_resource = null;
try {

  const request_object = {
    ifMatch: <ifMatch>,
    id: <id>,
    key: <key>,
    assignment: <file_id_to_be_assigned>
  };

  asset_type_resource = await asset_type_client.saveAssetTypeFileAssignment(request_object);
} catch (ex) {
  // Exception handling
}

从 Asset Type 中删除文件分配

从 Asset type 中删除文件分配。如果文件被分配给类型的父类,那么它的密钥将显示在继承值字段中。

// Construct the AssettypeClient object as shown above

let asset_type_resource = null;
try {

  const request_object = {
    id: <id>,
    key: <key>,
    ifMatch: <ifMatch>
  };

  asset_type_resource = await asset_type_client.deleteAssetTypeFileAssignment(request_object);
} catch (ex) {
  // Exception handling
}

Asset 操作

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

客户端名称: AssetsClient

列出所有 Assets

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

// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;

// Require AssetsClient from assetmanagement-sdk module
const AssetsClient = require('assetmanagement-sdk').AssetsClient;

// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();

// Construct the AssetsClient object
let assets_client = new AssetsClient(config, credentials);

let assets = null;
try{
  const request_object = {
    page: <page>,
    size: <size>,
    sort: <sort>,
    filter: <filter>,
    ifNoneMatch: <ifNoneMatch>
  };

  assets = await assets_client.listAssets(request_object);
} catch (ex) {
  // Exception handling
}

创建 Asset

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

// Construct the AssetsClient object as shown above

let asset_resource = null;
try{
  const request_object = {
    asset: <asset>
  };

  asset_resource = await assets_client.addAsset(request_object);
} catch (ex) {
  // Exception handling
}

读取 Asset

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

// Construct the AssetsClient object as shown above

let asset_resource = null;
try{

  const request_object = {
    id: <id>,
    ifNoneMatch: <ifNoneMatch>
  };

  asset_resource = await assets_client.getAsset(request_object);
} catch (ex) {
  // Exception handling
}

更新 asset

使用提供的内容更新现有 asset。只有值可以被修改,asset 结构无法被修改。可以在 asset type 中修改 asset 结构。

// Construct the AssetsClient object as shown above

let asset_resource = null;
try{
  const request_object = {
    ifMatch: <ifMatch>,
    id: <id>,
    asset: <asset_update>
  };

  const asset_resource = await assets_client.updateAsset(request_object);
} catch (ex) {
  // Exception handling
}

删除 Asset

删除现有的 asset。删除之后,具有管理员角色的用户仍然可以读取 asset,但是不可能再进行修改。如果 asset 有子 asset,则不能删除它。

// Construct the AssetsClient object as shown above

try{
  const request_object = {
    ifMatch: <ifMatch>,
    id: <id>
  };

  await assets_client.deleteAsset(request_object);
} catch (ex) {
  // Exception handling
}

移动 Asset

在实例层级中移动现有 asset 及其所有子 asset。

// Construct the AssetsClient object as shown above

let asset_resource = null;
try{

  const request_object = {
    ifMatch: <ifMatch>,
    id: <id>,
    moveParameters: <asset_move>
  };

  asset_resource = await assets_client.moveAsset(request_object);
} catch (ex) {
  // Exception handling
}

替换 Asset

使用提供的内容更新 asset。

// Construct the AssetsClient object as shown above

let asset_resource = null;
try{
  const request_object = {
    ifMatch: <ifMatch>,
    id: <id>,
    asset: <asset_update>
  };

  asset_resource = await assets_client.replaceAsset(request_object);
} catch (ex) {
  // Exception handling
}

获得用户的根 Asset

读取用户的根 asset,从中可以重新构建整个 asset 层级。

// Construct the AssetsClient object as shown above

let root_asset_resource = null;
try{
  const request_object = {
    ifNoneMatch: <ifNoneMatch>
  };

  root_asset_resource = await assets_client.getRootAsset(request_object);
} catch (ex) {
  // Exception handling
}

添加新文件分配到 Asset

添加新文件分配到 asset,默认情况下,该文件被分配给 asset 的所有子元素。

// Construct the AssetsClient object as shown above

let asset_resource = null;
try {

  const request_object = {
    id: <id>,
    key: <key>,
    ifMatch: <ifMatch>,
    assignment: <file_id_to_be_assigned>
  };

  asset_resource = await assets_client.saveAssetFileAssignment(request_object);
} catch (ex) {
  // Exception handling
}

从 Asset 中删除文件分配

从 asset 中删除文件分配。

// Construct the AssetsClient object as shown above

let asset_resource = null;
try {

  const request_object = {
    id: <id>,
    key: <key>,
    ifMatch: <ifMatch>
  };
    asset_resource = await assets_client.deleteAssetFileAssigment(request_object);
} catch (ex) {
  // Exception handling
}

结构操作

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

客户端名称:StructureClient

获得 asset 的 variable

获得 asset 的所有 variables。

// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;

// Require StructureClient from assetmanagement-sdk module
const StructureClient = require('assetmanagement-sdk').StructureClient;

// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();

// Construct the StructureClient object
let structure_client = new StructureClient(config, credentials);

let structure_variables = null;
try{
  const request_object = {
    id: <id>,
    page: <page>,
    size: <size>,
    sort: <sort>,
    filter: <filter>,
    ifNoneMatch: <ifNoneMatch>
  };

  structure_variables = await structure_client.listAssetVariables(request_object);
} catch (ex) {
  // Exception handling
}

获得 asset 的所有 aspects

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

// Construct the StructureClient object as shown above

let structure_aspects = null;
try{
  const request_object = {
    id: <id>,
    page: <page>,
    size: <size>,
    sort: <sort>,
    filter: <filter>,
    ifNoneMatch: <ifNoneMatch>
  };

  structure_aspects = await structure_client.listAssetAspects(request_object);
} catch (ex) {
  // Exception handling
}

位置操作

位置客户端管理 asset 的位置。您可以用它来创建、更新和删除 asset 的位置。

客户端名称: LocationsClient

创建或更新 asset 位置

创建或更新分配给 asset 的位置。如果还没有为 asset 定义位置,则创建一个新位置。否则,它将被更新。

// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;

// Require LocationsClient from assetmanagement-sdk module
const LocationsClient = require('assetmanagement-sdk').LocationsClient;

// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();

// Construct the LocationsClient object
let locations_client = new LocationsClient(config, credentials);

let updated_asset = null;
try{
  const request_object = {
    ifMatch: <ifMatch>,
    id: <id>,
    location: <location>
  };

  updated_asset = await locations_client.saveAssetLocation(request_object);
} catch (ex) {
  // Exception handling
}

删除 asset 位置

删除 asset 的位置。

// Construct the LocationsClient object as shown above

let updated_asset = null;
try{
  const request_object = {
    ifMatch: <ifMatch>,
    id: <id>
  };

  updated_asset = await locations_client.deleteAssetLocation(request_object);
} catch (ex) {
  // Exception handling
}

公告板操作

公告板客户端可以用来列出所有可用的资源。

客户端名称: BillboardClient

列出所有可用的资源

列出可用资源的所有链接。

// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;

// Require BillboardClient from assetmanagement-sdk module
const BillboardClient = require('assetmanagement-sdk').BillboardClient;

// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();

// Construct the BillboardClient object
let billboard_client = new BillboardClient(config, credentials);

let billboard_resource = null;
try{
  billboard_resource = await billboard_client.getBillboard();
} catch (ex) {
  // Exception handling
}

文件操作

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

客户端名称: FilesClient

列出所有文件

获得所有上传文件的元数据。

// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;

// Require FilesClient from assetmanagement-sdk module
const FilesClient = require('assetmanagement-sdk').FilesClient;

// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();

// Construct the FilesClient object
let files_client = new FilesClient(config, credentials);

let file_metadata_list_resource = null;
try{
  const request_object = {
    page: <page>,
    size: <size>,
    sort: <sort>,
    filter: <filter>,
    ifNoneMatch: <ifNoneMatch>
  };

  file_metadata_list_resource = await files_client.listFiles(request_object);
} catch (ex) {
  // Exception handling
}

获取文件

获取具有用户定义 ID 的文件的元数据。

// Construct the FilesClient object as shown above

let file_metadata_list_resource = null;
try{
  const request_object = {
    fileId: <file_id>,
    ifNoneMatch: <ifNoneMatch>
  };

  file_metadata_list_resource = await files_client.getFile(requestObject);
} catch (ex) {
  // Exception handling
}

下载文件

返回具有用户定义 ID 的文件。

// Construct the FilesClient object as shown above

let file_content = null;
try{
  const request_object = {
    fileId: <file_id>
  };

  file_content = await files_client.downloadFile(request_object);
} catch (ex) {
  // Exception handling
}

替换文件

更新一个过去上传过的文件。文件的最大大小是 5 MB。

// Construct the FilesClient object as shown above

let file_metadata_resource = null;
try{
  const request_object = {
    ifMatch: <ifMatch>,
    fileId: <file_id>,
    file: <file>,
    name: <name>,
    scope: <scope>,
    description: <description>
  };

  file_metadata_resource = await files_client.replaceFile(request_object);
} catch (ex) {
  // Exception handling
}

上传文件

上传一个用于 Asset Management 的文件。

// Construct the FilesClient object as shown above

let file_metadata_resource = null;
try{
  const request_object = {
    file: <file>,
    name: <name>,
    scope: <scope>,
    description: <description>
  };

  file_metadata_resource = await files_client.uploadFile(request_object);
} catch (ex) {
  // Exception handling
}

删除文件

// Construct the FilesClient object as shown above

try{

  const request_object = {
    ifMatch: <ifMatch>,
    fileId: <file_id>
  };

  await files_client.deleteFile(request_object);
} catch (ex) {
  // Exception handling
}

Last update: March 22, 2023