Search in sources :

Example 81 with APIMgtResourceNotFoundException

use of org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.

the class ImportUtils method retrieveApiProductToOverwrite.

/**
 * This method retrieves an API Product to overwrite in the current tenant domain.
 *
 * @param apiProductName      API Product Name
 * @param currentTenantDomain Current tenant domain
 * @param apiProvider         API Provider
 * @param ignoreAndImport     This should be true if the exception should be ignored
 * @param organization        Identifier of the organization
 * @throws APIManagementException If an error occurs when retrieving the API to overwrite
 */
private static APIProduct retrieveApiProductToOverwrite(String apiProductName, String currentTenantDomain, APIProvider apiProvider, Boolean ignoreAndImport, String organization) throws APIManagementException {
    String provider = APIUtil.getAPIProviderFromAPINameVersionTenant(apiProductName, ImportExportConstants.DEFAULT_API_PRODUCT_VERSION, currentTenantDomain);
    APIProductIdentifier apiProductIdentifier = new APIProductIdentifier(APIUtil.replaceEmailDomain(provider), apiProductName, ImportExportConstants.DEFAULT_API_PRODUCT_VERSION);
    // Checking whether the API exists
    if (!apiProvider.isAPIProductAvailable(apiProductIdentifier, organization)) {
        if (ignoreAndImport) {
            return null;
        }
        throw new APIMgtResourceNotFoundException("Error occurred while retrieving the API Product. API Product: " + apiProductName + StringUtils.SPACE + APIConstants.API_DATA_VERSION + ": " + ImportExportConstants.DEFAULT_API_PRODUCT_VERSION + " not found");
    }
    return apiProvider.getAPIProduct(apiProductIdentifier);
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)

Example 82 with APIMgtResourceNotFoundException

use of org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.

the class RestApiUtilTest method testIsDueToResourceNotFoundWithAPIMgtResourceNotFoundException.

// TODO : The passed error message will not get displayed in the thrown exception. Implementation in
// InternalServerErrorException class is not done right to reflect the error message description
// @Test
// public void testHandleInternalServerError() {
// String errorMessage = "Error while updating application owner.";
// Throwable throwable = new Throwable();
// Exception exceptionCaught = null;
// 
// Log log = Mockito.mock(Log.class);
// PowerMockito.mockStatic(LogFactory.class);
// PowerMockito.when(LogFactory.getLog(Mockito.any(Class.class))).thenReturn(log);
// 
// try {
// RestApiUtil.handleInternalServerError(errorMessage, throwable, log);
// } catch (InternalServerErrorException exception) {
// exceptionCaught = exception;
// }
// 
// Assert.assertEquals(errorMessage, exceptionCaught.getMessage());
// Mockito.verify(log).error(errorMessage, throwable);
// }
@Test
public void testIsDueToResourceNotFoundWithAPIMgtResourceNotFoundException() throws Exception {
    APIMgtResourceNotFoundException sampleAPIMgtResourceNotFoundException = new APIMgtResourceNotFoundException("New Sample exception");
    Throwable testThrowable = new Throwable();
    PowerMockito.spy(RestApiUtil.class);
    PowerMockito.doReturn(sampleAPIMgtResourceNotFoundException).when(RestApiUtil.class, "getPossibleErrorCause", testThrowable);
    Assert.assertTrue("Invalid exception has been passed.", RestApiUtil.isDueToResourceNotFound(testThrowable));
}
Also used : APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 83 with APIMgtResourceNotFoundException

use of org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.

the class APIProviderImpl method setThumbnailToAPI.

@Override
public void setThumbnailToAPI(String apiId, ResourceFile resource, String organization) throws APIManagementException {
    try {
        org.wso2.carbon.apimgt.persistence.dto.ResourceFile iconResourceFile = new org.wso2.carbon.apimgt.persistence.dto.ResourceFile(resource.getContent(), resource.getContentType());
        apiPersistenceInstance.saveThumbnail(new Organization(organization), apiId, iconResourceFile);
    } catch (ThumbnailPersistenceException e) {
        if (e.getErrorHandler() == ExceptionCodes.API_NOT_FOUND) {
            throw new APIMgtResourceNotFoundException(e);
        } else {
            throw new APIManagementException("Error while saving thumbnail ", e);
        }
    }
}
Also used : ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ThumbnailPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.ThumbnailPersistenceException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)

Example 84 with APIMgtResourceNotFoundException

use of org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.

the class APIProviderImpl method getApiSpecificMediationPolicyByPolicyId.

@Override
public Mediation getApiSpecificMediationPolicyByPolicyId(String apiId, String policyId, String organization) throws APIManagementException {
    try {
        org.wso2.carbon.apimgt.persistence.dto.Mediation policy = apiPersistenceInstance.getMediationPolicy(new Organization(organization), apiId, policyId);
        if (policy != null) {
            Mediation mediation = new Mediation();
            mediation.setName(policy.getName());
            mediation.setUuid(policy.getId());
            mediation.setType(policy.getType());
            mediation.setConfig(policy.getConfig());
            return mediation;
        }
    } catch (MediationPolicyPersistenceException e) {
        if (e.getErrorHandler() == ExceptionCodes.API_NOT_FOUND) {
            throw new APIMgtResourceNotFoundException(e);
        } else {
            throw new APIManagementException("Error while accessing mediation policies ", e);
        }
    }
    return null;
}
Also used : Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) MediationPolicyPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.MediationPolicyPersistenceException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) Mediation(org.wso2.carbon.apimgt.api.model.Mediation)

Example 85 with APIMgtResourceNotFoundException

use of org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.

the class APIProviderImpl method getSharedScopeByUUID.

/**
 * Get shared scope by UUID.
 *
 * @param sharedScopeId Shared scope Id
 * @param tenantDomain  tenant domain
 * @return Shared Scope
 * @throws APIManagementException If failed to get the scope
 */
@Override
public Scope getSharedScopeByUUID(String sharedScopeId, String tenantDomain) throws APIManagementException {
    Scope sharedScope;
    if (log.isDebugEnabled()) {
        log.debug("Retrieving shared scope: " + sharedScopeId);
    }
    String scopeKey = ApiMgtDAO.getInstance().getSharedScopeKeyByUUID(sharedScopeId);
    if (scopeKey != null) {
        sharedScope = scopesDAO.getScope(scopeKey, APIUtil.getTenantIdFromTenantDomain(tenantDomain));
        sharedScope.setId(sharedScopeId);
    } else {
        throw new APIMgtResourceNotFoundException("Shared Scope not found for scope ID: " + sharedScopeId, ExceptionCodes.from(ExceptionCodes.SHARED_SCOPE_NOT_FOUND, sharedScopeId));
    }
    return sharedScope;
}
Also used : Scope(org.wso2.carbon.apimgt.api.model.Scope) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)

Aggregations

APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)67 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)48 API (org.wso2.carbon.apimgt.api.model.API)22 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)22 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)22 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)21 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)21 HashMap (java.util.HashMap)19 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)19 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)17 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)16 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)14 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)14 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)12 APIRevision (org.wso2.carbon.apimgt.api.model.APIRevision)11 DeployedAPIRevision (org.wso2.carbon.apimgt.api.model.DeployedAPIRevision)11 APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)10 ParseException (org.json.simple.parser.ParseException)9 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)9 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)8