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

@@ -36,17 +36,17 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;
import org.glyptodon.guacamole.GuacamoleClientException; import org.glyptodon.guacamole.GuacamoleClientException;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.GuacamoleResourceNotFoundException;
import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.Connection;
import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.ConnectionGroup;
import org.glyptodon.guacamole.net.auth.ConnectionRecord; import org.glyptodon.guacamole.net.auth.ConnectionRecord;
import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.Directory;
import org.glyptodon.guacamole.net.auth.UserContext; import org.glyptodon.guacamole.net.auth.UserContext;
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure; import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService; import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
import org.glyptodon.guacamole.net.basic.rest.connectiongroup.APIConnectionGroup;
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -56,7 +56,7 @@ import org.slf4j.LoggerFactory;
* *
* @author James Muehlner * @author James Muehlner
*/ */
@Path("/connection") @Path("/connections")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public class ConnectionRESTService { public class ConnectionRESTService {
@@ -73,13 +73,20 @@ public class ConnectionRESTService {
private AuthenticationService authenticationService; private AuthenticationService authenticationService;
/** /**
* Gets an individual connection. * Retrieves an individual connection.
* *
* @param authToken The authentication token that is used to authenticate * @param authToken
* the user performing the operation. * The authentication token that is used to authenticate the user
* @param connectionID The ID of the Connection.. * performing the operation.
* @return The connection. *
* @throws GuacamoleException If a problem is encountered while retrieving the connection. * @param connectionID
* The identifier of the connection to retrieve.
*
* @return
* The connection having the given identifier.
*
* @throws GuacamoleException
* If an error occurs while retrieving the connection.
*/ */
@GET @GET
@Path("/{connectionID}") @Path("/{connectionID}")
@@ -97,7 +104,7 @@ public class ConnectionRESTService {
// Get the connection // Get the connection
Connection connection = connectionDirectory.get(connectionID); Connection connection = connectionDirectory.get(connectionID);
if (connection == null) if (connection == null)
throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID."); throw new GuacamoleResourceNotFoundException("No such connection: \"" + connectionID + "\"");
return new APIConnection(connection); return new APIConnection(connection);
@@ -111,7 +118,7 @@ public class ConnectionRESTService {
* performing the operation. * performing the operation.
* *
* @param connectionID * @param connectionID
* The ID of the connection. * The identifier of the connection.
* *
* @return * @return
* A map of parameter name/value pairs. * A map of parameter name/value pairs.
@@ -135,7 +142,7 @@ public class ConnectionRESTService {
// Get the connection // Get the connection
Connection connection = connectionDirectory.get(connectionID); Connection connection = connectionDirectory.get(connectionID);
if (connection == null) if (connection == null)
throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID."); throw new GuacamoleResourceNotFoundException("No such connection: \"" + connectionID + "\"");
// Retrieve connection configuration // Retrieve connection configuration
GuacamoleConfiguration config = connection.getConfiguration(); GuacamoleConfiguration config = connection.getConfiguration();
@@ -157,7 +164,7 @@ public class ConnectionRESTService {
* performing the operation. * performing the operation.
* *
* @param connectionID * @param connectionID
* The ID of the connection. * The identifier of the connection.
* *
* @return * @return
* A list of connection records, describing the start and end times of * A list of connection records, describing the start and end times of
@@ -182,7 +189,7 @@ public class ConnectionRESTService {
// Get the connection // Get the connection
Connection connection = connectionDirectory.get(connectionID); Connection connection = connectionDirectory.get(connectionID);
if (connection == null) if (connection == null)
throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID."); throw new GuacamoleResourceNotFoundException("No such connection: \"" + connectionID + "\"");
return connection.getHistory(); return connection.getHistory();
@@ -191,10 +198,15 @@ public class ConnectionRESTService {
/** /**
* Deletes an individual connection. * Deletes an individual connection.
* *
* @param authToken The authentication token that is used to authenticate * @param authToken
* the user performing the operation. * The authentication token that is used to authenticate the user
* @param connectionID The ID of the Connection to delete. * performing the operation.
* @throws GuacamoleException If a problem is encountered while deleting the connection. *
* @param connectionID
* The identifier of the connection to delete.
*
* @throws GuacamoleException
* If an error occurs while deleting the connection.
*/ */
@DELETE @DELETE
@Path("/{connectionID}") @Path("/{connectionID}")
@@ -211,72 +223,112 @@ public class ConnectionRESTService {
// Make sure the connection is there before trying to delete // Make sure the connection is there before trying to delete
if (connectionDirectory.get(connectionID) == null) if (connectionDirectory.get(connectionID) == null)
throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID."); throw new GuacamoleResourceNotFoundException("No such connection: \"" + connectionID + "\"");
// Delete the connection // Delete the connection
connectionDirectory.remove(connectionID); connectionDirectory.remove(connectionID);
} }
/** /**
* Creates a new connection and returns the identifier of the new connection. * Retrieves a single connection group from the given user context. If
* If a parentID is provided, the connection will be created in the * the given identifier is null or the root identifier, the root connection
* connection group with the parentID. Otherwise, the root connection group * group will be returned.
* will be used. *
* @param userContext
* The user context to retrieve the connection group from.
*
* @param identifier
* The identifier of the connection group to retrieve.
*
* @return
* The connection group having the given identifier, or the root
* connection group if the identifier is null or the root identifier.
*
* @throws GuacamoleException
* If an error occurs while retrieving the connection group, or if the
* connection group does not exist.
*/
private ConnectionGroup retrieveConnectionGroup(UserContext userContext,
String identifier) throws GuacamoleException {
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
// Use root group if identifier is null (or the standard root identifier)
if (identifier == null || identifier.equals(APIConnectionGroup.ROOT_IDENTIFIER))
return rootGroup;
// Pull specified connection group otherwise
Directory<String, ConnectionGroup> directory = rootGroup.getConnectionGroupDirectory();
ConnectionGroup connectionGroup = directory.get(identifier);
if (connectionGroup == null)
throw new GuacamoleResourceNotFoundException("No such connection group: \"" + identifier + "\"");
return connectionGroup;
}
/**
* Creates a new connection and returns the identifier of the new
* connection.
* *
* @param authToken The authentication token that is used to authenticate * @param authToken
* the user performing the operation. * The authentication token that is used to authenticate the user
* @param parentID The ID of the ConnectionGroup the connections * performing the operation.
* belong to. If null, the root connection group will be used. *
* @param connection The connection to create. * @param connection
* @return The identifier of the new connection. * The connection to create.
* @throws GuacamoleException If a problem is encountered while creating the connection. *
* @return
* The identifier of the new connection.
*
* @throws GuacamoleException
* If an error occurs while creating the connection.
*/ */
@POST @POST
@AuthProviderRESTExposure @AuthProviderRESTExposure
public String createConnection(@QueryParam("token") String authToken, public String createConnection(@QueryParam("token") String authToken,
@QueryParam("parentID") String parentID, APIConnection connection) throws GuacamoleException { APIConnection connection) throws GuacamoleException {
UserContext userContext = authenticationService.getUserContext(authToken); UserContext userContext = authenticationService.getUserContext(authToken);
// Validate that connection data was provided
if (connection == null) if (connection == null)
throw new GuacamoleClientException("A connection is required for this request."); throw new GuacamoleClientException("Connection JSON must be submitted when creating connections.");
// If the parent connection group is passed in, try to find it. // Retrieve parent group
ConnectionGroup parentConnectionGroup; String parentID = connection.getParentIdentifier();
if (parentID == null) ConnectionGroup parentConnectionGroup = retrieveConnectionGroup(userContext, parentID);
parentConnectionGroup = userContext.getRootConnectionGroup();
else { // Add the new connection
ConnectionGroup rootGroup = userContext.getRootConnectionGroup(); Directory<String, Connection> connectionDirectory = parentConnectionGroup.getConnectionDirectory();
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
parentConnectionGroup = connectionGroupDirectory.get(parentID);
}
if (parentConnectionGroup == null)
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
Directory<String, Connection> connectionDirectory =
parentConnectionGroup.getConnectionDirectory();
// Create the connection
connectionDirectory.add(new APIConnectionWrapper(connection)); connectionDirectory.add(new APIConnectionWrapper(connection));
// Return the new connection identifier // Return the new connection identifier
return connection.getIdentifier(); return connection.getIdentifier();
} }
/** /**
* Updates a connection. * Updates an existing connection. If the parent identifier of the
* connection is changed, the connection will also be moved to the new
* parent group.
* *
* @param authToken The authentication token that is used to authenticate * @param authToken
* the user performing the operation. * The authentication token that is used to authenticate the user
* @param connectionID The ID of the Connection to move. * performing the operation.
* @param connection The connection to update. *
* @throws GuacamoleException If a problem is encountered while updating the connection. * @param connectionID
* The identifier of the connection to update.
*
* @param connection
* The connection data to update the specified connection with.
*
* @throws GuacamoleException
* If an error occurs while updating the connection.
*/ */
@POST @PUT
@Path("/{connectionID}") @Path("/{connectionID}")
@AuthProviderRESTExposure @AuthProviderRESTExposure
public void updateConnection(@QueryParam("token") String authToken, public void updateConnection(@QueryParam("token") String authToken,
@@ -284,62 +336,27 @@ public class ConnectionRESTService {
UserContext userContext = authenticationService.getUserContext(authToken); UserContext userContext = authenticationService.getUserContext(authToken);
// Validate that connection data was provided
if (connection == null) if (connection == null)
throw new GuacamoleClientException("A connection is required for this request."); throw new GuacamoleClientException("Connection JSON must be submitted when updating connections.");
// Get the connection directory // Get the connection directory
ConnectionGroup rootGroup = userContext.getRootConnectionGroup(); ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
Directory<String, Connection> connectionDirectory = Directory<String, Connection> connectionDirectory =
rootGroup.getConnectionDirectory(); rootGroup.getConnectionDirectory();
Connection connectionFromAuthProvider = connectionDirectory.get(connectionID);
// Make sure the connection is there before trying to update // Make sure the connection is there before trying to update
if (connectionFromAuthProvider == null) Connection existingConnection = connectionDirectory.get(connectionID);
throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID."); if (existingConnection == null)
throw new GuacamoleResourceNotFoundException("No such connection: \"" + connectionID + "\"");
// Copy the information from this connection over to an object from the Auth Provider Connection wrappedConnection = new APIConnectionWrapper(connection);
APIConnectionWrapper wrappedConnection = new APIConnectionWrapper(connection);
connectionFromAuthProvider.setConfiguration(wrappedConnection.getConfiguration());
connectionFromAuthProvider.setName(wrappedConnection.getName());
// Update the connection // Update the connection
connectionDirectory.update(connectionFromAuthProvider); existingConnection.setConfiguration(wrappedConnection.getConfiguration());
existingConnection.setName(wrappedConnection.getName());
connectionDirectory.update(existingConnection);
} }
/**
* Moves an individual connection to a different connection group.
*
* @param authToken The authentication token that is used to authenticate
* the user performing the operation.
* @param connectionID The ID of the Connection to move.
* @param parentID The ID of the ConnectionGroup the connection is to be moved to.
* @throws GuacamoleException If a problem is encountered while moving the connection.
*/
@PUT
@Path("/{connectionID}")
@AuthProviderRESTExposure
public void moveConnection(@QueryParam("token") String authToken,
@PathParam("connectionID") String connectionID, @QueryParam("parentID") String parentID)
throws GuacamoleException {
UserContext userContext = authenticationService.getUserContext(authToken);
// Get the connection directory
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
Directory<String, Connection> connectionDirectory =
rootGroup.getConnectionDirectory();
// Find the new parent connection group
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
ConnectionGroup parentConnectionGroup = connectionGroupDirectory.get(parentID);
if (parentConnectionGroup == null)
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
// Move the connection
connectionDirectory.move(connectionID, parentConnectionGroup.getConnectionDirectory());
}
} }

View File

@@ -58,7 +58,7 @@ import org.slf4j.LoggerFactory;
* *
* @author James Muehlner * @author James Muehlner
*/ */
@Path("/connectionGroup") @Path("/connectionGroups")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public class ConnectionGroupRESTService { public class ConnectionGroupRESTService {
@@ -256,10 +256,15 @@ public class ConnectionGroupRESTService {
/** /**
* Deletes an individual connection group. * Deletes an individual connection group.
* *
* @param authToken The authentication token that is used to authenticate * @param authToken
* the user performing the operation. * The authentication token that is used to authenticate the user
* @param connectionGroupID The ID of the ConnectionGroup to delete. * performing the operation.
* @throws GuacamoleException If a problem is encountered while deleting the connection group. *
* @param connectionGroupID
* The identifier of the connection group to delete.
*
* @throws GuacamoleException
* If an error occurs while deleting the connection group.
*/ */
@DELETE @DELETE
@Path("/{connectionGroupID}") @Path("/{connectionGroupID}")
@@ -281,7 +286,7 @@ public class ConnectionGroupRESTService {
// Make sure the connection is there before trying to delete // Make sure the connection is there before trying to delete
if (connectionGroupDirectory.get(connectionGroupID) == null) if (connectionGroupDirectory.get(connectionGroupID) == null)
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided ID."); throw new GuacamoleResourceNotFoundException("No such connection group: \"" + connectionGroupID + "\"");
// Delete the connection group // Delete the connection group
connectionGroupDirectory.remove(connectionGroupID); connectionGroupDirectory.remove(connectionGroupID);
@@ -294,42 +299,49 @@ public class ConnectionGroupRESTService {
* connection group with the parentID. Otherwise, the root connection group * connection group with the parentID. Otherwise, the root connection group
* will be used. * will be used.
* *
* @param authToken The authentication token that is used to authenticate * @param authToken
* the user performing the operation. * The authentication token that is used to authenticate the user
* @param parentID The ID of the ConnectionGroup the connection groups * performing the operation.
* belong to. If null, the root connection group will be used. *
* @param connectionGroup The connection group to create. * @param connectionGroup
* @return The identifier of the new connection group. * The connection group to create.
* @throws GuacamoleException If a problem is encountered while creating the connection group. *
* @return
* The identifier of the new connection group.
*
* @throws GuacamoleException
* If an error occurs while creating the connection group.
*/ */
@POST @POST
@AuthProviderRESTExposure @AuthProviderRESTExposure
public String createConnectionGroup(@QueryParam("token") String authToken, public String createConnectionGroup(@QueryParam("token") String authToken,
@QueryParam("parentID") String parentID, APIConnectionGroup connectionGroup) throws GuacamoleException { APIConnectionGroup connectionGroup) throws GuacamoleException {
UserContext userContext = authenticationService.getUserContext(authToken); UserContext userContext = authenticationService.getUserContext(authToken);
// Validate that connection group data was provided
if (connectionGroup == null) if (connectionGroup == null)
throw new GuacamoleClientException("A connection group is required for this request."); throw new GuacamoleClientException("Connection group JSON must be submitted when creating connections groups.");
// If the parent connection group is passed in, try to find it. String parentID = connectionGroup.getParentIdentifier();
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
// Use root group if no parent is specified
ConnectionGroup parentConnectionGroup; ConnectionGroup parentConnectionGroup;
if (parentID == null) if (parentID == null)
parentConnectionGroup = userContext.getRootConnectionGroup(); parentConnectionGroup = rootGroup;
// Pull specified connection group otherwise
else { else {
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory(); Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
parentConnectionGroup = connectionGroupDirectory.get(parentID); parentConnectionGroup = connectionGroupDirectory.get(parentID);
if (parentConnectionGroup == null)
throw new GuacamoleResourceNotFoundException("No such connection group: \"" + parentID + "\"");
} }
if (parentConnectionGroup == null) // Add the new connection group
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID."); Directory<String, ConnectionGroup> connectionGroupDirectory = parentConnectionGroup.getConnectionGroupDirectory();
Directory<String, ConnectionGroup> connectionGroupDirectory =
parentConnectionGroup.getConnectionGroupDirectory();
// Create the connection group
connectionGroupDirectory.add(new APIConnectionGroupWrapper(connectionGroup)); connectionGroupDirectory.add(new APIConnectionGroupWrapper(connectionGroup));
// Return the new connection group identifier // Return the new connection group identifier
@@ -338,15 +350,24 @@ public class ConnectionGroupRESTService {
} }
/** /**
* Updates a connection group. * Updates a connection group. If the parent identifier of the
* connection group is changed, the connection group will also be moved to
* the new parent group.
* *
* @param authToken The authentication token that is used to authenticate * @param authToken
* the user performing the operation. * The authentication token that is used to authenticate the user
* @param connectionGroupID The ID of the ConnectionGroup to update. * performing the operation.
* @param connectionGroup The connection group to update. *
* @throws GuacamoleException If a problem is encountered while updating the connection group. * @param connectionGroupID
* The identifier of the existing connection group to update.
*
* @param connectionGroup
* The data to update the existing connection group with.
*
* @throws GuacamoleException
* If an error occurs while updating the connection group.
*/ */
@POST @PUT
@Path("/{connectionGroupID}") @Path("/{connectionGroupID}")
@AuthProviderRESTExposure @AuthProviderRESTExposure
public void updateConnectionGroup(@QueryParam("token") String authToken, public void updateConnectionGroup(@QueryParam("token") String authToken,
@@ -355,8 +376,9 @@ public class ConnectionGroupRESTService {
UserContext userContext = authenticationService.getUserContext(authToken); UserContext userContext = authenticationService.getUserContext(authToken);
// Validate that connection group data was provided
if (connectionGroup == null) if (connectionGroup == null)
throw new GuacamoleClientException("A connection group is required for this request."); throw new GuacamoleClientException("Connection group JSON must be submitted when updating connection groups.");
// Get the connection directory // Get the connection directory
ConnectionGroup rootGroup = userContext.getRootConnectionGroup(); ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
@@ -370,51 +392,11 @@ public class ConnectionGroupRESTService {
// Make sure the connection group is there before trying to update // Make sure the connection group is there before trying to update
if (connectionGroupDirectory.get(connectionGroupID) == null) if (connectionGroupDirectory.get(connectionGroupID) == null)
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided ID."); throw new GuacamoleResourceNotFoundException("No such connection group: \"" + connectionGroupID + "\"");
// Update the connection group // Update the connection group
connectionGroupDirectory.update(new APIConnectionGroupWrapper(connectionGroup)); connectionGroupDirectory.update(new APIConnectionGroupWrapper(connectionGroup));
} }
/**
* Moves an individual connection group to a different connection group.
*
* @param authToken The authentication token that is used to authenticate
* the user performing the operation.
* @param connectionGroupID The ID of the ConnectionGroup to move.
* @param parentID The ID of the ConnectionGroup the connection group is to be moved to.
* @throws GuacamoleException If a problem is encountered while moving the connection group.
*/
@PUT
@Path("/{connectionGroupID}")
@AuthProviderRESTExposure
public void moveConnectionGroup(@QueryParam("token") String authToken,
@PathParam("connectionGroupID") String connectionGroupID,
@QueryParam("parentID") String parentID) throws GuacamoleException {
UserContext userContext = authenticationService.getUserContext(authToken);
// Get the connection group directory
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
// Use the root group if it was asked for
if (connectionGroupID != null && connectionGroupID.equals(APIConnectionGroup.ROOT_IDENTIFIER))
connectionGroupID = rootGroup.getIdentifier();
Directory<String, ConnectionGroup> connectionGroupDirectory =
rootGroup.getConnectionGroupDirectory();
// Find the new parent connection group
Directory<String, ConnectionGroup> newConnectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
ConnectionGroup parentConnectionGroup = newConnectionGroupDirectory.get(parentID);
if (parentConnectionGroup == null)
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
// Move the connection group
connectionGroupDirectory.move(connectionGroupID, parentConnectionGroup.getConnectionGroupDirectory());
}
} }

View File

@@ -66,7 +66,7 @@ angular.module('rest').factory('connectionGroupService', ['$http', 'authenticati
// Retrieve connection group // Retrieve connection group
return $http({ return $http({
method : 'GET', method : 'GET',
url : 'api/connectionGroup/' + encodeURIComponent(connectionGroupID) + '/tree', url : 'api/connectionGroups/' + encodeURIComponent(connectionGroupID) + '/tree',
params : httpParameters params : httpParameters
}); });
@@ -98,7 +98,7 @@ angular.module('rest').factory('connectionGroupService', ['$http', 'authenticati
// Retrieve connection group // Retrieve connection group
return $http({ return $http({
method : 'GET', method : 'GET',
url : 'api/connectionGroup/' + encodeURIComponent(connectionGroupID), url : 'api/connectionGroups/' + encodeURIComponent(connectionGroupID),
params : httpParameters params : httpParameters
}); });
@@ -119,50 +119,38 @@ angular.module('rest').factory('connectionGroupService', ['$http', 'authenticati
*/ */
service.saveConnectionGroup = function saveConnectionGroup(connectionGroup) { 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 connection group is new, add it and set the identifier automatically
if (!connectionGroup.identifier) { 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 // Set the identifier on the new connection group
function setConnectionGroupID(connectionGroupID){ .success(function connectionGroupCreated(identifier){
connectionGroup.identifier = connectionGroupID; connectionGroup.identifier = identifier;
} });
);
} }
// Otherwise, update the existing connection group // Otherwise, update the existing connection group
else { else {
return $http.post( return $http({
"api/connectionGroup/" + connectionGroup.identifier + method : 'PUT',
"?token=" + authenticationService.getCurrentToken(), url : 'api/connectionGroups/' + encodeURIComponent(connectionGroup.identifier),
connectionGroup); 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 * 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. * 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. * delete operation is successful.
*/ */
service.deleteConnectionGroup = function deleteConnectionGroup(connectionGroup) { service.deleteConnectionGroup = function deleteConnectionGroup(connectionGroup) {
return $http['delete'](
"api/connectionGroup/" + connectionGroup.identifier + // Build HTTP parameters set
"?token=" + authenticationService.getCurrentToken()); var httpParameters = {
token : authenticationService.getCurrentToken()
};
// Delete connection group
return $http({
method : 'DELETE',
url : 'api/connectionGroups/' + encodeURIComponent(connectionGroup.identifier),
params : httpParameters
});
}; };
return service; return service;

View File

@@ -44,7 +44,19 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
* }); * });
*/ */
service.getConnection = function getConnection(id) { 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. * @link{ConnectionHistoryEntry} objects upon success.
*/ */
service.getConnectionHistory = function getConnectionHistory(id) { 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. * pairs upon success.
*/ */
service.getConnectionParameters = function getConnectionParameters(id) { 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) { 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 is new, add it and set the identifier automatically
if (!connection.identifier) { 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 // Set the identifier on the new connection
function setConnectionID(connectionID){ .success(function connectionCreated(identifier){
connection.identifier = connectionID; connection.identifier = identifier;
} });
);
} }
// Otherwise, update the existing connection // Otherwise, update the existing connection
else { else {
return $http.post( return $http({
"api/connection/" + connection.identifier + method : 'PUT',
"?token=" + authenticationService.getCurrentToken(), url : 'api/connections/' + encodeURIComponent(connection.identifier),
connection); 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, * 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.
@@ -150,9 +173,19 @@ angular.module('rest').factory('connectionService', ['$http', 'authenticationSer
* delete operation is successful. * delete operation is successful.
*/ */
service.deleteConnection = function deleteConnection(connection) { service.deleteConnection = function deleteConnection(connection) {
return $http['delete'](
"api/connection/" + connection.identifier + // Build HTTP parameters set
"?token=" + authenticationService.getCurrentToken()); var httpParameters = {
token : authenticationService.getCurrentToken()
};
// Delete connection
return $http({
method : 'DELETE',
url : 'api/connections/' + encodeURIComponent(connection.identifier),
params : httpParameters
});
}; };
return service; return service;