Foundations Apex API Developer Reference

fferpcore.DataTransformationService

global with sharing class DataTransformationService

Perform data transformation using the Transformation Tables.

Methods

transform

global static fferpcore.DataTransformationService.TransformResult transform(Set<fferpcore.DataTransformationService.TransformRequest> requests)

The method takes a set of TransformRequests and performs the transformation. It yields a Transformation result which wraps all the DataResults for each TransformRequest.

Input Parameters

Name Type Description
requests Set<fferpcore.DataTransformationService.TransformRequest> A set of objects that contain the details of the transform table and input values.

Return Value

This service returns a DataTransformationService.TransformResult.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

public Map<fferpcore.DataTransformationService.TransformRequest, fferpcore.DataTransformationService.DataResult> transformAndGetDataResults(Set<fferpcore.DataTransformationService.TransformRequest> requests)
{
    Map<fferpcore.DataTransformationService.TransformRequest, fferpcore.DataTransformationService.DataResult> results = new Map<fferpcore.DataTransformationService.TransformRequest, fferpcore.DataTransformationService.DataResult>();

    fferpcore.DataTransformationService.TransformResult result = fferpcore.DataTransformationService.transform(requests);

    for (fferpcore.DataTransformationService.TransformRequest request: requests)
    {
        results.put(request, result.getDataResultForTransformRequest(request));
    }

    return results;
}

fferpcore.DataTransformationService.TransformRequest

global class TransformRequest

Used to construct a request passed into the transform method fferpcore.DataTransformationService service.

Methods

TransformRequest

global TransformRequest(Id transformTableId, String[] inputs)

Used to construct a request passed into the transform method fferpcore.DataTransformationService service.

Input Parameters

Name Type Description
transformTableId Id The Id of the transformation table from which to request an output.
inputs String[] List of one or two input values used to select the relevant output value.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

List<String> inputValues = new List<String>{'Lead', 'Developer'};
String outputValue = 'Technical Lead';

fferpcore__DataTransformationTable table = new fferpcore__DataTransformationTable(
    fferpcore__Description__c = 'Data Transformation table for roles'
);

insert table;

fferpcore__DataTransformation transformation = new fferpcore__DataTransformation(
    fferpcore__DataTransformationTable__c = table.Id,
    fferpcore__RequiredSourceValues__c = 2;
    fferpcore__SourceValue1__c = inputValues[0],
    fferpcore__SourceValue2__c = inputValues[1],
    fferpcore__TargetValue__c = outputValue,
    fferpcore__UniquenessConstraint__c = DataTransformations.generateUniquenessConstraint(table.Id, fferpcore__inputValues);
);

insert transformation;

fferpcore.DataTransformationService.TranformRequest transformRequest = fferpcore.DataTransformationService.TranformRequest(table.Id, inputValues);

fferpcore.DataTransformationService.TransformResult result = fferpcore.DataTransformationService.transform(transformRequest);

System.assertEquals('Techincal Lead', result.getDataResultForTransformRequest().getOutput());

getTransformTableId

global Id getTransformTableId()

Used to get the Id used to construct the object.

Return Value

This service returns an Id object.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

public Id getTransformTableId(fferpcore.DataTransformationService.TransformRequest request)
{
    return request.getTransformTableId();
}

getInputs

global String[] getInputs()

Used to extract to the inputValues used to construct the object.

Return Value

This service returns a String[] object.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

return List<String> getInputValues(fferpcore.DataTransformationService.TransformRequest request)
{
    return request.getInputValues();
}

equals

global Boolean equals(Object other)

hashCode

global Integer hashCode()

fferpcore.DataTransformationService.TransformResult

global class TransformResult

Result of a transform operation.

Methods

TransformResult

global TransformResult(Map<fferpcore.DataTransformationService.TransformRequest, fferpcore.DataTransformationService.DataResult> requestToResultMap)

Construct a TransformResult using the specified DataResults, keyed by TransformRequest.

Input Parameters

Name Type Description
requestToResultMap Map<fferpcore.DataTransformationService.TransformRequest, fferpcore.DataTransformationService.DataResult> DataResults keyed by TransformRequest.

Return Value

The TransformResult instance.

getDataResultForTransformRequest

global fferpcore.DataTransformationService.DataResult getDataResultForTransformRequest(fferpcore.DataTransformationService.TransformRequest transformRequest)

Input Parameters

Name Type Description
transformRequest fferpcore.DataTransformationService.TransformRequest An object that contains the details of the transform table and input values.

Return Value

This service returns a DataTransformationService.DataResult

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

public class DataTransformationRequestCollector
{
    private final Set<DataTransformationService.TransformRequest> m_requests = new Set<DataTransformationService.TransformRequest>();
    private DataTransformationService.TransformResult m_result = null;

    public void addRequest(DataTransformationService.TransformRequest request)
    {
        m_result = null;
        m_requests.add(request);
    }

    public DataTransformationService.DataResult getResult(DataTransformationService.TransformRequest request)
    {
        if (m_result == null)
        {
            m_result = DataTransformationService.transform(m_requests);
            m_requests.clear();
        }

        return m_result == null ? null : m_result.getDataResultForTransformRequest(request);
    }
}

fferpcore.DataTransformationService.DataResult

global class DataResult

Result for a single transform request.

Methods

DataResult

global DataResult(String output, String error)

Construct a DataResult with the given output and error. If output and error are both null, an explicit null output is assumed.

Input Parameters

Name Type Description
output String The output of the transformation.
error String The error that occured while attempting to transform.

Return Value

The DataResult instance.

isError

global Boolean isError()

This method returns true if a data transformation has failed. This could occur when a data transformation table has been deleted but a mapping is still associated with it.

Return Value

True if there is an error.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

void processResults(Set<fferpcore.DataTransformationService.DataResult> results)
{
    for (fferpcore.DataTransformationService.DataResult result : result)
    {
        if (result.isError())
        {
            logError(result.getError());
        }
        else
        {
            applyOutput(result.getOutput());
        }
    }
}

getError

global String getError()

This method returns the error message associated with the DataResult, if one is present. If one isn't present null will be used.

Return Value

The error as a string object, or null.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

void processResults(Set<fferpcore.DataTransformationService.DataResult> results)
{
    for (fferpcore.DataTransformationService.DataResult result : result)
    {
        if (result.isError())
        {
            logError(result.getError());
        }
        else
        {
            applyOutput(result.getOutput());
        }
    }
}

getOutput

global String getOutput()

This method returns the output of the data transformation. This output can be null if the value is null or if there is an error.

Return Value

The output value. Can be null if the value is null, or if there is an error.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

void processResults(Set<fferpcore.DataTransformationService.DataResult> results)
{
    for (fferpcore.DataTransformationService.DataResult result : result)
    {
        if (result.isError())
        {
            logError(result.getError());
        }
        else
        {
            applyOutput(result.getOutput());
        }
    }
}
© Copyright 2009–2022 FinancialForce.com, inc. All rights reserved. Various trademarks held by their respective owners.