use of com.kloia.eventapis.view.EntityEventWrapper in project eventapis by kloiasoft.
the class CassandraViewQuery method queryEntityInternal.
private E queryEntityInternal(String entityId, Select select, E previousEntity) throws EventStoreException {
E currentEntity = previousEntity;
List<Row> entityEventDatas = cassandraSession.execute(select, PagingIterable::all);
for (Row entityEventData : entityEventDatas) {
EntityEvent entityEvent = convertToEntityEvent(entityEventData);
if (entityEvent.getStatus() == EventState.CREATED) {
EntityFunctionSpec<E, ?> functionSpec = functionMap.get(entityEvent.getEventType());
if (functionSpec != null) {
EntityEventWrapper eventWrapper = new EntityEventWrapper<>(functionSpec.getQueryType(), objectMapper, entityEvent);
EntityFunction<E, ?> entityFunction = functionSpec.getEntityFunction();
currentEntity = (E) entityFunction.apply(currentEntity, eventWrapper);
} else
log.trace("Function Spec is not available for " + entityEvent.getEventType() + " EntityId:" + entityId + " Table:" + tableName);
}
if (currentEntity != null) {
currentEntity.setId(entityId);
currentEntity.setVersion(entityEvent.getEventKey().getVersion());
}
}
return (currentEntity == null || currentEntity.getId() == null) ? null : currentEntity;
}
use of com.kloia.eventapis.view.EntityEventWrapper in project eventapis by kloiasoft.
the class CassandraViewQuery method queryEntityInternal.
private E queryEntityInternal(String entityId, Select select) throws EventStoreException {
E initialInstance;
E result = null;
try {
initialInstance = entityType.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
log.error(e.getMessage(), e);
throw new EventStoreException(e);
}
List<Row> entityEventDatas = cassandraSession.execute(select, PagingIterable::all);
for (Row entityEventData : entityEventDatas) {
EntityEvent entityEvent = convertToEntityEvent(entityEventData);
if (entityEvent.getStatus() == EventState.CREATED) {
EntityFunctionSpec<E, ?> functionSpec = functionMap.get(entityEvent.getEventType());
if (functionSpec != null) {
EntityEventWrapper eventWrapper = new EntityEventWrapper<>(functionSpec.getQueryType(), objectMapper, entityEvent);
EntityFunction<E, ?> entityFunction = functionSpec.getEntityFunction();
result = (E) entityFunction.apply(result == null ? initialInstance : result, eventWrapper);
} else
log.trace("Function Spec is not available for " + entityEvent.getEventType() + " EntityId:" + entityId + " Table:" + tableName);
}
if (result != null) {
result.setId(entityId);
result.setVersion(entityEvent.getEventKey().getVersion());
}
}
return (result == null || result.getId() == null) ? null : result;
}
Aggregations