Skip to content

Commit

Permalink
Updated test methods for special PUT/POST calls. Cleaned up device.db
Browse files Browse the repository at this point in the history
file write to not keep junk around.
  • Loading branch information
bwssytems committed Oct 5, 2015
1 parent 7514e36 commit 1602ed0
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import java.io.IOException;
import java.io.StringReader;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -106,7 +108,10 @@ private void repositoryWriter(String content, Path filePath) {
}

try {
Path target = FileSystems.getDefault().getPath("data", "device.db.old");
Files.move(filePath, target);
Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE);
Files.delete(target);
} catch (IOException e) {
log.error("Error writing the file: " + filePath + " message: " + e.getMessage(), e);
}
Expand Down
82 changes: 74 additions & 8 deletions src/main/resources/public/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ app.service('bridgeService', function ($http, BridgeSettings) {
}
);
} else {
if(type == null || type == "")
type = "switch";
return $http.post(this.state.base, {
name: name,
deviceType: type,
Expand Down Expand Up @@ -241,14 +243,46 @@ app.controller('ViewingController', function ($scope, $location, $http, bridgeSe
};
$scope.testUrl = function (device, type) {
if(type == "on") {
if(device.httpVerb == "PUT" || device.httpVerb == "POST")
$http.put(device.onUrl, device.contentBody);
if(device.httpVerb == "PUT")
$http.put(device.onUrl, device.contentBody).then(
function (response) {
$scope.responsedata = response.data;
},
function (error) {
console.log(error);
}
);
else if(device.httpVerb == "POST")
$http.post(device.onUrl, device.contentBody).then(
function (response) {
$scope.responsedata = response.data;
},
function (error) {
console.log(error);
}
);
else
window.open(device.onUrl, "_blank");
}
else {
if(device.httpVerb == "PUT" || device.httpVerb == "POST")
$http.put(device.offUrl, device.contentBodyOff);
if(device.httpVerb == "PUT")
$http.put(device.offUrl, device.contentBodyOff).then(
function (response) {
$scope.responsedata = response.data;
},
function (error) {
console.log(error);
}
);
else if(device.httpVerb == "POST")
$http.post(device.offUrl, device.contentBody).then(
function (response) {
$scope.responsedata = response.data;
},
function (error) {
console.log(error);
}
);
else
window.open(device.offUrl, "_blank");
}
Expand Down Expand Up @@ -335,14 +369,46 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer

$scope.testUrl = function (url) {
if(type == "on") {
if(device.httpVerb == "PUT" || device.httpVerb == "POST")
$http.put(device.onUrl, device.contentBody);
if(device.httpVerb == "PUT")
$http.put(device.onUrl, device.contentBody).then(
function (response) {
$scope.responsedata = response.data;
},
function (error) {
console.log(error);
}
);
else if(device.httpVerb == "POST")
$http.post(device.onUrl, device.contentBody).then(
function (response) {
$scope.responsedata = response.data;
},
function (error) {
console.log(error);
}
);
else
window.open(device.onUrl, "_blank");
}
else {
if(device.httpVerb == "PUT" || device.httpVerb == "POST")
$http.put(device.offUrl, device.contentBodyOff);
if(device.httpVerb == "PUT")
$http.put(device.offUrl, device.contentBodyOff).then(
function (response) {
$scope.responsedata = response.data;
},
function (error) {
console.log(error);
}
);
else if(device.httpVerb == "POST")
$http.post(device.offUrl, device.contentBody).then(
function (response) {
$scope.responsedata = response.data;
},
function (error) {
console.log(error);
}
);
else
window.open(device.offUrl, "_blank");
}
Expand Down

0 comments on commit 1602ed0

Please sign in to comment.