Search in sources :

Example 16 with LinkedHashMap

use of java.util.LinkedHashMap in project camel by apache.

the class DefaultCamelContext method explainComponentJson.

public String explainComponentJson(String componentName, boolean includeAllOptions) {
    try {
        String json = getComponentParameterJsonSchema(componentName);
        if (json == null) {
            return null;
        }
        List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("componentProperties", json, true);
        // selected rows to use for answer
        Map<String, String[]> selected = new LinkedHashMap<String, String[]>();
        // insert values from component
        Component component = getComponent(componentName);
        Map<String, Object> options = new HashMap<String, Object>();
        IntrospectionSupport.getProperties(component, options, null);
        for (Map.Entry<String, Object> entry : options.entrySet()) {
            String name = entry.getKey();
            // skip unwanted options which is default inherited from DefaultComponent
            if ("camelContext".equals(name) || "endpointClass".equals(name)) {
                continue;
            }
            String value = "";
            if (entry.getValue() != null) {
                value = entry.getValue().toString();
            }
            value = URISupport.sanitizePath(value);
            // find type and description from the json schema
            String type = null;
            String kind = null;
            String group = null;
            String label = null;
            String required = null;
            String javaType = null;
            String deprecated = null;
            String secret = null;
            String defaultValue = null;
            String description = null;
            for (Map<String, String> row : rows) {
                if (name.equals(row.get("name"))) {
                    type = row.get("type");
                    kind = row.get("kind");
                    group = row.get("group");
                    label = row.get("label");
                    required = row.get("required");
                    javaType = row.get("javaType");
                    deprecated = row.get("deprecated");
                    secret = row.get("secret");
                    defaultValue = row.get("defaultValue");
                    description = row.get("description");
                    break;
                }
            }
            // add as selected row
            selected.put(name, new String[] { name, kind, group, label, required, type, javaType, deprecated, secret, value, defaultValue, description });
        }
        // include other rows
        for (Map<String, String> row : rows) {
            String name = row.get("name");
            String kind = row.get("kind");
            String group = row.get("group");
            String label = row.get("label");
            String required = row.get("required");
            String value = row.get("value");
            String defaultValue = row.get("defaultValue");
            String type = row.get("type");
            String javaType = row.get("javaType");
            String deprecated = row.get("deprecated");
            String secret = row.get("secret");
            value = URISupport.sanitizePath(value);
            String description = row.get("description");
            // always include path options
            if (includeAllOptions) {
                // add as selected row
                if (!selected.containsKey(name)) {
                    selected.put(name, new String[] { name, kind, group, label, required, type, javaType, deprecated, secret, value, defaultValue, description });
                }
            }
        }
        json = ObjectHelper.before(json, "  \"componentProperties\": {");
        StringBuilder buffer = new StringBuilder("  \"componentProperties\": {");
        boolean first = true;
        for (String[] row : selected.values()) {
            if (first) {
                first = false;
            } else {
                buffer.append(",");
            }
            buffer.append("\n    ");
            String name = row[0];
            String kind = row[1];
            String group = row[2];
            String label = row[3];
            String required = row[4];
            String type = row[5];
            String javaType = row[6];
            String deprecated = row[7];
            String secret = row[8];
            String value = row[9];
            String defaultValue = row[10];
            String description = row[11];
            // add json of the option
            buffer.append(StringQuoteHelper.doubleQuote(name)).append(": { ");
            CollectionStringBuffer csb = new CollectionStringBuffer();
            if (kind != null) {
                csb.append("\"kind\": \"" + kind + "\"");
            }
            if (group != null) {
                csb.append("\"group\": \"" + group + "\"");
            }
            if (label != null) {
                csb.append("\"label\": \"" + label + "\"");
            }
            if (required != null) {
                csb.append("\"required\": \"" + required + "\"");
            }
            if (type != null) {
                csb.append("\"type\": \"" + type + "\"");
            }
            if (javaType != null) {
                csb.append("\"javaType\": \"" + javaType + "\"");
            }
            if (deprecated != null) {
                csb.append("\"deprecated\": \"" + deprecated + "\"");
            }
            if (secret != null) {
                csb.append("\"secret\": \"" + secret + "\"");
            }
            if (value != null) {
                csb.append("\"value\": \"" + value + "\"");
            }
            if (defaultValue != null) {
                csb.append("\"defaultValue\": \"" + defaultValue + "\"");
            }
            if (description != null) {
                csb.append("\"description\": \"" + description + "\"");
            }
            if (!csb.isEmpty()) {
                buffer.append(csb.toString());
            }
            buffer.append(" }");
        }
        buffer.append("\n  }\n}\n");
        // insert the original first part of the json into the start of the buffer
        buffer.insert(0, json);
        return buffer.toString();
    } catch (Exception e) {
        // ignore and return empty response
        return null;
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MalformedObjectNameException(javax.management.MalformedObjectNameException) VetoCamelContextStartException(org.apache.camel.VetoCamelContextStartException) IOException(java.io.IOException) LoadPropertiesException(org.apache.camel.util.LoadPropertiesException) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) FailedToStartRouteException(org.apache.camel.FailedToStartRouteException) LinkedHashMap(java.util.LinkedHashMap) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) Component(org.apache.camel.Component) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 17 with LinkedHashMap

