-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(catalog): Sort Processor's properties
Currently, since the component's schema is generated from the Camel's components catalog, iterating over the properties dictionary, the output is written using the same sorting as well. Ths is not the case for processors, which are extracted from the Camel YAML DSL schema first, and then decorated with elements from the Camel's catalog. This commit change the iteration to be performed from the Camel's processor catalog instead. Changes: * Move the `class:xxx` information from `$comment` to `format` * Move the `duration` information from `$comment` to `format` * Add `format: password` for `secret: true` fields fix: #51
- Loading branch information
Showing
4 changed files
with
117 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...-catalog-maven-plugin/src/main/java/io/kaoto/camelcatalog/CamelYamlDSLKeysComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.kaoto.camelcatalog; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.apache.camel.tooling.model.EipModel.EipOptionModel; | ||
|
||
public class CamelYamlDSLKeysComparator implements Comparator<String> { | ||
|
||
private final List<EipOptionModel> eipOptions; | ||
|
||
CamelYamlDSLKeysComparator(List<EipOptionModel> eipOptions) { | ||
this.eipOptions = eipOptions; | ||
} | ||
|
||
@Override | ||
public int compare(String firstKey, String secondKey) { | ||
Optional<EipOptionModel> firstOption = eipOptions.stream().filter(e -> e.getName().equals(firstKey)).findFirst(); | ||
Optional<EipOptionModel> secondOption = eipOptions.stream().filter(e -> e.getName().equals(secondKey)).findFirst(); | ||
|
||
var firstIndex = firstOption.isPresent() ? firstOption.get().getIndex() : Integer.MAX_VALUE; | ||
var secondIndex = secondOption.isPresent() ? secondOption.get().getIndex() : Integer.MAX_VALUE; | ||
|
||
return Integer.compare(firstIndex, secondIndex); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...alog-maven-plugin/src/test/java/io/kaoto/camelcatalog/CamelYamlDSLKeysComparatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.kaoto.camelcatalog; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
import org.apache.camel.catalog.DefaultCamelCatalog; | ||
import org.apache.camel.catalog.Kind; | ||
import org.apache.camel.tooling.model.EipModel; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class CamelYamlDSLKeysComparatorTest { | ||
private DefaultCamelCatalog api; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
this.api = new DefaultCamelCatalog(); | ||
} | ||
|
||
@Test | ||
public void sort_keys_using_the_catalog_index() throws Exception { | ||
var aggregateCatalogModel = (EipModel) api.model(Kind.eip, "aggregate"); | ||
|
||
List<String> aggregateKeysFromCamelYAMLDsl = List.of("aggregateController", "aggregationRepository", | ||
"aggregationStrategy", "aggregationStrategyMethodAllowNull", "aggregationStrategyMethodName", | ||
"closeCorrelationKeyOnCompletion", "completeAllOnStop", "completionFromBatchConsumer", | ||
"completionInterval", "completionOnNewCorrelationGroup", "completionPredicate", "completionSize", | ||
"completionSizeExpression", "completionTimeout", "completionTimeoutCheckerInterval", | ||
"completionTimeoutExpression", "correlationExpression", "description", "disabled", | ||
"discardOnAggregationFailure", "discardOnCompletionTimeout", "eagerCheckCompletion", "executorService", | ||
"forceCompletionOnStop", "id", "ignoreInvalidCorrelationKeys", "optimisticLockRetryPolicy", | ||
"optimisticLocking", "parallelProcessing", "steps", "timeoutCheckerExecutorService"); | ||
|
||
List<String> expected = List.of("id", "description", "disabled", "correlationExpression", "completionPredicate", | ||
"completionTimeoutExpression", "completionSizeExpression", "optimisticLockRetryPolicy", | ||
"parallelProcessing", "optimisticLocking", "executorService", "timeoutCheckerExecutorService", | ||
"aggregateController", "aggregationRepository", "aggregationStrategy", "aggregationStrategyMethodName", | ||
"aggregationStrategyMethodAllowNull", "completionSize", "completionInterval", "completionTimeout", | ||
"completionTimeoutCheckerInterval", "completionFromBatchConsumer", "completionOnNewCorrelationGroup", | ||
"eagerCheckCompletion", "ignoreInvalidCorrelationKeys", "closeCorrelationKeyOnCompletion", | ||
"discardOnCompletionTimeout", "discardOnAggregationFailure", "forceCompletionOnStop", | ||
"completeAllOnStop", "steps"); | ||
|
||
Comparator<String> comparator = new CamelYamlDSLKeysComparator(aggregateCatalogModel.getOptions()); | ||
|
||
List<String> result = aggregateKeysFromCamelYAMLDsl.stream().sorted(comparator).toList(); | ||
|
||
assertEquals(result, expected); | ||
} | ||
|
||
} |