Packages

  • package root

    Documentation for the Axiell Utilities Project

    Documentation for the Axiell Utilities Project

    Overview

    The Axiell Utilities Project attempts to provide a small library of classes and object applicable to most Axiell developments. The library is not geared towards any one project and so should be useful for new projects as well as existing ones.

    The library is based on a few simple principles, namely:

    • referential transparency. The principle that defines a call to a method with the same arguments will always return the same result and that the method does not have any side effects (e.g. updating global variables, etc).
    • functional programming support. If a method or class does have side effects then the method or class is marked as effectful. The library has been designed to not contain any effectful code.
    • minimal functionality. The library is designed to be small with support for a small number of common utilities. The main reason for the small size is to limit the number of dependencies drawn in by the package.

    Package structure

    The com.axiell.util package consists of a number of utilities, where each utility provides a single piece of functionality.

    Notable utilities are:

    • Configure generic configuration reader allowing application settings defined as resources to be interrogated.
    • Error generic error handling class defining a locale independent error message along with details relating to the context of the error. The context may include an exception and other relevant values.
    • Formatter retrieves and formats a locale specific string from a specified resource bundle. The formatting is specified in a C printf style.
    • Implicits implements implicit methods and classes used to pimp methods onto existing classes (e.g. fold() method to Boolean class) and to provide implicit implementations for the JsonLocal and ShowLocal type classes.
    • JsonLocal type class used to output locale specific JSON structures. Implementations exist for Message and Error.
    • Message provides a locale independent mechanism for handling strings. The strings for a given locale are stored in resource bundles that are accessed when the message is to be displayed.
    • ShowLocal type class used to show locale specific strings. Allows Message and Error to be converted to a given language string.

    Dependencies

    The list of dependencies are:

    • Typesafe Config a generic configuration file reader. The library is used by the Configure class to access settings stored as resources within an application.
    Definition Classes
    root
  • package com
    Definition Classes
    root
  • package axiell
    Definition Classes
    com
  • package util

    Axiell Utilities Project

    Axiell Utilities Project

    A set of classes and traits that provide a simple mechanism for the internationalisation of strings and error handling. A mechanism is also supplied to read an application's configuration resource. All methods have been designed to be referentially transparent without the introduction of an effectful library (e.g. cats).

    Imports

    The utility classes/traits can be imported in the usual way, however it is necessary to include the Implicits object if the showLocal and jsonLocal type class methods are used, similarly for the read method on Configure.

    Example:

    import com.axiell.util.Implicits._

    A shorthand way to gain access to all utility classes is to import:

    import com.axiell.util._
    import com.axiell.util.Implicits._

    For more detail on project see the root package page.

    Definition Classes
    axiell
  • package syntax

    Contains implicit classes used to add extension methods.

    Contains implicit classes used to add extension methods.

    The implicit classes are used to add the following extension methods:

    • showLocal displays a language dependent version of an object
    • jsonLocal generates a JSON string with language dependent strings
    • masonLocal generates a Mason Draft 2 compliant JSON string for Error
    • fold functionality for Boolean type

    All traits found in the package are for the implementation of extension methods. The traits are mixed into the Implicits object so they can be easily imported into clients when required.

    Definition Classes
    util
  • trait MasonLocalSyntax extends AnyRef

    Adds extension methods to Error

    Adds extension methods to Error

    The implicit class used to contain the extension methods is wrapped in this trait so they can be mixed in with the Implicits object.

    The Syntax naming convention implies the trait adjusts the syntax of Error. In this case it adds extension methods.

    The extension methods provided allow error context information to be added to an Error that allows a Mason Draft 2 JSON error object to be generated. The following methods, along with their context label, are supported:

    • withId (@id)
    • withMessages (@messages)
    • withDetails (@details)
    • withHttpStatusCode (@httpStatusCode)
    • withControls (@controls)
    • withTime (@time)

    The mason extension method is also added to generate the Mason Draft 2 compliant JSON error object as a string.

    Definition Classes
    syntax
  • MasonLocalOps

