use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class ApiCategoriesApiServiceImpl method apiCategoriesApiCategoryIdDelete.
@Override
public Response apiCategoriesApiCategoryIdDelete(String apiCategoryId, MessageContext messageContext) {
try {
APIAdmin apiAdmin = new APIAdminImpl();
String userName = RestApiCommonUtil.getLoggedInUsername();
apiAdmin.deleteCategory(apiCategoryId, userName);
return Response.ok().build();
} catch (APIManagementException e) {
String errorMessage = "Error while deleting API Category '" + apiCategoryId + "' - " + e.getMessage();
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class ApiCategoriesApiServiceImpl method apiCategoriesApiCategoryIdPut.
@Override
public Response apiCategoriesApiCategoryIdPut(String apiCategoryId, APICategoryDTO body, MessageContext messageContext) {
try {
APIAdmin apiAdmin = new APIAdminImpl();
String organization = RestApiUtil.getOrganization(messageContext);
int tenantID = APIUtil.getInternalOrganizationId(organization);
APICategory apiCategoryToUpdate = APICategoryMappingUtil.fromCategoryDTOToCategory(body);
APICategory apiCategoryOriginal = apiAdmin.getAPICategoryByID(apiCategoryId);
if (apiCategoryOriginal == null) {
String errorMsg = "No API category with the given category ID exists: " + apiCategoryId;
throw new APIManagementException(errorMsg);
}
// Override several properties as they are not allowed to be updated
apiCategoryToUpdate.setName(apiCategoryOriginal.getName());
apiCategoryToUpdate.setId(apiCategoryOriginal.getId());
apiCategoryToUpdate.setTenantID(apiCategoryOriginal.getTenantID());
apiCategoryToUpdate.setOrganization(organization);
// We allow to update API Category name given that the new category name is not taken yet
String oldName = apiCategoryOriginal.getName();
String updatedName = apiCategoryToUpdate.getName();
if (!oldName.equals(updatedName) && apiAdmin.isCategoryNameExists(updatedName, apiCategoryId, organization)) {
String errorMsg = "An API category already exists by the new API category name :" + updatedName;
throw new APIManagementException(errorMsg);
}
apiAdmin.updateCategory(apiCategoryToUpdate);
APICategory updatedAPICategory = apiAdmin.getAPICategoryByID(apiCategoryId);
APICategoryDTO updatedAPICategoryDTO = APICategoryMappingUtil.fromCategoryToCategoryDTO(updatedAPICategory);
return Response.ok().entity(updatedAPICategoryDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while updating API Category '" + body.getName() + "' - " + e.getMessage();
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class BotDetectionDataApiServiceImpl method getBotDetectionData.
/**
* Get all bot detected data
*
* @param messageContext CXF Message Context
* @return list of all bot detected data
* @throws APIManagementException if an error occurs when retrieving bot detection data
*/
public Response getBotDetectionData(MessageContext messageContext) throws APIManagementException {
if (APIUtil.isAnalyticsEnabled()) {
APIAdmin apiAdmin = new APIAdminImpl();
List<BotDetectionData> botDetectionDataList = apiAdmin.retrieveBotDetectionData();
BotDetectionDataListDTO listDTO = BotDetectionMappingUtil.fromBotDetectionModelToDTO(botDetectionDataList);
return Response.ok().entity(listDTO).build();
} else {
throw new APIManagementException("Analytics Not Enabled", ExceptionCodes.from(ExceptionCodes.ANALYTICS_NOT_ENABLED, "Bot Detection Data is", "Bot Detection Data"));
}
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class KeyManagersApiServiceImpl method getAllKeyManagers.
@Override
public Response getAllKeyManagers(MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getOrganization(messageContext);
APIAdmin apiAdmin = new APIAdminImpl();
List<KeyManagerConfigurationDTO> keyManagerConfigurations = apiAdmin.getKeyManagerConfigurationsByOrganization(organization);
return Response.ok(KeyManagerMappingUtil.toKeyManagerListDto(keyManagerConfigurations)).build();
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class APIAdminImplTest method getTenantConfigSchema.
@Test
public void getTenantConfigSchema() throws Exception {
APIAdmin apiAdmin = new APIAdminImpl();
Schema schema = Mockito.mock(Schema.class);
PowerMockito.when(APIUtil.class, "retrieveTenantConfigJsonSchema").thenReturn(schema);
Assert.assertEquals(apiAdmin.getTenantConfigSchema("abc.com"), schema.toString());
}
Aggregations