-
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.
Merge branch 'backport-4167' into release-2.0.x
- Loading branch information
Showing
8 changed files
with
122 additions
and
8 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...g/eclipse/kapua/commons/rest/errors/KapuaIntegrityConstraintViolationExceptionMapper.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,44 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2018, 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.kapuaIntegrityConstraintViolationException; | ||
import org.eclipse.kapua.commons.rest.model.errors.ExceptionInfo; | ||
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 KapuaIntegrityConstraintViolationExceptionMapper implements ExceptionMapper<kapuaIntegrityConstraintViolationException> { | ||
private static final Logger LOG = LoggerFactory.getLogger(kapuaIntegrityConstraintViolationException.class); | ||
|
||
private static final Status STATUS = Status.CONFLICT; | ||
@Inject | ||
public ExceptionConfigurationProvider exceptionConfigurationProvider; | ||
|
||
@Override | ||
public Response toResponse(kapuaIntegrityConstraintViolationException kapuaIntegrityConstraintViolationException) { | ||
final boolean showStackTrace = exceptionConfigurationProvider.showStackTrace(); | ||
LOG.error(kapuaIntegrityConstraintViolationException.getMessage(), kapuaIntegrityConstraintViolationException); | ||
return Response | ||
.status(STATUS) | ||
.entity(new ExceptionInfo(STATUS.getStatusCode(), kapuaIntegrityConstraintViolationException, 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
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
39 changes: 39 additions & 0 deletions
39
service/api/src/main/java/org/eclipse/kapua/kapuaIntegrityConstraintViolationException.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,39 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016, 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; | ||
|
||
/** | ||
* kapuaIntegrityConstraintViolationException is thrown when the integrity constraints of the underlying datastore have been violated | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public class kapuaIntegrityConstraintViolationException extends KapuaException { | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public kapuaIntegrityConstraintViolationException() { | ||
super(KapuaErrorCodes.DATASTORE_INTEGRITY_VIOLATION); | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public kapuaIntegrityConstraintViolationException(String detailedMessage) { | ||
super(KapuaErrorCodes.DATASTORE_INTEGRITY_VIOLATION, detailedMessage); | ||
} | ||
} |
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