-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
… resources Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
- Loading branch information
There are no files selected for viewing
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); | ||
Check warning on line 29 in commons-rest/errors/src/main/java/org/eclipse/kapua/commons/rest/errors/StorableNotFoundExceptionMapper.java Codecov / codecov/patchcommons-rest/errors/src/main/java/org/eclipse/kapua/commons/rest/errors/StorableNotFoundExceptionMapper.java#L29
|
||
|
||
private final boolean showStackTrace; | ||
|
||
@Inject | ||
public StorableNotFoundExceptionMapper(ExceptionConfigurationProvider exceptionConfigurationProvider) { | ||
this.showStackTrace = exceptionConfigurationProvider.showStackTrace(); | ||
} | ||
Check warning on line 36 in commons-rest/errors/src/main/java/org/eclipse/kapua/commons/rest/errors/StorableNotFoundExceptionMapper.java Codecov / codecov/patchcommons-rest/errors/src/main/java/org/eclipse/kapua/commons/rest/errors/StorableNotFoundExceptionMapper.java#L34-L36
|
||
|
||
@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(); | ||
Check warning on line 44 in commons-rest/errors/src/main/java/org/eclipse/kapua/commons/rest/errors/StorableNotFoundExceptionMapper.java Codecov / codecov/patchcommons-rest/errors/src/main/java/org/eclipse/kapua/commons/rest/errors/StorableNotFoundExceptionMapper.java#L40-L44
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/******************************************************************************* | ||
* 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.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 1.0.0 | ||
*/ | ||
protected StorableNotFoundExceptionInfo() { | ||
super(); | ||
} | ||
Check warning on line 43 in commons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java Codecov / codecov/patchcommons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java#L42-L43
|
||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param httpStatusCode The http status code of the response containing this info | ||
* @param storableNotFoundException The {@link StorableNotFoundException}. | ||
* @since 1.0.0 | ||
*/ | ||
public StorableNotFoundExceptionInfo(int httpStatusCode, StorableNotFoundException storableNotFoundException, boolean showStackTrace) { | ||
super(httpStatusCode, storableNotFoundException, showStackTrace); | ||
Check warning on line 53 in commons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java Codecov / codecov/patchcommons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java#L53
|
||
|
||
this.storableType = storableNotFoundException.getStorableType(); | ||
this.storableId = storableNotFoundException.getStorableId(); | ||
} | ||
Check warning on line 57 in commons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java Codecov / codecov/patchcommons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java#L55-L57
|
||
|
||
/** | ||
* Gets the {@link StorableNotFoundException#getStorableType()} | ||
* | ||
* @return The {@link StorableNotFoundException#getStorableType()}. | ||
* @since 2.0.0 | ||
*/ | ||
public String getEntityType() { | ||
return storableType; | ||
Check warning on line 66 in commons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java Codecov / codecov/patchcommons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java#L66
|
||
} | ||
|
||
/** | ||
* Gets the {@link StorableNotFoundException#getStorableId()}. | ||
* | ||
* @return The {@link StorableNotFoundException#getStorableId()}. | ||
* @since 2.0.0 | ||
*/ | ||
public StorableId getStorableId() { | ||
return storableId; | ||
Check warning on line 76 in commons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java Codecov / codecov/patchcommons-rest/model/src/main/java/org/eclipse/kapua/commons/rest/model/errors/StorableNotFoundExceptionInfo.java#L76
|
||
} | ||
} |