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);
}
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));
}
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);
}
}
}
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;
}
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;
}
Aggregations