use of org.wso2.apimgt.gateway.cli.model.rest.policy.ThrottlePolicyListMapper in project product-microgateway by wso2.
the class ThrottlePolicyGenerator method generate.
/**
* Generate ballerina and stream source for a given app and subs policies.
*
* @param outPath Destination file path to save generated source files. If not provided
* {@code definitionPath} will be used as the default destination path
* @param projectName Project name
* @throws IOException when file operations fail
*/
public void generate(String outPath, String projectName) throws IOException {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
String policyFileLocation = CmdUtils.getProjectDirectoryPath(projectName) + File.separator + CliConstants.GW_DIST_POLICIES_FILE;
ThrottlePolicyListMapper throttlePolicyListMapper = mapper.readValue(new File(policyFileLocation), ThrottlePolicyListMapper.class);
// read application throttle policies and subscription throttle policies
List<ThrottlePolicyMapper> applicationPolicies = throttlePolicyListMapper.getApplicationPolicies();
List<ThrottlePolicyMapper> subscriptionPolicies = throttlePolicyListMapper.getSubscriptionPolicies();
List<ThrottlePolicyMapper> resourcePolicies = throttlePolicyListMapper.getResourcePolicies();
if (applicationPolicies == null && subscriptionPolicies == null && resourcePolicies == null) {
return;
}
checkDuplicatePolicyNames(applicationPolicies, subscriptionPolicies, resourcePolicies);
List<GenSrcFile> genFiles = new ArrayList<>();
GenSrcFile initGenFile = generateInitBal(applicationPolicies, subscriptionPolicies, resourcePolicies);
genFiles.add(initGenFile);
CodegenUtils.writeGeneratedSources(genFiles, Paths.get(outPath), true);
}
Aggregations