use of java.util.LinkedHashMap in project camel by apache.

the class MBeanInfoAssembler method getMBeanInfo.

/**
     * Gets the {@link ModelMBeanInfo} for the given managed bean
     *
     * @param defaultManagedBean  the default managed bean
     * @param customManagedBean   an optional custom managed bean
     * @param objectName   the object name
     * @return the model info, or <tt>null</tt> if not possible to create, for example due the managed bean is a proxy class
     * @throws JMException is thrown if error creating the model info
     */
public ModelMBeanInfo getMBeanInfo(Object defaultManagedBean, Object customManagedBean, String objectName) throws JMException {
    // skip proxy classes
    if (defaultManagedBean != null && Proxy.isProxyClass(defaultManagedBean.getClass())) {
        LOG.trace("Skip creating ModelMBeanInfo due proxy class {}", defaultManagedBean.getClass());
        return null;
    }
    // maps and lists to contain information about attributes and operations
    Map<String, ManagedAttributeInfo> attributes = new LinkedHashMap<String, ManagedAttributeInfo>();
    Set<ManagedOperationInfo> operations = new LinkedHashSet<ManagedOperationInfo>();
    Set<ModelMBeanAttributeInfo> mBeanAttributes = new LinkedHashSet<ModelMBeanAttributeInfo>();
    Set<ModelMBeanOperationInfo> mBeanOperations = new LinkedHashSet<ModelMBeanOperationInfo>();
    Set<ModelMBeanNotificationInfo> mBeanNotifications = new LinkedHashSet<ModelMBeanNotificationInfo>();
    // extract details from default managed bean
    if (defaultManagedBean != null) {
        extractAttributesAndOperations(defaultManagedBean.getClass(), attributes, operations);
        extractMbeanAttributes(defaultManagedBean, attributes, mBeanAttributes, mBeanOperations);
        extractMbeanOperations(defaultManagedBean, operations, mBeanOperations);
        extractMbeanNotifications(defaultManagedBean, mBeanNotifications);
    }
    // extract details from custom managed bean
    if (customManagedBean != null) {
        extractAttributesAndOperations(customManagedBean.getClass(), attributes, operations);
        extractMbeanAttributes(customManagedBean, attributes, mBeanAttributes, mBeanOperations);
        extractMbeanOperations(customManagedBean, operations, mBeanOperations);
        extractMbeanNotifications(customManagedBean, mBeanNotifications);
    }
    // create the ModelMBeanInfo
    String name = getName(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
    String description = getDescription(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
    ModelMBeanAttributeInfo[] arrayAttributes = mBeanAttributes.toArray(new ModelMBeanAttributeInfo[mBeanAttributes.size()]);
    ModelMBeanOperationInfo[] arrayOperations = mBeanOperations.toArray(new ModelMBeanOperationInfo[mBeanOperations.size()]);
    ModelMBeanNotificationInfo[] arrayNotifications = mBeanNotifications.toArray(new ModelMBeanNotificationInfo[mBeanNotifications.size()]);
    ModelMBeanInfo info = new ModelMBeanInfoSupport(name, description, arrayAttributes, null, arrayOperations, arrayNotifications);
    LOG.trace("Created ModelMBeanInfo {}", info);
    return info;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) ModelMBeanNotificationInfo(javax.management.modelmbean.ModelMBeanNotificationInfo) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) LinkedHashMap(java.util.LinkedHashMap) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport)

Example 18 with LinkedHashMap

use of java.util.LinkedHashMap in project camel by apache.

the class CwComponentTest method setsMeticDimensions.

