-
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.
✨ [Service] Added KapuaFeatureDisabledException
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
- Loading branch information
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
.../main/java/org/eclipse/kapua/commons/rest/errors/KapuaFeatureDisabledExceptionMapper.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,53 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025, 2025 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.ExceptionInfo; | ||
import org.eclipse.kapua.commons.service.internal.KapuaServiceDisabledException; | ||
import org.eclipse.kapua.exception.KapuaFeatureDisabledException; | ||
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; | ||
|
||
/** | ||
* {@link KapuaFeatureDisabledException}'s {@link ExceptionMapper} | ||
* | ||
* @since 2.1.0 | ||
*/ | ||
@Provider | ||
public class KapuaFeatureDisabledExceptionMapper implements ExceptionMapper<KapuaFeatureDisabledException> { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(KapuaServiceDisabledException.class); | ||
|
||
private static final Status STATUS = Status.FORBIDDEN; | ||
|
||
@Inject | ||
public ExceptionConfigurationProvider exceptionConfigurationProvider; | ||
|
||
@Override | ||
public Response toResponse(KapuaFeatureDisabledException kapuaFeatureDisabledException) { | ||
LOG.error(kapuaFeatureDisabledException.getMessage(), kapuaFeatureDisabledException); | ||
|
||
boolean showStackTrace = exceptionConfigurationProvider.showStackTrace(); | ||
return Response | ||
.status(STATUS) | ||
.entity(new ExceptionInfo(STATUS.getStatusCode(), kapuaFeatureDisabledException, 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
48 changes: 48 additions & 0 deletions
48
service/api/src/main/java/org/eclipse/kapua/exception/KapuaFeatureDisabledException.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,48 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025, 2025 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.exception; | ||
|
||
import org.eclipse.kapua.KapuaErrorCodes; | ||
import org.eclipse.kapua.KapuaException; | ||
import org.eclipse.kapua.model.id.KapuaId; | ||
import org.eclipse.kapua.service.KapuaService; | ||
|
||
/** | ||
* {@link KapuaException} to throw when a {@link KapuaService} feature is disabled per {@link KapuaService} configuration or by other means/ | ||
* | ||
* @since 2.1.0 | ||
*/ | ||
public class KapuaFeatureDisabledException extends KapuaException { | ||
|
||
private final KapuaId scopeId; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @since 2.1.0 | ||
*/ | ||
public KapuaFeatureDisabledException(KapuaId scopeId) { | ||
super(KapuaErrorCodes.SERVICE_DISABLED, scopeId); | ||
|
||
this.scopeId = scopeId; | ||
} | ||
|
||
/** | ||
* Gets the Account.id for which the feature is disabled | ||
* | ||
* @return The Account.id for which the feature is disabled | ||
*/ | ||
public KapuaId getScopeId() { | ||
return scopeId; | ||
} | ||
} |
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