-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ServiceConfigurationLimitExceeded Exception Mappers
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
- Loading branch information
Showing
5 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...eclipse/kapua/app/api/core/exception/mapper/ServiceConfigurationLimitExceptionMapper.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,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(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...e/kapua/app/api/core/exception/mapper/ServiceConfigurationParentLimitExceptionMapper.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,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(); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...se/kapua/app/api/core/exception/model/ServiceConfigurationLimitExceededExceptionInfo.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,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; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
...ua/app/api/core/exception/model/ServiceConfigurationParentLimitExceededExceptionInfo.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,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; | ||
} | ||
} |
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