Skip to content

Asset Management Client for Java

Introduction

The Asset Management Java client is used to interact with the digital representation of a machine or automation system. The interaction with the MindSphere API is abstracted through a Java object model.

Refer to Asset Management for more information about the service.

Aspect Type Operations

The aspect type client manages static and dynamic aspect types. It lists, creates, updates, reads and deletes the aspect types.

Client name: AspecttypeClient

List all Aspect Types

Get all aspect types of the tenant.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// Construct the AspecttypeClient object
AspecttypeClient aspecttypeClient = AspecttypeClient.builder()
                                        .mindsphereCredentials(credentials)
                                        .restClientConfig(config)
                                        .build();

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

Create an Aspect Type

Create an aspect type.

1
2
3
4
5
6
7
8
9
//Create client object "aspecttypeClient" as shown above

AspectTypeResource aspectType = null;

try {
  aspectType = aspecttypeClient.saveAspectType(id, aspectTypeDto, ifMatch);
} catch (MindsphereException e) {
  // Exception handling
}

Update an Aspect Type

Update an existing aspect type. Only adding variables is supported. Removing or renaming variables is not supported.

1
2
3
4
5
6
7
8
9
//Create client object "aspecttypeClient" as shown above

AspectTypeResource aspectType = null;

try {
  aspectType = aspecttypeClient.updateAspectType(ifMatch, id, aspectTypeDto);
} catch (MindsphereException e) {
  // Exception handling
}

Read an Aspect Type

Read an aspect type.

1
2
3
4
5
6
7
8
9
//Create client object "aspecttypeClient" as shown above

AspectTypeResource aspectTypeResource = null;

try {
  aspectTypeResource = aspecttypeClient.getAspectType(id, ifNoneMatch);
} catch (MindsphereException e) {
  // Exception handling
}

Delete an Aspect Type

Delete an aspect type. An aspect type can only be deleted, if no asset type uses it.

1
2
3
4
5
6
7
//Create client object "aspecttypeClient" as shown above

try {
  aspecttypeClient.deleteAspectType(ifMatch, id);
} catch (MindsphereException e) {
  // Exception handling
}

Asset Type Operations

The asset type client manages asset types. It lists, creates, updates, reads and deletes the asset types. It can also be used to add and delete file assignments to the asset types.

Client name: AssettypeClient

List all Asset Types

List all asset types of the tenant.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// Construct the AssettypeClient object
AssettypeClient assetTypeClient = AssettypeClient.builder()
                                      .mindsphereCredentials(credentials)
                                      .restClientConfig(config)
                                      .build();

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

Create an Asset Type

Create an asset type.

1
2
3
4
5
6
7
8
9
//Create client object "assetTypeClient" as shown above

AssetTypeResource assetTypeResource = null

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

Update an Asset Type

Update an existing asset type.

1
2
3
4
5
6
7
8
9
//Create client object "assetTypeClient" as shown above

AssetTypeResource assetTypeResource = null;

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

Read an Asset Type

Read an asset type.

1
2
3
4
5
6
7
8
9
//Create client object "assetTypeClient" as shown above

AssetTypeResource assetTypeResource = null;

try {
    assetTypeResource = assetTypeClient.getAssetType(id, ifNoneMatch, exploded);
} catch (MindsphereException e) {
    // Exception handling
}

Delete an Asset Type

Delete an asset type. Deletion is only possible for asset types without children and when there is no asset instantiating them.

1
2
3
4
5
6
7
//Create client object "assetTypeClient" as shown above

try {
    assetTypeClient.deleteAssetType(ifMatch, id);
} catch (MindsphereException e) {
    // Exception handling
}

Add a New File Assignment to an Asset Type

Add a new file assignment to an asset type. Asset types which extend this type and assets instantiated from it have this file assigned by default.

1
2
3
4
5
6
7
8
//Create client object "assetTypeClient" as shown above

AssetTypeResource assetTypeResource = null;
try {
    assetTypeResource = assetTypeClient.saveAssetTypeFileAssignment(ifMatch, id, key, keyedFileAssignmentDto);
} catch (MindsphereException e) {
    // Exception handling
}

Delete a File Assignment from an Asset Type

Deletes a file assignment from an asset type. If the type's parent is assigned a file with the same key, the key will be displayed in the inherited value field.

1
2
3
4
5
6
7
8
9
//Create client object "assetTypeClient" as shown above

