Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(440): Sort language/dataformat properties with catalog index order #1518

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.camel.catalog.CamelCatalog;
import org.apache.camel.tooling.model.ComponentModel;
import org.apache.camel.tooling.model.EipModel;
import org.apache.camel.tooling.model.EipModel.EipOptionModel;
import org.apache.camel.tooling.model.JsonMapper;
import org.apache.camel.tooling.model.Kind;

Expand Down Expand Up @@ -200,11 +201,24 @@
* @throws Exception
*/
public String getDataFormatCatalog() throws Exception {
var catalogMap = new LinkedHashMap<String, EipModel>();

Check warning on line 204 in packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java

View check run for this annotation

Codecov / codecov/patch

packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java#L204

Added line #L204 was not covered by tests
for (var name : camelCatalog.findDataFormatNames()) {
var modelCatalog = camelCatalog.dataFormatModel(name);
catalogMap.put(modelCatalog.getName(), camelCatalog.eipModel(name));
}

Check warning on line 208 in packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java

View check run for this annotation

Codecov / codecov/patch

packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java#L206-L208

Added lines #L206 - L208 were not covered by tests
var answer = jsonMapper.createObjectNode();
var dataFormatSchemaMap = schemaProcessor.getDataFormats();
for (var entry : dataFormatSchemaMap.entrySet()) {
var dataFormatName = entry.getKey();
var dataFormatSchema = entry.getValue();
EipModel eipModel = catalogMap.get(dataFormatName);
List<EipOptionModel> eipModelOptions = Arrays.asList();

Check warning on line 215 in packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java

View check run for this annotation

Codecov / codecov/patch

packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java#L214-L215

Added lines #L214 - L215 were not covered by tests
if (eipModel != null) {
eipModelOptions = eipModel.getOptions();

Check warning on line 217 in packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java

View check run for this annotation

Codecov / codecov/patch

packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java#L217

Added line #L217 was not covered by tests
}

sortPropertiesAccordingToCamelCatalog(dataFormatSchema, eipModelOptions);

Check warning on line 220 in packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java

View check run for this annotation

Codecov / codecov/patch

packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java#L220

Added line #L220 was not covered by tests

var dataFormatCatalog = (EipModel) camelCatalog.model(Kind.eip, dataFormatName);
if (dataFormatCatalog == null) {
throw new Exception("DataFormat " + dataFormatName + " is not found in Camel model catalog.");
Expand All @@ -230,9 +244,22 @@
public String getLanguageCatalog() throws Exception {
var answer = jsonMapper.createObjectNode();
var languageSchemaMap = schemaProcessor.getLanguages();
var catalogMap = new LinkedHashMap<String, EipModel>();

Check warning on line 247 in packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java

View check run for this annotation

Codecov / codecov/patch

packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java#L247

Added line #L247 was not covered by tests
for (var name : camelCatalog.findLanguageNames()) {
var modelCatalog = camelCatalog.languageModel(name);
catalogMap.put(modelCatalog.getName(), camelCatalog.eipModel(name));
}

Check warning on line 251 in packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java

View check run for this annotation

Codecov / codecov/patch

packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java#L249-L251

Added lines #L249 - L251 were not covered by tests
for (var entry : languageSchemaMap.entrySet()) {
var languageName = entry.getKey();
var languageSchema = entry.getValue();
EipModel eipModel = catalogMap.get(languageName);
List<EipOptionModel> eipModelOptions = Arrays.asList();

Check warning on line 256 in packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java

View check run for this annotation

Codecov / codecov/patch

packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java#L255-L256

Added lines #L255 - L256 were not covered by tests
if (eipModel != null) {
eipModelOptions = eipModel.getOptions();

Check warning on line 258 in packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java

View check run for this annotation

Codecov / codecov/patch

packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java#L258

Added line #L258 was not covered by tests
}

sortPropertiesAccordingToCamelCatalog(languageSchema, eipModelOptions);

Check warning on line 261 in packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java

View check run for this annotation

Codecov / codecov/patch

packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java#L261

Added line #L261 was not covered by tests

var languageCatalog = (EipModel) camelCatalog.model(Kind.eip, languageName);
if (languageCatalog == null) {
throw new Exception("Language " + languageName + " is not found in Camel model catalog.");
Expand Down Expand Up @@ -426,7 +453,7 @@
processEntityParameters(entityName, entitySchema, entityCatalog);
}

sortPropertiesAccordingToCamelCatalog(entitySchema, entityCatalog);
sortPropertiesAccordingToCamelCatalog(entitySchema, entityCatalog.getOptions());

Check warning on line 456 in packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java

View check run for this annotation

Codecov / codecov/patch

packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java#L456

Added line #L456 was not covered by tests

var json = JsonMapper.asJsonObject(entityCatalog).toJson();
var catalogTree = (ObjectNode) jsonMapper.readTree(json);
Expand Down Expand Up @@ -624,11 +651,11 @@
}
}

private void sortPropertiesAccordingToCamelCatalog(ObjectNode entitySchema, EipModel entityCatalog) {
private void sortPropertiesAccordingToCamelCatalog(ObjectNode entitySchema, List<EipOptionModel> entityCatalogOptions) {
var sortedSchemaProperties = jsonMapper.createObjectNode();
var camelYamlDslProperties = entitySchema.withObject("/properties").properties().stream().map(Map.Entry::getKey)
.sorted(
new CamelYamlDSLKeysComparator(entityCatalog.getOptions()))
new CamelYamlDSLKeysComparator(entityCatalogOptions))
.toList();

for (var propertyName : camelYamlDslProperties) {
Expand Down