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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations