Created
July 15, 2014 14:05
-
-
Save saranicole/e92bb938b534db7f9755 to your computer and use it in GitHub Desktop.
SimpleAssetSerialize
This file contains hidden or 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
| import net.sf.json.JSONArray | |
| import com.axeda.drm.sdk.Context | |
| import static com.axeda.sdk.v2.dsl.Bridges.* | |
| import groovy.xml.MarkupBuilder | |
| import com.axeda.services.v2.AssetReference | |
| import com.axeda.services.v2.AssetCriteria | |
| import com.axeda.common.sdk.id.Identifier | |
| import com.axeda.drm.sdk.device.Model | |
| import com.axeda.drm.sdk.device.DataItem | |
| import com.axeda.drm.sdk.device.DataItemValue | |
| import com.axeda.drm.sdk.data.DataValue | |
| import com.axeda.drm.sdk.device.DeviceFinder | |
| import com.axeda.drm.sdk.device.Device | |
| import com.axeda.drm.sdk.mobilelocation.MobileLocation | |
| import com.axeda.drm.sdk.data.DataValueList | |
| import com.axeda.drm.sdk.data.CurrentDataFinder | |
| import com.axeda.drm.sdk.mobilelocation.CurrentMobileLocationFinder | |
| import com.axeda.drm.sdk.mobilelocation.HistoricalMobileLocationFinder | |
| def writer = new StringWriter() | |
| def xml = new MarkupBuilder(writer) | |
| // def assetId = "23924" | |
| // def asset1 = assetBridge.findById(assetId) | |
| // def response = JSONArray.fromObject(asset1).toString(2) | |
| Context CONTEXT = Context.getSDKContext() | |
| DeviceFinder deviceFinder = new DeviceFinder(CONTEXT, new Identifier(23924)) | |
| def device = deviceFinder.find() | |
| CurrentMobileLocationFinder currentMobileLocationFinder = new CurrentMobileLocationFinder(CONTEXT) | |
| currentMobileLocationFinder.deviceId = device.id.value | |
| MobileLocation mobileLocation = currentMobileLocationFinder.find() | |
| logger.info(mobileLocation.lng) | |
| HistoricalMobileLocationFinder hmlFinder = new HistoricalMobileLocationFinder(CONTEXT) | |
| hmlFinder.setLastN(10) | |
| hmlFinder.setDeviceId(23924) | |
| def mobileLocations = hmlFinder.findAll() | |
| mobileLocations.each{ | |
| def friendlydate = new Date(it.endTimeStamp).format("MM/dd/yyyy HH:mm:ss a") | |
| logger.info("$it.lat $it.lng $friendlydate")} | |
| /* | |
| def writer = new StringWriter() | |
| def xml = new MarkupBuilder(writer) | |
| def modelName = "baba_location" | |
| def findAssetResult = assetBridge.find(new AssetCriteria(modelNumber: modelName)) | |
| // find operation returns AssetReference class. Contains asset id only | |
| def assets = findAssetResult.assets | |
| xml.Response() { | |
| Assets() { | |
| assets.each { AssetReference assetRef -> | |
| def asset = assetBridge.findById(assetRef.id) | |
| Asset() { | |
| id(asset.id) | |
| name(asset.name) | |
| serial_number(asset.serialNumber) | |
| model_id(asset.model.id) | |
| model_name(asset.model.detail) | |
| } | |
| } | |
| } | |
| } | |
| */ | |
| return ['Content-Type': 'text/xml', 'Content': writer.toString()] | |
| // return ["Content-Type": "application/json", "Content": response] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment