public static Set<String> componentsFromArtifact(CamelCatalog camelCatalog, String artifactId) { Set<String> answer = new TreeSet<String>(); // use the camel catalog to find what components the artifact has for (String name : camelCatalog.findComponentNames()) { String json = camelCatalog.componentJSonSchema(name); if (json != null) { List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("component", json, false); String scheme = null; String artifact = null; for (Map<String, String> row : data) { if (row.get("artifactId") != null) { artifact = row.get("artifactId"); } if (row.get("scheme") != null) { scheme = row.get("scheme"); } } if (artifactId.equals(artifact) && scheme != null) { answer.add(scheme); } } } return answer; }
public static Set<String> dataFormatsFromArtifact(CamelCatalog camelCatalog, String artifactId) { Set<String> answer = new TreeSet<String>(); // use the camel catalog to find what components the artifact has for (String name : camelCatalog.findDataFormatNames()) { String json = camelCatalog.dataFormatJSonSchema(name); if (json != null) { List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("dataformat", json, false); String df = null; String artifact = null; for (Map<String, String> row : data) { if (row.get("artifactId") != null) { artifact = row.get("artifactId"); } if (row.get("name") != null) { df = row.get("name"); } } if (artifactId.equals(artifact) && df != null) { answer.add(df); } } } return answer; }
public static Set<String> languagesFromArtifact(CamelCatalog camelCatalog, String artifactId) { Set<String> answer = new TreeSet<String>(); // use the camel catalog to find what components the artifact has for (String name : camelCatalog.findLanguageNames()) { String json = camelCatalog.languageJSonSchema(name); if (json != null) { List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("language", json, false); String lan = null; String artifact = null; for (Map<String, String> row : data) { if (row.get("artifactId") != null) { artifact = row.get("artifactId"); } if (row.get("name") != null) { lan = row.get("name"); } } if (artifactId.equals(artifact) && lan != null) { answer.add(lan); } } } return answer; }
/** * Checks whether the given value is matching the default value from the given component. * * @param scheme the component name * @param key the option key * @param value the option value * @return <tt>true</tt> if matching the default value, <tt>false</tt> otherwise */ public static boolean isDefaultValue(CamelCatalog camelCatalog, String scheme, String key, String value) { // use the camel catalog String json = camelCatalog.componentJSonSchema(scheme); if (json == null) { throw new IllegalArgumentException("Could not find catalog entry for component name: " + scheme); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("properties", json, true); if (data != null) { for (Map<String, String> propertyMap : data) { String name = propertyMap.get("name"); String defaultValue = propertyMap.get("defaultValue"); if (key.equals(name)) { return value.equalsIgnoreCase(defaultValue); } } } return false; }
/** * Checks whether the given value is matching the default value from the given component. * * @param scheme the component name * @param key the option key * @param value the option value * @return <tt>true</tt> if matching the default value, <tt>false</tt> otherwise */ public static boolean isDefaultValueComponent(CamelCatalog camelCatalog, String scheme, String key, String value) { // use the camel catalog String json = camelCatalog.componentJSonSchema(scheme); if (json == null) { throw new IllegalArgumentException("Could not find catalog entry for component name: " + scheme); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("componentProperties", json, true); if (data != null) { for (Map<String, String> propertyMap : data) { String name = propertyMap.get("name"); String defaultValue = propertyMap.get("defaultValue"); if (key.equals(name)) { return value.equalsIgnoreCase(defaultValue); } } } return false; }
/** * Checks whether the given key is a multi valued option * * @param scheme the component name * @param key the option key * @return <tt>true</tt> if the key is multi valued, <tt>false</tt> otherwise */ public static boolean isMultiValue(CamelCatalog camelCatalog, String scheme, String key) { // use the camel catalog String json = camelCatalog.componentJSonSchema(scheme); if (json == null) { throw new IllegalArgumentException("Could not find catalog entry for component name: " + scheme); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("properties", json, true); if (data != null) { for (Map<String, String> propertyMap : data) { String name = propertyMap.get("name"); String multiValue = propertyMap.get("multiValue"); if (key.equals(name)) { return "true".equals(multiValue); } } } return false; }
/** * Checks whether the given key is a multi valued option * * @param scheme the component name * @param key the option key * @return <tt>true</tt> if the key is multi valued, <tt>false</tt> otherwise */ public static String getPrefix(CamelCatalog camelCatalog, String scheme, String key) { // use the camel catalog String json = camelCatalog.componentJSonSchema(scheme); if (json == null) { throw new IllegalArgumentException("Could not find catalog entry for component name: " + scheme); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("properties", json, true); if (data != null) { for (Map<String, String> propertyMap : data) { String name = propertyMap.get("name"); String prefix = propertyMap.get("prefix"); if (key.equals(name)) { return prefix; } } } return null; }
/** * Checks whether the given value corresponds to a dummy none placeholder for an enum type * * @param scheme the component name * @param key the option key * @return <tt>true</tt> if matching the default value, <tt>false</tt> otherwise */ public static boolean isNonePlaceholderEnumValue(CamelCatalog camelCatalog, String scheme, String key) { // use the camel catalog String json = camelCatalog.componentJSonSchema(scheme); if (json == null) { throw new IllegalArgumentException("Could not find catalog entry for component name: " + scheme); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("properties", json, true); if (data != null) { for (Map<String, String> propertyMap : data) { String name = propertyMap.get("name"); String enums = propertyMap.get("enum"); if (key.equals(name) && enums != null) { if (!enums.contains("none")) { return true; } else { return false; } } } } return false; }
/** * Checks whether the given value corresponds to a dummy none placeholder for an enum type * * @param scheme the component name * @param key the option key * @return <tt>true</tt> if matching the default value, <tt>false</tt> otherwise */ public static boolean isNonePlaceholderEnumValueComponent(CamelCatalog camelCatalog, String scheme, String key) { // use the camel catalog String json = camelCatalog.componentJSonSchema(scheme); if (json == null) { throw new IllegalArgumentException("Could not find catalog entry for component name: " + scheme); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("componentProperties", json, true); if (data != null) { for (Map<String, String> propertyMap : data) { String name = propertyMap.get("name"); String enums = propertyMap.get("enum"); if (key.equals(name) && enums != null) { if (!enums.contains("none")) { return true; } else { return false; } } } } return false; }
/** * Get's the java type for the given option if its enum based, otherwise it returns null * * @param scheme the component name * @param key the option key * @return <tt>true</tt> if matching the default value, <tt>false</tt> otherwise */ public static String getEnumJavaTypeComponent(CamelCatalog camelCatalog, String scheme, String key) { // use the camel catalog String json = camelCatalog.componentJSonSchema(scheme); if (json == null) { throw new IllegalArgumentException("Could not find catalog entry for component name: " + scheme); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("componentProperties", json, true); if (data != null) { for (Map<String, String> propertyMap : data) { String javaType = propertyMap.get("javaType"); String name = propertyMap.get("name"); String enums = propertyMap.get("enum"); if (key.equals(name) && enums != null) { return javaType; } } } return null; }
/** * Checks whether the given value is matching the default value from the given model. * * @param modelName the model name * @param key the option key * @param value the option value * @return <tt>true</tt> if matching the default value, <tt>false</tt> otherwise */ public static boolean isModelDefaultValue(CamelCatalog camelCatalog, String modelName, String key, String value) { // use the camel catalog String json = camelCatalog.modelJSonSchema(modelName); if (json == null) { throw new IllegalArgumentException("Could not find catalog entry for model name: " + modelName); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("properties", json, true); if (data != null) { for (Map<String, String> propertyMap : data) { String name = propertyMap.get("name"); String defaultValue = propertyMap.get("defaultValue"); if (key.equals(name)) { return value.equalsIgnoreCase(defaultValue); } } } return false; }
/** * Checks whether the given key is an expression kind * * @param modelName the model name * @param key the option key * @return <tt>true</tt> if the key is an expression type, <tt>false</tt> otherwise */ public static boolean isModelExpressionKind(CamelCatalog camelCatalog, String modelName, String key) { // use the camel catalog String json = camelCatalog.modelJSonSchema(modelName); if (json == null) { throw new IllegalArgumentException("Could not find catalog entry for model name: " + modelName); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("properties", json, true); if (data != null) { for (Map<String, String> propertyMap : data) { String name = propertyMap.get("name"); if (key.equals(name)) { return "expression".equals(propertyMap.get("kind")); } } } return false; }
/** * Gets the java type of the given model * * @param modelName the model name * @return the java type */ public static String getModelJavaType(CamelCatalog camelCatalog, String modelName) { // use the camel catalog String json = camelCatalog.modelJSonSchema(modelName); if (json == null) { throw new IllegalArgumentException("Could not find catalog entry for model name: " + modelName); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("model", json, false); if (data != null) { for (Map<String, String> propertyMap : data) { String javaType = propertyMap.get("javaType"); if (javaType != null) { return javaType; } } } return null; }
/** * Whether the EIP supports outputs * * @param modelName the model name * @return <tt>true</tt> if output supported, <tt>false</tt> otherwise */ public static boolean isModelSupportOutput(CamelCatalog camelCatalog, String modelName) { // use the camel catalog String json = camelCatalog.modelJSonSchema(modelName); if (json == null) { throw new IllegalArgumentException("Could not find catalog entry for model name: " + modelName); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("model", json, false); if (data != null) { for (Map<String, String> propertyMap : data) { String output = propertyMap.get("output"); if (output != null) { return "true".equals(output); } } } return false; }
/** * Whether the component is consumer only */ public static boolean isComponentConsumerOnly(CamelCatalog camelCatalog, String scheme) { // use the camel catalog String json = camelCatalog.componentJSonSchema(scheme); if (json == null) { return false; } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("component", json, false); if (data != null) { for (Map<String, String> propertyMap : data) { String consumerOnly = propertyMap.get("consumerOnly"); if (consumerOnly != null) { return true; } } } return false; }
/** * Whether the component is consumer only */ public static boolean isComponentProducerOnly(CamelCatalog camelCatalog, String scheme) { // use the camel catalog String json = camelCatalog.componentJSonSchema(scheme); if (json == null) { return false; } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("component", json, false); if (data != null) { for (Map<String, String> propertyMap : data) { String consumerOnly = propertyMap.get("producerOnly"); if (consumerOnly != null) { return true; } } } return false; }
public static ComponentDto createComponentDto(CamelCatalog camelCatalog, String scheme) { // use the camel catalog String json = camelCatalog.componentJSonSchema(scheme); if (json == null) { return null; } ComponentDto dto = new ComponentDto(); List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("component", json, false); for (Map<String, String> row : data) { if (row.get("scheme") != null) { dto.setScheme(row.get("scheme")); } else if (row.get("syntax") != null) { dto.setSyntax(row.get("syntax")); } else if (row.get("title") != null) { dto.setTitle(row.get("title")); } else if (row.get("description") != null) { dto.setDescription(row.get("description")); } else if (row.get("label") != null) { String labelText = row.get("label"); if (Strings.isNotBlank(labelText)) { dto.setTags(labelText.split(",")); } } else if (row.get("consumerOnly") != null) { dto.setConsumerOnly("true".equals(row.get("consumerOnly"))); } else if (row.get("producerOnly") != null) { dto.setProducerOnly("true".equals(row.get("producerOnly"))); } else if (row.get("javaType") != null) { dto.setJavaType(row.get("javaType")); } else if (row.get("groupId") != null) { dto.setGroupId(row.get("groupId")); } else if (row.get("artifactId") != null) { dto.setArtifactId(row.get("artifactId")); } else if (row.get("version") != null) { dto.setVersion(row.get("version")); } } return dto; }
public static EipDto createEipDto(CamelCatalog camelCatalog, String modelName) { // use the camel catalog String json = camelCatalog.modelJSonSchema(modelName); if (json == null) { return null; } EipDto dto = new EipDto(); List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("model", json, false); for (Map<String, String> row : data) { if (row.get("name") != null) { dto.setName(row.get("name")); } else if (row.get("title") != null) { dto.setTitle(row.get("title")); } else if (row.get("description") != null) { dto.setDescription(row.get("description")); } else if (row.get("label") != null) { String labelText = row.get("label"); if (Strings.isNotBlank(labelText)) { dto.setTags(labelText.split(",")); } } else if (row.get("javaType") != null) { dto.setJavaType(row.get("javaType")); } } return dto; }
public static DataFormatDto createDataFormatDto(CamelCatalog camelCatalog, String name) { // use the camel catalog String json = camelCatalog.dataFormatJSonSchema(name); if (json == null) { return null; } DataFormatDto dto = new DataFormatDto(); List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("dataformat", json, false); for (Map<String, String> row : data) { if (row.get("name") != null) { dto.setName(row.get("name")); } else if (row.get("modelName") != null) { dto.setModelName(row.get("modelName")); } else if (row.get("title") != null) { dto.setTitle(row.get("title")); } else if (row.get("description") != null) { dto.setDescription(row.get("description")); } else if (row.get("label") != null) { String labelText = row.get("label"); if (Strings.isNotBlank(labelText)) { dto.setTags(labelText.split(",")); } } else if (row.get("javaType") != null) { dto.setJavaType(row.get("javaType")); } else if (row.get("modelJavaType") != null) { dto.setModelJavaType(row.get("modelJavaType")); } else if (row.get("groupId") != null) { dto.setGroupId(row.get("groupId")); } else if (row.get("artifactId") != null) { dto.setArtifactId(row.get("artifactId")); } else if (row.get("version") != null) { dto.setVersion(row.get("version")); } } return dto; }
/** * Populates the details for the given component, returning a Result if it fails. */ public static Result loadCamelComponentDetails(CamelCatalog camelCatalog, String camelComponentName, CamelComponentDetails details) { String json = camelCatalog.componentJSonSchema(camelComponentName); if (json == null) { return Results.fail("Could not find catalog entry for component name: " + camelComponentName); } List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("component", json, false); for (Map<String, String> row : data) { String javaType = row.get("javaType"); if (!Strings.isNullOrEmpty(javaType)) { details.setComponentClassQName(javaType); } String groupId = row.get("groupId"); if (!Strings.isNullOrEmpty(groupId)) { details.setGroupId(groupId); } String artifactId = row.get("artifactId"); if (!Strings.isNullOrEmpty(artifactId)) { details.setArtifactId(artifactId); } String version = row.get("version"); if (!Strings.isNullOrEmpty(version)) { details.setVersion(version); } } if (Strings.isNullOrEmpty(details.getComponentClassQName())) { return Results.fail("Could not find fully qualified class name in catalog for component name: " + camelComponentName); } return null; }
private static String findLabel(String json) { List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("model", json, false); for (Map<String, String> row : data) { if (row.get("label") != null) { return row.get("label"); } } return null; }
private static String findArtifactId(String json) { List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("dataformat", json, false); for (Map<String, String> row : data) { if (row.get("artifactId") != null) { return row.get("artifactId"); } } return null; }
private List<String> filterByMustHaveOptions(List<String> choices) { List<String> answer = new ArrayList<String>(); for (String name : choices) { String json = camelCatalog.componentJSonSchema(name); // must have at least one component option List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("componentProperties", json, true); if (!data.isEmpty()) { answer.add(name); } } return answer; }
private static String findArtifactId(String json) { List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("component", json, false); for (Map<String, String> row : data) { if (row.get("artifactId") != null) { return row.get("artifactId"); } } return null; }
private static String findConsumerOnly(String json) { List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("component", json, false); for (Map<String, String> row : data) { if (row.get("consumerOnly") != null) { return row.get("consumerOnly"); } } return null; }
private static String findProducerOnly(String json) { List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("component", json, false); for (Map<String, String> row : data) { if (row.get("producerOnly") != null) { return row.get("producerOnly"); } } return null; }
private static String findLabel(String json) { List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("component", json, false); for (Map<String, String> row : data) { if (row.get("label") != null) { return row.get("label"); } } return null; }
private static String findArtifactId(String json) { List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("language", json, false); for (Map<String, String> row : data) { if (row.get("artifactId") != null) { return row.get("artifactId"); } } return null; }
public static LanguageDto createLanguageDto(CamelCatalog camelCatalog, String name) { // use the camel catalog // TODO: 2.17.3/2.18 method is bean language if ("method".equals(name)) { name = "bean"; } String json = camelCatalog.languageJSonSchema(name); if (json == null) { return null; } LanguageDto dto = new LanguageDto(); List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("language", json, false); for (Map<String, String> row : data) { if (row.get("name") != null) { dto.setName(row.get("name")); } else if (row.get("modelName") != null) { dto.setModelName(row.get("modelName")); } else if (row.get("title") != null) { dto.setTitle(row.get("title")); } else if (row.get("description") != null) { dto.setDescription(row.get("description")); } else if (row.get("label") != null) { String labelText = row.get("label"); if (Strings.isNotBlank(labelText)) { dto.setTags(labelText.split(",")); } } else if (row.get("javaType") != null) { dto.setJavaType(row.get("javaType")); } else if (row.get("modelJavaType") != null) { dto.setModelJavaType(row.get("modelJavaType")); } else if (row.get("groupId") != null) { dto.setGroupId(row.get("groupId")); } else if (row.get("artifactId") != null) { dto.setArtifactId(row.get("artifactId")); } else if (row.get("version") != null) { dto.setVersion(row.get("version")); } } return dto; }
private void expressionOptions(String k, ExpressionDefinition exp, Map<String, String> options) { // special for aggregate as it has naming clash if ("completionSizeExpression".equals(k)) { k = "completionSize"; } else if ("completionTimeoutExpression".equals(k)) { k = "completionTimeout"; } String text = exp.getExpression(); String lan = exp.getLanguage(); options.put(k, lan); if (text != null) { options.put(k + "_value", text); } // when using a language as an expression it can contain additional options which we // cannot build a nice UI in forge as forge is not that dynamic. So instead we have an extra // input field where we allow users to edit the values using a Camel multivalue uri style with // key=value&key2=value2 ... CollectionStringBuffer csb = new CollectionStringBuffer("&"); String json = getCamelCatalog().languageJSonSchema(lan); if (json != null) { List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("properties", json, true); if (data != null) { for (Map<String, String> map : data) { String name = map.get("name"); // skip expression/id as we are not interested in those if (name != null && !"id".equals(name) && !"expression".equals(name)) { try { Object value = IntrospectionSupport.getProperty(exp, name); if (value != null) { text = value.toString(); csb.append(name + "=" + text); } } catch (Exception e) { // ignore } } } } if (!csb.isEmpty()) { String extra = csb.toString(); options.put(k + "_extra", extra); } } }