use of org.wso2.carbon.apimgt.core.template.APITemplateException in project carbon-apimgt by wso2.
the class APIConfigContextTestCase method testWithNullParameters.
@Test(expectedExceptions = APITemplateException.class)
public void testWithNullParameters() throws APITemplateException {
API emptyNamedAPI = new API.APIBuilder(null, null, "1.0.0").context("testcontext").id(UUID.randomUUID().toString()).build();
APIConfigContext apiConfigContext = new APIConfigContext(emptyNamedAPI, "org.test");
apiConfigContext.validate();
}
use of org.wso2.carbon.apimgt.core.template.APITemplateException in project carbon-apimgt by wso2.
the class APIConfigContextTestCase method testWithEmptyParameters.
@Test(expectedExceptions = APITemplateException.class)
public void testWithEmptyParameters() throws APITemplateException {
API emptyNamedAPI = new API.APIBuilder("", "", "").context("testcontext").id(UUID.randomUUID().toString()).build();
APIConfigContext apiConfigContext = new APIConfigContext(emptyNamedAPI, "org.test");
apiConfigContext.validate();
}
use of org.wso2.carbon.apimgt.core.template.APITemplateException in project carbon-apimgt by wso2.
the class PolicyExportManager method getCustomPolicySiddhiApps.
/**
* Get execution plan/ siddhi apps for custom policies.
*
* @param customPolicies custom policy object list
* @return Map<String, String> containing execution plan name and execution plans.
* @throws APITemplateException If template generating fails
*/
private Map<String, String> getCustomPolicySiddhiApps(List<CustomPolicy> customPolicies) throws APITemplateException {
if (log.isDebugEnabled()) {
log.debug("Get execution plans for custom policies.");
}
Map<String, String> siddhiApps = new HashMap<>();
String name;
String executionPlan;
CustomThrottlePolicyTemplateBuilder templateBuilder;
for (CustomPolicy policy : customPolicies) {
templateBuilder = new CustomThrottlePolicyTemplateBuilder(policy);
name = CUSTOM + policy.getPolicyName();
executionPlan = templateBuilder.getThrottlePolicyTemplateForCustomPolicy();
siddhiApps.put(name, executionPlan);
}
return siddhiApps;
}
use of org.wso2.carbon.apimgt.core.template.APITemplateException in project carbon-apimgt by wso2.
the class PolicyExportManager method getAppPolicySiddhiApps.
/**
* Get execution plan/ siddhi apps for custom policies.
*
* @param applicationPolicies ApplicationPolicy object list
* @return Map<String, String> containing execution plan name and execution plans.
* @throws APITemplateException If template generating fails
*/
private Map<String, String> getAppPolicySiddhiApps(List<ApplicationPolicy> applicationPolicies) throws APITemplateException {
if (log.isDebugEnabled()) {
log.debug("Get execution plans for application policy.");
}
Map<String, String> siddhiApps = new HashMap<>();
String name;
String executionPlan;
ApplicationThrottlePolicyTemplateBuilder templateBuilder;
for (ApplicationPolicy policy : applicationPolicies) {
templateBuilder = new ApplicationThrottlePolicyTemplateBuilder(policy);
name = APPLICATION + policy.getPolicyName();
executionPlan = templateBuilder.getThrottlePolicyForAppLevel();
siddhiApps.put(name, executionPlan);
}
return siddhiApps;
}
use of org.wso2.carbon.apimgt.core.template.APITemplateException in project carbon-apimgt by wso2.
the class APIThrottlePolicyTemplateBuilder method getThrottlePolicyTemplateForAPILevelDefaultCondition.
/**
* Generate default policy for api level throttling
*
* @return throttle policies for default api
* @throws APITemplateException throws if generation failure occur
*/
public String getThrottlePolicyTemplateForAPILevelDefaultCondition() throws APITemplateException {
if (log.isDebugEnabled()) {
log.debug("Generating Siddhi App for apiLevel :" + apiPolicy.toString());
}
// get velocity template for API policy and generate the template
Set<String> conditionsSet = new HashSet<String>();
List<Pipeline> pipelines = apiPolicy.getPipelines();
VelocityEngine velocityengine = initVelocityEngine();
Template template = velocityengine.getTemplate(getTemplatePathForAPIDefaultPolicy());
StringWriter writer;
VelocityContext context;
// when APIPolicy contains pipelines, get template as a string
if (pipelines != null) {
for (Pipeline pipeline : pipelines) {
String conditionString = getPolicyConditionForDefault(pipeline.getConditions());
if (!StringUtils.isEmpty(conditionString)) {
conditionsSet.add(conditionString);
}
}
}
// for default API policy
context = new VelocityContext();
setConstantContext(context);
// default policy is defined as 'elseCondition' , set values for velocity context
context.put(PIPELINE, ELSE_CONDITION);
context.put(PIPELINE_ITEM, null);
context.put(POLICY, apiPolicy);
context.put(QUOTA_POLICY, apiPolicy.getDefaultQuotaPolicy());
String conditionSetString = getConditionForDefault(conditionsSet);
if (!StringUtils.isEmpty(conditionSetString)) {
context.put(CONDITION, AND + conditionSetString);
} else {
context.put(CONDITION, EMPTY_STRING);
}
writer = new StringWriter();
template.merge(context, writer);
if (log.isDebugEnabled()) {
log.debug("Generated Siddhi App : " + writer.toString());
}
return writer.toString();
}
Aggregations