Skip to content

Instantly share code, notes, and snippets.

@axeda
axeda / gist:935419
Created April 21, 2011 20:40
AxedaFirstGist
def getthegist = [this: 'is', the: 'gist']
getthegist.each {k,v-> println "$k = $v" }
@axeda
axeda / associateasset.groovy
Created July 26, 2011 14:21
Asset Association
/**
* Script to run from a rule, associates the device running the rule to the provided model/serialnumber
*/
import com.axeda.drm.sdk.Context
import com.axeda.drm.sdk.device.*
import com.axeda.drm.sdk.m2m.*
try {
Context ctx = Context.create()
// get the parameters
@axeda
axeda / AddAssetToAssetGroup.groovy
Created July 26, 2011 14:23
Add an asset to an asset group
<!-- Add parameter "assetgroupname" -->
import com.axeda.drm.sdk.device.DeviceGroupFinder
import com.axeda.drm.sdk.device.DeviceGroup
import com.axeda.drm.sdk.Context
try {
def assetgroupname = parameters.assetgroupname
DeviceGroupFinder dgf = new DeviceGroupFinder(Context.create())
@axeda
axeda / alarmObject.groovy
Created July 26, 2011 14:24
Alarm Object Script
import com.axeda.drm.sdk.Context
import com.axeda.drm.sdk.data.HistoricalAlarmFinder
import java.util.Calendar
import com.axeda.common.sdk.jdbc.DateQuery
// get Date object for an hour ago
Calendar cal = Calendar.getInstance()
cal.add(Calendar.HOUR, -parameters.hours.toInteger())
Date sinceTime = cal.getTime()
@axeda
axeda / checkAlarmHistory.groovy
Created July 26, 2011 14:24
Check Alarm History Script
// explicit parameters:
// numHours check alarms since this many hours ago
// implicit parameters:
// alarm alarm object passed by the platform
import com.axeda.drm.sdk.Context
import com.axeda.drm.sdk.data.HistoricalAlarmFinder
import java.util.Calendar
import com.axeda.common.sdk.jdbc.DateQuery
@axeda
axeda / closeAlarm.groovy
Created July 26, 2011 14:25
Close Alarms on Condition script
import com.axeda.drm.sdk.data.*;
import com.axeda.drm.sdk.Context;
import java.util.*;
try{
AlarmFinder alarmFinder = new AlarmFinder(Context.create());
alarmFinder.setDevice(context.device);
List alarms = alarmFinder.findAll();
for (Alarm alarm : alarms)
{
@axeda
axeda / dataitemToProperty.groovy
Created July 26, 2011 14:26
Copy Data Item value to Asset Property value swcript
import com.axeda.drm.sdk.user.User
import com.axeda.drm.sdk.data.DataValue
import groovy.lang.PropertyValue
import com.axeda.drm.sdk.device.DevicePropertyFinder
import com.axeda.drm.sdk.device.Property
import com.axeda.drm.sdk.device.PropertyType
import com.axeda.drm.sdk.device.DeviceProperty
logger.info "Executing groovy script for device: " + context?.device?.serialNumber
@axeda
axeda / precipitationfromCoordinate.groovy
Created July 26, 2011 14:27
Get Precipitation by a given latitude and Longitude
import org.apache.commons.httpclient.methods.*
import org.apache.commons.httpclient.*
import java.text.SimpleDateFormat
def location = parameters.location.toString()
def locparts = location.split(',')
def lat = locparts[0]
def lon = locparts[1]
@axeda
axeda / handleFile.groovy
Created July 26, 2011 14:28
Handling uploaded files script
import com.axeda.drm.sdk.scm.CompressedFile
if (compressedFile != null)
{
File file = compressedFile.getFiles()[0].extractFile()
def result = file.eachLine { line ->
return line
}
}
@axeda
axeda / mobileLocationObject.groovy
Created July 26, 2011 14:29
MobileLocation Object script
import groovyx.net.http.RESTClient
String rmdHostname = "http://ws.geonames.org";
if (mobileLocation != null)
{
rmd = new RESTClient(rmdHostname);
try {
def resp = rmd.get( path: 'findNearestAddress',