Live Platform
  • Introduction
  • Release Notes
    • Live 3
      • 3.59.0
      • 3.58.0
      • 3.57.0
      • 3.56.0
      • 3.55.0
      • 3.54.0
      • 3.53.0
      • 3.52.0
      • 3.51.0
      • 3.50.0
      • 3.49.0
      • 3.48.0
      • 3.47.0
      • 3.46.0
      • 3.45.0
      • 3.44.0
      • 3.43.0
      • 3.42.0
      • 3.41.0
      • 3.40.0
      • 3.39.0
      • 3.38.0
      • 3.37.0
      • 3.36.0
      • 3.35.0
      • 3.34.0
      • 3.33.0
      • 3.32.0
      • 3.31.0
      • 3.30.0
      • 3.29.0
      • 3.28.0
      • 3.27.0
      • 3.26.0
      • 3.25.0
      • 3.24.0
      • 3.23.0
      • 3.22.0
      • 3.21.0
      • 3.20.0
      • 3.19.0
      • 3.18.0
      • 3.17.0
      • 3.16.0
      • 3.15.0
      • 3.14.0
      • 3.13.0
      • 3.12.0
      • 3.11.0
      • 3.10.0
      • 3.9.0
      • 3.8.0
      • 3.7.0
      • 3.6.0
      • 3.5.0
      • 3.4.0
      • 3.3.0
      • 3.2.0
      • 3.1.0
      • 3.0.0
    • Live 2
  • Articles
    • Creating an aggregation
    • Creating a pipe
  • Theoretical Background
    • Fundamentals
    • Key Advantages
  • Platform Architecture
    • Introduction
    • Queries
    • Glossary
  • Featured plugins
    • Annotations
    • Groovy support
    • Messenger
    • Microsoft Teams
    • MongoDB
    • MongoDB Timeseries
    • MongoDB Kit
    • Purge plugin
    • SQL
    • TCP Input
    • TimescaleDB
  • Data visualization
    • Pipes widgets
      • Temporal
      • Cartesian
      • Multi-value snapshot
      • Single-value snapshot
      • Tables
      • Heatmap
      • JSX Widgets
      • Lollipop
      • Histogram
      • State Timeline
      • Boxplot
    • Pipes modifiers on Pipes charts
  • Alerts and notifications
    • Pipes modifiers on rules
  • Pipes Queries
    • Introduction
    • Dynamic filters
    • Meta parameters
    • Reducer
      • Uniform compress
      • PIP
    • Storage Hints
    • Execution Context
    • Event flow modifiers
  • Developers
    • Plugins
    • Packages
    • Backend API
      • Lookup Tables
      • Extensions
      • Settings
      • Storage Providers
      • Web Services
      • Web Setup
      • Entity Audit
    • Web application
      • Services
        • Point service
        • Menu service
      • Browser Compatibility
      • Runtime modules
        • Core Javascript modules
        • Library modules
        • Adding modules to runtime
      • Localization (i18n)
      • Date formatting
      • Dashboard and Widgets
        • Widget API
        • Custom widget editors
        • Live Event Types
        • Live Widget Configuration
        • Live Widget Packaging
        • Widget Request Interceptors
      • React Contexts
        • Dashboard
        • Dashboard widget
      • Registering Home Page options
    • Python application
    • Subscribing to Live Events
  • Administration
    • Configuration
      • Home Page Customization
      • live.properties
    • Infrastructure Monitoring
    • Storage Monitoring
    • Queries Monitoring
    • Logs Monitoring
    • Data Purging
  • Features
    • Access Permission
    • Datasources
    • Export Dashboard
    • Partial Indexes
    • WebApp Metrics
    • Entity Audit
Powered by GitBook
On this page
  • Permissions
  • Permissions based on Assets

Was this helpful?

  1. Developers
  2. Backend API

Lookup Tables

PreviousBackend APINextExtensions

Last updated 2 years ago

Was this helpful?

A Lookup Table represents a table with two columns: key and vale. It is used to map values that represents Lookups and Assets. So, they provide a way to filter Lookups and Assets.

Lookup Tables can be created inside the code, by creating a new instance of LookupTable.class or using Live's interface.

Permissions

Sometimes, developers may need to implement different forms of permissions to ensure correct filters. To do so, Live provides an extendable LookupTable which allows your own solution.

public class LookupTable {
    private final String key;
    private final String name;
    private final Lookup lookup;
    private final String source;
    private final String sourceUrl;

    public LookupTable(String key, String name, Lookup lookup) {
        this(key, name, lookup, null, null);
    }

