Search in sources :

Example 1 with ThrottlePolicyListMapper

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);
}
Also used : GenSrcFile(org.wso2.apimgt.gateway.cli.model.template.GenSrcFile) ThrottlePolicyListMapper(org.wso2.apimgt.gateway.cli.model.rest.policy.ThrottlePolicyListMapper) ThrottlePolicyMapper(org.wso2.apimgt.gateway.cli.model.rest.policy.ThrottlePolicyMapper) ArrayList(java.util.ArrayList) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) GenSrcFile(org.wso2.apimgt.gateway.cli.model.template.GenSrcFile) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ThrottlePolicyListMapper (org.wso2.apimgt.gateway.cli.model.rest.policy.ThrottlePolicyListMapper)1 ThrottlePolicyMapper (org.wso2.apimgt.gateway.cli.model.rest.policy.ThrottlePolicyMapper)1 GenSrcFile (org.wso2.apimgt.gateway.cli.model.template.GenSrcFile)1