diff --git a/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/exception/mapper/ServiceConfigurationLimitExceptionMapper.java b/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/exception/mapper/ServiceConfigurationLimitExceptionMapper.java new file mode 100644 index 00000000000..8e38d259616 --- /dev/null +++ b/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/exception/mapper/ServiceConfigurationLimitExceptionMapper.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 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.app.api.core.exception.mapper; + +import org.eclipse.kapua.app.api.core.exception.model.ServiceConfigurationLimitExceededExceptionInfo; +import org.eclipse.kapua.commons.configuration.exception.ServiceConfigurationLimitExceededException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +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 ServiceConfigurationLimitExceptionMapper implements ExceptionMapper { + + private static final Logger LOG = LoggerFactory.getLogger(ServiceConfigurationLimitExceptionMapper.class); + + @Override + public Response toResponse(ServiceConfigurationLimitExceededException serviceConfigurationLimitExceededException) { + LOG.error(serviceConfigurationLimitExceededException.getMessage(), serviceConfigurationLimitExceededException); + + return Response + .status(Status.BAD_REQUEST) + .entity(new ServiceConfigurationLimitExceededExceptionInfo(serviceConfigurationLimitExceededException)) + .build(); + } +} diff --git a/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/exception/mapper/ServiceConfigurationParentLimitExceptionMapper.java b/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/exception/mapper/ServiceConfigurationParentLimitExceptionMapper.java new file mode 100644 index 00000000000..5cc3e25a4b5 --- /dev/null +++ b/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/exception/mapper/ServiceConfigurationParentLimitExceptionMapper.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 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.app.api.core.exception.mapper; + +import org.eclipse.kapua.app.api.core.exception.model.ServiceConfigurationParentLimitExceededExceptionInfo; +import org.eclipse.kapua.commons.configuration.exception.ServiceConfigurationParentLimitExceededException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +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 ServiceConfigurationParentLimitExceptionMapper implements ExceptionMapper { + + private static final Logger LOG = LoggerFactory.getLogger(ServiceConfigurationParentLimitExceptionMapper.class); + + @Override + public Response toResponse(ServiceConfigurationParentLimitExceededException serviceConfigurationParentLimitExceededException) { + LOG.error(serviceConfigurationParentLimitExceededException.getMessage(), serviceConfigurationParentLimitExceededException); + + return Response + .status(Status.BAD_REQUEST) + .entity(new ServiceConfigurationParentLimitExceededExceptionInfo(serviceConfigurationParentLimitExceededException)) + .build(); + } +} diff --git a/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/exception/model/ServiceConfigurationLimitExceededExceptionInfo.java b/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/exception/model/ServiceConfigurationLimitExceededExceptionInfo.java new file mode 100644 index 00000000000..b2d0543ca11 --- /dev/null +++ b/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/exception/model/ServiceConfigurationLimitExceededExceptionInfo.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2021, 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.app.api.core.exception.model; + +import org.eclipse.kapua.commons.configuration.exception.ServiceConfigurationLimitExceededException; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.service.config.KapuaConfigurableService; + +import javax.ws.rs.core.Response; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "serviceConfigurationLimitExceededExceptionInfo") +@XmlAccessorType(XmlAccessType.FIELD) +public class ServiceConfigurationLimitExceededExceptionInfo extends ExceptionInfo { + + + @XmlElement(name = "servicePid") + private String servicePid; + + @XmlElement(name = "scopeId") + private KapuaId scopeId; + + @XmlElement(name = "limitExceededBy") + private long limitExceededBy; + + /** + * Constructor. + * + * @since 1.0.0 + */ + protected ServiceConfigurationLimitExceededExceptionInfo() { + super(); + } + + /** + * Constructor. + * + * @param serviceConfigurationLimitExceededException The root exception. + * @since 1.0.0 + */ + public ServiceConfigurationLimitExceededExceptionInfo(ServiceConfigurationLimitExceededException serviceConfigurationLimitExceededException) { + super(Response.Status.BAD_REQUEST, serviceConfigurationLimitExceededException.getCode(), serviceConfigurationLimitExceededException); + + this.servicePid = serviceConfigurationLimitExceededException.getServicePid(); + this.scopeId = serviceConfigurationLimitExceededException.getScopeId(); + this.limitExceededBy = serviceConfigurationLimitExceededException.getLimitExceededBy(); + } + + /** + * Gets the {@link KapuaConfigurableService} pid. + * + * @return he {@link KapuaConfigurableService} pid. + * @since 2.0.0 + */ + public String getServicePid() { + return servicePid; + } + + /** + * Gets the scope {@link KapuaId} for which limit has been exceeded. + * + * @return The scope {@link KapuaId} for which limit has been exceeded. + * @since 2.0.0 + */ + public KapuaId getScopeId() { + return scopeId; + } + + /** + * Gets the amount of exceed. + * + * @return the amount of exceed. + * @since 2.0.0 + */ + public long getLimitExceededBy() { + return limitExceededBy; + } +} diff --git a/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/exception/model/ServiceConfigurationParentLimitExceededExceptionInfo.java b/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/exception/model/ServiceConfigurationParentLimitExceededExceptionInfo.java new file mode 100644 index 00000000000..25c1ccae109 --- /dev/null +++ b/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/exception/model/ServiceConfigurationParentLimitExceededExceptionInfo.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2021, 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.app.api.core.exception.model; + +import org.eclipse.kapua.commons.configuration.exception.ServiceConfigurationParentLimitExceededException; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.service.config.KapuaConfigurableService; + +import javax.ws.rs.core.Response; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "serviceConfigurationParentLimitExceededExceptionInfo") +@XmlAccessorType(XmlAccessType.FIELD) +public class ServiceConfigurationParentLimitExceededExceptionInfo extends ExceptionInfo { + + + @XmlElement(name = "servicePid") + private String servicePid; + + @XmlElement(name = "parentScopeId") + + private KapuaId parentScopeId; + + @XmlElement(name = "limitExceededBy") + private long limitExceededBy; + + /** + * Constructor. + * + * @since 1.0.0 + */ + protected ServiceConfigurationParentLimitExceededExceptionInfo() { + super(); + } + + /** + * Constructor. + * + * @param serviceConfigurationParentLimitExceededException The root exception. + * @since 1.0.0 + */ + public ServiceConfigurationParentLimitExceededExceptionInfo(ServiceConfigurationParentLimitExceededException serviceConfigurationParentLimitExceededException) { + super(Response.Status.BAD_REQUEST, serviceConfigurationParentLimitExceededException.getCode(), serviceConfigurationParentLimitExceededException); + + this.servicePid = serviceConfigurationParentLimitExceededException.getServicePid(); + this.parentScopeId = serviceConfigurationParentLimitExceededException.getScopeId(); + this.limitExceededBy = serviceConfigurationParentLimitExceededException.getLimitExceededBy(); + } + + /** + * Gets the {@link KapuaConfigurableService} pid. + * + * @return he {@link KapuaConfigurableService} pid. + * @since 2.0.0 + */ + public String getServicePid() { + return servicePid; + } + + /** + * Gets the scope {@link KapuaId} for which limit has been exceeded. + * + * @return The parent scope {@link KapuaId} for which limit has been exceeded. + * @since 2.0.0 + */ + public KapuaId getParentScopeId() { + return parentScopeId; + } + + /** + * Gets the amount of exceed. + * + * @return the amount of exceed. + * @since 2.0.0 + */ + public long getLimitExceededBy() { + return limitExceededBy; + } +} diff --git a/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/JaxbContextResolver.java b/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/JaxbContextResolver.java index 4fe856418c9..bdfdaa79676 100644 --- a/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/JaxbContextResolver.java +++ b/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/JaxbContextResolver.java @@ -38,6 +38,8 @@ import org.eclipse.kapua.app.api.core.exception.model.JobStoppingExceptionInfo; import org.eclipse.kapua.app.api.core.exception.model.MfaRequiredExceptionInfo; import org.eclipse.kapua.app.api.core.exception.model.SelfManagedOnlyExceptionInfo; +import org.eclipse.kapua.app.api.core.exception.model.ServiceConfigurationLimitExceededExceptionInfo; +import org.eclipse.kapua.app.api.core.exception.model.ServiceConfigurationParentLimitExceededExceptionInfo; import org.eclipse.kapua.app.api.core.exception.model.SubjectUnauthorizedExceptionInfo; import org.eclipse.kapua.app.api.core.exception.model.ThrowableInfo; import org.eclipse.kapua.app.api.core.model.CountResult; @@ -373,6 +375,10 @@ public JaxbContextResolver() { DeviceManagementTimeoutExceptionInfo.class, DeviceNotConnectedExceptionInfo.class, + // Service Configuration Exception Info + ServiceConfigurationLimitExceededExceptionInfo.class, + ServiceConfigurationParentLimitExceededExceptionInfo.class, + // Commons KapuaSerializable.class,