Skip to content

Commit

Permalink
Address PR review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiyanwso2 committed Sep 3, 2024
1 parent 82afa10 commit adb0337
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Constants for Ballerina Project Gen tool
*/
public class CdsBallerinaProjectConstants {
public class BallerinaCDSProjectConstants {
public static final String CONFIG_ENABLE = "enable";
public static final String RESOURCE_PATH_TEMPLATES = "template";
public static final String TEMPLATE_NAME = "templateName";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

package org.wso2.healthcare.cds.codegen.ballerina.tool;

import org.wso2.healthcare.cds.codegen.ballerina.tool.config.BallerinaProjectToolConfig;
import org.wso2.healthcare.cds.codegen.ballerina.tool.generator.BallerinaProjectGenerator;
import org.wso2.healthcare.cds.codegen.ballerina.tool.config.BallerinaCDSProjectToolConfig;
import org.wso2.healthcare.cds.codegen.ballerina.tool.generator.BallerinaCDSProjectGenerator;
import org.wso2.healthcare.codegen.tool.framework.commons.config.ToolConfig;
import org.wso2.healthcare.codegen.tool.framework.commons.core.AbstractTool;
import org.wso2.healthcare.codegen.tool.framework.commons.core.TemplateGenerator;
Expand All @@ -30,14 +30,14 @@
import java.util.HashMap;
import java.util.Map;

import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.CONFIG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.CONFIG;

public class CdsBallerinaProjectTool extends AbstractTool {
private BallerinaProjectToolConfig ballerinaProjectToolConfig;
public class BallerinaCDSProjectTool extends AbstractTool {
private BallerinaCDSProjectToolConfig ballerinaCDSProjectToolConfig;

@Override
public void initialize(ToolConfig toolConfig) throws CodeGenException {
ballerinaProjectToolConfig = (BallerinaProjectToolConfig) toolConfig;
ballerinaCDSProjectToolConfig = (BallerinaCDSProjectToolConfig) toolConfig;
}

@Override
Expand All @@ -52,12 +52,12 @@ public void setToolContext(ToolContext toolContext) throws CodeGenException {

@Override
public TemplateGenerator execute(ToolContext toolContext) throws CodeGenException {
String targetRoot = ballerinaProjectToolConfig.getTargetDir();
String targetRoot = ballerinaCDSProjectToolConfig.getTargetDir();
String targetDirectory = targetRoot + File.separator;
BallerinaProjectGenerator cdsBalGenerator = new BallerinaProjectGenerator(targetDirectory);
BallerinaCDSProjectGenerator cdsBalGenerator = new BallerinaCDSProjectGenerator(targetDirectory);

Map<String, Object> generatorProperties = new HashMap<>();
generatorProperties.put(CONFIG, ballerinaProjectToolConfig);
generatorProperties.put(CONFIG, ballerinaCDSProjectToolConfig);
cdsBalGenerator.setGeneratorProperties(generatorProperties);
return cdsBalGenerator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@
import java.util.ArrayList;
import java.util.List;

import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.CDS_SERVICES;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.CONFIG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.DEPENDENCIES;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.DEPENDENT_PACKAGE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.HOOKS;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.PACKAGE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.PROJECT_PACKAGE_DEPENDENT_PACKAGE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.PROJECT_PACKAGE_NAME_PREFIX;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.PROJECT_PACKAGE_ORG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.PROJECT_PACKAGE_VERSION;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.CDS_SERVICES;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.CONFIG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.DEPENDENCIES;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.DEPENDENT_PACKAGE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.HOOKS;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.PACKAGE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.PROJECT_PACKAGE_DEPENDENT_PACKAGE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.PROJECT_PACKAGE_NAME_PREFIX;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.PROJECT_PACKAGE_ORG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.PROJECT_PACKAGE_VERSION;


/**
* Main config class to hold all the config objects.
*/
public class BallerinaProjectToolConfig extends AbstractToolConfig {
public class BallerinaCDSProjectToolConfig extends AbstractToolConfig {

private static final Log LOG = LogFactory.getLog(BallerinaProjectToolConfig.class);
private static final Log LOG = LogFactory.getLog(BallerinaCDSProjectToolConfig.class);
private MetadataConfig metadataConfig;
private final List<DependencyConfig> dependencyConfigs = new ArrayList<>();
private String dependentPackage;
Expand All @@ -75,12 +75,7 @@ public void configure(ConfigType<?> configObj) throws CodeGenException {
}

public void loadCdsHooks(JsonObject cdsHookConfig) {
if (cdsHookConfig.get(CDS_SERVICES) instanceof JsonObject) {
System.out.println(cdsHookConfig.getAsJsonObject(CDS_SERVICES));

} else if (cdsHookConfig.get(CDS_SERVICES) instanceof JsonArray) {
System.out.println(cdsHookConfig.getAsJsonArray(CDS_SERVICES));

if (cdsHookConfig.get(CDS_SERVICES) instanceof JsonArray) {
cdsHookConfig.getAsJsonArray(CDS_SERVICES).forEach(a -> {
cdsHooks.add(new CdsHook(a.getAsJsonObject()));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import com.google.gson.JsonObject;

import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.NAME;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.ORG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.VERSION;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.NAME;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.ORG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.VERSION;


public class DependencyConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
import java.util.ArrayList;
import java.util.List;

import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.AUTHORS;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.DISTRIBUTION;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.KEYWORDS;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.NAME_PREFIX;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.ONE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.ORG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.REGEX_STRING_FOR_NON_WORD_CHARACTER;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.UNDERSCORE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.VERSION;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.ZERO;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.AUTHORS;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.DISTRIBUTION;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.KEYWORDS;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.NAME_PREFIX;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.ONE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.ORG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.REGEX_STRING_FOR_NON_WORD_CHARACTER;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.UNDERSCORE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.VERSION;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.ZERO;


public class MetadataConfig {
Expand All @@ -46,7 +46,6 @@ public class MetadataConfig {
private final List<String> keywords = new ArrayList<>();

public MetadataConfig(JsonObject packageConfig) {
//todo: add null checks
if (packageConfig.has(ORG)) {
this.org = packageConfig.getAsJsonPrimitive(ORG).getAsString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

package org.wso2.healthcare.cds.codegen.ballerina.tool.generator;

import org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants;
import org.wso2.healthcare.cds.codegen.ballerina.tool.config.BallerinaProjectToolConfig;
import org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants;
import org.wso2.healthcare.cds.codegen.ballerina.tool.config.BallerinaCDSProjectToolConfig;
import org.wso2.healthcare.cds.codegen.ballerina.tool.model.BallerinaService;
import org.wso2.healthcare.cds.codegen.ballerina.tool.model.CdsHook;
import org.wso2.healthcare.codegen.tool.framework.commons.core.ToolContext;
Expand All @@ -35,32 +35,32 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.CMD_MESSAGE_OVERRIDE_OUTPUT_DIRECTORY;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.CONFIG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.NO;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.ONE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.REGEX_STRING_FOR_NON_WORD_CHARACTER;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.REGEX_STRING_FOR_UNDERSCORE_AND_HYPHEN;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.SERVICE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.UNDERSCORE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.YES;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.ZERO;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.CMD_MESSAGE_OVERRIDE_OUTPUT_DIRECTORY;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.CONFIG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.NO;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.ONE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.REGEX_STRING_FOR_NON_WORD_CHARACTER;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.REGEX_STRING_FOR_UNDERSCORE_AND_HYPHEN;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.SERVICE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.UNDERSCORE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.YES;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.ZERO;


/**
* Generator class to wrap all the generator classes in Ballerina project generator.
*/
public class BallerinaProjectGenerator extends AbstractFHIRTemplateGenerator {
public class BallerinaCDSProjectGenerator extends AbstractFHIRTemplateGenerator {

public BallerinaProjectGenerator(String targetDir) throws CodeGenException {
public BallerinaCDSProjectGenerator(String targetDir) throws CodeGenException {
super(targetDir);
}

@Override
public void generate(ToolContext toolContext, Map<String, Object> generatorProperties) throws CodeGenException {

BallerinaProjectToolConfig ballerinaProjectToolConfig = (BallerinaProjectToolConfig) generatorProperties.get(CONFIG);
String packagePath = this.getTargetDir() + ballerinaProjectToolConfig.getMetadataConfig().getNamePrefix() + File.separator;
BallerinaCDSProjectToolConfig ballerinaCDSProjectToolConfig = (BallerinaCDSProjectToolConfig) generatorProperties.get(CONFIG);
String packagePath = this.getTargetDir() + ballerinaCDSProjectToolConfig.getMetadataConfig().getNamePrefix() + File.separator;

// Provide option to check and overwrite the existing package
Console console = System.console();
Expand All @@ -69,9 +69,9 @@ public void generate(ToolContext toolContext, Map<String, Object> generatorPrope
if (NO.equalsIgnoreCase(input)) {
System.exit(ZERO);
} else if (YES.equalsIgnoreCase(input)) {
System.out.println(CdsBallerinaProjectConstants.PrintStrings.OVERWRITING_EXISTING_TEMPLATES);
System.out.println(BallerinaCDSProjectConstants.PrintStrings.OVERWRITING_EXISTING_TEMPLATES);
} else {
System.out.println(CdsBallerinaProjectConstants.PrintStrings.INVALID_INPUT);
System.out.println(BallerinaCDSProjectConstants.PrintStrings.INVALID_INPUT);
System.exit(ZERO);
}
}
Expand All @@ -92,7 +92,7 @@ public void generate(ToolContext toolContext, Map<String, Object> generatorPrope

private BallerinaService populateServiceObject(Map<String, Object> generatorProperties) {
BallerinaService ballerinaService = new BallerinaService();
BallerinaProjectToolConfig config = (BallerinaProjectToolConfig) generatorProperties.get(CONFIG);
BallerinaCDSProjectToolConfig config = (BallerinaCDSProjectToolConfig) generatorProperties.get(CONFIG);
ballerinaService.setName(config.getMetadataConfig().getNamePrefix());

Map<String, CdsHook> cdsHookMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@

package org.wso2.healthcare.cds.codegen.ballerina.tool.generator;

import org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants;
import org.wso2.healthcare.cds.codegen.ballerina.tool.config.BallerinaProjectToolConfig;
import org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants;
import org.wso2.healthcare.cds.codegen.ballerina.tool.config.BallerinaCDSProjectToolConfig;
import org.wso2.healthcare.codegen.tool.framework.commons.core.TemplateContext;
import org.wso2.healthcare.codegen.tool.framework.commons.core.ToolContext;
import org.wso2.healthcare.codegen.tool.framework.commons.exception.CodeGenException;
import org.wso2.healthcare.codegen.tool.framework.fhir.core.AbstractFHIRTemplateGenerator;

import java.util.Map;

import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.BAL_GIT_IGNORE_FILE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.BAL_GIT_IGNORE_VM;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.BAL_PACKAGE_MD_FILE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.BAL_PACKAGE_MD_VM;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.CONFIG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.CdsBallerinaProjectConstants.META_CONFIG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.BAL_GIT_IGNORE_FILE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.BAL_GIT_IGNORE_VM;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.BAL_PACKAGE_MD_FILE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.BAL_PACKAGE_MD_VM;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.CONFIG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.META_CONFIG;


public class MetaGenerator extends AbstractFHIRTemplateGenerator {
Expand All @@ -44,18 +44,18 @@ public MetaGenerator(String targetDir) throws CodeGenException {
@Override
public void generate(ToolContext toolContext, Map<String, Object> generatorProperties) throws CodeGenException {
String directoryPath = getTargetDir();
this.getTemplateEngine().generateOutputAsFile(CdsBallerinaProjectConstants.RESOURCE_PATH_TEMPLATES +
CdsBallerinaProjectConstants.RESOURCE_PATH_SEPARATOR + BAL_PACKAGE_MD_VM, createTemplateContextForMeta(generatorProperties), directoryPath,
this.getTemplateEngine().generateOutputAsFile(BallerinaCDSProjectConstants.RESOURCE_PATH_TEMPLATES +
BallerinaCDSProjectConstants.RESOURCE_PATH_SEPARATOR + BAL_PACKAGE_MD_VM, createTemplateContextForMeta(generatorProperties), directoryPath,
BAL_PACKAGE_MD_FILE);
this.getTemplateEngine().generateOutputAsFile(CdsBallerinaProjectConstants.RESOURCE_PATH_TEMPLATES +
CdsBallerinaProjectConstants.RESOURCE_PATH_SEPARATOR + BAL_GIT_IGNORE_VM, createTemplateContextForMeta(generatorProperties), directoryPath,
this.getTemplateEngine().generateOutputAsFile(BallerinaCDSProjectConstants.RESOURCE_PATH_TEMPLATES +
BallerinaCDSProjectConstants.RESOURCE_PATH_SEPARATOR + BAL_GIT_IGNORE_VM, createTemplateContextForMeta(generatorProperties), directoryPath,
BAL_GIT_IGNORE_FILE);
}

private TemplateContext createTemplateContextForMeta(Map<String, Object> generatorProperties) {

TemplateContext templateContext = this.getNewTemplateContext();
BallerinaProjectToolConfig config = (BallerinaProjectToolConfig) generatorProperties.get(CONFIG);
BallerinaCDSProjectToolConfig config = (BallerinaCDSProjectToolConfig) generatorProperties.get(CONFIG);
templateContext.setProperty(CONFIG, config);
templateContext.setProperty(META_CONFIG, config.getMetadataConfig());
return templateContext;
Expand Down
Loading

0 comments on commit adb0337

Please sign in to comment.