AssetTypeResource assetTypeResource = null;

try {
    assetTypeResource = assetTypeClient.deleteAssetTypeFileAssignment(id, key, ifMatch);
} catch (MindsphereException e) {
    // Exception handling
}

Asset Operations

The asset client manages the user's assets and their locations. Three different types of assets can be created: device types, agent types and hierarchy types. The asset client lists, creates, updates, reads, deletes, moves and replaces the asset. It can also be used to add and delete file assignments to the asset.

Client name: AssetsClient

List all Assets

List all assets available for the authenticated user.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// Construct the AssetClient object
AssetsClient assetClient = AssetsClient.builder()
                              .mindsphereCredentials(credentials)
                              .restClientConfig(config)
                              .build();

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

Create an Asset

Create a new asset with the provided content.

1
2
3
4
5
6
7
8
9
//Create client object "assetClient" as shown above

AssetResourceWithHierarchyPath assetResource = null;

try{
    assetResource = assetClient.addAsset(assetDto);
} catch (MindsphereException e) {
    // Exception handling
}

Read an Asset

Read a single asset. All static properties of an asset are returned.

1
2
3
4
5
6
7
8
9
//Create client object "assetClient" as shown above

AssetResourceWithHierarchyPath assetResource = null;

try{
    assetResource = assetClient.getAsset(id, ifNoneMatch);
} catch (MindsphereException e) {
    // Exception handling
}

Update an Asset

Update an existing asset with the provided content. Only values can be modified. The asset structure can only be modified in the asset type.

1
2
3
4
5
6
7
8
//Create client object "assetClient" as shown above

AssetResourceWithHierarchyPath assetResource = null;
try{
    assetResource = assetClient.updateAsset(ifMatch, id, assetUpdateDto );
} catch (MindsphereException e) {
    // Exception handling
}

Delete an Asset

Delete an existing asset. After deletion, users with an admin role can still read the asset, but modification is not possible anymore. It is not possible to delete an asset if it has children.

1
2
3
4
5
6
7
//Create client object "assetClient" as shown above

try{
    assetClient.deleteAsset(ifMatch, id);
} catch (MindsphereException e) {
    // Exception handling
}

Move an Asset

Move an existing asset and all of its children in the instance hierarchy.

1
2
3
4
5
6
7
8
9
//Create client object "assetClient" as shown above

AssetResourceWithHierarchyPath assetResource = null;

try{
    assetResource = assetClient.moveAsset(ifMatch, id, assetMoveDto);
} catch (MindsphereException e) {
    // Exception handling
}

Replace an Asset

Updates an asset with the provided content.

1
2
3
4
5
6
7
8
9
//Create client object "assetClient" as shown above

AssetResourceWithHierarchyPath assetResource = null;

try{
    assetResource = assetClient.replaceAsset(ifMatch, id, assetUpdateDto );
} catch (MindsphereException e) {
    // Exception handling
}

Get the User's Root Asset

Read the user's root asset, from which the whole asset hierarchy can be rebuilt.

1
2
3
4
5
6
7
8
//Create client object "assetClient" as shown above

RootAssetResource rootAssetResource = null;
try{
    rootAssetResource = assetClient.getRootAsset(ifNoneMatch);
} catch (MindsphereException e) {
    // Exception handling
}

Add a New File Assignment to an Asset

Add a new file assignment to an asset. All children of the asset have this file assigned by default.

1
2
3
4
5
6
7
8
//Create client object "assetClient" as shown above

AssetResourceWithHierarchyPath assetResource = null;
try {
    assetResource = assetClient.saveAssetFileAssignment(id, key, ifMatch, keyedFileAssignmentDto);
} catch (MindsphereException e) {
    // Exception handling
}

Delete a File Assignment from an Asset

Deletes a file assignment from an asset.

1
2
3
4
5
6
7
8
9
//Create client object "assetClient" as shown above

AssetResourceWithHierarchyPath assetResource = null;

try {
    assetResource = assetClient.deleteAssetFileAssigment(id, key, ifMatch);
} catch (MindsphereException e) {
    // Exception handling
}

Structure Operations

The structure client is used to list an asset's aspects and variables.

Client name: StructureClient

Get an Asset's Variables

Get all variables of an asset.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// Construct the StructureClient object
StructureClient structureClient = StructureClient.builder()
                                                .mindsphereCredentials(credentials)
                                                .restClientConfig(config)
                                                .build();

