Skip to content

Commit

Permalink
Added ServiceConfigurationLimitExceeded Exception Mappers
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 Aug 25, 2022
1 parent c6cf146 commit 2ce5789
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<ServiceConfigurationLimitExceededException> {

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();
}
}
Original file line number Diff line number Diff line change
@@ -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<ServiceConfigurationParentLimitExceededException> {

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();
}
}
Original file line number Diff line number Diff line change
@@ -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);

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;
}
}
Original file line number Diff line number Diff line change
@@ -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);

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -373,6 +375,10 @@ public JaxbContextResolver() {
DeviceManagementTimeoutExceptionInfo.class,
DeviceNotConnectedExceptionInfo.class,

// Service Configuration Exception Info
ServiceConfigurationLimitExceededExceptionInfo.class,
ServiceConfigurationParentLimitExceededExceptionInfo.class,

// Commons
KapuaSerializable.class,

Expand Down

0 comments on commit 2ce5789

Please sign in to comment.