Commit 43bd347b authored by Noel Alonso's avatar Noel Alonso
Browse files

Merge branch 'feature-atlasMicroservice' into 'dev'

Feature atlas microservice

See merge request redmic-project/server/library/elasticsearch-lib!16
parents 699753ee e44c004a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -13,13 +13,13 @@
	<groupId>es.redmic.lib</groupId>
	<artifactId>elasticsearch-lib</artifactId>
	<packaging>jar</packaging>
	<version>0.12.0</version>
	<version>0.12.0-feature-atlasMicroservice</version>
	<name>elasticsearch-lib</name>

	<properties>
		<!-- REDMIC -->
		<redmic.exceptions.version>0.8.0</redmic.exceptions.version>
		<redmic.models.version>0.9.1</redmic.models.version>
		<redmic.exceptions.version>0.10.0</redmic.exceptions.version>
		<redmic.models.version>0.11.0</redmic.models.version>

		<!-- Others -->
		<commons-io.version>1.3.2</commons-io.version>
+31 −0
Original line number Diff line number Diff line
@@ -44,4 +44,35 @@ public class JoinIndex {
	public void setParent(String parent) {
		this.parent = parent;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((parent == null) ? 0 : parent.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		JoinIndex other = (JoinIndex) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (parent == null) {
			if (other.parent != null)
				return false;
		} else if (!parent.equals(other.parent))
			return false;
		return true;
	}
}
+2 −0
Original line number Diff line number Diff line
@@ -42,4 +42,6 @@ public interface IRWBaseESRepository<TModel extends BaseES<?>> {
	EventApplicationResult delete(String id);

	EventApplicationResult delete(String id, String parentId);

	EventApplicationResult rollback(TModel modelToIndex, String id);
}
+33 −0
Original line number Diff line number Diff line
@@ -25,9 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired;

import es.redmic.elasticsearchlib.common.repository.IRWBaseESRepository;
import es.redmic.elasticsearchlib.common.utils.ElasticPersistenceUtils;
import es.redmic.exception.data.ItemNotFoundException;
import es.redmic.models.es.common.dto.EventApplicationResult;
import es.redmic.models.es.common.model.BaseES;
import es.redmic.models.es.common.query.dto.SimpleQueryDTO;
import es.redmic.models.es.data.common.model.DataHitWrapper;

public abstract class RWDataESRepository<TModel extends BaseES<?>, TQueryDTO extends SimpleQueryDTO>
		extends RDataESRepository<TModel, TQueryDTO> implements IRWBaseESRepository<TModel> {
@@ -115,6 +117,37 @@ public abstract class RWDataESRepository<TModel extends BaseES<?>, TQueryDTO ext
		return elasticPersistenceUtils.delete(getIndex()[0], getType(), id, parentId);
	}

	@Override
	public EventApplicationResult rollback(TModel modelToIndex, String id) {

		return rollback(modelToIndex, id, null);
	}

	@SuppressWarnings("unchecked")
	public EventApplicationResult rollback(TModel modelToIndex, String id, String parentId) {

		// rollback de un insert
		if (modelToIndex == null) {
			return delete(id, parentId);
		}

		// rollback de un delete
		DataHitWrapper<?> currentRecord;
		try {
			currentRecord = findById(id, parentId);
		} catch (ItemNotFoundException e) {
			return save(modelToIndex, parentId);
		}

		// rollback de un update
		if (rollbackIsRequired((TModel) currentRecord.get_source(), modelToIndex)) {
			return update(modelToIndex, parentId);
		}
		return new EventApplicationResult(true);
	}

	protected abstract boolean rollbackIsRequired(TModel currentModel, TModel modelToIndex);

	/*
	 * Función que comprueba que las restricciones necesarias para añadir el item se
	 * cumplen. Por ejemplo que no exista el identificador, que no haya códigos