-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [REST API] Implemented StorableNotFoundExceptionMapper and releated…
… resources Signed-off-by: Alberto Codutti <[email protected]>
- Loading branch information
Showing
12 changed files
with
169 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
.../src/main/java/org/eclipse/kapua/commons/rest/errors/StorableNotFoundExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/******************************************************************************* | ||
* 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<StorableNotFoundException> { | ||
|
||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
.../main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/******************************************************************************* | ||
* 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters