Click the following links to display these examples of custom objects for IDM Agents:
Requesting Software Revision Information from an IDM Agent
The following example will handle the Software Director software version data as device properties.
// Groovy script for handling the IDM agent software revision data as device properties
// Register this script as a custom object of type "IDM Agent WS Extension"
// Then define an IDM Web Service Extension with the following:
// Service Name = SoftwareDirector
// Operation Name = updateSwRevs
// Extension Type = service or post-consume
// Custom Object = this one
import com.questra.a2b.softwaredirector.common.SoftwareRevisionInstallations
import com.questra.a2b.softwaredirector.common.SoftwareRevisionInstallation
import com.questra.xml.IXmlWriter
import com.questra.xml.XmlSerializableBase
import org.w3c.dom.Element
import org.w3c.dom.NodeList
import com.axeda.drm.sdk.device.Device
import com.axeda.drm.sdk.device.DeviceFinder
import com.axeda.drm.sdk.device.DeviceProperty
import com.axeda.drm.sdk.device.DevicePropertyFinder
import com.axeda.drm.sdk.device.Property
import com.axeda.drm.sdk.device.PropertyType
Element operationEntity = request.getOperationEntity()
if (operationEntity == null)
{
response.fault = "Invalid content"
return
}
NodeList nodeList = operationEntity.getElementsByTagName("SwRevInstallations")
if (nodeList == null || nodeList.length != 1)
{
response.fault = "Invalid content"
return
}
SoftwareRevisionInstallations swRevs = new SoftwareRevisionInstallations(nodeList.item(0))
//logger.info "installations = " + swRevs.toString();
def sdkContext = context.context
// the software revisions specify the member name for the revision data.
// Use this instead of the context.device
DeviceFinder df = new DeviceFinder(sdkContext)
df.setSerialNumber swRevs.memberName
Device targetDevice = df.find()
//logger.info "Found target device $targetDevice.serialNumber"
DevicePropertyFinder dpf = new DevicePropertyFinder(sdkContext)
dpf.type = PropertyType.DEVICE_TYPE
dpf.id = targetDevice.id
swRevs.installations.each()
{ SoftwareRevisionInstallation swRevInst ->
// logger.info("Revision " + swRevInst.softwareRevision.componentName + " = " + swRevInst.softwareRevision.version)
boolean found = false;
DeviceProperty dp = dpf.findOne()
if (dp != null)
{
List<Property> props = dp.getProperties()
if (props != null) props.each
{ Property prop->
if (prop.name.equals(swRevInst.softwareRevision.componentName))
{
prop.value = swRevInst.softwareRevision.version
found = true;
dp.store()
}
}
}
// if the model does not currently have a property by this name, add it
// then set the value a second time
if (!found)
{
DeviceProperty updatedDP = new DeviceProperty(sdkContext)
updatedDP.id = targetDevice.model.id
updatedDP.type = PropertyType.MODEL_TYPE
ArrayList<Property> newProperties = new ArrayList<Property>(1)
newProperties.add(new Property(-1, swRevInst.softwareRevision.componentName, contactable))
updatedDP.properties = newProperties
updatedDP.store()
dp = dpf.findOne()
props = dp.getProperties()
props.each
{ Property prop->
if (prop.name.equals(swRevInst.softwareRevision.componentName))
{
prop.value = swRevInst.softwareRevision.version
dp.store()
}
}
}
}
Requesting the Directory Structure for an IDM Agent
The following custom object sends a request to the Agent for its directory structure:
import com.axeda.platform.sdk.v1.services.ServiceFactory
import com.axeda.platform.sdk.v1.services.idmwsext.IDMMessageService
import com.questra.a2b.filerepositorymanager.common.ListDirectoryAsyncOperation
ServiceFactory factory = new ServiceFactory();
IDMMessageService sdkService = factory.getIDMMessageService();
ListDirectoryAsyncOperation operation = new ListDirectoryAsyncOperation()
operation.directory = "/"
operation.filter = "*"
operation.recurse = false
operation.referenceId = 1 // async id, required.
sdkService.queue(context.device, operation)
return true
The following custom object code uses the Axeda Platform SDK to create an alarm and write an audit message:
import com.axeda.drm.sdk.Context;
import com.axeda.drm.sdk.device.*;
import com.axeda.drm.sdk.data.*
import com.axeda.drm.sdk.audit.*
import com.axeda.drm.sdk.mobilelocation.*
import java.util.*;
import groovy.xml.MarkupBuilder
import org.custommonkey.xmlunit.*
import com.axeda.common.sdk.id.Identifier;
import com.axeda.drm.sdk.contact.*
def writer
def xml
ArrayList<String> argArray = new ArrayList<String>();
Context ctx = context.getContext()
Device device = context.getDevice()
try {
writer
= new StringWriter()
xml
= new MarkupBuilder(writer)
//create
alarm
AlarmEntry
ae = new AlarmEntry(ctx, device, "ALtest", 100)
ae.store()
//logging
xml.Response()
{
xml.CreatedAlarm('Name':
ae.getName(), 'State': ae.getState(), 'Severity': ae.getSeverity())
}
argArray.add(writer.toString());
/**AuditCategory
ac= AuditCategory.getByString("data-management")
AuditMessage
am = new AuditMessage(ctx, "testSdkAudit", ac, device, argArray)
am.store()**/
} catch (Exception ex) {
writer = new StringWriter()
xml = new MarkupBuilder(writer)
xml.Response() {
Fault {
Code('Groovy Exception')
Message(ex.getMessage())
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
Detail(sw.toString())
}
}
}
logger.info(writer.toString());
return ['Content-Type': 'text/xml', 'Content': writer.toString()]
See also Custom Object Example - Creating a Communications Mode Property for Axeda IDM Agents.