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 Industrial IoT API. 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 and reads the aspect types.
Client name: AspectTypeClient
List all Aspect Types¶
Get all aspect types of the tenant.
// 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.
//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.
//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.
//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.
//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.
// 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¶
//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:
Using Aspect Type name and Aspect Type 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);
Using AspectTypeResource instance
//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);
Using AssetTypeDtoAspects instance
//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);
Using a list of AspectTypeResource instances
//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);
Using a list of AssetTypeDtoAspects instances
//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¶
//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¶
//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.
//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¶
//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¶
//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. 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.
// 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.
//Create client object "assetClient" as shown above
AssetResource assetResource = null;
try{
assetResource = assetClient.createAsset(assetDto);
} catch (MindsphereException e) {
// Exception handling
}
Read an Asset¶
Read an asset. All static properties of the asset are returned.
//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, but not the asset structure. The asset structure can be modified in the 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
}
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.
//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.
//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.
//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¶
//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¶
//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.
// 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 an asset.
//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 Update Location¶
Creates or updates the location that is assigned to an 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
}
Delete Location assigned to the Asset¶
//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.
// 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.
// 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 the metadata of a file with the user defined ID.
// 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 the content of a file with the user defined ID.
// 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:
- AspectTypePageIterator
- AssetTypePageIterator
- AssetPageIterator
- StructureAspectsPageIterator
- StructureVariablesPageIterator
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
}