@Test
public void setsMeticDimensions() throws Exception {
    template.send("direct:start", ExchangePattern.InOnly, new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(CwConstants.METRIC_NAME, "errorCount");
            Map<String, String> dimensionsMap = new LinkedHashMap<String, String>();
            dimensionsMap.put("keyOne", "valueOne");
            dimensionsMap.put("keyTwo", "valueTwo");
            exchange.getIn().setHeader(CwConstants.METRIC_DIMENSIONS, dimensionsMap);
        }
    });
    ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
    verify(cloudWatchClient).putMetricData(argument.capture());
    List<Dimension> dimensions = argument.getValue().getMetricData().get(0).getDimensions();
    Dimension dimension = dimensions.get(0);
    assertThat(dimensions.size(), is(2));
    assertEquals("keyOne", dimension.getName());
    assertEquals("valueOne", dimension.getValue());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 19 with LinkedHashMap

use of java.util.LinkedHashMap in project camel by apache.

the class ResultSetIterator method next.

@Override
public Map<String, Object> next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    try {
        Map<String, Object> row = new LinkedHashMap<String, Object>();
        for (Column column : columns) {
            if (useGetBytes && column instanceof BlobColumn) {
                row.put(column.getName(), ((BlobColumn) column).getBytes(resultSet));
            } else {
                row.put(column.getName(), column.getValue(resultSet));
            }
        }
        loadNext();
        return row;
    } catch (SQLException e) {
        close();
        throw new RuntimeCamelException("Cannot process result", e);
    }
}
Also used : SQLException(java.sql.SQLException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) NoSuchElementException(java.util.NoSuchElementException) LinkedHashMap(java.util.LinkedHashMap)

Example 20 with LinkedHashMap

use of java.util.LinkedHashMap in project groovy by apache.

the class ASTTransformationCollectorCodeVisitor method visitAnnotations.

/**
     * If the annotation is annotated with {@link GroovyASTTransformation}
     * the annotation is added to <code>stageVisitors</code> at the appropriate processor visitor.
     *
     * @param node the node to process
     */
public void visitAnnotations(AnnotatedNode node) {
    super.visitAnnotations(node);
    Map<Integer, List<AnnotationNode>> existing = new TreeMap<Integer, List<AnnotationNode>>();
    Map<Integer, List<AnnotationNode>> replacements = new LinkedHashMap<Integer, List<AnnotationNode>>();
    Map<Integer, AnnotationCollectorMode> modes = new LinkedHashMap<Integer, AnnotationCollectorMode>();
    int index = 0;
    for (AnnotationNode annotation : node.getAnnotations()) {
        findCollectedAnnotations(annotation, node, index, modes, existing, replacements);
        index++;
    }
    for (Integer replacementIndex : replacements.keySet()) {
        mergeCollectedAnnotations(modes.get(replacementIndex), existing, replacements.get(replacementIndex));
        existing.put(replacementIndex, replacements.get(replacementIndex));
    }
    List<AnnotationNode> mergedList = new ArrayList<AnnotationNode>();
    for (List<AnnotationNode> next : existing.values()) {
        mergedList.addAll(next);
    }
    node.getAnnotations().clear();
    node.getAnnotations().addAll(mergedList);
    for (AnnotationNode annotation : node.getAnnotations()) {
        Annotation transformClassAnnotation = getTransformClassAnnotation(annotation.getClassNode());
        if (transformClassAnnotation == null) {
            // skip if there is no such annotation
            continue;
        }
        addTransformsToClassNode(annotation, transformClassAnnotation);
    }
}
Also used : AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) AnnotationCollectorMode(groovy.transform.AnnotationCollectorMode) Annotation(java.lang.annotation.Annotation) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1944 ArrayList (java.util.ArrayList)575 Map (java.util.Map)561 HashMap (java.util.HashMap)373 Test (org.junit.Test)275 List (java.util.List)255 IOException (java.io.IOException)122 HashSet (java.util.HashSet)91 Set (java.util.Set)79 File (java.io.File)76 LinkedHashSet (java.util.LinkedHashSet)68 TreeMap (java.util.TreeMap)68 Node (org.apache.hadoop.hive.ql.lib.Node)59 NodeProcessor (org.apache.hadoop.hive.ql.lib.NodeProcessor)58 Rule (org.apache.hadoop.hive.ql.lib.Rule)58 Date (java.util.Date)57 GraphWalker (org.apache.hadoop.hive.ql.lib.GraphWalker)56 Dispatcher (org.apache.hadoop.hive.ql.lib.Dispatcher)55 Iterator (java.util.Iterator)54 DefaultRuleDispatcher (org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher)54