Hi
I am using the below code to parse a CSV file but when I run the code in Axeda Server 6.5 I get the error as groovy.lang.MissingPropertyException: No such property: compressedFile for class
- import com.axeda.drm.sdk.Context
- import com.axeda.drm.sdk.device.DeviceFinder
- import com.axeda.drm.sdk.device.ModelFinder
- import com.axeda.drm.sdk.device.DataItemFinder
- import com.axeda.drm.sdk.device.DataItem
- import com.axeda.drm.sdk.data.DataValueEntry
- import java.util.regex.Pattern
- import groovy.json.*
- import com.axeda.drm.services.device.DataItemType
- import net.sf.json.JSONObject
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- def json = new groovy.json.JsonBuilder()
- def infoString = new StringBuilder()
- def contentType = "application/json"
- def scriptName = "CSVToData.groovy"
- def root = ["result":["items":[]]]
-
- def columns = []
-
- try {
-
- Context CONTEXT = Context.getSDKContext()
-
- def modelIndex
- def serialIndex
-
-
- ModelFinder modelFinder = new ModelFinder(CONTEXT)
- DeviceFinder deviceFinder = new DeviceFinder(CONTEXT)
-
-
- File file = compressedFile.getFiles()[0].extractFile()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- file.eachLine {line ->
- def row = line.tokenize(',')
-
-
- if (columns.size() == 0){
- columns = row
-
-
- def modelpatt = Pattern.compile(/[A-Za-z_\-]{0,}model[A-Za-z_\-]{0,}/, Pattern.CASE_INSENSITIVE)
- def serialpatt = Pattern.compile(/[A-Za-z_\-]{0,}serial[A-Za-z_\-]{0,}/, Pattern.CASE_INSENSITIVE)
- modelIndex = columns.findIndexOf{ it ==~ modelpatt } > -1 ? columns.findIndexOf{ it ==~ modelpatt } : 0
- serialIndex = columns.findIndexOf{ it ==~ serialpatt } > -1 ? columns.findIndexOf{ it ==~ serialpatt } : 1
-
- }
-
- else {
-
- modelFinder.setName(row.get(modelIndex))
- def model = modelFinder.find()
-
- deviceFinder.setModel(model)
- deviceFinder.setSerialNumber(row.get(serialIndex))
-
- def device = deviceFinder.find()
-
- def assetInfo = [
- "model": model.name,
- "serial": device.serialNumber,
- "data":[]
- ]
-
- row.eachWithIndex{ item, index ->
- if (index != modelIndex && index != serialIndex){
- def dataItemName = columns[index].replace(" ","")
- DataItemFinder dif = new DataItemFinder(CONTEXT);
- dif.setDataItemName(dataItemName);
- dif.setModel(model);
- DataItem dataItem = dif.find();
-
- if (dataItem){
- if (item.isNumber()){
- item = Double.valueOf(item)
- }
- DataValueEntry dve = new DataValueEntry(CONTEXT, device, dataItem, item)
- dve.store()
- }
- else {
- DataItem newDataItem
- if (item.isNumber()){
- newDataItem = new DataItem(CONTEXT, model,DataItemType.ANALOG, dataItemName)
- item = Double.valueOf(item)
- }
- else {
- newDataItem = new DataItem(CONTEXT, model,DataItemType.STRING, dataItemName)
- }
- newDataItem.store()
- DataValueEntry dve = new DataValueEntry(CONTEXT, device, newDataItem, item)
- dve.store()
- }
- assetInfo.data << [
- "name": dataItemName,
- "value": item
- ]
-
- }
- root.result.items << assetInfo
- }
-
- }
- }
- logger.info(JSONObject.fromObject(root).toString(2))
-
- } catch (Exception e) {
-
- processException(scriptName,json,e)
- }
-
-
-
-
-
-
-
-
-
- private def processException(String scriptName, JsonBuilder json, Exception e) {
-
- def logStringWriter = new StringWriter()
- e.printStackTrace(new PrintWriter(logStringWriter))
- logger.error("Exception occurred in ${scriptName}: ${logStringWriter.toString()}")
-
-
-
-
-
-
- json.errors {
- error {
- message "[${scriptName}]: " + e.getMessage()
- timestamp "${System.currentTimeMillis()}"
- }
- }
-
- return json
- }