Skip to content

Commit

Permalink
fix(440): Sort language/dataformat properties with catalog index order
Browse files Browse the repository at this point in the history
  • Loading branch information
tplevko committed Oct 3, 2024
1 parent b201f6b commit 08259af
Showing 1 changed file with 30 additions and 3 deletions.
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 @@ private void generatePropertiesSchema(ObjectNode parent) {
* @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 getDataFormatCatalog() throws Exception {
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 @@ public String getEntityCatalog() throws Exception {
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 processEntityParameters(String entityName, ObjectNode entitySchema,
}
}

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

0 comments on commit 08259af

Please sign in to comment.