Search in sources :

Example 11 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createApplicationPolicyWithBndwidthLimit.

public static ApplicationPolicy createApplicationPolicyWithBndwidthLimit(String name) {
    ApplicationPolicy applicationPolicy = new ApplicationPolicy(name);
    applicationPolicy.setDescription("testDescription");
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType("bandwidth");
    BandwidthLimit bandwidthLimit = new BandwidthLimit("s", 60, 10, "mb");
    quotaPolicy.setLimit(bandwidthLimit);
    applicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
    applicationPolicy.setDisplayName("displayName");
    return applicationPolicy;
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 12 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class PoliciesApiServiceImpl method policiesThrottlingApplicationIdPut.

/**
 * Updates/adds a new Application throttle policy to the system
 *
 * @param id          Uuid of the policy.
 * @param body              DTO object including the Policy meta information
 * @param ifMatch           If-Match header value
 * @param ifUnmodifiedSince If-Unmodified-Since header value
 * @param request           msf4j request object
 * @return Response object  response object with the updated application throttle policy resource
 * @throws NotFoundException if an error occurred when particular resource does not exits in the system.
 */
@Override
public Response policiesThrottlingApplicationIdPut(String id, ApplicationThrottlePolicyDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
    APIMgtAdminService.PolicyLevel tierLevel = APIMgtAdminService.PolicyLevel.application;
    if (log.isDebugEnabled()) {
        log.info("Received Application Policy PUT request " + body + " with tierLevel = " + tierLevel);
    }
    try {
        APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
        ApplicationPolicy applicationPolicy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(body);
        applicationPolicy.setUuid(id);
        apiMgtAdminService.updateApplicationPolicy(applicationPolicy);
        return Response.status(Response.Status.OK).entity(ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(apiMgtAdminService.getApplicationPolicyByUuid(id))).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while updating Application Policy. policy uuid: " + id;
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)

Example 13 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class ApplicationThrottlePolicyMappingUtil method fromApplicationPolicyArrayToListDTO.

/**
 * Converts an array of Application Policy objects into a List DTO
 *
 * @param appPolicies Array of Application Policies
 * @return A List DTO of converted Application Policies
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 */
public static ApplicationThrottlePolicyListDTO fromApplicationPolicyArrayToListDTO(List<ApplicationPolicy> appPolicies) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
    ApplicationThrottlePolicyListDTO listDTO = new ApplicationThrottlePolicyListDTO();
    List<ApplicationThrottlePolicyDTO> appPolicyDTOList = new ArrayList<>();
    if (appPolicies != null) {
        for (Policy policy : appPolicies) {
            ApplicationThrottlePolicyDTO dto = fromApplicationThrottlePolicyToDTO(policy);
            appPolicyDTOList.add(dto);
        }
    }
    listDTO.setCount(appPolicyDTOList.size());
    listDTO.setList(appPolicyDTOList);
    return listDTO;
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ArrayList(java.util.ArrayList) ApplicationThrottlePolicyListDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyListDTO) ApplicationThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyDTO)

Example 14 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class PolicyExportManagerTest method testCreateArchiveFromExecutionPlans.

@Test(description = "testing creating archive from execution plans")
public void testCreateArchiveFromExecutionPlans() throws APIManagementException {
    APIMgtAdminService apiMgtAdminService = Mockito.mock(APIMgtAdminService.class);
    List<APIPolicy> apiPolicies = new ArrayList<>();
    List<ApplicationPolicy> applicationPolicies = new ArrayList<>();
    List<SubscriptionPolicy> subscriptionPolicies = new ArrayList<>();
    List<CustomPolicy> customPolicies = new ArrayList<>();
    apiPolicies.add(SampleTestObjectCreator.createDefaultAPIPolicy());
    applicationPolicies.add(SampleTestObjectCreator.createDefaultApplicationPolicy());
    subscriptionPolicies.add(SampleTestObjectCreator.createDefaultSubscriptionPolicy());
    customPolicies.add(SampleTestObjectCreator.createDefaultCustomPolicy());
    Mockito.when(apiMgtAdminService.getApiPolicies()).thenReturn(apiPolicies);
    Mockito.when(apiMgtAdminService.getApplicationPolicies()).thenReturn(applicationPolicies);
    Mockito.when(apiMgtAdminService.getCustomRules()).thenReturn(customPolicies);
    Mockito.when(apiMgtAdminService.getSubscriptionPolicies()).thenReturn(subscriptionPolicies);
    PolicyExportManager policyExportManager = new PolicyExportManager(apiMgtAdminService);
    String path = policyExportManager.createArchiveFromExecutionPlans("exportDir", exportRootDirectory, "policies");
    String unzippedPath = exportRootDirectory + File.separator + "export-policies";
    APIFileUtils.extractArchive(path, unzippedPath);
    Assert.assertEquals(new File(APIFileUtils.getDirectoryList(unzippedPath).iterator().next()).listFiles().length == 6, true, "Exported policy count is not equal to ");
}
Also used : CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) ArrayList(java.util.ArrayList) APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) File(java.io.File) Test(org.testng.annotations.Test)

Example 15 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class ApplicationMappingUtil method fromDTOtoApplication.

public static Application fromDTOtoApplication(ApplicationDTO applicationDTO, String createdUser) {
    // subscriber field of the body is not honored
    Application application = new Application(applicationDTO.getName(), createdUser);
    application.setPolicy(new ApplicationPolicy(applicationDTO.getThrottlingTier()));
    application.setDescription(applicationDTO.getDescription());
    application.setId(applicationDTO.getApplicationId());
    application.setPermissionString(applicationDTO.getPermission());
    application.setStatus(applicationDTO.getLifeCycleStatus());
    // application.setGroupId(applicationDTO.getGroupId());
    return application;
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) Application(org.wso2.carbon.apimgt.core.models.Application)

Aggregations

ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)56 Test (org.testng.annotations.Test)30 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)29 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)24 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)18 Application (org.wso2.carbon.apimgt.core.models.Application)17 Connection (java.sql.Connection)16 PreparedStatement (java.sql.PreparedStatement)16 SQLException (java.sql.SQLException)16 ResultSet (java.sql.ResultSet)13 BeforeTest (org.testng.annotations.BeforeTest)13 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)13 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)13 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)13 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)13 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)12 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)12