Mapping component

The objective of this component is to enable the mapping of fields to be able to save or retrieve properties of heterogeneous objects.
The original need is related to the setting of the connectors.

Graphic component

The graphical control to use is com.axemble.studio.expressions.components.MappingComponent.
This control will allow us to set the mapping between the different elements.

To use this component, the following object providers must be defined:

  • sourceMappingProvider: input provider.
  • targetMappingProvider: output provider.

They can be defined directly in the XML definition in the case where the providers does not need parameters to their initialization.
Otherwise, it is necessary that both providers be initialized at loading with the onAfterLoad() of the document.

XML Definition

The XML will define the name of the field associated to the MappingComponent and the target provider.
The UserMappingProvider will implement BaseCustomMappingProvider.

    <fields>
        <field name="fldUserMappingComponent" label="" ctrl="com.axemble.studio.expressions.components.MappingComponent" 
            target-provider="com.axemble.vdoc.connectors.directory.mapping.providers.UserMappingProvider" />
    </fields>

onAfterLoad method

Here's an example of the initialization of the mappingComponant in the onAfterLoad method.\

    MappingComponent<?, ?> mappingComponent = (MappingComponent<?, ?>)getResourceController().getDefaultWidget( "fldUserMappingComponent" );
    IMappingProvider<?> sourceMappingProvider = mappingComponent.createSourceProvider( TableCreationMappingProvider.class.getName(), getTableCreation() );
    mappingComponent.setSourceMappingProvider( sourceMappingProvider );

Object provider definition

The provider must extend com.axemble.vdoc.sdk.components.BaseCustomMappingProvider.

All external objects must be mapped to vdoc MappingStructure objects. The MappingStructure object allows to link external objects to vdoc objects.

MappingStructure object

The external object (MappingStructure) defined the following objects :

private String name;
private String label;
private String description;
private String dataType;
private boolean isMandatory;
private boolean isVisible;
private int mappingType;
private List<IMappingStructure> childValues = new ArrayList<>();
private List<IOption> options = new ArrayList<>();     

Methods to implement by the provider

The provider must implement the following 3 methods :

Method Description
public List<IMappingStructure> getValues(); Returns the list of external objects linked to known vdoc objects
public abstract Object getValue( T mappedObject, String mappingStructureName); Get the value of the external object corresponding to mappingStructureName
public abstract void setValue( T mappedObject, String mappingStructureName, Object value ); Set the value of the external object corresponding to mappingStructureName

Assigning values

After having set the different binding components in the User interface (UI), the values assignment is done via com.axemble.vdoc.sdk.components.MappingObject

Method Description
getTargetValue() This method is used to get the value of the target mappingStructure name.
applyMapping() This method is used to assign the values of the source object to the target object.

Example in CreateUserService.java

MappingObject<IResource, IUser> mappingObject = new MappingObject<>( new TableCreationMappingProvider<>( getTableCreation() ), 
                                                                     new UserMappingProvider<>( null ) );

IOrganization organization = (IOrganization)mappingObject.getTargetValue( directoryContext, getResource(),
                                    getServiceDefinition().getValue( "fldUserMappingComponent" ), 
                                    UserMappingProvider.FIELD_ORGANIZATION );

IUser user = directoryModule.createUser( directoryContext, "CreateUserServiceLoginTemp", "CreateUserServicePasswordTemp", organization );

mappingObject.applyMapping( directoryContext, getResource(), user, getServiceDefinition().getValue( "fldUserMappingComponent" ) );