Class BidiMappingService

java.lang.Object
org.openehealth.ipf.commons.map.BidiMappingService
All Implemented Interfaces:
MappingService
Direct Known Subclasses:
SpringBidiMappingService

@Deprecated(since="6.0", forRemoval=true) public class BidiMappingService extends Object implements MappingService
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0, use Mappings - DefaultMappings is the implementation to build on, and SpringMappings in ipf-commons-spring the bean to wire. This class remains as an adapter for applications still holding a MappingService, and is scheduled for removal in IPF 7.0.
MappingService implementation backed by Mappings, which is where the actual model and the loading of mapping sources live as of IPF 6.0.

This class exists to keep the untyped, null-returning MappingService contract working for existing applications. It answers exactly what Mappings answers, with null where that returns an empty Optional.

Two conventions of the Groovy implementation it replaces are gone:

  • an empty value is a value: an entry mapping to "" yields "", rather than the mapping's fallback, and a default passed in applies only where there is no value at all;
  • there is no composite convention: a value containing ~ is returned as the string it is rather than as a List, and a Collection passed as a key or value is rejected rather than joined. A mapping whose keys or values consist of several parts must either be split into separate mappings, or the calling code joins and splits the parts itself.

New code should use Mappings directly — it is String-typed and returns Optional. getMappings() hands out the instance this service delegates to.

Mapping sources are dispatched to a MappingLoader by file extension, so the format of a mapping file is a decision per file. Reading the legacy .map script format needs ipf-commons-map-groovy on the classpath.

As of version 3.1, the add/setMappingScript(Resource) methods have been out-factored into the class SpringBidiMappingService located in the ipf-commons-spring module.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    Deprecated, for removal: This API element is subject to removal in a future version.
    Wraps mappings somebody else owns, so that the same content is reachable through both this service and the typed Mappings API.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Forgets every mapping; the registered functions stay.
    get(Object mappingKey, Object key)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    get(Object mappingKey, Object key, Object defaultValue)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    getKey(Object mappingKey, Object value)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Reverse mapping (Optional implementation)
    getKey(Object mappingKey, Object value, Object defaultKey)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Reverse mapping (Optional implementation)
    getKeySystem(Object mappingKey)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    getValueSystem(Object mappingKey)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    Set<?>
    keys(Object mappingKey)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    Set<?>
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Registers the functions that a mapping's computed fallback refers to by name, i.e. what <unmatched mode="function" ref="..."/> resolves against.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    values(Object mappingKey)
    Deprecated, for removal: This API element is subject to removal in a future version.
     

    Methods inherited from class Object

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

    • BidiMappingService

      public BidiMappingService()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • BidiMappingService

      public BidiMappingService(DefaultMappings mappings)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Wraps mappings somebody else owns, so that the same content is reachable through both this service and the typed Mappings API. Whoever created the instance configures it; this constructor changes nothing about it.
      Parameters:
      mappings - the mappings to delegate to
  • Method Details

    • getMappings

      public Mappings getMappings()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      the mappings this service delegates to, for call sites moving to the typed API
    • setMappingScript

      public void setMappingScript(URL script)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • setMappingScripts

      public void setMappingScripts(URL[] scripts)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • clearMappings

      public void clearMappings()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Forgets every mapping; the registered functions stay.
    • setMappingFunctions

      public void setMappingFunctions(Map<String, Function<String,String>> functions)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Registers the functions that a mapping's computed fallback refers to by name, i.e. what <unmatched mode="function" ref="..."/> resolves against. A function receives the key that had no entry and returns the value for it, so a mapping can derive its answer from its input rather than list it:
      mappingService.setMappingFunctions(Map.of(
              "first4", key -> key == null || key.length() <= 4 ? key : key.substring(0, 4)));
      
      A mapping source naming a function that is not registered is rejected as it is read, so register them first. As a Spring bean property that happens before any configurer adds mapping resources; a module that ships both a mapping file and the function it names should contribute a MappingFunctionProvider instead.
      Parameters:
      functions - functions by name, replacing any registered under the same name before
    • registerMappingFunction

      public void registerMappingFunction(String name, Function<String,String> function)
      Deprecated, for removal: This API element is subject to removal in a future version.
      See Also:
    • getScripts

      public List<URL> getScripts()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • get

      public Object get(Object mappingKey, Object key)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      get in interface MappingService
      Parameters:
      mappingKey - mapping name
      key - left side of the mapping
      Returns:
      the value mapped by a registered mapping. The implementation of the mapping implements the behavior if the key does not exist.
    • get

      public Object get(Object mappingKey, Object key, Object defaultValue)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      get in interface MappingService
      Parameters:
      mappingKey - mapping name
      key - left side of the mapping
      defaultValue - default right side if there is no mapping for the code
      Returns:
      the value mapped by a registered mapping. If no mapping exists, the default value if returned. The implementation of the mapping implements the behavior if the key does not exist.
    • getKey

      public Object getKey(Object mappingKey, Object value)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: MappingService
      Reverse mapping (Optional implementation)
      Specified by:
      getKey in interface MappingService
      Parameters:
      mappingKey - mapping name
      value - right side of the mapping
      Returns:
      the key mapped by a registered mapping. The implementation of the mapping implements the behavior if the value does not exist.
    • getKey

      public Object getKey(Object mappingKey, Object value, Object defaultKey)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: MappingService
      Reverse mapping (Optional implementation)
      Specified by:
      getKey in interface MappingService
      Parameters:
      mappingKey - mapping name
      value - right side of the mapping
      defaultKey - default left side
      Returns:
      the key mapped by a registered mapping. If no mapping exists, the default value if returned. The implementation of the mapping implements the behavior if the key does not exist.
    • getKeySystem

      public Object getKeySystem(Object mappingKey)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      getKeySystem in interface MappingService
      Parameters:
      mappingKey - mapping name
      Returns:
      a formal identification of the key system (e.g. an OID)
    • getValueSystem

      public Object getValueSystem(Object mappingKey)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      getValueSystem in interface MappingService
      Parameters:
      mappingKey - mapping name
      Returns:
      a formal identification of the value system (e.g. an OID)
    • mappingKeys

      public Set<?> mappingKeys()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      mappingKeys in interface MappingService
      Returns:
      a set of names of all registered mappings. Changes to the set do not change the registry itself.
    • keys

      public Set<?> keys(Object mappingKey)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      keys in interface MappingService
      Parameters:
      mappingKey - mapping key
      Returns:
      key set of a registered mapping. Changes to the set do not change the registry itself.
    • values

      public Collection<?> values(Object mappingKey)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      values in interface MappingService
      Parameters:
      mappingKey - mapping key
      Returns:
      value set of a registered mapping. Changes to the set do not change the registry itself.