From 26122ebc3eb07934264618c319f93738a230a973 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 9 Sep 2017 13:20:43 -0700 Subject: [PATCH] GUACAMOLE-394: Deprecate ConnectionRecordSet. Refactor accordingly. --- .../jdbc/connection/ConnectionRecordSet.java | 10 ++- .../ConnectionRecordSortPredicate.java | 8 +- .../jdbc/sharing/user/SharedUserContext.java | 9 +- .../connection/ConnectionRecordMapper.xml | 4 +- .../connection/ConnectionRecordMapper.xml | 4 +- .../guacamole/auth/ldap/user/UserContext.java | 9 +- .../net/auth/ConnectionRecordSet.java | 82 ++----------------- .../guacamole/net/auth/UserContext.java | 5 +- .../auth/simple/SimpleActivityRecordSet.java | 62 ++++++++++++++ .../simple/SimpleConnectionRecordSet.java | 14 ++-- .../net/auth/simple/SimpleUserContext.java | 7 +- .../APIConnectionRecordSortPredicate.java | 26 +++--- .../rest/history/HistoryResource.java | 4 +- 13 files changed, 123 insertions(+), 121 deletions(-) create mode 100644 guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleActivityRecordSet.java diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordSet.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordSet.java index f89a45028..7b3d629c4 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordSet.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordSet.java @@ -27,15 +27,17 @@ import java.util.List; import java.util.Set; import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.auth.jdbc.base.RestrictedObject; +import org.apache.guacamole.net.auth.ActivityRecordSet; +import org.apache.guacamole.net.auth.ActivityRecordSet.SortableProperty; import org.apache.guacamole.net.auth.ConnectionRecord; /** - * A JDBC implementation of ConnectionRecordSet. Calls to asCollection() will - * query connection history records from the database. Which records are - * returned will be determined by the values passed in earlier. + * A JDBC implementation of ActivityRecordSet for ConnectionRecords. Calls to + * asCollection() will query connection history records from the database. Which + * records are returned will be determined by the values passed in earlier. */ public class ConnectionRecordSet extends RestrictedObject - implements org.apache.guacamole.net.auth.ConnectionRecordSet { + implements ActivityRecordSet { /** * Service for managing connection objects. diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordSortPredicate.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordSortPredicate.java index 17f43806d..69eee780b 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordSortPredicate.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordSortPredicate.java @@ -19,7 +19,7 @@ package org.apache.guacamole.auth.jdbc.connection; -import org.apache.guacamole.net.auth.ConnectionRecordSet; +import org.apache.guacamole.net.auth.ActivityRecordSet; /** * A sort predicate which species the property to use when sorting connection @@ -30,7 +30,7 @@ public class ConnectionRecordSortPredicate { /** * The property to use when sorting ConnectionRecords. */ - private final ConnectionRecordSet.SortableProperty property; + private final ActivityRecordSet.SortableProperty property; /** * Whether the sort order is descending (true) or ascending (false). @@ -47,7 +47,7 @@ public class ConnectionRecordSortPredicate { * @param descending * Whether the sort order is descending (true) or ascending (false). */ - public ConnectionRecordSortPredicate(ConnectionRecordSet.SortableProperty property, + public ConnectionRecordSortPredicate(ActivityRecordSet.SortableProperty property, boolean descending) { this.property = property; this.descending = descending; @@ -59,7 +59,7 @@ public class ConnectionRecordSortPredicate { * @return * The property that should be used when sorting ConnectionRecords. */ - public ConnectionRecordSet.SortableProperty getProperty() { + public ActivityRecordSet.SortableProperty getProperty() { return property; } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUserContext.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUserContext.java index 2092898ae..cdfe0fca6 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUserContext.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUserContext.java @@ -28,16 +28,17 @@ import org.apache.guacamole.auth.jdbc.sharing.connectiongroup.SharedRootConnecti import org.apache.guacamole.auth.jdbc.user.RemoteAuthenticatedUser; import org.apache.guacamole.form.Form; import org.apache.guacamole.net.auth.ActiveConnection; +import org.apache.guacamole.net.auth.ActivityRecordSet; import org.apache.guacamole.net.auth.AuthenticationProvider; import org.apache.guacamole.net.auth.Connection; import org.apache.guacamole.net.auth.ConnectionGroup; -import org.apache.guacamole.net.auth.ConnectionRecordSet; +import org.apache.guacamole.net.auth.ConnectionRecord; import org.apache.guacamole.net.auth.Directory; import org.apache.guacamole.net.auth.SharingProfile; import org.apache.guacamole.net.auth.User; import org.apache.guacamole.net.auth.UserContext; +import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet; import org.apache.guacamole.net.auth.simple.SimpleConnectionGroupDirectory; -import org.apache.guacamole.net.auth.simple.SimpleConnectionRecordSet; import org.apache.guacamole.net.auth.simple.SimpleDirectory; /** @@ -175,8 +176,8 @@ public class SharedUserContext implements UserContext { } @Override - public ConnectionRecordSet getConnectionHistory() { - return new SimpleConnectionRecordSet(); + public ActivityRecordSet getConnectionHistory() { + return new SimpleActivityRecordSet(); } @Override diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml index c2c12c138..287ca02fa 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml @@ -129,7 +129,7 @@ - + - + - + - + getConnectionHistory() throws GuacamoleException { - return new SimpleConnectionRecordSet(); + return new SimpleActivityRecordSet(); } @Override diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/ConnectionRecordSet.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/ConnectionRecordSet.java index 87f91bb57..62c84ec44 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/ConnectionRecordSet.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/ConnectionRecordSet.java @@ -19,83 +19,13 @@ package org.apache.guacamole.net.auth; -import org.apache.guacamole.GuacamoleException; - /** * The set of all available connection records, or a subset of those records. + * + * @deprecated + * Use {@link ActivityRecordSet}<{@link ConnectionRecord}> instead. */ -public interface ConnectionRecordSet extends ActivityRecordSet { - - /** - * Returns the subset of connection records to only those where the - * connection name, user identifier, or any associated date field contain - * the given value. This function may also affect the contents of the - * current ConnectionRecordSet. The contents of the current - * ConnectionRecordSet should NOT be relied upon after this function is - * called. - * - * @param value - * The value which all connection records within the resulting subset - * should contain within their associated connection name or user - * identifier. - * - * @return - * The subset of connection history records which contain the specified - * value within their associated connection name or user identifier. - * - * @throws GuacamoleException - * If an error occurs while restricting the current subset. - */ - @Override - ConnectionRecordSet contains(String value) throws GuacamoleException; - - /** - * Returns the subset of connection history records containing only the - * first limit records. If the subset has fewer than - * limit records, then this function has no effect. This - * function may also affect the contents of the current - * ConnectionRecordSet. The contents of the current ConnectionRecordSet - * should NOT be relied upon after this function is called. - * - * @param limit - * The maximum number of records that the new subset should contain. - * - * @return - * The subset of connection history records that containing only the - * first limit records. - * - * @throws GuacamoleException - * If an error occurs while limiting the current subset. - */ - @Override - ConnectionRecordSet limit(int limit) throws GuacamoleException; - - /** - * Returns a ConnectionRecordSet containing identically the records within - * this set, sorted according to the specified criteria. The sort operation - * performed is guaranteed to be stable with respect to any past call to - * sort(). This function may also affect the contents of the current - * ConnectionRecordSet. The contents of the current ConnectionRecordSet - * should NOT be relied upon after this function is called. - * - * @param property - * The property by which the connection records within the resulting - * set should be sorted. - * - * @param desc - * Whether the records should be sorted according to the specified - * property in descending order. If false, records will be sorted - * according to the specified property in ascending order. - * - * @return - * The ConnnectionRecordSet, sorted according to the specified - * criteria. - * - * @throws GuacamoleException - * If an error occurs while sorting the current subset. - */ - @Override - ConnectionRecordSet sort(SortableProperty property, boolean desc) - throws GuacamoleException; - +@Deprecated +public interface ConnectionRecordSet + extends ActivityRecordSet { } diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/UserContext.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/UserContext.java index 596c5d94f..92f360459 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/UserContext.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/UserContext.java @@ -145,7 +145,7 @@ public interface UserContext { /** * Retrieves all connection records visible to current user. The resulting * set of connection records can be further filtered and ordered using the - * methods defined on ConnectionRecordSet. + * methods defined on ActivityRecordSet. * * @return * A set of all connection records visible to the current user. @@ -153,7 +153,8 @@ public interface UserContext { * @throws GuacamoleException * If an error occurs while retrieving the connection records. */ - ConnectionRecordSet getConnectionHistory() throws GuacamoleException; + ActivityRecordSet getConnectionHistory() + throws GuacamoleException; /** * Retrieves a connection group which can be used to view and manipulate diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleActivityRecordSet.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleActivityRecordSet.java new file mode 100644 index 000000000..a9a3c3eed --- /dev/null +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleActivityRecordSet.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.guacamole.net.auth.simple; + +import java.util.Collection; +import java.util.Collections; +import org.apache.guacamole.GuacamoleException; +import org.apache.guacamole.net.auth.ActivityRecord; +import org.apache.guacamole.net.auth.ActivityRecordSet; +import org.apache.guacamole.net.auth.ActivityRecordSet.SortableProperty; + +/** + * An immutable and empty ActivityRecordSet. + * + * @param + * The type of ActivityRecord contained within this set. + */ +public class SimpleActivityRecordSet + implements ActivityRecordSet { + + @Override + public Collection asCollection() + throws GuacamoleException { + return Collections.emptyList(); + } + + @Override + public ActivityRecordSet contains(String value) + throws GuacamoleException { + return this; + } + + @Override + public ActivityRecordSet limit(int limit) + throws GuacamoleException { + return this; + } + + @Override + public ActivityRecordSet sort(SortableProperty property, + boolean desc) throws GuacamoleException { + return this; + } + +} diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnectionRecordSet.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnectionRecordSet.java index f18b3d6eb..41971c9ae 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnectionRecordSet.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnectionRecordSet.java @@ -23,12 +23,16 @@ import java.util.Collection; import java.util.Collections; import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.net.auth.ConnectionRecord; -import org.apache.guacamole.net.auth.ConnectionRecordSet; /** * An immutable and empty ConnectionRecordSet. + * + * @deprecated + * Use {@link SimpleActivityRecordSet}<{@link ConnectionRecord}> + * instead. */ -public class SimpleConnectionRecordSet implements ConnectionRecordSet { +@Deprecated +public class SimpleConnectionRecordSet implements org.apache.guacamole.net.auth.ConnectionRecordSet { @Override public Collection asCollection() @@ -37,19 +41,19 @@ public class SimpleConnectionRecordSet implements ConnectionRecordSet { } @Override - public ConnectionRecordSet contains(String value) + public org.apache.guacamole.net.auth.ConnectionRecordSet contains(String value) throws GuacamoleException { return this; } @Override - public ConnectionRecordSet limit(int limit) + public org.apache.guacamole.net.auth.ConnectionRecordSet limit(int limit) throws GuacamoleException { return this; } @Override - public ConnectionRecordSet sort(SortableProperty property, boolean desc) + public org.apache.guacamole.net.auth.ConnectionRecordSet sort(SortableProperty property, boolean desc) throws GuacamoleException { return this; } diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUserContext.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUserContext.java index d87cf950b..97584ed28 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUserContext.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUserContext.java @@ -27,10 +27,11 @@ import java.util.UUID; import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.form.Form; import org.apache.guacamole.net.auth.ActiveConnection; +import org.apache.guacamole.net.auth.ActivityRecordSet; import org.apache.guacamole.net.auth.AuthenticationProvider; import org.apache.guacamole.net.auth.Connection; import org.apache.guacamole.net.auth.ConnectionGroup; -import org.apache.guacamole.net.auth.ConnectionRecordSet; +import org.apache.guacamole.net.auth.ConnectionRecord; import org.apache.guacamole.net.auth.Directory; import org.apache.guacamole.net.auth.SharingProfile; import org.apache.guacamole.net.auth.User; @@ -209,9 +210,9 @@ public class SimpleUserContext implements UserContext { } @Override - public ConnectionRecordSet getConnectionHistory() + public ActivityRecordSet getConnectionHistory() throws GuacamoleException { - return new SimpleConnectionRecordSet(); + return new SimpleActivityRecordSet(); } @Override diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/history/APIConnectionRecordSortPredicate.java b/guacamole/src/main/java/org/apache/guacamole/rest/history/APIConnectionRecordSortPredicate.java index 2a4c81878..d2281d037 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/history/APIConnectionRecordSortPredicate.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/history/APIConnectionRecordSortPredicate.java @@ -21,7 +21,7 @@ package org.apache.guacamole.rest.history; import javax.ws.rs.core.Response; import org.apache.guacamole.GuacamoleClientException; -import org.apache.guacamole.net.auth.ConnectionRecordSet; +import org.apache.guacamole.net.auth.ActivityRecordSet; import org.apache.guacamole.rest.APIException; /** @@ -38,7 +38,7 @@ public class APIConnectionRecordSortPredicate { /** * All possible property name strings and their corresponding - * ConnectionRecordSet.SortableProperty values. + * ActivityRecordSet.SortableProperty values. */ public enum SortableProperty { @@ -46,24 +46,24 @@ public class APIConnectionRecordSortPredicate { * The date that the connection associated with the connection record * began (connected). */ - startDate(ConnectionRecordSet.SortableProperty.START_DATE); + startDate(ActivityRecordSet.SortableProperty.START_DATE); /** - * The ConnectionRecordSet.SortableProperty that this property name + * The ActivityRecordSet.SortableProperty that this property name * string represents. */ - public final ConnectionRecordSet.SortableProperty recordProperty; + public final ActivityRecordSet.SortableProperty recordProperty; /** * Creates a new SortableProperty which associates the property name * string (identical to its own name) with the given - * ConnectionRecordSet.SortableProperty value. + * ActivityRecordSet.SortableProperty value. * * @param recordProperty - * The ConnectionRecordSet.SortableProperty value to associate with + * The ActivityRecordSet.SortableProperty value to associate with * the new SortableProperty. */ - SortableProperty(ConnectionRecordSet.SortableProperty recordProperty) { + SortableProperty(ActivityRecordSet.SortableProperty recordProperty) { this.recordProperty = recordProperty; } @@ -72,7 +72,7 @@ public class APIConnectionRecordSortPredicate { /** * The property to use when sorting ConnectionRecords. */ - private ConnectionRecordSet.SortableProperty property; + private ActivityRecordSet.SortableProperty property; /** * Whether the requested sort order is descending (true) or ascending @@ -102,7 +102,7 @@ public class APIConnectionRecordSortPredicate { value = value.substring(DESCENDING_PREFIX.length()); } - // Parse sorting property into ConnectionRecordSet.SortableProperty + // Parse sorting property into ActivityRecordSet.SortableProperty try { this.property = SortableProperty.valueOf(value).recordProperty; } @@ -118,15 +118,15 @@ public class APIConnectionRecordSortPredicate { } /** - * Returns the SortableProperty defined by ConnectionRecordSet which + * Returns the SortableProperty defined by ActivityRecordSet which * represents the property requested. * * @return - * The ConnectionRecordSet.SortableProperty which refers to the same + * The ActivityRecordSet.SortableProperty which refers to the same * property as the string originally provided when this * APIConnectionRecordSortPredicate was created. */ - public ConnectionRecordSet.SortableProperty getProperty() { + public ActivityRecordSet.SortableProperty getProperty() { return property; } diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryResource.java b/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryResource.java index 49695c4d3..53a8cdba8 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryResource.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryResource.java @@ -28,8 +28,8 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import org.apache.guacamole.GuacamoleException; +import org.apache.guacamole.net.auth.ActivityRecordSet; import org.apache.guacamole.net.auth.ConnectionRecord; -import org.apache.guacamole.net.auth.ConnectionRecordSet; import org.apache.guacamole.net.auth.UserContext; /** @@ -92,7 +92,7 @@ public class HistoryResource { throws GuacamoleException { // Retrieve overall connection history - ConnectionRecordSet history = userContext.getConnectionHistory(); + ActivityRecordSet history = userContext.getConnectionHistory(); // Restrict to records which contain the specified strings for (String required : requiredContents) {