If you want the Asset dashboard for assets running Axeda IDM Agents to show that the asset is running in Occasionally Connected mode, you can use the following Groovy script as a custom object of type IDM WS Extension. Then, define an IDM Web Service (WS) Extension with the following attributes:
o Service Name - select Registration from the list
o Operation Name - registerAsset or updateAssetProfile, or both
o Extension Type - post-consume
o Custom Object - this object
The following script creates a property named Communication Mode and sets its value to the value currently in the asset. For example, if the IDM Agent is running in Occasionally Connected mode, the value is Occasionally Connected. You also need to add the property to the Model for the assets (Model wizard - Modify Properties step). Once it extracts the communication mode from the XML, this script uses the Axeda Platform Web Services SDK to update the value of the property.
// ***********************************************
// Copyright (c) Axeda Corporation 2011 - All rights reserved
// ***********************************************
// Groovy script for storing the IDM asset communication mode as a device property
// The IDM registerAsset and updateAssetProfile both have an XML element named "Asset" that contains
// this field. Extract this data from the XML then use the assetService Platform SDK service to
// update the Platform with the current value.
//
// Register this script as a Custom Object of type "IDM Agent WS Extension"
// Then define a IDM WebService Extension with the following:
// Service Name = Registration
// Operation Name = registerAsset or updateAssetProfile or both
// Extension Type = post-consume
// Custom Object = this object
//
import com.axeda.platform.sdk.v1.services.ServiceFactory
import com.axeda.platform.sdk.v1.services.asset.Asset
import com.axeda.platform.sdk.v1.services.asset.AssetSearchCriteria
import com.axeda.platform.sdk.v1.services.asset.AssetService
import com.axeda.platform.sdk.v1.services.asset.Property
import org.w3c.dom.Element
import org.w3c.dom.NodeList
Element operationEntity = request.getOperationEntity()
if (operationEntity == null)
{
response.fault = "Invalid content"
return
}
NodeList nodeList = operationEntity.getElementsByTagName("Asset")
if (nodeList == null || nodeList.length != 1)
{
response.fault = "Invalid content"
return
}
com.questra.a2b.registration.common.Asset idmAsset = new com.questra.a2b.registration.common.Asset(nodeList.item(0))
// Use the Platform SDK ServiceFactory to get a reference to the AssetService
ServiceFactory factory = new ServiceFactory()
AssetService sdkService = factory.getAssetService()
AssetSearchCriteria criteria = new AssetSearchCriteria()
criteria.serialNumber = idmAsset.memberName
// if this script is registered as a post-consume interceptor, the asset should always exist
List<Asset> assets = sdkService.find(criteria)
Asset myasset = null;
for (Asset a : assets)
{
if (a.serialNumber.equals(idmAsset.memberName))
{
myasset = a;
break;
}
}
if (myasset == null)
{
response.fault = "Asset not found"
return
}
Property p = new Property()
p.name = "CommunicationMode"
p.value = idmAsset.communicationMode
sdkService.setAssetProperties(myasset.id, Collections.singletonList(p))