Search in sources :

Example 1 with XmEntityIdKeyTypeKey

use of com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey 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)

Example 2 with XmEntityIdKeyTypeKey

use of com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey in project xm-ms-entity by xm-online.

the class XmEntityServiceImpl method findOne.

/**
 * Get one xmEntity by id or key.
 *
 * @param idOrKey the id or key of the entity
 * @return the entity
 */
@LogicExtensionPoint("FindOne")
@Override
@Transactional(readOnly = true)
public XmEntity findOne(IdOrKey idOrKey) {
    log.debug("Request to get XmEntity : {}", idOrKey);
    Long xmEntityId;
    if (idOrKey.isKey()) {
        XmEntityIdKeyTypeKey projection = getXmEntityIdKeyTypeKey(idOrKey);
        xmEntityId = projection.getId();
    } else {
        xmEntityId = idOrKey.getId();
    }
    return xmEntityRepository.findOneById(xmEntityId);
}
Also used : XmEntityIdKeyTypeKey(com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with XmEntityIdKeyTypeKey

use of com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey in project xm-ms-entity by xm-online.

the class XmEntityServiceImpl method selectAndUpdate.

@Override
@Transactional
public XmEntity selectAndUpdate(IdOrKey idOrKey, Consumer<XmEntity> consumer) {
    log.debug("Request to get XmEntity : {}", idOrKey);
    Long xmEntityId;
    if (idOrKey.isKey()) {
        XmEntityIdKeyTypeKey projection = getXmEntityIdKeyTypeKey(idOrKey);
        xmEntityId = projection.getId();
    } else {
        xmEntityId = idOrKey.getId();
    }
    XmEntity entity = xmEntityRepository.findOneByIdForUpdate(xmEntityId);
    consumer.accept(entity);
    return save(entity);
}
Also used : XmEntityIdKeyTypeKey(com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

XmEntityIdKeyTypeKey (com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey)3 Transactional (org.springframework.transaction.annotation.Transactional)2 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)1 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)1 FunctionSpec (com.icthh.xm.ms.entity.domain.spec.FunctionSpec)1