File

libs/core/src/lib/api-communication/connectors/sta-api-v1-connector/read/sta-read-interface.service.ts

Index

Methods

Constructor

constructor(httpService: HttpService)
Parameters :
Name Type Optional
httpService HttpService No

Methods

Public aggregatePaging
aggregatePaging(request: Observable>)
Type parameters :
  • T
Parameters :
Name Type Optional
request Observable<StaValueListResponse<T>> No
Protected createRequestUrl
createRequestUrl(url: string, endpoint: string, id?: string, relation?: string)
Parameters :
Name Type Optional
url string No
endpoint string No
id string Yes
relation string Yes
Returns : string
getDatastream
getDatastream(url: string, id: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
id string No
params StaFilter<DatastreamSelectParams | DatastreamExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<Datastream>
getDatastreamObservationsRelation
getDatastreamObservationsRelation(url: string, id: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
id string No
params StaFilter<DatastreamSelectParams | DatastreamExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<StaValueListResponse<Observation>>
getDatastreams
getDatastreams(url: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
params StaFilter<DatastreamSelectParams | DatastreamExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<StaValueListResponse<Datastream>>
getDatastreamsByNavigationLink
getDatastreamsByNavigationLink(url: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
params StaFilter<DatastreamSelectParams | DatastreamExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<StaValueListResponse<Datastream>>
getFeatureOfInterest
getFeatureOfInterest(url: string, id: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
id string No
params StaFilter<FeatureOfInterestSelectParams | FeatureOfInterestExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<FeatureOfInterest>
getFeaturesOfInterest
getFeaturesOfInterest(url: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
params StaFilter<FeatureOfInterestSelectParams | FeatureOfInterestExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<StaValueListResponse<FeatureOfInterest>>
getHistoricalLocation
getHistoricalLocation(url: string, id: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
id string No
params StaFilter<HistoricalLocationSelectParams | HistoricalLocationExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<HistoricalLocation>
getHistoricalLocations
getHistoricalLocations(url: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
params StaFilter<HistoricalLocationSelectParams | HistoricalLocationExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<StaValueListResponse<HistoricalLocation>>
getLocation
getLocation(url: string, id: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
id string No
params StaFilter<LocationSelectParams | LocationExpandParams> Yes
options HttpRequestOptions Yes
getLocations
getLocations(url: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
params StaFilter<LocationSelectParams | LocationExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<StaValueListResponse<Location>>
getObservation
getObservation(url: string, id: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
id string No
params StaFilter<ObservationSelectParams | ObservationExpandParams> Yes
options HttpRequestOptions Yes
getObservations
getObservations(url: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
params StaFilter<ObservationSelectParams | ObservationExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<StaValueListResponse<Observation>>
getObservedProperties
getObservedProperties(url: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
params StaFilter<ObservedPropertySelectParams | ObservedPropertyExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<StaValueListResponse<ObservedProperty>>
getObservedProperty
getObservedProperty(url: string, id: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
id string No
params StaFilter<ObservedPropertySelectParams | ObservedPropertyExpandParams> Yes
options HttpRequestOptions Yes
getSensor
getSensor(url: string, id: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
id string No
params StaFilter<SensorSelectParams | SensorExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<Sensor>
getSensors
getSensors(url: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
params StaFilter<SensorSelectParams | SensorExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<StaValueListResponse<Sensor>>
getThing
getThing(url: string, id: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
id string No
params StaFilter<ThingSelectParams | ThingExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<Thing>
getThings
getThings(url: string, params?: StaFilter, options?: HttpRequestOptions)
Parameters :
Name Type Optional
url string No
params StaFilter<ThingSelectParams | ThingExpandParams> Yes
options HttpRequestOptions Yes
Returns : Observable<StaValueListResponse<Thing>>
Protected prepareParams
prepareParams(params: literal type, filter: StaFilter)
Parameters :
Name Type Optional Default value
params literal type No {}
filter StaFilter<StaSelectParams | StaExpandParams> No {}
Returns : HttpParams
Protected requestApi
requestApi(url: string, params: literal type, filter: StaFilter, options: HttpRequestOptions)
Type parameters :
  • T
Parameters :
Name Type Optional Default value
url string No
params literal type No {}
filter StaFilter<StaSelectParams | StaExpandParams> No {}
options HttpRequestOptions No {}
Returns : Observable<T>
import { HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, Observer } from 'rxjs';

import { UriParameterCoder } from '../../../../dataset-api/api-interface';
import { HttpService } from '../../../../dataset-api/http.service';
import { HttpRequestOptions } from '../../../../model/internal/http-requests';
import { Datastream, DatastreamExpandParams, DatastreamSelectParams } from '../model/datasetreams';
import {
  FeatureOfInterest,
  FeatureOfInterestExpandParams,
  FeatureOfInterestSelectParams,
} from '../model/features-of-interest';
import {
  HistoricalLocation,
  HistoricalLocationExpandParams,
  HistoricalLocationSelectParams,
} from '../model/historical-locations';
import { Location, LocationExpandParams, LocationSelectParams } from '../model/locations';
import { Observation, ObservationExpandParams, ObservationSelectParams } from '../model/observations';
import { ObservedProperty, ObservedPropertyExpandParams, ObservedPropertySelectParams } from '../model/observed-properties';
import { Sensor, SensorExpandParams, SensorSelectParams } from '../model/sensors';
import {
  StaEndpoint,
  StaExpandParams,
  StaFilter,
  StaReadInterface,
  StaSelectParams,
  StaValueListResponse,
} from '../model/sta-interface';
import { Thing, ThingExpandParams, ThingSelectParams } from '../model/things';

@Injectable({ providedIn: 'root' })
export class StaReadInterfaceService implements StaReadInterface {

  constructor(
    protected httpService: HttpService
  ) { }

  getThings(url: string, params?: StaFilter<ThingSelectParams, ThingExpandParams>, options?: HttpRequestOptions): Observable<StaValueListResponse<Thing>> {
    return this.requestApi<StaValueListResponse<Thing>>(this.createRequestUrl(url, StaEndpoint.Things), {}, params, options);
  }

  getThing(url: string, id: string, params?: StaFilter<ThingSelectParams, ThingExpandParams>, options?: HttpRequestOptions): Observable<Thing> {
    return this.requestApi<Thing>(this.createRequestUrl(url, StaEndpoint.Things, id), {}, params, options);
  }

  getObservations(url: string, params?: StaFilter<ObservationSelectParams, ObservationExpandParams>, options?: HttpRequestOptions): Observable<StaValueListResponse<Observation>> {
    return this.requestApi<StaValueListResponse<Observation>>(this.createRequestUrl(url, StaEndpoint.Observations), {}, params, options);
  }

  getObservation(url: string, id: string, params?: StaFilter<ObservationSelectParams, ObservationExpandParams>, options?: HttpRequestOptions): Observable<Observation> {
    return this.requestApi<Observation>(this.createRequestUrl(url, StaEndpoint.Observations, id), {}, params, options);
  }

  getHistoricalLocations(url: string, params?: StaFilter<HistoricalLocationSelectParams, HistoricalLocationExpandParams>, options?: HttpRequestOptions)
    : Observable<StaValueListResponse<HistoricalLocation>> {
    return this.requestApi<StaValueListResponse<HistoricalLocation>>(this.createRequestUrl(url, StaEndpoint.HistoricalLocations), {}, params, options);
  }

  getHistoricalLocation(url: string, id: string, params?: StaFilter<HistoricalLocationSelectParams, HistoricalLocationExpandParams>, options?: HttpRequestOptions): Observable<HistoricalLocation> {
    return this.requestApi<HistoricalLocation>(this.createRequestUrl(url, StaEndpoint.HistoricalLocations, id), {}, params, options);
  }

  getLocations(url: string, params?: StaFilter<LocationSelectParams, LocationExpandParams>, options?: HttpRequestOptions): Observable<StaValueListResponse<Location>> {
    return this.requestApi<StaValueListResponse<Location>>(this.createRequestUrl(url, StaEndpoint.Locations), {}, params, options);
  }

  getLocation(url: string, id: string, params?: StaFilter<LocationSelectParams, LocationExpandParams>, options?: HttpRequestOptions): Observable<Location> {
    return this.requestApi<Location>(this.createRequestUrl(url, StaEndpoint.Locations, id), {}, params, options);
  }

  getSensors(url: string, params?: StaFilter<SensorSelectParams, SensorExpandParams>, options?: HttpRequestOptions): Observable<StaValueListResponse<Sensor>> {
    return this.requestApi<StaValueListResponse<Sensor>>(this.createRequestUrl(url, StaEndpoint.Sensors), {}, params, options);
  }

  getSensor(url: string, id: string, params?: StaFilter<SensorSelectParams, SensorExpandParams>, options?: HttpRequestOptions): Observable<Sensor> {
    return this.requestApi<Sensor>(this.createRequestUrl(url, StaEndpoint.Sensors, id), {}, params, options);
  }

  getFeaturesOfInterest(url: string, params?: StaFilter<FeatureOfInterestSelectParams, FeatureOfInterestExpandParams>, options?: HttpRequestOptions)
    : Observable<StaValueListResponse<FeatureOfInterest>> {
    return this.requestApi<StaValueListResponse<FeatureOfInterest>>(this.createRequestUrl(url, StaEndpoint.FeaturesOfInterest), {}, params, options);
  }

  getFeatureOfInterest(url: string, id: string, params?: StaFilter<FeatureOfInterestSelectParams, FeatureOfInterestExpandParams>, options?: HttpRequestOptions): Observable<FeatureOfInterest> {
    return this.requestApi<FeatureOfInterest>(this.createRequestUrl(url, StaEndpoint.FeaturesOfInterest, id), {}, params, options);
  }

  getObservedProperties(url: string, params?: StaFilter<ObservedPropertySelectParams, ObservedPropertyExpandParams>, options?: HttpRequestOptions)
    : Observable<StaValueListResponse<ObservedProperty>> {
    return this.requestApi<StaValueListResponse<ObservedProperty>>(this.createRequestUrl(url, StaEndpoint.ObservedProperties), {}, params, options);
  }

  getObservedProperty(url: string, id: string, params?: StaFilter<ObservedPropertySelectParams, ObservedPropertyExpandParams>, options?: HttpRequestOptions): Observable<ObservedProperty> {
    return this.requestApi<ObservedProperty>(this.createRequestUrl(url, StaEndpoint.ObservedProperties, id), {}, params, options);
  }

  getDatastreams(url: string, params?: StaFilter<DatastreamSelectParams, DatastreamExpandParams>, options?: HttpRequestOptions): Observable<StaValueListResponse<Datastream>> {
    return this.requestApi<StaValueListResponse<Datastream>>(this.createRequestUrl(url, StaEndpoint.Datastreams), {}, params, options);
  }

  getDatastream(url: string, id: string, params?: StaFilter<DatastreamSelectParams, DatastreamExpandParams>, options?: HttpRequestOptions): Observable<Datastream> {
    return this.requestApi<Datastream>(this.createRequestUrl(url, StaEndpoint.Datastreams, id), {}, params, options);
  }

  getDatastreamsByNavigationLink(
    url: string, params?: StaFilter<DatastreamSelectParams, DatastreamExpandParams>, options?: HttpRequestOptions
  ): Observable<StaValueListResponse<Datastream>> {
    return this.requestApi<StaValueListResponse<Datastream>>(url, {}, params, options);
  }

  // TODO: make function more generic
  getDatastreamObservationsRelation(
    url: string, id: string, params?: StaFilter<DatastreamSelectParams, DatastreamExpandParams>, options?: HttpRequestOptions
  ): Observable<StaValueListResponse<Observation>> {
    return this.requestApi<StaValueListResponse<Observation>>(this.createRequestUrl(url, StaEndpoint.Datastreams, id, 'Observations'), {}, params, options);
  }

  public aggregatePaging<T>(request: Observable<StaValueListResponse<T>>): Observable<StaValueListResponse<T>> {
    return new Observable((observer: Observer<StaValueListResponse<T>>) => {
      request.subscribe(
        res => {
          if (res['@iot.nextLink']) {
            this.aggregatePaging(this.httpService.client().get<StaValueListResponse<T>>(res['@iot.nextLink'])).subscribe(nextPage => {
              res.value.push(...nextPage.value);
              delete res['@iot.nextLink'];
              observer.next(res);
              observer.complete();
            });
          } else {
            observer.next(res);
            observer.complete();
          }
        },
        error => {
          observer.error(error);
          observer.complete();
        });
    });
  }

  protected requestApi<T>(
    url: string,
    params: { [key: string]: string } = {},
    filter: StaFilter<StaSelectParams, StaExpandParams> = {},
    options: HttpRequestOptions = {}
  ): Observable<T> {
    return this.httpService.client(options).get<T>(url,
      {
        params: this.prepareParams(params, filter)
      }
    );
  }

  protected prepareParams(
    params: { [key: string]: string } = {},
    filter: StaFilter<StaSelectParams, StaExpandParams> = {}
  ): HttpParams {
    let httpParams = new HttpParams({ encoder: new UriParameterCoder() });
    Object.getOwnPropertyNames(params).forEach((key) => httpParams = httpParams.set(key, params[key]));
    if (filter.$expand) {
      if (typeof filter.$expand === 'string') {
        httpParams = httpParams.set('$expand', filter.$expand);
      } else {
        const $expand = [];
        for (const key in filter.$expand as StaExpandParams) {
          if (filter.$expand.hasOwnProperty(key) && filter.$expand[key]) {
            $expand.push(key);
          }
        }
        httpParams = httpParams.set('$expand', $expand.join(','));
      }
    }
    if (filter.$select) {
      const $select = [];
      for (const key in filter.$select) {
        if (filter.$select.hasOwnProperty(key) && filter.$select[key]) {
          $select.push(key);
        }
      }
      httpParams = httpParams.set('$select', $select.join(','));
    }
    if (filter.$orderby) {
      httpParams = httpParams.set('$orderby', filter.$orderby);
    }
    if (filter.$filter) {
      httpParams = httpParams.set('$filter', filter.$filter);
    }
    if (filter.$count) {
      httpParams = httpParams.set('$count', 'true');
    }
    if (filter.$top !== undefined) {
      httpParams = httpParams.set('$top', filter.$top.toString());
    }
    return httpParams;
  }

  protected createRequestUrl(url: string, endpoint: string, id?: string, relation?: string) {
    let requestStub = `${url}${endpoint}`;
    if (id !== null && id !== undefined) {
      requestStub += `(${id})`;
      if (relation !== undefined) {
        requestStub += `/${relation}`;
      }
    }
    return requestStub;
  }

}

result-matching ""

    No results matching ""