Commit 2ce68e4f authored by Noel Alonso's avatar Noel Alonso
Browse files

Controla caso especial, con envío de parentId

Como existe herencia entre layer y category, es necesario enviar
parentId. En caso de creación, no se envía snapshot, por lo que no se
dispone de parentId. Es necesario primero hacer una búsqueda por id, para
confirmar si es necesario hacer rollback.
parent 80551bc7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@ public class LayerController extends DataController<Layer, LayerDTO, GeoDataQuer

		EventApplicationResult result = null;

		String parentId = event.getLastSnapshotItem().getParent() != null
		String parentId = (event.getLastSnapshotItem() != null && event.getLastSnapshotItem().getParent() != null)
				? event.getLastSnapshotItem().getParent().getId()
				: null;

+19 −0
Original line number Diff line number Diff line
@@ -239,6 +239,25 @@ public class LayerESRepository extends RWDataESRepository<Layer, GeoDataQueryDTO
		return result.getHits().getHits().get(0);
	}

	/*
	 * Controla los casos de un create fallido, sin snapshot y por tanto sin
	 * parentId para ir a buscar el registro
	 */
	@Override
	public EventApplicationResult rollback(Layer modelToIndex, String id, String parentId) {

		if (parentId == null) {
			DataSearchWrapper<?> result = findBy(QueryBuilders.termQuery(ID_PROPERTY, id));
			Layer model = (Layer) result.getSource(0);
			if (model != null)
				return super.rollback(modelToIndex, id, model.getJoinIndex().getParent());
			else
				return new EventApplicationResult(true);
		}

		return super.rollback(modelToIndex, id, parentId);
	}

	/**
	 * Sobrescribe a la función base por incompatibilidad de query. Función que dado
	 * un conjunto de términos, nos devuelve una query de elasticsearch. Debe estar
+1 −1
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ public class LayerESService extends RDataService<Layer, LayerDTO, GeoDataQueryDT
	}

	public EventApplicationResult rollback(Layer model, String id, String parentId) {
		return repository.rollback(model, parentId);
		return repository.rollback(model, id, parentId);
	}

	/**