Class SensorThingsService

java.lang.Object
de.fraunhofer.iosb.ilt.frostclient.SensorThingsService

public class SensorThingsService extends Object
A SensorThingsService represents the service endpoint of a server.
Author:
Nils Sommer, Hylke van der Schaaf, Michael Jacoby
  • Constructor Details

    • SensorThingsService

      public SensorThingsService(ModelRegistry modelRegistry)
      Creates a new SensorThingsService without an endpoint url set.The endpoint url MUST be set before the service can be used.
      Parameters:
      modelRegistry - The registry with the model to use.
    • SensorThingsService

      public SensorThingsService(ModelRegistry modelRegistry, URI endpoint) throws MalformedURLException
      Constructor.
      Parameters:
      modelRegistry - The registry with the model to use.
      endpoint - the base URI of the SensorThings service
      Throws:
      MalformedURLException - when building the final url fails.
    • SensorThingsService

      public SensorThingsService(ModelRegistry modelRegistry, URL endpoint) throws MalformedURLException
      Constructor.
      Parameters:
      modelRegistry - The registry with the model to use.
      endpoint - the base URL of the SensorThings service
      Throws:
      MalformedURLException - when building the final url fails.
  • Method Details

    • getModelRegistry

      public ModelRegistry getModelRegistry()
    • getJsonReader

      public JsonReader getJsonReader()
    • setEndpoint

      public final void setEndpoint(URI endpoint) throws MalformedURLException
      Sets the endpoint URL/URI. Once the endpoint URL/URI is set it can not be changed. The endpoint url MUST be set before the service can be used.
      Parameters:
      endpoint - The URI of the endpoint.
      Throws:
      MalformedURLException - when building the final url fails.
    • setEndpoint

      public final void setEndpoint(URL endpoint) throws MalformedURLException
      Sets the endpoint URL/URI. Once the endpoint URL/URI is set it can not be changed. The endpoint url MUST be set before the service can be used.
      Parameters:
      endpoint - The URL of the endpoint.
      Throws:
      MalformedURLException - when building the final url fails.
    • setUrlReplace

      public final void setUrlReplace(String urlReplace)
      In some cases the server generates URLs using a different base URL. For instance when the server has a different external and internal address. This option will replace the start part of each URL generated by the server that matches the given string, with the service URL.
      Parameters:
      urlReplace - the endpoint url the server uses, that needs to be replaced.
    • getEndpoint

      public URL getEndpoint()
      Gets the endpoint URL for the service. Throws an IllegalStateException if the endpoint is not set.
      Returns:
      the endpoint URL for the service.
    • isEndpointSet

      public boolean isEndpointSet()
      Check if the endpoint is set.
      Returns:
      true if the endpoint is set, false otherwise.
    • getPath

      public String getPath(Entity parent, NavigationProperty relation)
      The local path to the entity or collection. e.g.:
      • Things(2)/Datastreams
      • Datastreams(5)/Thing
      Parameters:
      parent - The entity holding the relation, can be null.
      relation - The relation or collection to get.
      Returns:
      The path to the entity collection.
    • getFullPath

      public URL getFullPath(Entity parent, NavigationProperty relation) throws ServiceFailureException
      The full path to the entity or collection.
      Parameters:
      parent - The entity holding the relation, can be null.
      relation - The relation or collection to get.
      Returns:
      the full path to the entity or collection.
      Throws:
      ServiceFailureException - If generating the path fails.
    • getFullPath

      public URL getFullPath(EntityType entityType) throws ServiceFailureException
      The full path to the entity or collection.
      Parameters:
      entityType - entity type to get the path for.
      Returns:
      the full path to the entity or collection.
      Throws:
      ServiceFailureException - If generating the path fails.
    • execute

      public org.apache.http.client.methods.CloseableHttpResponse execute(org.apache.http.client.methods.HttpRequestBase request) throws IOException
      Execute the given request, adding a token header if needed.
      Parameters:
      request - The request to execute.
      Returns:
      the response.
      Throws:
      IOException - in case of problems.
    • query

      public Query query(EntityType type)
      Query a main entity set.
      Parameters:
      type - the type to query.
      Returns:
      a new Query for the given type.
    • dao

      public Dao dao(EntityType type)
    • create

      public void create(Entity entity) throws ServiceFailureException
      Create the given entity in this service. Executes a POST to the Collection of the entity type. The entity will be updated with the ID of the entity in the Service and it will be linked to the Service.
      Parameters:
      entity - The entity to create in the service.
      Throws:
      ServiceFailureException - in case the server rejects the POST.
    • update

      public void update(Entity entity) throws ServiceFailureException
      Patches the entity in the Service.
      Parameters:
      entity - The entity to update in the service.
      Throws:
      ServiceFailureException - in case the server rejects the PATCH.
    • patch

      public void patch(Entity entity, List<com.github.fge.jsonpatch.JsonPatchOperation> patch) throws ServiceFailureException
      Update the given entity with the given patch. Does not update the entity object itself. To see the result, fetch it anew from the server.
      Parameters:
      entity - The entity to update on the server.
      patch - The patch to apply to the entity.
      Throws:
      ServiceFailureException - in case the server rejects the PATCH.
    • delete

      public void delete(Entity entity) throws ServiceFailureException
      Deletes the given entity from the service.
      Parameters:
      entity - The entity to delete in the service.
      Throws:
      ServiceFailureException - in case the server rejects the DELETE.
    • setTokenManager

      public SensorThingsService setTokenManager(TokenManager tokenManager)
      Sets the TokenManager. Before each request is sent to the Service, the TokenManager has the opportunity to modify the request and add any headers required for Authentication and Authorisation.
      Parameters:
      tokenManager - The TokenManager to use, can be null.
      Returns:
      This SensorThingsService.
    • getTokenManager

      public TokenManager getTokenManager()
      Returns:
      The current TokenManager.
    • getHttpClient

      public org.apache.http.impl.client.CloseableHttpClient getHttpClient()
      Get the httpclient used for requests.
      Returns:
      the client
    • getClientBuilder

      public org.apache.http.impl.client.HttpClientBuilder getClientBuilder()
      Get the Builder used to generate the httpClient. If changes are made to the builder after the httpClient is already generated, call rebuildHttpClient() to trigger the httpClient to be built anew. The clientBuilder is initialised using: HttpClients.custom().useSystemProperties()
      Returns:
      The client Builder used to generate the httpClient.
    • rebuildHttpClient

      public void rebuildHttpClient()
      Triggers a rebuild of the httpClient, using the latest changes to the clientBuilder.
    • getVersion

      public Version getVersion()