New user registration
Here is example of creating new user. This code validates, that userEmail is not already stored in DataSet and then creates it.
USERID_DS = 26 USER_EMAIL_COLUMN = 'L_USER_EMAIL' USER_GROUP_ID = 1 USER_DOMAIN_ID = 1 def body = JSON.fromJSONString(body) userEmail = body.getString("email") def filter = isEqualFilter(USER_EMAIL_COLUMN, userEmail) def asset = readDataset(USERID_DS, 1, filter) if (asset.size() == 0) { def user = new JSONObject() user.put("domain_id", USER_DOMAIN_ID) user.put("uiAccessDisabled", "true") user.put("requestPin", "true") user.put("firstName", frameNumber) user.put("lastName", frameNumber) user.put("username", userEmail) user.put("email", userEmail) user.put("locale", body.getString("locale")) def r1 = new JSONObject() r1.put("role", "DATA_ADMIN") def r2 = new JSONObject() r2.put("role", "SCHEMA_ADMIN") def roles = new JSONArray() roles.add(r1) roles.add(r2) user.put("roles", roles) def groups = new JSONArray() def g1 = new JSONObject() g1.put("id", USER_GROUP_ID) groups.add(g1) user.put("groups", groups) return createUser(user) } Response.status(400).build()
Firmware Download
Here is an example of code, that will download firmware file from Media Gallery. This code expect ID of file that should be downloaded
def fileId = request.getPath().split('/') downloadFile(fileId.last() as Integer)
If you have stored your ID of newest firmware in DataSet, this code will provide newest firmware automatically.
def rows = readDataset(1118 , 1, null, com.belladati.common.sort.Sort.descending('row_uid')) downloadFile(rows[0].getValues()['L_FILE_ID'] as Integer)
This code does not need to return only firmware, it can be any file Media Gallery contains.
Deleting data from data set
This code will delete records from the data set specified in the endpoint setting. Filtering condition is specified in the request.
def record_ds_id = 396 //ID of thee data set def recordId = request.getParameters("id")[0] //get value from request parameter ID def recordFilter = isEqualFilter('L_ID', recordId) //filter to load the record based on the ID specified in the request def rows = readDataset(record_ds_id , 1, recordFilter, com.belladati.common.sort.Sort.descending('row_uid')) //load data from the specified data set based on the ID from the request if (rows.size() == 0) { return Response.ok('does not exist').build() //this response is returned in case when the the data set does not contain any data for the specified filter }else { deleteData(record_ds_id, recordFilter) //this function will delete data set records based on the specified filter return Response.ok('success').build() }
Overview
Content Tools