Search in sources :

Example 1 with DataFormatOptionModel

use of org.apache.camel.maven.packaging.model.DataFormatOptionModel in project camel by apache.

the class SpringBootAutoConfigurationMojo method generateDataFormatModel.

private static DataFormatModel generateDataFormatModel(String dataFormatName, String json) {
    List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("dataformat", json, false);
    DataFormatModel dataFormat = new DataFormatModel();
    dataFormat.setTitle(getSafeValue("title", rows));
    dataFormat.setName(getSafeValue("name", rows));
    dataFormat.setModelName(getSafeValue("modelName", rows));
    dataFormat.setDescription(getSafeValue("description", rows));
    dataFormat.setFirstVersion(JSonSchemaHelper.getSafeValue("firstVersion", rows));
    dataFormat.setLabel(getSafeValue("label", rows));
    dataFormat.setDeprecated(getSafeValue("deprecated", rows));
    dataFormat.setJavaType(getSafeValue("javaType", rows));
    dataFormat.setGroupId(getSafeValue("groupId", rows));
    dataFormat.setArtifactId(getSafeValue("artifactId", rows));
    dataFormat.setVersion(getSafeValue("version", rows));
    rows = JSonSchemaHelper.parseJsonSchema("properties", json, true);
    for (Map<String, String> row : rows) {
        DataFormatOptionModel option = new DataFormatOptionModel();
        option.setName(getSafeValue("name", row));
        option.setDisplayName(getSafeValue("displayName", row));
        option.setKind(getSafeValue("kind", row));
        option.setType(getSafeValue("type", row));
        option.setJavaType(getSafeValue("javaType", row));
        option.setDeprecated(getSafeValue("deprecated", row));
        option.setDescription(getSafeValue("description", row));
        option.setDefaultValue(getSafeValue("defaultValue", row));
        option.setEnumValues(getSafeValue("enum", row));
        dataFormat.addDataFormatOption(option);
    }
    return dataFormat;
}
Also used : DataFormatModel(org.apache.camel.maven.packaging.model.DataFormatModel) DataFormatOptionModel(org.apache.camel.maven.packaging.model.DataFormatOptionModel) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with DataFormatOptionModel

use of org.apache.camel.maven.packaging.model.DataFormatOptionModel in project camel by apache.

the class SpringBootAutoConfigurationMojo method createDataFormatConfigurationSource.

// CHECKSTYLE:ON
private void createDataFormatConfigurationSource(String packageName, DataFormatModel model, String overrideDataFormatName) throws MojoFailureException {
    final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
    int pos = model.getJavaType().lastIndexOf(".");
    String name = model.getJavaType().substring(pos + 1);
    name = name.replace("DataFormat", "DataFormatConfiguration");
    javaClass.setPackage(packageName).setName(name);
    String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
    if (!Strings.isBlank(model.getDescription())) {
        doc = model.getDescription() + "\n\n" + doc;
    }
    javaClass.getJavaDoc().setFullText(doc);
    String prefix = "camel.dataformat." + (overrideDataFormatName != null ? overrideDataFormatName : model.getName());
    // make sure prefix is in lower case
    prefix = prefix.toLowerCase(Locale.US);
    javaClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", prefix);
    for (DataFormatOptionModel option : model.getDataFormatOptions()) {
        // skip option with name id in data format as we do not need that
        if ("id".equals(option.getName())) {
            continue;
        }
        String type = option.getJavaType();
        type = getSimpleJavaType(type);
        PropertySource<JavaClassSource> prop = javaClass.addProperty(type, option.getName());
        if ("true".equals(option.getDeprecated())) {
            prop.getField().addAnnotation(Deprecated.class);
            prop.getAccessor().addAnnotation(Deprecated.class);
            prop.getMutator().addAnnotation(Deprecated.class);
            // DeprecatedConfigurationProperty must be on getter when deprecated
            prop.getAccessor().addAnnotation(DeprecatedConfigurationProperty.class);
        }
        if (!Strings.isBlank(option.getDescription())) {
            prop.getField().getJavaDoc().setFullText(option.getDescription());
        }
        if (!Strings.isBlank(option.getDefaultValue())) {
            if ("java.lang.String".equals(option.getType())) {
                prop.getField().setStringInitializer(option.getDefaultValue());
            } else if ("long".equals(option.getJavaType()) || "java.lang.Long".equals(option.getJavaType())) {
                // the value should be a Long number
                String value = option.getDefaultValue() + "L";
                prop.getField().setLiteralInitializer(value);
            } else if ("integer".equals(option.getType()) || "boolean".equals(option.getType())) {
                prop.getField().setLiteralInitializer(option.getDefaultValue());
            } else if (!Strings.isBlank(option.getEnumValues())) {
                String enumShortName = type.substring(type.lastIndexOf(".") + 1);
                prop.getField().setLiteralInitializer(enumShortName + "." + option.getDefaultValue());
                javaClass.addImport(model.getJavaType());
            }
        }
    }
    sortImports(javaClass);
    String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
    writeSourceIfChanged(javaClass, fileName);
}
Also used : DataFormatOptionModel(org.apache.camel.maven.packaging.model.DataFormatOptionModel) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 3 with DataFormatOptionModel

