Commit 0257c9db authored by Noel Alonso's avatar Noel Alonso
Browse files

Descarta eventos no finales en loadFromHistory

También añade función para comprobar si el evento está bloqueado
antes de cargarlo en el agregado
parent 53773c9e
Loading
Loading
Loading
Loading
+11 −37
Original line number Diff line number Diff line
@@ -64,10 +64,18 @@ public abstract class Aggregate {
			logger.error("Intentando modificar un elemento eliminado, ", id);
			throw new ItemNotFoundException("id", id);
		}
	}

	protected void check(Event event) {

		if (isLocked(event.getType()) && !event.getType().equals(EventTypes.DELETED)) {

			// TODO: Si el tiempo entre el último y el actual es superior a el máximo del
			// ciclo, compensar.

		if (isLocked(eventType)) {
			logger.error("Intentando modificar un elemento bloqueado por una edición en curso, ", id);
			throw new ItemLockedException("id", id);
			logger.error("Intentando modificar un elemento bloqueado por una edición en curso, ",
					event.getAggregateId());
			throw new ItemLockedException("id", event.getAggregateId());
		}
	}

@@ -120,40 +128,6 @@ public abstract class Aggregate {
	 */
	public abstract void loadFromHistory(Event event);

	protected void _loadFromHistory(Event history) {

		String eventType = history.getType();

		switch (eventType) {
		case "CREATE_CONFIRMED":
			logger.debug("Creación confirmada");
			apply(history);
			break;
		case "UPDATE_CONFIRMED":
			logger.debug("Modificación confirmada");
			apply(history);
			break;
		case "DELETE":
			logger.debug("En fase de borrado");
			apply(history);
			break;
		case "DELETE_CONFIRMED":
			logger.debug("Borrado confirmado");
			apply(history);
			break;
		// FAILED
		case "CREATE_FAILED":
		case "UPDATE_FAILED":
		case "DELETE_FAILED":
			logger.debug("Evento fallido");
			apply(history);
			break;
		default:
			logger.debug("Evento no manejado ", history.getType());
			break;
		}
	}

	protected void reset() {

		setVersion(null);