Ticket #263: Switched to enum for connection group type.

This commit is contained in:
James Muehlner
2013-08-07 22:15:31 -07:00
parent a7f45e8244
commit 52490ca8ab
5 changed files with 36 additions and 53 deletions

View File

@@ -65,11 +65,6 @@ public class MySQLConnectionGroup extends AbstractConnectionGroup {
*/ */
private Integer parentID; private Integer parentID;
/**
* The type of this connection group.
*/
private String type;
/** /**
* The ID of the user who queried or created this connection group. * The ID of the user who queried or created this connection group.
*/ */
@@ -160,7 +155,6 @@ public class MySQLConnectionGroup extends AbstractConnectionGroup {
this.parentID = parentID; this.parentID = parentID;
setName(name); setName(name);
setIdentifier(identifier); setIdentifier(identifier);
this.type = type;
this.userID = userID; this.userID = userID;
connectionDirectory = connectionDirectoryProvider.get(); connectionDirectory = connectionDirectoryProvider.get();
@@ -195,33 +189,4 @@ public class MySQLConnectionGroup extends AbstractConnectionGroup {
return connectionGroupDirectory; return connectionGroupDirectory;
} }
/**
* Returns the connection group type.
* @return the connection group type.
*/
public String getType() {
return type;
}
/**
* Sets the connection group type.
* @param type the connection group type.
*/
public void setType(String type) {
this.type = type;
}
@Override
public void setBalancing(boolean balancing) {
if(balancing)
this.type = MySQLConstants.CONNECTION_GROUP_BALANCING;
else
this.type = MySQLConstants.CONNECTION_GROUP_ORGANIZATIONAL;
}
@Override
public boolean isBalancing() {
return MySQLConstants.CONNECTION_GROUP_BALANCING.equals(this.type);
}
} }

View File

@@ -50,6 +50,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import net.sourceforge.guacamole.net.GuacamoleSocket; import net.sourceforge.guacamole.net.GuacamoleSocket;
import net.sourceforge.guacamole.net.auth.mysql.MySQLConnectionGroup; import net.sourceforge.guacamole.net.auth.mysql.MySQLConnectionGroup;
import net.sourceforge.guacamole.net.auth.mysql.MySQLConstants;
import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionGroupMapper; import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionGroupMapper;
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroup; import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroup;
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroupExample; import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroupExample;
@@ -353,7 +354,15 @@ public class ConnectionGroupService {
connectionGroup.setConnection_group_id(mySQLConnectionGroup.getConnectionGroupID()); connectionGroup.setConnection_group_id(mySQLConnectionGroup.getConnectionGroupID());
connectionGroup.setParent_id(mySQLConnectionGroup.getParentID()); connectionGroup.setParent_id(mySQLConnectionGroup.getParentID());
connectionGroup.setConnection_group_name(mySQLConnectionGroup.getName()); connectionGroup.setConnection_group_name(mySQLConnectionGroup.getName());
connectionGroup.setType(mySQLConnectionGroup.getType());
switch(mySQLConnectionGroup.getType()) {
case BALANCING :
connectionGroup.setType(MySQLConstants.CONNECTION_GROUP_BALANCING);
break;
case ORGANIZATIONAL:
connectionGroup.setType(MySQLConstants.CONNECTION_GROUP_ORGANIZATIONAL);
break;
}
// Update the connection in the database // Update the connection in the database
connectionGroupDAO.updateByPrimaryKeySelective(connectionGroup); connectionGroupDAO.updateByPrimaryKeySelective(connectionGroup);

View File

@@ -55,6 +55,11 @@ public abstract class AbstractConnectionGroup implements ConnectionGroup {
*/ */
private String identifier; private String identifier;
/**
* The type of this connection group.
*/
private ConnectionGroup.Type type;
@Override @Override
public String getName() { public String getName() {
return name; return name;
@@ -75,6 +80,16 @@ public abstract class AbstractConnectionGroup implements ConnectionGroup {
this.identifier = identifier; this.identifier = identifier;
} }
@Override
public ConnectionGroup.Type getType() {
return type;
}
@Override
public void setType(ConnectionGroup.Type type) {
this.type = type;
}
@Override @Override
public int hashCode() { public int hashCode() {
if (identifier == null) return 0; if (identifier == null) return 0;

View File

@@ -50,6 +50,10 @@ import net.sourceforge.guacamole.protocol.GuacamoleClientInformation;
*/ */
public interface ConnectionGroup { public interface ConnectionGroup {
public enum Type {
ORGANIZATIONAL, BALANCING
};
/** /**
* Returns the name assigned to this ConnectionGroup. * Returns the name assigned to this ConnectionGroup.
* @return The name assigned to this ConnectionGroup. * @return The name assigned to this ConnectionGroup.
@@ -77,17 +81,17 @@ public interface ConnectionGroup {
public void setIdentifier(String identifier); public void setIdentifier(String identifier);
/** /**
* Sets whether this is a balancing ConnectionGroup. * Set the type of this ConnectionGroup.
* *
* @param balancing whether this is a balancing ConnectionGroup. * @param type The type of this ConnectionGroup.
*/ */
public void setBalancing(boolean balancing); public void setType(Type type);
/** /**
* Returns true if this is a balancing ConnectionGroup, false otherwise. * Returns the type of this connection.
* @return true if this is a balancing ConnectionGroup, false otherwise. * @return the type of this connection.
*/ */
public boolean isBalancing(); public Type getType();
/** /**
* Retrieves a Directory which can be used to view and manipulate * Retrieves a Directory which can be used to view and manipulate

View File

@@ -64,6 +64,7 @@ public class SimpleConnectionGroup extends AbstractConnectionGroup {
Directory<String, ConnectionGroup> connectionGroupDirectory) { Directory<String, ConnectionGroup> connectionGroupDirectory) {
this.connectionDirectory = connectionDirectory; this.connectionDirectory = connectionDirectory;
this.connectionGroupDirectory = connectionGroupDirectory; this.connectionGroupDirectory = connectionGroupDirectory;
this.setType(ConnectionGroup.Type.ORGANIZATIONAL);
} }
@Override @Override
@@ -84,15 +85,4 @@ public class SimpleConnectionGroup extends AbstractConnectionGroup {
throw new GuacamoleSecurityException("Permission denied."); throw new GuacamoleSecurityException("Permission denied.");
} }
@Override
public void setBalancing(boolean balancing) {
// All SimpleConnectionGroups are organizational only
}
@Override
public boolean isBalancing() {
// All SimpleConnectionGroups are organizational only
return false;
}
} }