Search in sources :

Example 1 with FunctionSpec

use of com.icthh.xm.ms.entity.domain.spec.FunctionSpec in project xm-ms-entity by xm-online.

the class FunctionServiceImpl method execute.

/**
 * {@inheritDoc}
 */
@Override
public FunctionContext execute(String functionKey, IdOrKey idOrKey, Map<String, Object> functionInput) {
    Objects.requireNonNull(functionKey, "functionKey can't be null");
    Objects.requireNonNull(idOrKey, "idOrKey can't be null");
    // get type key
    XmEntityIdKeyTypeKey projection = xmEntityService.getXmEntityIdKeyTypeKey(idOrKey);
    String xmEntityTypeKey = projection.getTypeKey();
    // validate that current XmEntity has function
    Optional<FunctionSpec> functionSpec = xmEntitySpecService.findFunction(xmEntityTypeKey, functionKey);
    if (!functionSpec.isPresent()) {
        throw new IllegalArgumentException("Function not found for entity type key " + xmEntityTypeKey + " and function key: " + functionKey);
    }
    if (functionInput == null) {
        functionInput = Collections.emptyMap();
    }
    // execute function
    Map<String, Object> data = functionExecutorService.execute(functionKey, idOrKey, xmEntityTypeKey, functionInput);
    // save result in FunctionContext
    if (functionSpec.get().getSaveFunctionContext()) {
        return saveResult(functionKey, idOrKey, data);
    } else {
        return toFunctionContext(functionKey, idOrKey, data);
    }
}
Also used : FunctionSpec(com.icthh.xm.ms.entity.domain.spec.FunctionSpec) XmEntityIdKeyTypeKey(com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey)

Aggregations

FunctionSpec (com.icthh.xm.ms.entity.domain.spec.FunctionSpec)1 XmEntityIdKeyTypeKey (com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey)1