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);
}
}
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);
}
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);
}
Aggregations