Search in sources :

Example 11 with APITemplateException

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

the class ThrottleTemplateBuilderTestCase method testSiddhiQueryForCustomPolicy.

@Test
public void testSiddhiQueryForCustomPolicy() throws APITemplateException {
    CustomPolicy policy = SampleTestObjectCreator.createDefaultCustomPolicy();
    CustomThrottlePolicyTemplateBuilder templateBuilder = new CustomThrottlePolicyTemplateBuilder(policy);
    String siddhiQuery = templateBuilder.getThrottlePolicyTemplateForCustomPolicy();
    String sampleQuery = SampleTestObjectCreator.createDefaultCustomPolicySiddhiApp();
    Assert.assertEquals(siddhiQuery, sampleQuery);
}
Also used : CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) Test(org.testng.annotations.Test)

Example 12 with APITemplateException

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

the class ThrottleTemplateBuilderTestCase method testSiddhiQueryForAPILevelDefaultConditions.

@Test
public void testSiddhiQueryForAPILevelDefaultConditions() throws APITemplateException {
    APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
    APIThrottlePolicyTemplateBuilder templateBuilder = new APIThrottlePolicyTemplateBuilder(apiPolicy);
    String actualQuery = templateBuilder.getThrottlePolicyTemplateForAPILevelDefaultCondition();
    String expectedQuery = SampleTestObjectCreator.createDefaultSiddhiAppForAPILevelDefaultThrottlePolicy();
    Assert.assertEquals(actualQuery, expectedQuery);
}
Also used : APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) Test(org.testng.annotations.Test)

Example 13 with APITemplateException

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

the class PolicyExportManager method getSubscriptionPolicySiddhiApps.

/**
 * Get execution plan/ siddhi apps for custom policies.
 *
 * @param subscriptionPolicies SubscriptionPolicy object list
 * @return Map<String, String> containing execution plan name and execution plans.
 * @throws APITemplateException If template generating fails
 */
private Map<String, String> getSubscriptionPolicySiddhiApps(List<SubscriptionPolicy> subscriptionPolicies) throws APITemplateException {
    if (log.isDebugEnabled()) {
        log.debug("Get execution plans for Subscription policies.");
    }
    Map<String, String> siddhiApps = new HashMap<>();
    String name;
    String executionPlan;
    SubscriptionThrottlePolicyTemplateBuilder templateBuilder;
    for (SubscriptionPolicy policy : subscriptionPolicies) {
        name = SUBSCRIPTION + policy.getPolicyName();
        templateBuilder = new SubscriptionThrottlePolicyTemplateBuilder(policy);
        executionPlan = templateBuilder.getThrottlePolicyForSubscriptionLevel();
        siddhiApps.put(name, executionPlan);
    }
    return siddhiApps;
}
Also used : HashMap(java.util.HashMap) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) SubscriptionThrottlePolicyTemplateBuilder(org.wso2.carbon.apimgt.core.template.SubscriptionThrottlePolicyTemplateBuilder)

Example 14 with APITemplateException

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

the class PolicyExportManager method getApiPolicySiddhiApps.

/**
 * Get execution plan/ siddhi apps for custom policies.
 *
 * @param apiPolicies APIPolicy object list
 * @return Map<String, String> containing execution plan name and execution plans.
 * @throws APITemplateException If template generating fails
 */
private List<Map<String, String>> getApiPolicySiddhiApps(List<APIPolicy> apiPolicies) throws APITemplateException {
    if (log.isDebugEnabled()) {
        log.debug("Get execution plans for API policies.");
    }
    List<Map<String, String>> policies = new ArrayList<>();
    Map<String, String> siddhiApps = new HashMap<>();
    APIThrottlePolicyTemplateBuilder templateBuilder;
    for (APIPolicy apiPolicy : apiPolicies) {
        templateBuilder = new APIThrottlePolicyTemplateBuilder(apiPolicy);
        if (apiPolicy.getPipelines() != null) {
            siddhiApps = templateBuilder.getThrottlePolicyTemplateForPipelines();
        }
        siddhiApps.put(RESOURCE + apiPolicy.getPolicyName() + DEFAULT, templateBuilder.getThrottlePolicyTemplateForAPILevelDefaultCondition());
        policies.add(siddhiApps);
    }
    return policies;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) APIThrottlePolicyTemplateBuilder(org.wso2.carbon.apimgt.core.template.APIThrottlePolicyTemplateBuilder) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with APITemplateException

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

the class TemplateBuilderUtil method retrieveGatewayAPIDto.

public static GatewayAPIDTO retrieveGatewayAPIDto(API api, Environment environment, String tenantDomain, APIDTO apidto, String extractedFolderPath) throws APIManagementException, XMLStreamException, APITemplateException {
    List<ClientCertificateDTO> clientCertificatesDTOList = ImportUtils.retrieveClientCertificates(extractedFolderPath);
    List<SoapToRestMediationDto> soapToRestInMediationDtoList = ImportUtils.retrieveSoapToRestFlowMediations(extractedFolderPath, ImportUtils.IN);
    List<SoapToRestMediationDto> soapToRestOutMediationDtoList = ImportUtils.retrieveSoapToRestFlowMediations(extractedFolderPath, ImportUtils.OUT);
    JSONObject originalProperties = api.getAdditionalProperties();
    // add new property for entires that has a __display suffix
    JSONObject modifiedProperties = getModifiedProperties(originalProperties);
    api.setAdditionalProperties(modifiedProperties);
    APITemplateBuilder apiTemplateBuilder = TemplateBuilderUtil.getAPITemplateBuilder(api, tenantDomain, clientCertificatesDTOList, soapToRestInMediationDtoList, soapToRestOutMediationDtoList);
    GatewayAPIDTO gatewaAPIDto = createAPIGatewayDTOtoPublishAPI(environment, api, apiTemplateBuilder, tenantDomain, extractedFolderPath, apidto, clientCertificatesDTOList);
    // Reset the additional properties to the original values
    if (originalProperties != null) {
        api.setAdditionalProperties(originalProperties);
    }
    return gatewaAPIDto;
}
Also used : GatewayAPIDTO(org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO) JSONObject(org.json.simple.JSONObject) SoapToRestMediationDto(org.wso2.carbon.apimgt.impl.dto.SoapToRestMediationDto) APITemplateBuilder(org.wso2.carbon.apimgt.impl.template.APITemplateBuilder) ClientCertificateDTO(org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO)

Aggregations

StringWriter (java.io.StringWriter)14 Template (org.apache.velocity.Template)14 VelocityContext (org.apache.velocity.VelocityContext)14 VelocityEngine (org.apache.velocity.app.VelocityEngine)14 APITemplateException (org.wso2.carbon.apimgt.impl.template.APITemplateException)11 HashMap (java.util.HashMap)10 Test (org.testng.annotations.Test)9 API (org.wso2.carbon.apimgt.core.models.API)6 VelocityException (org.apache.velocity.exception.VelocityException)5 APITemplateException (org.wso2.carbon.apimgt.core.template.APITemplateException)5 RegistryException (org.wso2.carbon.registry.api.RegistryException)5 UserStoreException (org.wso2.carbon.user.api.UserStoreException)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 GatewayAPIDTO (org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO)4 GatewayContentDTO (org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO)4 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)4 APIConfigContext (org.wso2.carbon.apimgt.core.template.APIConfigContext)4 ParseErrorException (org.apache.velocity.exception.ParseErrorException)3