GUAC-932: Clean up REST JavaScript for connections and groups. Update Java style to match.

This commit is contained in:
Michael Jumper
2014-12-17 23:59:29 -08:00
parent 0dd2cd87fb
commit 3c5213e103
4 changed files with 287 additions and 257 deletions

View File

@@ -66,7 +66,7 @@ angular.module('rest').factory('connectionGroupService', ['$http', 'authenticati
// Retrieve connection group
return $http({
method : 'GET',
url : 'api/connectionGroup/' + encodeURIComponent(connectionGroupID) + '/tree',
url : 'api/connectionGroups/' + encodeURIComponent(connectionGroupID) + '/tree',
params : httpParameters
});
@@ -98,7 +98,7 @@ angular.module('rest').factory('connectionGroupService', ['$http', 'authenticati
// Retrieve connection group
return $http({
method : 'GET',
url : 'api/connectionGroup/' + encodeURIComponent(connectionGroupID),
url : 'api/connectionGroups/' + encodeURIComponent(connectionGroupID),
params : httpParameters
});
@@ -119,50 +119,38 @@ angular.module('rest').factory('connectionGroupService', ['$http', 'authenticati
*/
service.saveConnectionGroup = function saveConnectionGroup(connectionGroup) {
// Build HTTP parameters set
var httpParameters = {
token : authenticationService.getCurrentToken()
};
// If connection group is new, add it and set the identifier automatically
if (!connectionGroup.identifier) {
return $http.post("api/connectionGroup/?token=" + authenticationService.getCurrentToken(), connectionGroup).success(
return $http({
method : 'POST',
url : 'api/connectionGroups',
params : httpParameters,
data : connectionGroup
})
// Set the identifier on the new connection group
function setConnectionGroupID(connectionGroupID){
connectionGroup.identifier = connectionGroupID;
}
);
// Set the identifier on the new connection group
.success(function connectionGroupCreated(identifier){
connectionGroup.identifier = identifier;
});
}
// Otherwise, update the existing connection group
else {
return $http.post(
"api/connectionGroup/" + connectionGroup.identifier +
"?token=" + authenticationService.getCurrentToken(),
connectionGroup);
return $http({
method : 'PUT',
url : 'api/connectionGroups/' + encodeURIComponent(connectionGroup.identifier),
params : httpParameters,
data : connectionGroup
});
}
};
/**
* FIXME: Why is this different from save?
*
* Makes a request to the REST API to move a connection group to a
* different group, returning a promise that can be used for processing the
* results of the call.
*
* @param {ConnectionGroup} connectionGroup The connection group to move.
*
* @returns {Promise}
* A promise for the HTTP call which will succeed if and only if the
* move operation is successful.
*/
service.moveConnectionGroup = function moveConnectionGroup(connectionGroup) {
return $http.put(
"api/connectionGroup/" + connectionGroup.identifier +
"?token=" + authenticationService.getCurrentToken() +
"&parentID=" + connectionGroup.parentIdentifier,
connectionGroup);
};
/**
* Makes a request to the REST API to delete a connection group, returning
* a promise that can be used for processing the results of the call.
@@ -174,9 +162,19 @@ angular.module('rest').factory('connectionGroupService', ['$http', 'authenticati
* delete operation is successful.
*/
service.deleteConnectionGroup = function deleteConnectionGroup(connectionGroup) {
return $http['delete'](
"api/connectionGroup/" + connectionGroup.identifier +
"?token=" + authenticationService.getCurrentToken());
// Build HTTP parameters set
var httpParameters = {
token : authenticationService.getCurrentToken()
};
// Delete connection group
return $http({
method : 'DELETE',
url : 'api/connectionGroups/' + encodeURIComponent(connectionGroup.identifier),
params : httpParameters
});
};
return service;

View File

@@ -44,7 +44,19 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
* });
*/
service.getConnection = function getConnection(id) {
return $http.get("api/connection/" + id + "?token=" + authenticationService.getCurrentToken());
// Build HTTP parameters set
var httpParameters = {
token : authenticationService.getCurrentToken()
};
// Retrieve connection
return $http({
method : 'GET',
url : 'api/connections/' + encodeURIComponent(id),
params : httpParameters
});
};
/**
@@ -60,7 +72,19 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
* @link{ConnectionHistoryEntry} objects upon success.
*/
service.getConnectionHistory = function getConnectionHistory(id) {
return $http.get("api/connection/" + id + "/history?token=" + authenticationService.getCurrentToken());
// Build HTTP parameters set
var httpParameters = {
token : authenticationService.getCurrentToken()
};
// Retrieve connection history
return $http({
method : 'GET',
url : 'api/connections/' + encodeURIComponent(id) + '/history',
params : httpParameters
});
};
/**
@@ -76,7 +100,19 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
* pairs upon success.
*/
service.getConnectionParameters = function getConnectionParameters(id) {
return $http.get("api/connection/" + id + "/parameters?token=" + authenticationService.getCurrentToken());
// Build HTTP parameters set
var httpParameters = {
token : authenticationService.getCurrentToken()
};
// Retrieve connection parameters
return $http({
method : 'GET',
url : 'api/connections/' + encodeURIComponent(id) + '/parameters',
params : httpParameters
});
};
/**
@@ -94,51 +130,38 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
*/
service.saveConnection = function saveConnection(connection) {
// Build HTTP parameters set
var httpParameters = {
token : authenticationService.getCurrentToken()
};
// If connection is new, add it and set the identifier automatically
if (!connection.identifier) {
return $http.post("api/connection/?token=" + authenticationService.getCurrentToken(), connection).success(
return $http({
method : 'POST',
url : 'api/connections',
params : httpParameters,
data : connection
})
// Set the identifier on the new connection
function setConnectionID(connectionID){
connection.identifier = connectionID;
}
);
// Set the identifier on the new connection
.success(function connectionCreated(identifier){
connection.identifier = identifier;
});
}
// Otherwise, update the existing connection
else {
return $http.post(
"api/connection/" + connection.identifier +
"?token=" + authenticationService.getCurrentToken(),
connection);
return $http({
method : 'PUT',
url : 'api/connections/' + encodeURIComponent(connection.identifier),
params : httpParameters,
data : connection
});
}
};
/**
* FIXME: Why is this different from save?
*
* Makes a request to the REST API to move a connection to a different
* group, returning a promise that can be used for processing the results
* of the call.
*
* @param {Connection} connection The connection to move.
*
* @returns {Promise}
* A promise for the HTTP call which will succeed if and only if the
* move operation is successful.
*/
service.moveConnection = function moveConnection(connection) {
return $http.put(
"api/connection/" + connection.identifier +
"?token=" + authenticationService.getCurrentToken() +
"&parentID=" + connection.parentIdentifier,
connection);
};
/**
* Makes a request to the REST API to delete a connection,
* returning a promise that can be used for processing the results of the call.
@@ -150,9 +173,19 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
* delete operation is successful.
*/
service.deleteConnection = function deleteConnection(connection) {
return $http['delete'](
"api/connection/" + connection.identifier +
"?token=" + authenticationService.getCurrentToken());
// Build HTTP parameters set
var httpParameters = {
token : authenticationService.getCurrentToken()
};
// Delete connection
return $http({
method : 'DELETE',
url : 'api/connections/' + encodeURIComponent(connection.identifier),
params : httpParameters
});
};
return service;