Search in sources :

Example 1 with TenantResourceManagementClientException

use of org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementClientException in project identity-api-server by wso2.

the class NotificationSenderManagementService method handleTenantResourceManagementException.

private APIError handleTenantResourceManagementException(TenantResourceManagementException e, NotificationSenderManagementConstants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
    Response.Status status;
    if (e instanceof TenantResourceManagementClientException) {
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorCode = errorCode.contains(CONFIG_MGT_ERROR_CODE_DELIMITER) ? errorCode : NOTIFICATION_SENDER_ERROR_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.BAD_REQUEST;
    } else if (e instanceof TenantResourceManagementServerException) {
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorCode = errorCode.contains(CONFIG_MGT_ERROR_CODE_DELIMITER) ? errorCode : NOTIFICATION_SENDER_ERROR_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    } else {
        status = Response.Status.INTERNAL_SERVER_ERROR;
    }
    return new APIError(status, errorResponse);
}
Also used : Response(javax.ws.rs.core.Response) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) TenantResourceManagementServerException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementServerException) TenantResourceManagementClientException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementClientException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 2 with TenantResourceManagementClientException

use of org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementClientException in project identity-governance by wso2-extensions.

the class ResourceManagerImpl method removeEventPublisherConfiguration.

@Override
public void removeEventPublisherConfiguration(String resourceTypeName, String resourceName) throws TenantResourceManagementException {
    try {
        Resource resource = TenantResourceManagerDataHolder.getInstance().getConfigurationManager().getResource(resourceTypeName, resourceName);
        ResourceFile resourceFile = resource.getFiles().get(0);
        InputStream publisherConfig = TenantResourceManagerDataHolder.getInstance().getConfigurationManager().getFileById(PUBLISHER, resourceFile.getName(), resourceFile.getId());
        EventPublisherService carbonEventPublisherService = TenantResourceManagerDataHolder.getInstance().getCarbonEventPublisherService();
        EventPublisherConfiguration eventPublisherConfiguration = carbonEventPublisherService.getEventPublisherConfiguration(publisherConfig);
        if (TenantResourceManagerDataHolder.getInstance().getCarbonEventPublisherService().getActiveEventPublisherConfiguration(eventPublisherConfiguration.getEventPublisherName()) != null) {
            destroyEventPublisherConfiguration(eventPublisherConfiguration);
            // Since the tenant event publisher was removed, we should load super tenant configs.
            loadSuperTenantEventPublisherConfigs();
        }
    } catch (ConfigurationManagementException e) {
        if (e instanceof ConfigurationManagementClientException && e.getErrorCode().equals(ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCE_DOES_NOT_EXISTS.getCode())) {
            throw new TenantResourceManagementClientException(e.getMessage(), e.getErrorCode());
        }
        throw handleServerException(ERROR_CODE_ERROR_WHEN_FETCHING_EVENT_PUBLISHER_RESOURCE, e, resourceName, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
    } catch (EventPublisherConfigurationException e) {
        throw handleServerException(ERROR_CODE_ERROR_WHEN_DEPLOYING_EVENT_PUBLISHER_CONFIGURATION, e, resourceName);
    }
}
Also used : ResourceFile(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile) InputStream(java.io.InputStream) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) EventPublisherConfiguration(org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration) TenantResourceManagementClientException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementClientException) EventPublisherService(org.wso2.carbon.event.publisher.core.EventPublisherService) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) ConfigurationManagementClientException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementClientException) EventPublisherConfigurationException(org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException)

Aggregations

TenantResourceManagementClientException (org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementClientException)2 InputStream (java.io.InputStream)1 Response (javax.ws.rs.core.Response)1 EventPublisherService (org.wso2.carbon.event.publisher.core.EventPublisherService)1 EventPublisherConfiguration (org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration)1 EventPublisherConfigurationException (org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException)1 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)1 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)1 ConfigurationManagementClientException (org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementClientException)1 ConfigurationManagementException (org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException)1 Resource (org.wso2.carbon.identity.configuration.mgt.core.model.Resource)1 ResourceFile (org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile)1 TenantResourceManagementServerException (org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementServerException)1