use of org.apache.camel.maven.packaging.model.DataFormatOptionModel in project camel by apache.

the class UpdateReadmeMojo method generateDataFormatModel.

private DataFormatModel generateDataFormatModel(String dataFormatName, String json) {
    List<Map<String, String>> rows = parseJsonSchema("dataformat", json, false);
    DataFormatModel dataFormat = new DataFormatModel();
    dataFormat.setTitle(getSafeValue("title", rows));
    dataFormat.setModelName(getSafeValue("modelName", rows));
    dataFormat.setName(getSafeValue("name", rows));
    dataFormat.setDescription(getSafeValue("description", rows));
    dataFormat.setFirstVersion(getSafeValue("firstVersion", rows));
    dataFormat.setLabel(getSafeValue("label", rows));
    dataFormat.setDeprecated(getSafeValue("deprecated", rows));
    dataFormat.setJavaType(getSafeValue("javaType", rows));
    dataFormat.setGroupId(getSafeValue("groupId", rows));
    dataFormat.setArtifactId(getSafeValue("artifactId", rows));
    dataFormat.setVersion(getSafeValue("version", rows));
    rows = parseJsonSchema("properties", json, true);
    for (Map<String, String> row : rows) {
        DataFormatOptionModel option = new DataFormatOptionModel();
        option.setName(getSafeValue("name", row));
        option.setDisplayName(getSafeValue("displayName", row));
        option.setKind(getSafeValue("kind", row));
        option.setType(getSafeValue("type", row));
        option.setJavaType(getSafeValue("javaType", row));
        option.setDeprecated(getSafeValue("deprecated", row));
        option.setEnumValues(getSafeValue("enum", row));
        option.setDefaultValue(getSafeValue("defaultValue", row));
        option.setDescription(getSafeValue("description", row));
        // special for bindy as we reuse one readme file
        if (dataFormatName.startsWith("bindy") && option.getName().equals("type")) {
            option.setDefaultValue("");
            String doc = option.getDescription() + " The default value is either Csv or KeyValue depending on chosen dataformat.";
            option.setDescription(doc);
        }
        // skip option named id
        if ("id".equals(option.getName())) {
            getLog().debug("Skipping option: " + option.getName());
        } else {
            dataFormat.addDataFormatOption(option);
        }
    }
    return dataFormat;
}
Also used : DataFormatModel(org.apache.camel.maven.packaging.model.DataFormatModel) DataFormatOptionModel(org.apache.camel.maven.packaging.model.DataFormatOptionModel) Map(java.util.Map)

Aggregations

DataFormatOptionModel (org.apache.camel.maven.packaging.model.DataFormatOptionModel)3 Map (java.util.Map)2 DataFormatModel (org.apache.camel.maven.packaging.model.DataFormatModel)2 HashMap (java.util.HashMap)1 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)1