Skip to content

Asset Management Client for Java

Introduction

The Asset Management Java client allows you to interact with the digital representation of a machine or automation system through a Java object model, abstracting the interaction with the MindSphere API.

See 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 and reads 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();

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

Create an Aspect Type

Create an aspect type. Aspect types can be defined to contain variables.

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

Update an Aspect Type

Update an existing aspect type. Aspect types can be defined to contain variables.

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

Read an Aspect Type

Read an aspect type.

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

Delete an Aspect Type

Delete an aspect type. An aspect type can only be deleted if there is no asset type using it.

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

Asset Type Operations

The Asset type client manages 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();

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

Create an Asset Type

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
//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 can be added to an asset type in the following ways:

  1. Using Aspect Type name and Aspect Type id

    1
    2
    3
    4
    5
    6
    7
    8
    //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. Using AspectTypeResource instance

    1
    2
    3
    4
    5
    6
    7
    8
    9
    //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. Using AssetTypeDtoAspects instance

    1
    2
    3
    4
    5
    6
    7
    //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. Using a list of AspectTypeResource instances

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    //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. Using a list of AssetTypeDtoAspects instances

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    //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);
    

Update an Asset Type

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

Read an Asset Type

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

Delete an Asset Type

Delete an asset type. Deletion is only possible when the type has no children and there is no asset that instantiates it.

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

Assign a File to an Asset Type

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
//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
}

Delete a File from an Asset Type

1
2
3
4
5
6
7
8
9
//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 Operations

The Asset client manages the users' assets and their locations. Only three different types of assets can be created: device types, agent types and hierarchy types.

Client name: AssetClient

List all Asset Types

List all assets available for the authenticated user.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// 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
}

Create an Asset Type

Create a new asset with the provided content.

1
2
3
4
5
6
7
//Create client object "assetClient" as shown above
AssetResource assetResource = null;
try{
    assetResource = assetClient.createAsset(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
//Create client object "assetClient" as shown above
AssetResource assetResource = null;
try{
    assetResource = assetClient.getAssetById(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 has to be modified in the asset type.

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

Delete an Asset

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

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

Move an Asset

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

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

Read the Root Asset of the User

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

1
2
3
4
5
6
7
//Create client object "assetClient" as shown above
AssetResource assetResource = null;
try{
    assetResource = assetClient.getRootAsset(ifNoneMatch);
} catch (MindsphereException e) {
    // Exception handling
}

Assign a File to an Asset

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
//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
}

Delete a File from an Asset

1
2
3
4
5
6
7
8
9
//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 Structure Operations

Client name: AssetStructureClient

Read Variables of an Asset

Get all variables of an asset.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// 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
}

Read all Aspects of an Asset

Get all static and dynamic aspects of a specified asset.

1
2
3
4
5
6
7
//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 Location Operations

Client name: AssetLocationClient

Create or Updating Location

Creates or updates a location that is assigned to the given asset.

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

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

Delete Location assigned to the Asset

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

Asset File Operations

Client name: AssetFileClient

Upload a File

Upload files to be associated with asset types or assets.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// 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
}

List all Files

List the metadata of all uploaded files.

1
2
3
4
5
6
7
8
// Construct the AssetFileClient instance as shown above

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

Read the Metadata of a File

Read metadata of a file using the file ID.

1
2
3
4
5
6
7
8
// Construct the AssetFileClient instance as shown above

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

Read the Content of a File

Read content of a file using the file ID.

1
2
3
4
5
6
7
8
// Construct the AssetFileClient instance as shown above

String fileContents = null;
try{
    fileContents = assetFileClient.getFileContentById(fileId, ifNoneMatch);
} 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 currently 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 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
}

Any questions left?

Ask the community


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