VariableListResource structureVariables = null;
try{
    structureVariables = structureClient.listAssetVariables(id, page, size, sort, filter, ifNoneMatch);
} catch (MindsphereException e) {
    // Exception handling
}

Get all Aspects of an Asset

Get all static and dynamic aspects of a specified asset.

1
2
3
4
5
6
7
8
9
//Create client object "structureClient" as shown above

AspectListResource structureAspects = null;

try{
    structureAspects = structureClient.listAssetAspects(id, page, size, sort, filter, ifNoneMatch);
} catch (MindsphereException e) {
    // Exception handling
}

Locations Operations

The locations client manages the location of the asset. It can be used to create, update and delete an asset's location.

Client name: LocationsClient

Create or Update an Asset's Location

Creates or updates a location that is assigned to the asset. If no location is defined for the asset yet, a new one is created. Otherwise, it is updated.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// Construct the AssetLocationClient object
LocationsClient locationsClient = LocationsClient.builder()
                                              .mindsphereCredentials(credentials)
                                              .restClientConfig(config)
                                              .build();

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

Delete an Asset's Location

Delete the location that is assigned to the asset.

1
2
3
4
5
6
7
8
9
//Create client object "locationsClient" as shown above

AssetResourceWithHierarchyPath assetResource = null;

try{
    assetResource = locationsClient.deleteAssetLocation(ifMatch, id);
} catch (MindsphereException e) {
    // Exception handling
}

Billboard Operations

The billboard client can be used to list all available resources.

Client name: BillboardClient

List all Available Resources

List all links for available resources

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// Construct the BillboardClient object
BillboardClient billboardClient = BillboardClient.builder()
                                              .mindsphereCredentials(credentials)
                                              .restClientConfig(config)
                                              .build();

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

File Operations

The files client manages files that can be assigned to a resource. It is used to list, read, upload, delete, replace and download a file.

Client name: FilesClient

List all Files

Get metadata of uploaded files.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// Construct the AssetLocationClient object
FilesClient filesClient = FilesClient.builder()
                                      .mindsphereCredentials(credentials)
                                      .restClientConfig(config)
                                      .build();

FileMetadataListResource fileMetadataListResource = null;

try{
    fileMetadataListResource = filesClient.listFiles(page, size, sort, filter, ifNoneMatch);
} catch (MindsphereException e) {
    // Exception handling
}

Get a File

Get a file's metadata by its id.

1
2
3
4
5
6
7
8
9
//Create client object "filesClient" as shown above

FileMetadataResource fileMetadataResource = null;

try{
    fileMetadataResource = filesClient.getFile(fileId, ifNoneMatch);
} catch (MindsphereException e) {
    // Exception handling
}

Download a File

Returns a file by its id.

1
2
3
4
5
6
7
8
9
//Create client object "filesClient" as shown above

byte[] fileContents = null;

try{
    fileContents = filesClient.downloadFile(fileId);
} catch (MindsphereException e) {
    // Exception handling
}

Replace a File

Update a previously uploaded file. Max file size is 5 MB.

1
2
3
4
5
6
7
8
//Create client object "filesClient" as shown above

FileMetadataResource fileMetadataResource = null;
try{
    fileMetadataResource = filesClient.replaceFile(ifMatch, fileId, file, name, scope, description);
} catch (MindsphereException e) {
    // Exception handling
}

Upload a File

Upload a file to be used in Asset Management.

1
2
3
4
5
6
7
8
//Create client object "filesClient" as shown above

FileMetadataResource fileMetadataResource = null;
try{
    fileMetadataResource = filesClient.uploadFile(file, name, scope, description);
} catch (MindsphereException e) {
    // Exception handling
}

Delete a File

Delete a file.

1
2
3
4
5
6
7
//Create client object "filesClient" as shown above

try{
    deleteFile(ifMatch, fileId);
} catch (MindsphereException e) {
    // Exception handling
}

Page Iterators

The page iterators for the Asset Management API client can be used to get a specific page, the next page or the previous page of data.

The page iterators support the following operations:

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

The following iterators are provided for different controllers in Asset Management:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
try {
    // Create Assets Client
    AssetsClient assetClient =  AssetsClient.builder()
                                    .mindsphereCredentials(credentials)
                                    .restClientConfig(config)
                                    .build();

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

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

Any questions left?

Ask the community


Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.