    protected LookupTable(String key, String name, Lookup lookup, String source, String sourceUrl) {
        this.sourceUrl = sourceUrl;
        Preconditions.checkNotNull(lookup, "lookup");
        this.key = key;
        this.name = name;
        this.lookup = lookup;
        this.source = source;
    }

    public LookupTable withSource(String source, String sourceUrl) {
        return new LookupTable(key, name, lookup, source, sourceUrl);
    }

    public String getKey() {
        return key;
    }

    public String getName() {
        return name;
    }

    public Lookup getLookup() {
        return lookup;
    }

    public String getSource() {
        return source;
    }

    public String getSourceUrl() {
        return sourceUrl;
    }

    public LookupTable getFilteredLookupTable(LoggedUser user) { return this; }
}

You just need to implement your own LookupTable and override the methods withSource and getFilteredLookupTable. The first one should return a new instance of the created class, and the second one should contain your implementation of permission.

public class FilteredLookupTable extends LookupTable {

    public FilteredLookupTable(String key, String name, Lookup lookup) {
        super(key, name, lookup);
    }

    protected FilteredLookupTable(String key, String name, Lookup lookup, String source, String sourceUrl) {
        super(key, name, lookup, source, sourceUrl);
    }

    @Override
    public LookupTable withSource(String source, String sourceUrl) {
        return new FilteredLookupTable(this.getKey(), this.getName(), this.getLookup(), source, sourceUrl);
    }

    @Override
    public LookupTable getFilteredLookupTable(LoggedUser user) {
        if(this.getName().equals("test")) return this;
        else return withSource("sourceTest", "sourceUrl");
    }
}

Since the method getFilteredLookupTable is responsable to filter the LookupTable, you could use the LoggedUser passed by parameter or the Lookup which exists inside LookupTable.

Permissions based on Assets

Liverig already have an abstract generic LookupTable to get values of Assets. So, if you need control the permission based on Asset's permissions and perspectives, then we already have two LookupTables to do it.

public class AssetNameKeyLookupTable extends GenericLookupTablePermission {

    public AssetNameKeyLookupTable(String key, String name, Lookup lookup, AssetService assetService, AssetPerspectivePermission assetPerspectivePermission) {
        super(key, name, lookup, assetService, assetPerspectivePermission);
    }

    public AssetNameKeyLookupTable(GenericLookupTablePermission table, String source, String sourceUrl) {
        super(table, source, sourceUrl);
    }

    @Override
    public LookupTable withSource(String source, String sourceUrl) {
        return new AssetNameKeyLookupTable(this, source, sourceUrl);
    }

    @Override
    public LookupTable getFilteredLookupTable(LoggedUser user) {
        LookupPermission lookup = new LookupPermission(getAssets(user), this.getLookup()) {
            @Override
            public Object getKey(Entry entry) {
                return entry.getKey();
            }
        };
        return new AssetNameKeyLookupTable(this.getKey(), this.getName(), lookup, getAssetService(), getAssetPerspectivePermission());
    }
}
public class EventNameKeyLookupTable extends GenericLookupTablePermission {
    public EventNameKeyLookupTable(String key, String name, Lookup lookup, AssetService assetService, AssetPerspectivePermission assetPerspectivePermission) {
        super(key, name, lookup, assetService, assetPerspectivePermission);
    }

    public EventNameKeyLookupTable(GenericLookupTablePermission table, String source, String sourceUrl) {
        super(table, source, sourceUrl);
    }

    @Override
    public LookupTable withSource(String source, String sourceUrl) {
        return new EventNameKeyLookupTable(this, source, sourceUrl);
    }

    @Override
    public LookupTable getFilteredLookupTable(LoggedUser user) {
        LookupPermission lookup = new LookupPermission(getAssets(user), this.getLookup()) {
            @Override
            public Object getKey(Entry entry) {
                return entry.getValue();
            }
        };
        return new EventNameKeyLookupTable(this.getKey(), this.getName(), lookup, getAssetService(), getAssetPerspectivePermission());
    }
}

The AssetNameKeyLookupTableshould be used to LookupTables which use Asset's name as key. While EventNameKeyLookupTableshould be used to LookupTables which use Event's type as key.

engine.addLookupTable(new AssetNameKeyLookupTable("table-name", "Asset",
                lookup.nameToEventType(), assetService, assetPerspectivePermission));
engine.addLookupTable(new EventNameKeyLookupTable("table-name", "Event type",
                lookup.eventTypeToName(), assetService, assetPerspectivePermission));
Creating a new LookupTable