Java Code Examples for org.apache.camel.util.ObjectHelper#equal()

The following examples show how to use org.apache.camel.util.ObjectHelper#equal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeadersStepHandler.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"PMD.AvoidReassigningParameters", "PMD.AvoidDeeplyNestedIfStmts"})
@Override
public Optional<ProcessorDefinition<?>> handle(Step step, final ProcessorDefinition<?> route, IntegrationRouteBuilder builder, String flowIndex, String stepIndex) {
    ObjectHelper.notNull(route, "route");

    final Map<String, String> props = step.getConfiguredProperties();
    final String action = props.getOrDefault("action", "set");

    if (ObjectHelper.equal(action, "set", true)) {
        props.entrySet().stream()
            .filter(e -> !"action".equalsIgnoreCase(e.getKey()))
            .forEach(e-> route.setHeader(e.getKey()).constant(e.getValue()));
    } else if (ObjectHelper.equal(action, "remove", true)) {
        props.entrySet().stream()
            .filter(e -> !"action".equalsIgnoreCase(e.getKey()))
            .forEach(e-> route.removeHeaders(e.getKey()));
    } else {
        throw new IllegalArgumentException("Unknown action:" + action);
    }

    return Optional.of(route);
}
 
Example 2
Source File: ServiceNowMetaDataExtension.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private static Optional<JsonNode> findResultNode(Response response) {
    if (ObjectHelper.isNotEmpty(response.getHeaderString(HttpHeaders.CONTENT_TYPE))) {
        JsonNode root = response.readEntity(JsonNode.class);
        if (root != null) {
            Iterator<Map.Entry<String, JsonNode>> fields = root.fields();
            while (fields.hasNext()) {
                final Map.Entry<String, JsonNode> entry = fields.next();
                final String key = entry.getKey();
                final JsonNode node = entry.getValue();

                if (ObjectHelper.equal("result", key, true)) {
                    return Optional.of(node);
                }
            }
        }
    }

    return Optional.empty();
}
 
Example 3
Source File: HttpConnectorFactories.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public static String computeHttpUri(String scheme, Map<String, Object> options) {
    String baseUrl = (String)options.remove("baseUrl");

    if (ObjectHelper.isEmpty(baseUrl)) {
        throw new IllegalArgumentException("baseUrl si mandatory");
    }

    String uriScheme = StringHelper.before(baseUrl, "://");
    if (ObjectHelper.isNotEmpty(uriScheme) && !ObjectHelper.equal(scheme, uriScheme)) {
        throw new IllegalArgumentException("Unsupported scheme: " + uriScheme);
    }

    if (ObjectHelper.isNotEmpty(uriScheme)) {
        baseUrl = StringHelper.after(baseUrl, "://");
    }

    String path = (String)options.remove("path");
    if (StringUtils.isNotEmpty(path)) {
        return StringUtils.removeEnd(baseUrl, "/") + "/" + StringUtils.removeStart(path, "/");
    } else {
        return baseUrl;
    }
}
 
Example 4
Source File: GoogleSheetsMetaDataHelper.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public static JsonSchema createSchema(String range, String majorDimension, boolean split, String ... columnNames) {
    ObjectSchema spec = new ObjectSchema();

    spec.setTitle("VALUE_RANGE");
    spec.putProperty("spreadsheetId", new JsonSchemaFactory().stringSchema());

    RangeCoordinate coordinate = RangeCoordinate.fromRange(range);
    if (ObjectHelper.equal(RangeCoordinate.DIMENSION_ROWS, majorDimension)) {
        createSchemaFromRowDimension(spec, coordinate, columnNames);
    } else if (ObjectHelper.equal(RangeCoordinate.DIMENSION_COLUMNS, majorDimension)) {
        createSchemaFromColumnDimension(spec, coordinate);
    }

    if (split) {
        spec.set$schema(JSON_SCHEMA_ORG_SCHEMA);
        return spec;
    } else {
        ArraySchema arraySpec = new ArraySchema();
        arraySpec.set$schema(JSON_SCHEMA_ORG_SCHEMA);
        arraySpec.setItemsSchema(spec);
        return arraySpec;
    }
}
 
