Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [Service] Added KapuaFeatureDisabledException #4192

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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