Commit 5eb87e76 authored by Noel Alonso's avatar Noel Alonso
Browse files

Crea excepción de borrado de items referenciados

Si un item está referenciado en otro documento, se lanza una excepción para
controlar que no se borren.
parent bb0734c3
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -9,7 +9,8 @@ public enum ExceptionType implements ExceptionTypeItfc {
	// EventSource
	HISTORY_NOT_FOUND(Constants.HISTORY_NOT_FOUND),
	CONFIRMATION_TIMEOUT(Constants.CONFIRMATION_TIMEOUT),
	ITEM_LOCKED(Constants.ITEM_LOCKED);
	ITEM_LOCKED(Constants.ITEM_LOCKED),
	ITEM_REFERENCED(Constants.ITEM_REFERENCED);
	
	// @formatter:on

@@ -40,7 +41,8 @@ public enum ExceptionType implements ExceptionTypeItfc {
		// @formatter:off
		public static final String HISTORY_NOT_FOUND = "HistoryNotFound",
				CONFIRMATION_TIMEOUT = "ConfirmationTimeout",
				ITEM_LOCKED = "ItemLocked";
				ITEM_LOCKED = "ItemLocked",
				ITEM_REFERENCED = "ItemReferenced";
		// @formatter:on
	}

+16 −0
Original line number Diff line number Diff line
package es.redmic.commandslib.exceptions;

import java.util.Arrays;

import es.redmic.exception.common.BadRequestException;

public class ItemReferencedException extends BadRequestException {

	private static final long serialVersionUID = 1L;

	public ItemReferencedException(String field, String value) {

		super(ExceptionType.ITEM_REFERENCED);
		setFieldErrors(Arrays.asList(field, value));
	}
}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -2,3 +2,4 @@
HistoryNotFound=Error. Operation {0} for id {1} could not be performed because there is no event history for this item.
ConfirmationTimeout=Error. It has not received confirmation of the action receive.
ItemLocked=Error. Item with {0} equal to {1} is locked by an edition.
ItemReferenced=Error. Item with {0} equal to {1} is referenced in another document. It's necessary to delete the references before deleting the element.
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -2,3 +2,4 @@
HistoryNotFound=Error. No se ha podido realizar la operación {0} para el id {1} debido a que no se encuentra historial de eventos para este item.
ConfirmationTimeout=Error. No se ha recibido confirmación de la acción realizada.
ItemLocked=Error. El elemento con {0} igual a {1} está bloqueado por una edición.
ItemReferenced=Error. El elemento con {0} igual a {1} está referenciado en otro documento. Es necesario borrar las referencias antes de borrar el elemento.
 No newline at end of file
+23 −0
Original line number Diff line number Diff line
package es.redmic.commandslib.exceptions;

import java.io.IOException;
import java.util.Arrays;

import org.junit.Test;

public class ItemReferencedExceptionTest extends BaseExceptionTest {

	@Test
	public void checkPattern_IsEqualToMessage_WhenNoLocaleSet() throws IOException {

		// @formatter:off

		String field = "id",
				value = "23233";
		
		// @formatter:on

		checkMessage(new ItemReferencedException(field, value), ExceptionType.ITEM_REFERENCED.toString(),
				Arrays.asList(field, value));
	}
}
 No newline at end of file