Fix log issue in RaspberryAgent

merge-requests/1/head
charithag 9 years ago
parent f5976c3fb2
commit dbe107e538

@ -37,7 +37,7 @@ if (uriMatcher.match("/{context}/api/device/sketch/download/{downloadId}")) {
//Just download the already created zip archive
var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils;
var sketchFolder = "repository/resources/sketches";
var archivesPath = "file://"+CarbonUtils.getCarbonHome() + "/" + sketchFolder + "/archives/" + downloadId + ".zip";
var archivesPath = "file://" + CarbonUtils.getCarbonHome() + "/" + sketchFolder + "/archives/" + downloadId + ".zip";
var zipFile = new File(archivesPath);
response.addHeader('Content-type', "application/zip, application/octet-stream");
response.addHeader('Cache-Control', 'public,max-age=12960000');
@ -47,10 +47,10 @@ if (uriMatcher.match("/{context}/api/device/sketch/download/{downloadId}")) {
zipFile.open('r');
var stream = zipFile.getStream();
print(stream);
}catch(err){
} catch (err) {
}finally{
if(zipFile!=null) {
} finally {
if (zipFile != null) {
zipFile.close();
}
}
@ -99,7 +99,7 @@ if (uriMatcher.match("/{context}/api/device/sketch/download/{downloadId}")) {
if (!user) {
result = 403;
}else {
} else {
//URL: https://localhost:9443/{deviceType}/download?owner={username}
deviceManagerService = carbonHttpsServletTransport + "/" + deviceType + "/manager";
@ -120,15 +120,37 @@ if (uriMatcher.match("/{context}/api/device/sketch/download/{downloadId}")) {
//URL: https://localhost:9443/devicecloud/manager/devices/username/{username}
deviceCloudService = carbonHttpsServletTransport + "/devicecloud/device_manager";
listAllDevicesEndPoint = deviceCloudService + "/devices/username/" + user.username;
var data = {};
//XMLHTTPRequest's GET
try {
result = get(listAllDevicesEndPoint, data, "json");
}catch(err){
log.error("Error occured while retrieveing all devices with username: "+user.username);
result=[];
result = get(listAllDevicesEndPoint, {}, "json");
var ownDevices = result.data;
var allDevices = [];
deviceCloudService = carbonHttpsServletTransport + "/devicecloud/group_manager";
var endPoint = deviceCloudService + "/group/all";
var data = {"username": user.username};
var groups = get(endPoint, data, "json").data;
for (var g in groups) {
endPoint = deviceCloudService + "/group/id/" + groups[g].id + "/device/all";
data = {"username": user.username};
var deviceInGroup = get(endPoint, data, "json").data;
groups[g].devices = deviceInGroup;
allDevices.push(groups[g]);
for (var od in ownDevices) {
for (var gd in deviceInGroup) {
if (deviceInGroup[gd].deviceIdentifier == ownDevices[od].deviceIdentifier) {
ownDevices[od].deviceIdentifier = -1;
}
}
}
}
var unsharedDevices = [];
for (var od in ownDevices) {
if (ownDevices[od].deviceIdentifier != -1){
unsharedDevices.push(ownDevices[od]);
}
}
allDevices.push({id: 0, devices: unsharedDevices});
result.data = allDevices;
} else if (uriMatcher.match("/{context}/api/devices/types")) {
@ -142,7 +164,7 @@ if (uriMatcher.match("/{context}/api/device/sketch/download/{downloadId}")) {
}
var elements = uriMatcher.elements();
var deviceId=elements.deviceId;
var deviceId = elements.deviceId;
var deviceType = elements.deviceType;
result = deviceModule.removeDevice(deviceType, deviceId);
@ -154,14 +176,14 @@ if (uriMatcher.match("/{context}/api/device/sketch/download/{downloadId}")) {
}
var elements = uriMatcher.elements();
var deviceId=elements.deviceId;
var deviceId = elements.deviceId;
var deviceType = elements.deviceType;
var cont = request.getContent();
if(!cont.device){
if (!cont.device) {
// http status code 400 refers to - Bad request.
result = 400;
}else {
} else {
result = deviceModule.updateDevice(deviceType, deviceId, cont.device);
}
}

@ -76,7 +76,6 @@ if (uriMatcher.match("/{context}/api/group/add")) {
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}
endPoint = deviceCloudService + "/group/id/" + groupId;
log.info(endPoint);
data = {"username": user.username};
result = get(endPoint, data, "json");
@ -226,10 +225,17 @@ if (uriMatcher.match("/{context}/api/group/add")) {
groupId = uriMatcher.elements().groupId;
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}
endPoint = deviceCloudService + "/group/id/" + groupId;
data = {"username": user.username};
var group = get(endPoint, data, "json").data;
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/all
endPoint = deviceCloudService + "/group/id/" + groupId + "/device/all";
data = {"username": user.username};
result = get(endPoint, data, "json");
group.devices = result.data;
result.data = {group: group}
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/assign")) {

Loading…
Cancel
Save