GUAC-932: Handle FIXMEs for connection/connection group creation. Update connection group service to use ConnectionGroup class.

This commit is contained in:
Michael Jumper
2014-12-12 09:29:39 -08:00
parent 8fa0522ca4
commit 0ef7c4a527
2 changed files with 85 additions and 53 deletions

View File

@@ -23,30 +23,29 @@
/** /**
* Service for operating on connection groups via the REST API. * Service for operating on connection groups via the REST API.
*/ */
angular.module('rest').factory('connectionGroupService', ['$http', 'authenticationService', angular.module('rest').factory('connectionGroupService', ['$http', 'authenticationService', 'ConnectionGroup',
function connectionGrouService($http, authenticationService) { function connectionGroupService($http, authenticationService, ConnectionGroup) {
/**
* The ID of the root connection group.
*/
var ROOT_CONNECTION_GROUP_ID = "ROOT";
var service = {}; var service = {};
/** /**
* Makes a request to the REST API to get the list of connection groups, * Makes a request to the REST API to get the list of connection groups,
* returning a promise that can be used for processing the results of the call. * returning a promise that provides an array of
* @link{ConnectionGroup} objects if successful.
* *
* @param {string} parentID The parent ID for the connection group. * @param {String} [parentID=ConnectionGroup.ROOT_IDENTIFIER]
* If not passed in, it will query a list of the * The ID of the connection group whose child connection groups should
* connection groups in the root group. * be returned. If not provided, the root connection group will be
* used by default.
* *
* @returns {promise} A promise for the HTTP call. * @returns {Promise.<ConnectionGroup[]>}
* A promise which will resolve with an array of @link{ConnectionGroup}
* objects upon success.
*/ */
service.getConnectionGroups = function getConnectionGroups(parentID) { service.getConnectionGroups = function getConnectionGroups(parentID) {
var parentIDParam = ""; var parentIDParam = "";
if(parentID !== undefined) if (parentID)
parentIDParam = "&parentID=" + parentID; parentIDParam = "&parentID=" + parentID;
return $http.get("api/connectionGroup?token=" + authenticationService.getCurrentToken() + parentIDParam); return $http.get("api/connectionGroup?token=" + authenticationService.getCurrentToken() + parentIDParam);
@@ -54,54 +53,74 @@ angular.module('rest').factory('connectionGroupService', ['$http', 'authenticati
/** /**
* Makes a request to the REST API to get an individual connection group, * Makes a request to the REST API to get an individual connection group,
* returning a promise that can be used for processing the results of the call. * returning a promise that provides the corresponding
* @link{ConnectionGroup} if successful.
* *
* @param {string} connectionGroupID The ID for the connection group. * @param {String} [connectionGroupID=ConnectionGroup.ROOT_IDENTIFIER]
* If not passed in, it will query the * The ID of the connection group to retrieve. If not provided, the
* root connection group. * root connection group will be retrieved by default.
* *
* @returns {promise} A promise for the HTTP call. * @returns {Promise.<ConnectionGroup>} A promise for the HTTP call.
* A promise which will resolve with a @link{ConnectionGroup} upon
* success.
*/ */
service.getConnectionGroup = function getConnectionGroup(connectionGroupID) { service.getConnectionGroup = function getConnectionGroup(connectionGroupID) {
// Use the root connection group ID if no ID is passed in // Use the root connection group ID if no ID is passed in
connectionGroupID = connectionGroupID || ROOT_CONNECTION_GROUP_ID; connectionGroupID = connectionGroupID || ConnectionGroup.ROOT_IDENTIFIER;
return $http.get("api/connectionGroup/" + connectionGroupID + "?token=" + authenticationService.getCurrentToken()); return $http.get("api/connectionGroup/" + connectionGroupID + "?token=" + authenticationService.getCurrentToken());
}; };
/** /**
* Makes a request to the REST API to save a connection group, * Makes a request to the REST API to save a connection group, returning a
* returning a promise that can be used for processing the results of the call. * promise that can be used for processing the results of the call. If the
* connection group is new, and thus does not yet have an associated
* identifier, the identifier will be automatically set in the provided
* connection group upon success.
* *
* @param {object} connectionGroup The connection group to update * @param {ConnectionGroup} connectionGroup The connection group to update.
* *
* @returns {promise} A promise for the HTTP call. * @returns {Promise}
* A promise for the HTTP call which will succeed if and only if the
* save operation is successful.
*/ */
service.saveConnectionGroup = function saveConnectionGroup(connectionGroup) { service.saveConnectionGroup = function saveConnectionGroup(connectionGroup) {
// This is a new connection group
if(!connectionGroup.identifier) { // 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.post("api/connectionGroup/?token=" + authenticationService.getCurrentToken(), connectionGroup).success(
// Set the identifier on the new connection group
function setConnectionGroupID(connectionGroupID){ function setConnectionGroupID(connectionGroupID){
// Set the identifier on the new connection
connectionGroup.identifier = connectionGroupID; connectionGroup.identifier = connectionGroupID;
return connectionGroupID; }
});
} else { );
}
// Otherwise, update the existing connection group
else {
return $http.post( return $http.post(
"api/connectionGroup/" + connectionGroup.identifier + "api/connectionGroup/" + connectionGroup.identifier +
"?token=" + authenticationService.getCurrentToken(), "?token=" + authenticationService.getCurrentToken(),
connectionGroup); connectionGroup);
} }
}; };
/** /**
* Makes a request to the REST API to move a connection group to a different group, * FIXME: Why is this different from save?
* returning a promise that can be used for processing the results of the call.
* *
* @param {object} connectionGroup The connection group to move. * 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. * @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) { service.moveConnectionGroup = function moveConnectionGroup(connectionGroup) {
@@ -113,12 +132,14 @@ angular.module('rest').factory('connectionGroupService', ['$http', 'authenticati
}; };
/** /**
* Makes a request to the REST API to delete a connection group, * Makes a request to the REST API to delete a connection group, returning
* returning a promise that can be used for processing the results of the call. * a promise that can be used for processing the results of the call.
* *
* @param {object} connectionGroup The connection group to delete * @param {ConnectionGroup} connectionGroup The connection group to delete.
* *
* @returns {promise} A promise for the HTTP call. * @returns {Promise}
* A promise for the HTTP call which will succeed if and only if the
* delete operation is successful.
*/ */
service.deleteConnectionGroup = function deleteConnectionGroup(connectionGroup) { service.deleteConnectionGroup = function deleteConnectionGroup(connectionGroup) {
return $http['delete']( return $http['delete'](

View File

@@ -33,6 +33,7 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
* promise that provides the corresponding @link{Connection} if successful. * promise that provides the corresponding @link{Connection} if successful.
* *
* @param {String} id The ID of the connection. * @param {String} id The ID of the connection.
*
* @returns {Promise.<Connection>} * @returns {Promise.<Connection>}
* A promise which will resolve with a @link{Connection} upon success. * A promise which will resolve with a @link{Connection} upon success.
* *
@@ -48,12 +49,13 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
/** /**
* Makes a request to the REST API to get the list of connections, * Makes a request to the REST API to get the list of connections,
* returning a promise that can be used for processing the results of the * returning a promise that provides an array of
* call. * @link{Connection} objects if successful.
* *
* @param {string} parentID The parent ID for the connection. * @param {String} [parentID=ConnectionGroup.ROOT_IDENTIFIER]
* If not passed in, it will query a list of the * The ID of the connection group whose child connections should be
* connections in the root group. * returned. If not provided, the root connection group will be used
* by default.
* *
* @returns {Promise.<Connection[]>} * @returns {Promise.<Connection[]>}
* A promise which will resolve with an array of @link{Connection} * A promise which will resolve with an array of @link{Connection}
@@ -62,7 +64,7 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
service.getConnections = function getConnections(parentID) { service.getConnections = function getConnections(parentID) {
var parentIDParam = ""; var parentIDParam = "";
if(parentID !== undefined) if (parentID)
parentIDParam = "&parentID=" + parentID; parentIDParam = "&parentID=" + parentID;
return $http.get("api/connection?token=" + authenticationService.getCurrentToken() + parentIDParam); return $http.get("api/connection?token=" + authenticationService.getCurrentToken() + parentIDParam);
@@ -70,9 +72,12 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
/** /**
* Makes a request to the REST API to save a connection, returning a * Makes a request to the REST API to save a connection, returning a
* promise that can be used for processing the results of the call. * promise that can be used for processing the results of the call. If the
* connection is new, and thus does not yet have an associated identifier,
* the identifier will be automatically set in the provided connection
* upon success.
* *
* @param {Connection} connection The connection to update * @param {Connection} connection The connection to update.
* *
* @returns {Promise} * @returns {Promise}
* A promise for the HTTP call which will succeed if and only if the * A promise for the HTTP call which will succeed if and only if the
@@ -89,20 +94,26 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
var connectionToSave = angular.copy(connection); var connectionToSave = angular.copy(connection);
delete connectionToSave.history; delete connectionToSave.history;
// This is a new connection // If connection is new, add it and set the identifier automatically
if(!connectionToSave.identifier) { if (!connectionToSave.identifier) {
return $http.post("api/connection/?token=" + authenticationService.getCurrentToken(), connectionToSave).success( return $http.post("api/connection/?token=" + authenticationService.getCurrentToken(), connectionToSave).success(
// Set the identifier on the new connection
function setConnectionID(connectionID){ function setConnectionID(connectionID){
// Set the identifier on the new connection connection.identifier = connectionID;
connection.identifier = connectionID; // FIXME: Functions with side effects = bad }
return connectionID; // FIXME: Why? Where does this value go?
}); );
} else { }
// Otherwise, update the existing connection
else {
return $http.post( return $http.post(
"api/connection/" + connectionToSave.identifier + "api/connection/" + connectionToSave.identifier +
"?token=" + authenticationService.getCurrentToken(), "?token=" + authenticationService.getCurrentToken(),
connectionToSave); connectionToSave);
} }
}; };
/** /**
@@ -132,7 +143,7 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
* Makes a request to the REST API to delete a 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. * returning a promise that can be used for processing the results of the call.
* *
* @param {Connection} connection The connection to delete * @param {Connection} connection The connection to delete.
* *
* @returns {Promise} * @returns {Promise}
* A promise for the HTTP call which will succeed if and only if the * A promise for the HTTP call which will succeed if and only if the