From 8bc723ac91e564ff5755a05bb82b4db1a1222693 Mon Sep 17 00:00:00 2001 From: Alberto Codutti Date: Mon, 3 Jun 2024 16:11:13 +0200 Subject: [PATCH] asd Signed-off-by: Alberto Codutti --- .../StorableNotFoundExceptionMapper.java | 46 ----------- .../errors/StorableNotFoundExceptionInfo.java | 78 ------------------- .../core/resources/AbstractKapuaResource.java | 33 ++++---- .../resources/v1/resources/DataChannels.java | 2 +- .../exception/StorableErrorCodes.java | 7 -- .../exception/StorableNotFoundException.java | 62 --------------- 6 files changed, 15 insertions(+), 213 deletions(-) delete mode 100644 commons-rest/errors/src/main/java/org/eclipse/kapua/commons/rest/errors/StorableNotFoundExceptionMapper.java delete mode 100644 commons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java delete mode 100644 service/commons/storable/api/src/main/java/org/eclipse/kapua/service/storable/exception/StorableNotFoundException.java diff --git a/commons-rest/errors/src/main/java/org/eclipse/kapua/commons/rest/errors/StorableNotFoundExceptionMapper.java b/commons-rest/errors/src/main/java/org/eclipse/kapua/commons/rest/errors/StorableNotFoundExceptionMapper.java deleted file mode 100644 index febe55d65d4..00000000000 --- a/commons-rest/errors/src/main/java/org/eclipse/kapua/commons/rest/errors/StorableNotFoundExceptionMapper.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.rest.errors; - -import org.eclipse.kapua.commons.rest.model.errors.StorableNotFoundExceptionInfo; -import org.eclipse.kapua.service.storable.exception.StorableNotFoundException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -@Provider -public class StorableNotFoundExceptionMapper implements ExceptionMapper { - - private static final Logger LOG = LoggerFactory.getLogger(StorableNotFoundExceptionMapper.class); - - private final boolean showStackTrace; - - @Inject - public StorableNotFoundExceptionMapper(ExceptionConfigurationProvider exceptionConfigurationProvider) { - this.showStackTrace = exceptionConfigurationProvider.showStackTrace(); - } - - @Override - public Response toResponse(StorableNotFoundException kapuaEntityNotFoundException) { - LOG.error(kapuaEntityNotFoundException.getMessage(), kapuaEntityNotFoundException); - return Response - .status(Status.NOT_FOUND) - .entity(new StorableNotFoundExceptionInfo(Status.NOT_FOUND.getStatusCode(), kapuaEntityNotFoundException, showStackTrace)) - .build(); - } -} diff --git a/commons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java b/commons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java deleted file mode 100644 index 08e06a39f7c..00000000000 --- a/commons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2024, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.rest.model.errors; - -import org.eclipse.kapua.model.id.KapuaIdAdapter; -import org.eclipse.kapua.service.storable.exception.StorableNotFoundException; -import org.eclipse.kapua.service.storable.model.id.StorableId; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; - -@XmlRootElement(name = "storableNotFoundExceptionInfo") -@XmlAccessorType(XmlAccessType.FIELD) -public class StorableNotFoundExceptionInfo extends ExceptionInfo { - - @XmlElement(name = "storableType") - private String storableType; - - @XmlElement(name = "storableId") - @XmlJavaTypeAdapter(KapuaIdAdapter.class) - private StorableId storableId; - - /** - * Constructor. - * - * @since 2.0.0 - */ - protected StorableNotFoundExceptionInfo() { - super(); - } - - /** - * Constructor. - * - * @param httpStatusCode The http status code of the response containing this info - * @param storableNotFoundException The {@link StorableNotFoundException}. - * @since 2.0.0 - */ - public StorableNotFoundExceptionInfo(int httpStatusCode, StorableNotFoundException storableNotFoundException, boolean showStackTrace) { - super(httpStatusCode, storableNotFoundException, showStackTrace); - - this.storableType = storableNotFoundException.getStorableType(); - this.storableId = storableNotFoundException.getStorableId(); - } - - /** - * Gets the {@link StorableNotFoundException#getStorableType()} - * - * @return The {@link StorableNotFoundException#getStorableType()}. - * @since 2.0.0 - */ - public String getEntityType() { - return storableType; - } - - /** - * Gets the {@link StorableNotFoundException#getStorableId()}. - * - * @return The {@link StorableNotFoundException#getStorableId()}. - * @since 2.0.0 - */ - public StorableId getStorableId() { - return storableId; - } -} diff --git a/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/resources/AbstractKapuaResource.java b/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/resources/AbstractKapuaResource.java index fbe6dc46aed..6b9e4b2f977 100644 --- a/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/resources/AbstractKapuaResource.java +++ b/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/resources/AbstractKapuaResource.java @@ -15,7 +15,6 @@ import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.model.KapuaEntity; import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.storable.exception.StorableNotFoundException; import org.eclipse.kapua.service.storable.model.Storable; import org.eclipse.kapua.service.storable.model.id.StorableId; @@ -64,34 +63,30 @@ public T returnNotNullEntity(T object) { * @since 2.0.0 */ public T returnNotNullEntity(T entity, String entityType, KapuaId entityId) throws KapuaEntityNotFoundException { - if (entity == null) { - throw new KapuaEntityNotFoundException(entityType, entityId); - } - - return entity; + return returnNotNullEntity(entity, entityType, entityId.getId().toString()); } /** - * Checks id the given {@link Storable} is {@code null}. - *

- * Similar to {@link #returnNotNullEntity(KapuaEntity, String, KapuaId)} but for {@link Storable}s. + * Checks id the given {@link Object} is {@code null}. * - * @param storable The {@link Storable} to check. - * @param storableType The {@link Storable#getType()} - * @param storableId The {@link StorableId} - * @return The given {@link Storable} if not {@code null} - * @param The type of the {@link Storable}. - * @throws StorableNotFoundException if given {@link Storable} is {@code null}. + * @param entity The {@link Object} to check. + * @param entityType The {@link Object} type. + * @param entityId The {@link Object} id. + * @return The given entity if not {@code null} + * @param The {@link Object} type. + * @throws KapuaEntityNotFoundException if given {@link Object} is {@code null}. * @since 2.0.0 */ - public T returnNotNullStorable(T storable, String storableType, StorableId storableId) throws StorableNotFoundException { - if (storable == null) { - throw new StorableNotFoundException(storableType, storableId); + public T returnNotNullEntity(T entity, String entityType, String entityId) throws KapuaEntityNotFoundException { + if (entity == null) { + throw new KapuaEntityNotFoundException(entityType, entityId); } - return storable; + return entity; } + + /** * Builds a 200 HTTP Response. * diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataChannels.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataChannels.java index 10ae28ef3d4..f28253390e0 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataChannels.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataChannels.java @@ -160,6 +160,6 @@ public ChannelInfo find(@PathParam("scopeId") ScopeId scopeId, throws KapuaException { ChannelInfo channelInfo = channelInfoRegistryService.find(scopeId, channelInfoId); - return returnNotNullStorable(channelInfo, ChannelInfo.TYPE, channelInfoId); + return returnNotNullEntity(channelInfo, ChannelInfo.TYPE, channelInfoId.getId()); } } diff --git a/service/commons/storable/api/src/main/java/org/eclipse/kapua/service/storable/exception/StorableErrorCodes.java b/service/commons/storable/api/src/main/java/org/eclipse/kapua/service/storable/exception/StorableErrorCodes.java index 0109b160d9b..1d73f27693b 100644 --- a/service/commons/storable/api/src/main/java/org/eclipse/kapua/service/storable/exception/StorableErrorCodes.java +++ b/service/commons/storable/api/src/main/java/org/eclipse/kapua/service/storable/exception/StorableErrorCodes.java @@ -34,11 +34,4 @@ public enum StorableErrorCodes implements KapuaErrorCode { * @since 1.3.0 */ UNSUPPORTED_TYPE, - - /** - * See {@link StorableNotFoundException} - * - * @since 2.0.0 - */ - STORABLE_NOT_FOUND } diff --git a/service/commons/storable/api/src/main/java/org/eclipse/kapua/service/storable/exception/StorableNotFoundException.java b/service/commons/storable/api/src/main/java/org/eclipse/kapua/service/storable/exception/StorableNotFoundException.java deleted file mode 100644 index f681c454f1d..00000000000 --- a/service/commons/storable/api/src/main/java/org/eclipse/kapua/service/storable/exception/StorableNotFoundException.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2024, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.storable.exception; - -import org.eclipse.kapua.KapuaException; -import org.eclipse.kapua.service.storable.model.Storable; -import org.eclipse.kapua.service.storable.model.id.StorableId; - -/** - * {@link StorableNotFoundException} is thrown when an {@link Storable} could not be loaded from the database. - * - * @since 2.0.0 - */ -public class StorableNotFoundException extends KapuaException { - - private final String storableType; - private final StorableId storableId; - - /** - * Constructor. - * - * @param storableType The {@link Storable#getType()}. - * @param storableId The {@link StorableId}. - * @since 2.0.0 - */ - public StorableNotFoundException(String storableType, StorableId storableId) { - super(StorableErrorCodes.STORABLE_NOT_FOUND, storableType, storableId); - - this.storableType = storableType; - this.storableId = storableId; - } - - /** - * Gets the {@link Storable#getType()}. - * - * @return The {@link Storable#getType()}. - * @since 2.0.0 - */ - public String getStorableType() { - return storableType; - } - - /** - * Gets the {@link StorableId}. - * - * @return The {@link StorableId}. - * @since 2.0.0 - */ - public StorableId getStorableId() { - return storableId; - } -}