Created
July 26, 2011 14:24
-
-
Save axeda/1106879 to your computer and use it in GitHub Desktop.
Check Alarm History Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
// get Date object for "numHours" hour ago | |
Calendar cal = Calendar.getInstance() | |
cal.add(Calendar.HOUR, -parameters.numHours.toInteger()) | |
Date sinceTime = cal.getTime() | |
// find alarms with the same device and name as the | |
// alarm that called this script within "numHours" hours | |
HistoricalAlarmFinder findAlarms = new HistoricalAlarmFinder (Context.create()) | |
findAlarms.device = alarm.device | |
findAlarms.setAlarmName(alarm.name) | |
findAlarms.date = DateQuery.after(sinceTime) | |
List matchingAlarms = findAlarms.findAll() | |
return matchingAlarms.size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment