Source: map/filters/builders/STABuilder.js

import { AbstractBuilder } from "./AbstractBuilder.js";
const encodeQuery = (query) => encodeURIComponent(query);
/**
 * Represents a class for building http queries for STA services.
 * Extends the AbstractBuilder class.
 * @memberof vef.map.filters.builders
 */
class STABuilder extends AbstractBuilder {
    static getFilterParams(harmonizedFilters) {
        const entityMap = { // Maps the filter attribute entity to the path to this entity starting from Things (STA 1.1)
            "Sensors": "Datastreams/Sensor",
            "ObservedProperties": "Datastreams/ObservedProperty",
            "Locations": "Locations",
            "Things": "",
            "Datastreams": "Datastreams",
            "FeaturesOfInterest": "Datastreams/Observations/FeatureOfInterest",
            "HistoricalLocations": "HistoricalLocations",
            "Observations": "Datastreams/Observations"
        };

        let harmonizedFilters_ = {};
        for (let key in harmonizedFilters) {
            let pathElements = key.split('/');
            let mainEntity = pathElements[0]
            if (entityMap[mainEntity]) {
                pathElements[0] = entityMap[mainEntity];
                harmonizedFilters_[pathElements.join('/')] = harmonizedFilters[key];
            } else {
                throw new Error("STA entity not found: " + mainEntity);
            }
        }
        const filter = super.getFilterParams(harmonizedFilters_);
        return (filter.length) ? { sta_filter: encodeQuery(`(${filter})`) } : {};
    }

    static bt(property, begin, end) {
        return `${property} ge ${begin} and ${property} le ${end}`;
    }

    static eq(property, value) {
        return `${property} eq '${value}'`;
    }

    static like(property, value) {
        return `substringof('${value}',${property})`;
    }

    static gt(property, value) {
        return `${property} gt ${value}`;
    }

    static gteq(property, value) {
        return `${property} ge ${value}`;
    }

    static lt(property, value) {
        return `${property} lt ${value}`;
    }

    static lteq(property, value) {
        return `${property} le ${value}`;
    }

    static bbox(property, latMin, lngMin, latMax, lngMax) {
        return `geo.intersects(${property}, geography'POLYGON((${lngMin} ${latMin}, ${lngMax} ${latMin}, ${lngMax} ${latMax}, ${lngMin} ${latMax}, ${lngMin} ${latMin}))')`;
    }

    static null(property) {
        return `${property} eq null`;
    }

    static or(filters) {
        return filters.length > 0 ? `${filters.join(' or ')}` : '';
    }

    static and(filters) {
        return filters.length > 0 ? `${filters.join(' and ')}` : '';
    }
}

export { STABuilder as STABuilder };