-
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.
🐛 [REST API] Added missing mappings for ServiceConfigurationLimitExce…
…ededException Exception Mapper Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
- Loading branch information
Showing
2 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...eclipse/kapua/commons/rest/errors/ServiceConfigurationUpdateForbiddenExceptionMapper.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,47 @@ | ||
/******************************************************************************* | ||
* 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.configuration.exception.ServiceConfigurationForbiddenException; | ||
import org.eclipse.kapua.commons.rest.model.errors.ServiceConfigurationUpdateForbiddenExceptionInfo; | ||
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 ServiceConfigurationUpdateForbiddenExceptionMapper implements ExceptionMapper<ServiceConfigurationForbiddenException> { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(ServiceConfigurationUpdateForbiddenExceptionMapper.class); | ||
|
||
private final boolean showStackTrace; | ||
|
||
@Inject | ||
public ServiceConfigurationUpdateForbiddenExceptionMapper(ExceptionConfigurationProvider exceptionConfigurationProvider) { | ||
this.showStackTrace = exceptionConfigurationProvider.showStackTrace(); | ||
} | ||
|
||
@Override | ||
public Response toResponse(ServiceConfigurationForbiddenException serviceConfigurationForbiddenException) { | ||
LOG.error(serviceConfigurationForbiddenException.getMessage(), serviceConfigurationForbiddenException); | ||
|
||
return Response | ||
.status(Status.FORBIDDEN) | ||
.entity(new ServiceConfigurationUpdateForbiddenExceptionInfo(serviceConfigurationForbiddenException, showStackTrace)) | ||
.build(); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...pse/kapua/commons/rest/model/errors/ServiceConfigurationUpdateForbiddenExceptionInfo.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,107 @@ | ||
/******************************************************************************* | ||
* 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.model.errors; | ||
|
||
import org.eclipse.kapua.commons.configuration.exception.ServiceConfigurationForbiddenException; | ||
import org.eclipse.kapua.model.config.metatype.KapuaTad; | ||
import org.eclipse.kapua.model.id.KapuaId; | ||
import org.eclipse.kapua.model.id.KapuaIdAdapter; | ||
import org.eclipse.kapua.service.config.KapuaConfigurableService; | ||
|
||
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 = "serviceConfigurationUpdateForbiddenExceptionInfo") | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
public class ServiceConfigurationUpdateForbiddenExceptionInfo extends ExceptionInfo { | ||
|
||
@XmlElement(name = "scopeId") | ||
@XmlJavaTypeAdapter(KapuaIdAdapter.class) | ||
private KapuaId scopeId; | ||
|
||
@XmlElement(name = "servicePid") | ||
private String servicePid; | ||
|
||
@XmlElement(name = "propertyId") | ||
private String propertyId; | ||
|
||
@XmlElement(name = "propertyValue") | ||
private String propertyValue; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @since 2.1.0 | ||
*/ | ||
protected ServiceConfigurationUpdateForbiddenExceptionInfo() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param serviceConfigurationForbiddenException The original exception. | ||
* @since 2.1.0 | ||
*/ | ||
public ServiceConfigurationUpdateForbiddenExceptionInfo(ServiceConfigurationForbiddenException serviceConfigurationForbiddenException, boolean showStackTrace) { | ||
super(403/*Response.Status.FORBIDDEN*/, serviceConfigurationForbiddenException, showStackTrace); | ||
|
||
this.servicePid = serviceConfigurationForbiddenException.getServicePid(); | ||
this.scopeId = serviceConfigurationForbiddenException.getScopeId(); | ||
this.propertyId = serviceConfigurationForbiddenException.getPropertyId(); | ||
this.propertyValue = serviceConfigurationForbiddenException.getPropertyValue(); | ||
} | ||
|
||
/** | ||
* Gets the scope {@link KapuaId} for which the update is forbidden. | ||
* | ||
* @return The scope {@link KapuaId} for which the update is forbidden. | ||
* @since 2.1.0 | ||
*/ | ||
public KapuaId getScopeId() { | ||
return scopeId; | ||
} | ||
|
||
/** | ||
* Gets the {@link KapuaConfigurableService} pid. | ||
* | ||
* @return he {@link KapuaConfigurableService} pid. | ||
* @since 2.1.0 | ||
*/ | ||
public String getServicePid() { | ||
return servicePid; | ||
} | ||
|
||
/** | ||
* Gets the {@link KapuaTad#getId()} for which the update is forbidden. | ||
* | ||
* @return The {@link KapuaTad#getId()} for which the update is forbidden. | ||
* @since 2.1.0 | ||
*/ | ||
public String getPropertyId() { | ||
return propertyId; | ||
} | ||
|
||
/** | ||
* Gets the {@link KapuaTad} value for which the update is forbidden. | ||
* | ||
* @return The {@link KapuaTad} value for which the update is forbidden. | ||
* @since 2.1.0 | ||
*/ | ||
public String getPropertyValue() { | ||
return propertyValue; | ||
} | ||
} |