Search in sources :

Example 31 with APIAdminImpl

use of org.wso2.carbon.apimgt.impl.APIAdminImpl in project carbon-apimgt by wso2.

the class KeyManagersApiServiceImpl method keyManagersGet.

public Response keyManagersGet(String xWSO2Tenant, MessageContext messageContext) {
    String organization = RestApiUtil.getOrganization(messageContext);
    APIAdmin apiAdmin = new APIAdminImpl();
    try {
        List<KeyManagerConfigurationDTO> keyManagerConfigurations = apiAdmin.getKeyManagerConfigurationsByOrganization(organization);
        return Response.ok(KeyManagerMappingUtil.toKeyManagerListDto(keyManagerConfigurations)).build();
    } catch (APIManagementException e) {
        RestApiUtil.handleInternalServerError("Error while retrieving keyManager Details for organization " + organization, log);
    }
    return null;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 32 with APIAdminImpl

use of org.wso2.carbon.apimgt.impl.APIAdminImpl in project carbon-apimgt by wso2.

the class ThrottlingApiServiceImpl method throttlingPoliciesSubscriptionGet.

/**
 * Retrieves all Subscription level policies
 *
 * @param accept          Accept header value
 * @return All matched Subscription Throttle policies to the given request
 */
@Override
public Response throttlingPoliciesSubscriptionGet(String accept, MessageContext messageContext) {
    try {
        APIAdmin apiAdmin = new APIAdminImpl();
        String userName = RestApiCommonUtil.getLoggedInUsername();
        int tenantId = APIUtil.getTenantId(userName);
        Policy[] subscriptionPolicies = apiAdmin.getPolicies(tenantId, PolicyConstants.POLICY_LEVEL_SUB);
        List<SubscriptionPolicy> policies = new ArrayList<>();
        for (Policy policy : subscriptionPolicies) {
            policies.add((SubscriptionPolicy) policy);
        }
        SubscriptionThrottlePolicyListDTO listDTO = SubscriptionThrottlePolicyMappingUtil.fromSubscriptionPolicyArrayToListDTO(policies.toArray(new SubscriptionPolicy[policies.size()]));
        return Response.ok().entity(listDTO).build();
    } catch (APIManagementException | ParseException e) {
        String errorMessage = "Error while retrieving Subscription level policies";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : GlobalPolicy(org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) APIPolicy(org.wso2.carbon.apimgt.api.model.policy.APIPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.api.model.policy.Policy) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) ArrayList(java.util.ArrayList) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) ParseException(org.json.simple.parser.ParseException)

Example 33 with APIAdminImpl

use of org.wso2.carbon.apimgt.impl.APIAdminImpl in project carbon-apimgt by wso2.

the class ThrottlingApiServiceImpl method throttlingPoliciesAdvancedGet.

/**
 * Retrieves all Advanced level policies
 *
 * @param accept          Accept header value
 * @return All matched Advanced Throttle policies to the given request
 */
@Override
public Response throttlingPoliciesAdvancedGet(String accept, MessageContext messageContext) {
    try {
        APIAdmin apiAdmin = new APIAdminImpl();
        String userName = RestApiCommonUtil.getLoggedInUsername();
        int tenantId = APIUtil.getTenantId(userName);
        Policy[] apiPolicies = apiAdmin.getPolicies(tenantId, PolicyConstants.POLICY_LEVEL_API);
        List<APIPolicy> policies = new ArrayList<>();
        for (Policy policy : apiPolicies) {
            policies.add((APIPolicy) policy);
        }
        AdvancedThrottlePolicyListDTO listDTO = AdvancedThrottlePolicyMappingUtil.fromAPIPolicyArrayToListDTO(policies.toArray(new APIPolicy[policies.size()]));
        return Response.ok().entity(listDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving Advanced level policies";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : GlobalPolicy(org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) APIPolicy(org.wso2.carbon.apimgt.api.model.policy.APIPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.api.model.policy.Policy) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) ArrayList(java.util.ArrayList) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) APIPolicy(org.wso2.carbon.apimgt.api.model.policy.APIPolicy)

Example 34 with APIAdminImpl

use of org.wso2.carbon.apimgt.impl.APIAdminImpl in project carbon-apimgt by wso2.

the class ThrottlingApiServiceImpl method throttlingPoliciesCustomGet.

/**
 * Retrieves all Global level policies
 *
 * @param accept          Accept header value
 * @return All matched Global Throttle policies to the given request
 */
@Override
public Response throttlingPoliciesCustomGet(String accept, MessageContext messageContext) {
    try {
        APIAdmin apiAdmin = new APIAdminImpl();
        String userName = RestApiCommonUtil.getLoggedInUsername();
        int tenantId = APIUtil.getTenantId(userName);
        // only super tenant is allowed to access global policies/custom rules
        checkTenantDomainForCustomRules();
        Policy[] globalPolicies = apiAdmin.getPolicies(tenantId, PolicyConstants.POLICY_LEVEL_GLOBAL);
        List<GlobalPolicy> policies = new ArrayList<>();
        for (Policy policy : globalPolicies) {
            policies.add((GlobalPolicy) policy);
        }
        CustomRuleListDTO listDTO = GlobalThrottlePolicyMappingUtil.fromGlobalPolicyArrayToListDTO(policies.toArray(new GlobalPolicy[policies.size()]));
        return Response.ok().entity(listDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving Global level policies";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : GlobalPolicy(org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) APIPolicy(org.wso2.carbon.apimgt.api.model.policy.APIPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.api.model.policy.Policy) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) GlobalPolicy(org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) ArrayList(java.util.ArrayList) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 35 with APIAdminImpl

use of org.wso2.carbon.apimgt.impl.APIAdminImpl in project carbon-apimgt by wso2.

the class RestApiAdminUtils method restoreTenantTheme.

/**
 * Restores the tenant theme which existed before the current import operation was performed
 *
 * @param tenantId             tenant ID of the tenant to which the theme is imported
 * @param tenantThemeDirectory directory in the file system to where the tenant theme is imported
 * @param backupDirectory      directory in the file system where the tenant theme is temporarily backed-up
 * @param existingTenantTheme  tenant theme which existed before the current import operation
 * @throws APIManagementException if an error occurs when updating the tenant theme in the database
 * @throws IOException            if an error occurs when restoring the tenant theme directory
 */
public static void restoreTenantTheme(int tenantId, File tenantThemeDirectory, File backupDirectory, InputStream existingTenantTheme) throws APIManagementException, IOException {
    APIAdmin apiAdmin = new APIAdminImpl();
    FileUtils.copyDirectory(backupDirectory, tenantThemeDirectory);
    FileUtils.deleteDirectory(backupDirectory);
    apiAdmin.updateTenantTheme(tenantId, existingTenantTheme);
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

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