GUAC-1101: Implement connection parameter update.

This commit is contained in:
Michael Jumper
2015-02-25 11:51:41 -08:00
parent a0c2c666e7
commit 1851a394ac
3 changed files with 91 additions and 0 deletions

View File

@@ -48,4 +48,29 @@ public interface ParameterMapper {
*/
Collection<ParameterModel> select(@Param("identifier") String identifier);
/**
* Inserts each of the parameter model objects in the given collection as
* new connection parameters.
*
* @param parameters
* The connection parameters to insert.
*
* @return
* The number of rows inserted.
*/
int insert(@Param("parameters") Collection<ParameterModel> parameters);
/**
* Deletes all parameters associated with the connection having the given
* identifier.
*
* @param identifier
* The identifier of the connection whose parameters should be
* deleted.
*
* @return
* The number of rows deleted.
*/
int delete(@Param("identifier") String identifier);
}

View File

@@ -24,6 +24,8 @@ package net.sourceforge.guacamole.net.auth.mysql.service;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -151,6 +153,46 @@ public class ConnectionService extends DirectoryObjectService<MySQLConnection, C
}
@Override
public void updateObject(AuthenticatedUser user, MySQLConnection object)
throws GuacamoleException {
// Update connection
super.updateObject(user, object);
// Get identifier and connection parameters
String identifier = object.getIdentifier();
Map<String, String> parameters = object.getConfiguration().getParameters();
// Convert parameters to model objects
Collection<ParameterModel> parameterModels = new ArrayList(parameters.size());
for (Map.Entry<String, String> parameterEntry : parameters.entrySet()) {
// Get parameter name and value
String name = parameterEntry.getKey();
String value = parameterEntry.getValue();
// There is no need to insert empty parameters
if (value.isEmpty())
continue;
// Produce model object from parameter
ParameterModel model = new ParameterModel();
model.setConnectionIdentifier(identifier);
model.setName(name);
model.setValue(value);
// Add model to list
parameterModels.add(model);
}
// Replace existing parameters with new parameters
parameterMapper.delete(identifier);
parameterMapper.insert(parameterModels);
}
/**
* Returns the set of all identifiers for all connections within the root
* connection group that the user has read access to.

View File

@@ -44,4 +44,28 @@
connection_id = #{identifier,jdbcType=VARCHAR}
</select>
<!-- Delete all parameters of a given connection -->
<delete id="delete">
DELETE FROM guacamole_connection_parameter
WHERE connection_id = #{identifier,jdbcType=VARCHAR}
</delete>
<!-- Insert all given parameters -->
<insert id="insert" parameterType="net.sourceforge.guacamole.net.auth.mysql.model.ParameterModel">
INSERT INTO guacamole_connection_parameter (
connection_id,
parameter_name,
parameter_value
)
VALUES
<foreach collection="parameters" item="parameter" separator=",">
(#{parameter.connectionIdentifier,jdbcType=VARCHAR},
#{parameter.name,jdbcType=VARCHAR},
#{parameter.value,jdbcType=VARCHAR})
</foreach>
</insert>
</mapper>