Class HalClientImpl

  • All Implemented Interfaces:
    HalClient, org.refcodes.net.OauthTokenAccessor, org.refcodes.net.OauthTokenAccessor.OauthTokenBuilder<HalClient>, org.refcodes.net.OauthTokenAccessor.OauthTokenMutator, org.refcodes.net.OauthTokenAccessor.OauthTokenProperty


    public class HalClientImpl
    extends java.lang.Object
    implements HalClient
    Implementation of the HalClient using the HttpRestServer (HttpRestServerImpl) under the hood.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.refcodes.net.OauthTokenAccessor

        org.refcodes.net.OauthTokenAccessor.OauthTokenBuilder<B extends org.refcodes.net.OauthTokenAccessor.OauthTokenBuilder<B>>, org.refcodes.net.OauthTokenAccessor.OauthTokenMutator, org.refcodes.net.OauthTokenAccessor.OauthTokenProperty
    • Constructor Summary

      Constructors 
      Constructor Description
      HalClientImpl​(java.lang.String aHalUrl)
      Instantiates the HalClient with no authorization credentials passed.
      HalClientImpl​(java.lang.String aHalUrl, java.lang.String aOauthUrl, java.lang.String aOauthClientId, java.lang.String aOauthClientSecret, java.lang.String aOauthUserName, java.lang.String aOauthUserSecret)
      Instantiates the HalClient with no authorization credentials passed.
      HalClientImpl​(java.lang.String aHalUrl, org.refcodes.net.OauthToken aOauthToken)
      Instantiates the HalClient with a valid OauthToken passed.
      HalClientImpl​(org.refcodes.net.Url aHalUrl)
      Instantiates the HalClient with no authorization credentials passed.
      HalClientImpl​(org.refcodes.net.Url aHalUrl, org.refcodes.net.OauthToken aOauthToken)
      Instantiates the HalClient with a valid OauthToken passed.
      HalClientImpl​(org.refcodes.net.Url aHalUrl, org.refcodes.net.Url aOauthUrl, java.lang.String aOauthClientId, java.lang.String aOauthClientSecret, java.lang.String aOauthUserName, java.lang.String aOauthUserSecret)
      Instantiates the HalClient with no authorization credentials passed.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      HalData create​(java.lang.String aEntity, HalData aProperties)
      Creates a new entitie's element (row) at the HAL resource consisting of the properties as of the provided CanonicalMap.
      boolean delete​(java.lang.String aEntity, java.lang.String aId)
      Deletes an entitie's element (row) from the HAL resource.
      java.lang.String[] entities​()
      Determines the entities provided by the HAL resource.
      java.lang.String[] getExcludeEntities​()
      Gets the names of the entities to be excluded by the HalClient.
      java.lang.String[] getIncludeEntities​()
      Gets the names of the entities to be included by the HalClient.
      org.refcodes.net.OauthToken getOauthToken​()
      HalStruct introspect​(java.lang.String aEntity, TraversalMode aMode)
      Introspects the provided entity at the HAL resource and returns an instance of the CanonicalMap representing the reflected data structure.
      HalData read​(java.lang.String aEntity, java.lang.Long aId, TraversalMode aMode, org.refcodes.net.FormFields aQueryFields)
      Retrieves the properties with the according values for the given entity with the given ID from the HAL resource.
      java.util.List<HalData> readAll​(java.lang.String aEntity, TraversalMode aMode, org.refcodes.net.FormFields aQueryFields)
      Retrieves the properties with the according values of all elements (rows) for the given entity from the HAL resource.
      void setExcludeEntities​(java.lang.String[] theEntities)
      Sets the names of the entities to be excluded by the HalClient.
      void setIncludeEntities​(java.lang.String[] theEntities)
      Sets the names of the entities to be included by the HalClient.
      void setOauthToken​(org.refcodes.net.OauthToken aOauthToken)
      protected static java.lang.String toAttributePath​(java.lang.String path)  
      HalData update​(java.lang.String aEntity, java.lang.String aId, HalData aProperties)
      Updates an existing entitie's element (row) at the HAL resource using the properties as of the provided CanonicalMap.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HalClientImpl

        public HalClientImpl​(java.lang.String aHalUrl)
                      throws java.net.MalformedURLException
        Instantiates the HalClient with no authorization credentials passed.
        Parameters:
        aHalUrl - The URL pointing to the HAL-Endpoint.
        Throws:
        java.net.MalformedURLException - Thrown to indicate that a malformed OAuth URL has occurred.
      • HalClientImpl

        public HalClientImpl​(java.lang.String aHalUrl,
                             org.refcodes.net.OauthToken aOauthToken)
                      throws java.net.MalformedURLException
        Instantiates the HalClient with a valid OauthToken passed.
        Parameters:
        aHalUrl - The URL pointing to the HAL-Endpoint.
        aOauthToken - The OAuth-Token to be used when authorizing against the HAL-Endpoint.
        Throws:
        java.net.MalformedURLException - Thrown to indicate that a malformed OAuth URL has occurred.
      • HalClientImpl

        public HalClientImpl​(java.lang.String aHalUrl,
                             java.lang.String aOauthUrl,
                             java.lang.String aOauthClientId,
                             java.lang.String aOauthClientSecret,
                             java.lang.String aOauthUserName,
                             java.lang.String aOauthUserSecret)
                      throws org.refcodes.net.HttpStatusException,
                             java.net.MalformedURLException
        Instantiates the HalClient with no authorization credentials passed.
        Parameters:
        aHalUrl - The URL pointing to the HAL-Endpoint.
        aOauthUrl - The URL pointing to the OAuth authentication endpoint.
        aOauthClientId - The assigned OAuth client ID.
        aOauthClientSecret - The client's OAuth secret.
        aOauthUserName - The OAuth authorization user name.
        aOauthUserSecret - The OAuth authorization user secret.
        Throws:
        org.refcodes.net.HttpStatusException - Thrown in case a HTTP response was of an erroneous status when requesting the OAuth URL.
        java.net.MalformedURLException - Thrown to indicate that a malformed OAuth URL has occurred.
      • HalClientImpl

        public HalClientImpl​(org.refcodes.net.Url aHalUrl)
                      throws java.net.MalformedURLException
        Instantiates the HalClient with no authorization credentials passed.
        Parameters:
        aHalUrl - The URL pointing to the HAL-Endpoint.
        Throws:
        java.net.MalformedURLException - Thrown to indicate that a malformed OAuth URL has occurred.
      • HalClientImpl

        public HalClientImpl​(org.refcodes.net.Url aHalUrl,
                             org.refcodes.net.OauthToken aOauthToken)
                      throws java.net.MalformedURLException
        Instantiates the HalClient with a valid OauthToken passed.
        Parameters:
        aHalUrl - The URL pointing to the HAL-Endpoint.
        aOauthToken - The OAuth-Token to be used when authorizing against the HAL-Endpoint.
        Throws:
        java.net.MalformedURLException - Thrown to indicate that a malformed OAuth URL has occurred.
      • HalClientImpl

        public HalClientImpl​(org.refcodes.net.Url aHalUrl,
                             org.refcodes.net.Url aOauthUrl,
                             java.lang.String aOauthClientId,
                             java.lang.String aOauthClientSecret,
                             java.lang.String aOauthUserName,
                             java.lang.String aOauthUserSecret)
                      throws org.refcodes.net.HttpStatusException,
                             java.net.MalformedURLException
        Instantiates the HalClient with no authorization credentials passed.
        Parameters:
        aHalUrl - The URL pointing to the HAL-Endpoint.
        aOauthUrl - The URL pointing to the OAuth authentication endpoint.
        aOauthClientId - The assigned OAuth client ID.
        aOauthClientSecret - The client's OAuth secret.
        aOauthUserName - The OAuth authorization user name.
        aOauthUserSecret - The OAuth authorization user secret.
        Throws:
        org.refcodes.net.HttpStatusException - Thrown in case a HTTP response was of an erroneous status when requesting the OAuth URL.
        java.net.MalformedURLException - Thrown to indicate that a malformed OAuth URL has occurred.
    • Method Detail

      • toAttributePath

        protected static java.lang.String toAttributePath​(java.lang.String path)
      • create

        public HalData create​(java.lang.String aEntity,
                              HalData aProperties)
                       throws org.refcodes.net.HttpStatusException
        Creates a new entitie's element (row) at the HAL resource consisting of the properties as of the provided CanonicalMap.
        Specified by:
        create in interface HalClient
        Parameters:
        aEntity - The entity for which to create the element (row).
        aProperties - The CanonicalMap containing the properties of the entity be created.
        Returns:
        A HalData with the newly created element (row).
        Throws:
        org.refcodes.net.HttpStatusException - Thrown in case a HTTP response was of an erroneous status.
      • read

        public HalData read​(java.lang.String aEntity,
                            java.lang.Long aId,
                            TraversalMode aMode,
                            org.refcodes.net.FormFields aQueryFields)
                     throws org.refcodes.net.HttpStatusException
        Retrieves the properties with the according values for the given entity with the given ID from the HAL resource.
        Specified by:
        read in interface HalClient
        Parameters:
        aEntity - The entity for which to retrieve the properties.
        aId - The ID of the entity for which to retrieve the properties.
        aMode - The mode for handling HREF resources, e.g. load them as well or ignore them.
        aQueryFields - The query fields to be appended to the requesting URL.
        Returns:
        A CanonicalMap with the property names assigned to the according values.
        Throws:
        org.refcodes.net.HttpStatusException - Thrown in case a HTTP response was of an erroneous status.
      • readAll

        public java.util.List<HalData> readAll​(java.lang.String aEntity,
                                               TraversalMode aMode,
                                               org.refcodes.net.FormFields aQueryFields)
                                        throws org.refcodes.net.HttpStatusException
        Retrieves the properties with the according values of all elements (rows) for the given entity from the HAL resource.
        Specified by:
        readAll in interface HalClient
        Parameters:
        aEntity - The entity for which to retrieve the properties of all elements (rows).
        aMode - The mode for handling HREF resources, e.g. load them as well or ignore them.
        aQueryFields - The query fields to be appended to the requesting URL.
        Returns:
        A CanonicalMap array with the property names assigned to the according values. one CanonicalMap instance per element (row).
        Throws:
        org.refcodes.net.HttpStatusException - Thrown in case a HTTP response was of an erroneous status.
      • update

        public HalData update​(java.lang.String aEntity,
                              java.lang.String aId,
                              HalData aProperties)
                       throws org.refcodes.net.HttpStatusException
        Updates an existing entitie's element (row) at the HAL resource using the properties as of the provided CanonicalMap.
        Specified by:
        update in interface HalClient
        Parameters:
        aEntity - The entity for which to update the element (row).
        aId - The ID of the element (row) of the entity to be updated.
        aProperties - The CanonicalMap containing the properties of the entity to be updated.
        Returns:
        The updated representation of the entitie's element (row).
        Throws:
        org.refcodes.net.HttpStatusException - Thrown in case a HTTP response was of an erroneous status.
      • delete

        public boolean delete​(java.lang.String aEntity,
                              java.lang.String aId)
                       throws org.refcodes.net.HttpStatusException
        Deletes an entitie's element (row) from the HAL resource.
        Specified by:
        delete in interface HalClient
        Parameters:
        aEntity - The entity for which to delete the element (row).
        aId - The ID of the element (row) of the entity to be deleted.
        Returns:
        True in case the element (row) has been deleted, false if there was none such element (row) at the HAL resource (the expectation is satisfied now as there is no element (row) with the given ID in the HAL resource after the operation).
        Throws:
        org.refcodes.net.HttpStatusException - Thrown in case a HTTP response was of an erroneous status.
      • entities

        public java.lang.String[] entities​()
                                    throws org.refcodes.net.HttpStatusException
        Determines the entities provided by the HAL resource.
        Specified by:
        entities in interface HalClient
        Returns:
        A String array with the according entity names.
        Throws:
        org.refcodes.net.HttpStatusException - Thrown in case a HTTP response was of an erroneous status.
      • introspect

        public HalStruct introspect​(java.lang.String aEntity,
                                    TraversalMode aMode)
                             throws org.refcodes.net.HttpStatusException
        Introspects the provided entity at the HAL resource and returns an instance of the CanonicalMap representing the reflected data structure.
        Specified by:
        introspect in interface HalClient
        Parameters:
        aEntity - The entity to be introspected.
        aMode - The mode of operation whilst introspecting an entity: You may include MetaData as of TraversalMode.IMPORT_CHILDREN_KEEP_DANGLING_HREFS or just retrieve the plain data structure without Meta-Data as of TraversalMode.IMPORT_CHILDREN.
        Returns:
        A CanonicalMap instance representing the structure of the entity, e.g. providing the attribute names and the data types as well as other constraints representing the layout of the entity (think of a class defining the layout of its instances).
        Throws:
        org.refcodes.net.HttpStatusException - Thrown in case a HTTP response was of an erroneous status.
      • getExcludeEntities

        public java.lang.String[] getExcludeEntities​()
        Gets the names of the entities to be excluded by the HalClient.
        Specified by:
        getExcludeEntities in interface HalClient
        Returns:
        The entities to be excluded.
      • getIncludeEntities

        public java.lang.String[] getIncludeEntities​()
        Gets the names of the entities to be included by the HalClient.
        Specified by:
        getIncludeEntities in interface HalClient
        Returns:
        The entities to be included.
      • getOauthToken

        public org.refcodes.net.OauthToken getOauthToken​()
        Specified by:
        getOauthToken in interface org.refcodes.net.OauthTokenAccessor
      • setExcludeEntities

        public void setExcludeEntities​(java.lang.String[] theEntities)
        Sets the names of the entities to be excluded by the HalClient.
        Specified by:
        setExcludeEntities in interface HalClient
        Parameters:
        theEntities - The entities to be excluded.
      • setIncludeEntities

        public void setIncludeEntities​(java.lang.String[] theEntities)
        Sets the names of the entities to be included by the HalClient.
        Specified by:
        setIncludeEntities in interface HalClient
        Parameters:
        theEntities - The entities to be included.
      • setOauthToken

        public void setOauthToken​(org.refcodes.net.OauthToken aOauthToken)
        Specified by:
        setOauthToken in interface org.refcodes.net.OauthTokenAccessor.OauthTokenMutator