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

feat(entities): Sort entity properties using the Camel Catalog #964

Merged
merged 1 commit into from
Mar 21, 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 @@ -315,23 +315,19 @@ public String getEntityCatalog() throws Exception {
var entityName = entry.getKey();
var entitySchema = entry.getValue();
var entityCatalog = catalogMap.get(entityName);
if ("beans".equals(entityName)) {
processBeansParameters(entitySchema, entityCatalog);
} else if ("from".equals(entityName)) {
processFromParameters(entitySchema, entityCatalog);
} else if ("route".equals(entityName)) {
processRouteParameters(entitySchema, entityCatalog);
} else if ("routeTemplate".equals(entityName)) {
processRouteTemplateParameters(entitySchema, entityCatalog);
} else if ("templatedRoute".equals(entityName)) {
processTemplatedRouteParameters(entitySchema, entityCatalog);
} else if ("restConfiguration".equals(entityName)) {
processRestConfigurationParameters(entitySchema, entityCatalog);
} else if ("rest".equals(entityName)) {
processRestParameters(entitySchema, entityCatalog);
} else {
processEntityParameters(entityName, entitySchema, entityCatalog);
switch (entityName) {
case "beans" -> processBeansParameters(entitySchema, entityCatalog);
case "from" -> processFromParameters(entitySchema, entityCatalog);
case "route" -> processRouteParameters(entitySchema, entityCatalog);
case "routeTemplate" -> processRouteTemplateParameters(entitySchema, entityCatalog);
case "templatedRoute" -> processTemplatedRouteParameters(entitySchema, entityCatalog);
case "restConfiguration" -> processRestConfigurationParameters(entitySchema, entityCatalog);
case "rest" -> processRestParameters(entitySchema, entityCatalog);
case null, default -> processEntityParameters(entityName, entitySchema, entityCatalog);
}

sortPropertiesAccordingToCamelCatalog(entitySchema, entityCatalog);

var json = JsonMapper.asJsonObject(entityCatalog).toJson();
var catalogTree = (ObjectNode) jsonMapper.readTree(json);
catalogTree.set("propertiesSchema", entitySchema);
Expand Down Expand Up @@ -513,6 +509,20 @@ private void processEntityParameters(String entityName, ObjectNode entitySchema,
}
}

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

for (var propertyName : camelYamlDslProperties) {
var propertySchema = entitySchema.withObject("/properties").withObject("/" + propertyName);
sortedSchemaProperties.set(propertyName, propertySchema);
}

entitySchema.set("properties", sortedSchemaProperties);
}

private void addMoreBeans(ObjectNode answer, Map<String, EipModel> catalogMap) throws Exception {
var beansCatalog = catalogMap.get("beans");
var json = JsonMapper.asJsonObject(beansCatalog).toJson();
Expand Down
Loading