Skip to content

Commit

Permalink
✨ [Service] Added KapuaFeatureDisabledException
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Feb 7, 2025
1 parent 004b364 commit 951927c
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ public enum KapuaErrorCodes implements KapuaErrorCode {
*/
SERVICE_DISABLED,

/**
* @see org.eclipse.kapua.exception.KapuaFeatureDisabledException
*
* @since 2.1.0
*/
FEATURE_DISABLED,

/**
* Some parsing failed for some reason
* @since 2.0.0
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ PERMISSION_DELETE_NOT_ALLOWED=Operation not allowed on this specific permission.
RESOURCE_RESTRICTED_TO_FIRST_LEVEL_ACCOUNTS=The resource {0} can only be created and managed in the first level accounts (direct child account of the Sys Admin Account).
RESOURCE_RESTRICTED_TO_SYS_ADMIN_ACCOUNT=The resource {0} can only be created and managed in the system administrator account.
SERVICE_DISABLED=The Service is disabled: {0}
FEATURE_DISABLED=This feature is disabled for Account: {0}
UNAUTHENTICATED=No authenticated Subject found in context.
# Deprecated codes
USER_ALREADY_RESERVED_BY_ANOTHER_CONNECTION=This user is already reserved for another connection. Please select different user for this connection.
Expand Down

0 comments on commit 951927c

Please sign in to comment.