Add not found DS test & improve EntityNotFoundException (#1896)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -13,15 +13,16 @@ import java.io.Serial;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
|
||||
/**
|
||||
* the {@link EntityNotFoundException} is thrown when a entity queried but not
|
||||
* found.
|
||||
* the {@link EntityNotFoundException} is thrown when a entity queried but not found.
|
||||
*/
|
||||
@Getter
|
||||
public class EntityNotFoundException extends AbstractServerRtException {
|
||||
|
||||
@Serial
|
||||
@@ -29,6 +30,10 @@ public class EntityNotFoundException extends AbstractServerRtException {
|
||||
|
||||
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_ENTITY_NOT_EXISTS;
|
||||
|
||||
private Class<?> type;
|
||||
private Object entityId;
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
@@ -39,8 +44,7 @@ public class EntityNotFoundException extends AbstractServerRtException {
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
* @param cause
|
||||
* of the exception
|
||||
* @param cause of the exception
|
||||
*/
|
||||
public EntityNotFoundException(final Throwable cause) {
|
||||
super(THIS_ERROR, cause);
|
||||
@@ -49,10 +53,8 @@ public class EntityNotFoundException extends AbstractServerRtException {
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
* @param message
|
||||
* of the exception
|
||||
* @param cause
|
||||
* of the exception
|
||||
* @param message of the exception
|
||||
* @param cause of the exception
|
||||
*/
|
||||
public EntityNotFoundException(final String message, final Throwable cause) {
|
||||
super(message, THIS_ERROR, cause);
|
||||
@@ -61,8 +63,7 @@ public class EntityNotFoundException extends AbstractServerRtException {
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
* @param message
|
||||
* of the exception
|
||||
* @param message of the exception
|
||||
*/
|
||||
protected EntityNotFoundException(final String message) {
|
||||
super(message, THIS_ERROR);
|
||||
@@ -71,59 +72,55 @@ public class EntityNotFoundException extends AbstractServerRtException {
|
||||
/**
|
||||
* Parameterized constructor for {@link BaseEntity} not found.
|
||||
*
|
||||
* @param type
|
||||
* of the entity that was not found
|
||||
*
|
||||
* @param entityId
|
||||
* of the {@link BaseEntity}
|
||||
* @param type of the entity that was not found
|
||||
* @param entityId of the {@link BaseEntity}
|
||||
*/
|
||||
public EntityNotFoundException(final Class<? extends BaseEntity> type, final Object entityId) {
|
||||
this(type.getSimpleName() + " with given identifier {" + entityId + "} does not exist.");
|
||||
super(type.getSimpleName() + " with given identifier {" + entityId + "} does not exist.", THIS_ERROR);
|
||||
this.type = type;
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameterized constructor for {@link MetaData} not found.
|
||||
*
|
||||
* @param type
|
||||
* of the entity that was not found
|
||||
* @param entityId
|
||||
* of the {@link BaseEntity} the {@link MetaData} was for
|
||||
* @param key
|
||||
* for the {@link MetaData} entry
|
||||
* @param type of the entity that was not found
|
||||
* @param entityId of the {@link BaseEntity} the {@link MetaData} was for
|
||||
* @param key for the {@link MetaData} entry
|
||||
*/
|
||||
public EntityNotFoundException(final Class<? extends MetaData> type, final Long entityId, final String key) {
|
||||
this(type, String.valueOf(entityId), key);
|
||||
this.type = type;
|
||||
this.entityId = entityId;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameterized constructor for {@link MetaData} not found.
|
||||
*
|
||||
* @param type
|
||||
* of the entity that was not found
|
||||
* @param entityId
|
||||
* of the {@link BaseEntity} the {@link MetaData} was for
|
||||
* @param key
|
||||
* for the {@link MetaData} entry
|
||||
* @param type of the entity that was not found
|
||||
* @param entityId of the {@link BaseEntity} the {@link MetaData} was for
|
||||
* @param key for the {@link MetaData} entry
|
||||
*/
|
||||
public EntityNotFoundException(final Class<? extends MetaData> type, final String entityId, final String key) {
|
||||
this(type.getSimpleName() + " for given entity {" + entityId + "} and with key {" + key + "} does not exist.");
|
||||
this.type = type;
|
||||
this.entityId = entityId;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameterized constructor for a list of {@link BaseEntity}s not found.
|
||||
*
|
||||
* @param type
|
||||
* of the entity that was not found
|
||||
*
|
||||
* @param expected
|
||||
* collection of the {@link BaseEntity#getId()}s
|
||||
* @param found
|
||||
* collection of the {@link BaseEntity#getId()}s
|
||||
* @param type of the entity that was not found
|
||||
* @param expected collection of the {@link BaseEntity#getId()}s
|
||||
* @param found collection of the {@link BaseEntity#getId()}s
|
||||
*/
|
||||
public EntityNotFoundException(final Class<? extends BaseEntity> type, final Collection<?> expected,
|
||||
final Collection<?> found) {
|
||||
this(type.getSimpleName() + "s with given identifiers {" + expected.stream().filter(id -> !found.contains(id))
|
||||
.map(String::valueOf).collect(Collectors.joining(",")) + "} do not exist.");
|
||||
this.type = type;
|
||||
this.entityId = expected.stream().filter(id -> !found.contains(id)).map(String::valueOf);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user