implicit final class MasonLocalOps extends AnyRef

Adds extension methods to Error via implicit class

Source
MasonLocalSyntax.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. MasonLocalOps
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new MasonLocalOps(error: Error)

    error

    to add extension methods to

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  9. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def masonLocal(implicit locale: Locale): String

    Create a JSON object as a string formatted as a Mason Draft 2 error

    Create a JSON object as a string formatted as a Mason Draft 2 error

    The format of a Mason Draft 2 error containing all optional and mandatory properties is:

    "@error": {
      "@id": "...",
      "@message": "...",
      "@code": "...",
      "@messages": [...]
      "@details": "...",
      "@httpStatusCode": "...",
      "@controls": "...",
      "@time": "...",
    }

    The only mandatory property is message. Extra properties may be added to extend the information contained in the error. These extra properties are output with their context label and JSON value.

    locale

    to use for text based error messages (Message)

    returns

    string version of Mason Draft 2 error message

  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  17. def toString(): String
    Definition Classes
    AnyRef → Any
  18. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  19. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  20. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  21. final def withControls[A](controls: A)(implicit arg0: JsonLocal[A], arg1: ShowLocal[A]): Error

    Allows resource information to be associated with an error

    Allows resource information to be associated with an error

    The resource information to provide is typically a hypertext link to an on-line resource describing the error in detail. The value should result in a JSON object to conform with the Mason Draft 2 standard.

    A

    type of the resource information

    controls

    to associate with error

    returns

    error with resource information included

  22. final def withDetails[A](details: A)(implicit arg0: JsonLocal[A], arg1: ShowLocal[A]): Error

    Allows a detailed message to be associated with an error

    Allows a detailed message to be associated with an error

    The detailed message provides more information about the error than just a single one line of text. It may contain the text of the stack trace or detailed text about the cause and possible resolution of the error. The value should result in a JSON string to conform with the Mason Draft 2 standard.

    A

    type of the detailed message

    details

    to associate with error

    returns

    error with detailed message included

  23. final def withHttpStatusCode[A](status: A)(implicit arg0: JsonLocal[A], arg1: ShowLocal[A]): Error

    Allows an HTTP status code to be associated with an error

    Allows an HTTP status code to be associated with an error

    The HTTP status code is an integer representing the result of the latest response. The value should result in a JSON integer to conform with the Mason Draft 2 standard.

    A

    type of the HTTP status code, typically scala.Int

    status

    to associate with error

    returns

    error with HTTP status code included

  24. final def withId[A](id: A)(implicit arg0: JsonLocal[A], arg1: ShowLocal[A]): Error

    Allows a unique identifier to associated with an error

    Allows a unique identifier to associated with an error

    The unique identifier value can be any object, but is typically a string. If a custom type is used then implicit implementations of com.axiell.util.ShowLocal and JsonLocal will be required in scope.

    A

    type of the unique identifier

    id

    unique identifier to associate with error

    returns

    error with unique identifier included

  25. final def withMessages[A](messages: A)(implicit arg0: JsonLocal[A], arg1: ShowLocal[A]): Error

    Allows an array of messages to be associated with an error

    Allows an array of messages to be associated with an error

    The array of messages is typically provided as a List of some type. An entry in the array of messages is created for each element in the List. Each element should generate a single string value, not a JSON object so that the output conforms to the Mason Draft 2 standard.

    A

    type of the unique identifier

    messages

    to associate with error

    returns

    error with messages included

  26. final def withTime[A](time: A)(implicit arg0: JsonLocal[A], arg1: ShowLocal[A]): Error

    Allows a timestamp to be associated with an error

    Allows a timestamp to be associated with an error

    The timestamp is typically a java.time.OffsetDateTime object containing the time the error occurred. If a custom type is used then implicit implementations of ShowLocal and JsonLocal will be required in scope. The value should result in a JSON string to conform with the Mason Draft 2 standard.

    A

    type of the timestamp object

    time

    to associate with error

    returns

    error with timestamp included

Inherited from AnyRef

Inherited from Any

Ungrouped