GUACAMOLE-462: Allow individual records to be identified and retrieved directly.

This commit is contained in:
Michael Jumper
2022-02-09 15:33:56 -08:00
parent 6874f9c6bd
commit 449fcb828e
9 changed files with 124 additions and 59 deletions

View File

@@ -78,6 +78,21 @@ public interface ActivityRecord extends ReadableAttributes {
*/
public boolean isActive();
/**
* Returns the unique identifier assigned to this record, if any. If this
* record is not uniquely identifiable, this may be null. If provided, this
* unique identifier MUST be unique across all {@link ActivityRecord}
* objects within the same {@link ActivityRecordSet}.
*
* @return
* The unique identifier assigned to this record, or null if this
* record has no such identifier.
*/
public default String getIdentifier() {
UUID uuid = getUUID();
return uuid != null ? uuid.toString() : null;
}
/**
* Returns a UUID that uniquely identifies this record. If provided, this
* UUID MUST be deterministic and unique across all {@link ActivityRecord}

View File

@@ -57,6 +57,30 @@ public interface ActivityRecordSet<RecordType extends ActivityRecord> {
*/
Collection<RecordType> asCollection() throws GuacamoleException;
/**
* Returns the record having the given unique identifier, if records within
* this set have unique identifiers. If records within this set do not have
* defined unique identifiers, this function has no effect.
*
* @param identifier
* The unique identifier of the record to retrieve.
*
* @return
* The record having the given unique identifier, or null if there is
* no such record.
*
* @throws GuacamoleException
* If an error occurs while retrieving the record.
*/
default RecordType get(String identifier) throws GuacamoleException {
return asCollection().stream()
.filter((record) -> {
String recordIdentifier = record.getIdentifier();
return recordIdentifier != null && recordIdentifier.equals(identifier);
})
.findFirst().orElse(null);
}
/**
* Returns the subset of records which contain the given value. The
* properties and semantics involved with determining whether a particular

View File

@@ -122,6 +122,17 @@ public abstract class DecoratingActivityRecordSet<RecordType extends ActivityRec
};
}
@Override
public RecordType get(String string) throws GuacamoleException {
RecordType record = super.get(string);
if (record != null)
return decorate(record);
return null;
}
@Override
public ActivityRecordSet<RecordType> sort(SortableProperty property,
boolean desc) throws GuacamoleException {

View File

@@ -81,6 +81,11 @@ public class DelegatingActivityRecord implements ActivityRecord {
return record.isActive();
}
@Override
public String getIdentifier() {
return record.getIdentifier();
}
@Override
public UUID getUUID() {
return record.getUUID();

View File

@@ -59,6 +59,11 @@ public class DelegatingActivityRecordSet<RecordType extends ActivityRecord>
return recordSet;
}
@Override
public RecordType get(String identifier) throws GuacamoleException {
return recordSet.get(identifier);
}
@Override
public Collection<RecordType> asCollection() throws GuacamoleException {
return recordSet.asCollection();