mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-462: Allow individual records to be identified and retrieved directly.
This commit is contained in:
@@ -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}
|
||||
|
@@ -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
|
||||
|
@@ -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 {
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user