Example 5
Source File: ServiceNowMetadataRetrieval.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private static SyndesisMetadata adaptTableDefinitionMetadata(String actionId, Map<String, Object> properties, MetaDataExtension.MetaData metadata) {
    try {
        final Object table = ConnectorOptions.extractOption(properties, "table");
        final ObjectNode schema = (ObjectNode) metadata.getPayload();

        DataShape.Builder shapeBuilder = new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA)
            .type("servicenow." + table)
            .name("ServiceNow Import Set (" + table + ")");

        if (ObjectHelper.equal("io.syndesis:servicenow-action-retrieve-record", actionId)) {
            ObjectNode collectionSchema = schema.objectNode();
            collectionSchema.put("$schema", "http://json-schema.org/schema#");
            collectionSchema.put("type", "array");
            collectionSchema.set("items", schema);

            shapeBuilder.specification(JsonUtils.writer().writeValueAsString(collectionSchema));
            return SyndesisMetadata.outOnly(shapeBuilder.build());
        }
        if (ObjectHelper.equal("io.syndesis:servicenow-action-create-record", actionId)) {
            shapeBuilder.specification(JsonUtils.writer().writeValueAsString(schema));
            return SyndesisMetadata.inOnly(shapeBuilder.build());
        }
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }

    return SyndesisMetadata.EMPTY;
}
 
Example 6
Source File: HttpConnectorVerifierExtension.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
public Result verify(Scope scope, Map<String, Object> parameters) {
    final Map<String, Object> options = new HashMap<>(parameters);

    String baseUrl = (String) options.remove("baseUrl");
    String uriScheme = StringHelper.before(baseUrl, "://");

    if (ObjectHelper.isNotEmpty(uriScheme) && !ObjectHelper.equal(supportedScheme, uriScheme)) {
        return ResultBuilder.withScope(scope).error(
            ResultErrorBuilder.withCode("unsupported_scheme")
                .description("Unsupported scheme: " + uriScheme)
                .parameterKey("baseUrl")
                .build()
        ).build();
    }

    if (ObjectHelper.isEmpty(uriScheme)) {
        baseUrl = new StringBuilder(supportedScheme).append("://").append(baseUrl).toString();
    }

    String path = (String) options.remove("path");
    if (ObjectHelper.isNotEmpty(path)) {
        final String uri = StringUtils.removeEnd(baseUrl, "/") + "/" + StringUtils.removeStart(path, "/");

        options.put("httpUri", uri);
    } else {
        options.put("httpUri", baseUrl);
    }

    Component component = getCamelContext().getComponent(this.componentScheme);
    if (component == null) {
        return ResultBuilder.withScope(scope).error(
            ResultErrorBuilder.withCode(VerificationError.StandardCode.UNSUPPORTED_COMPONENT)
                .description("Unsupported component " + this.componentScheme)
                .build()
        ).build();
    }

    return component.getExtension(ComponentVerifierExtension.class)
        .map(extension -> extension.verify(scope, options))
        .orElseGet(() -> ResultBuilder.unsupported().build());
}
 
Example 7
Source File: KuduMetadataRetrieval.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
protected SyndesisMetadata adapt(CamelContext context, String componentId, String actionId, Map<String, Object> properties, MetaDataExtension.MetaData metadata) {
    final KuduMetaData kuduMetaData = (KuduMetaData) metadata.getPayload();

    if (kuduMetaData != null) {
        // build the input and output schemas
        final ObjectSchema spec = createSpec(kuduMetaData);

        try {
            DataShape.Builder inDataShapeBuilder = new DataShape.Builder().type("KUDU_TABLE_IN");
            if (ObjectHelper.equal(actionId, KUDU_INSERT_ACTION)) {
                inDataShapeBuilder.kind(DataShapeKinds.JSON_SCHEMA)
                        .name("Kudu table")
                        .description(String.format("Columns for table [%s]", kuduMetaData.getTableName()))
                        .specification(JsonUtils.writer().writeValueAsString(spec));
            } else {
                inDataShapeBuilder.kind(DataShapeKinds.NONE);
            }

            DataShape.Builder outDataShapeBuilder = new DataShape.Builder().type("KUDU_TABLE_OUT");
            if (ObjectHelper.equal(actionId, KUDU_SCAN_ACTION)) {
                outDataShapeBuilder.kind(DataShapeKinds.JSON_SCHEMA)
                        .name("Kudu table")
                        .description(String.format("Columns for table [%s]", kuduMetaData.getTableName()));

                ArraySchema collectionSpec = new ArraySchema();
                collectionSpec.set$schema(JSON_SCHEMA_ORG_SCHEMA);
                collectionSpec.setItemsSchema(spec);
                outDataShapeBuilder.specification(JsonUtils.writer().writeValueAsString(collectionSpec));
            } else {
                outDataShapeBuilder.kind(DataShapeKinds.NONE);
            }

            return SyndesisMetadata.of(inDataShapeBuilder.build(), outDataShapeBuilder.build());
        } catch (JsonProcessingException e) {
            throw new IllegalStateException(e);
        }
    } else {
        return SyndesisMetadata.EMPTY;
    }
}