Search in sources :

Example 26 with APIAdminImpl

use of org.wso2.carbon.apimgt.impl.APIAdminImpl 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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 27 with APIAdminImpl

use of org.wso2.carbon.apimgt.impl.APIAdminImpl 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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) APICategoryDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.APICategoryDTO) APICategory(org.wso2.carbon.apimgt.api.model.APICategory)

Example 28 with APIAdminImpl

use of org.wso2.carbon.apimgt.impl.APIAdminImpl 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"));
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData) BotDetectionDataListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionDataListDTO) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 29 with APIAdminImpl

use of org.wso2.carbon.apimgt.impl.APIAdminImpl 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();
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 30 with APIAdminImpl

use of org.wso2.carbon.apimgt.impl.APIAdminImpl 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());
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Schema(org.everit.json.schema.Schema) APIUtil(org.wso2.carbon.apimgt.impl.utils.APIUtil) Test(org.junit.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)46 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)39 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)31 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 BeforeTest (org.testng.annotations.BeforeTest)8 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)8 APIUtil (org.wso2.carbon.apimgt.impl.utils.APIUtil)6 ArrayList (java.util.ArrayList)5 Schema (org.everit.json.schema.Schema)5 File (java.io.File)4 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 BotDetectionData (org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData)4 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)4 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)4 GlobalPolicy (org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy)4 Policy (org.wso2.carbon.apimgt.api.model.policy.Policy)4 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)4 Gson (com.google.gson.Gson)3