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

Dynamic connection properties retrieval #7386

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -139,7 +139,7 @@ public void testReadFromMetaDataRetrieval() throws Exception {
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);

Map<String, List<PropertyPair>> properties = metadata.properties;
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());

//
Expand Down Expand Up @@ -180,7 +180,7 @@ public void testReadFromMetaDataRetrievalWithSplit() throws Exception {
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);

Map<String, List<PropertyPair>> properties = metadata.properties;
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());

//
Expand Down Expand Up @@ -225,7 +225,7 @@ public void testReadFromMetaDataRetrievalWithKeyPredicate() throws Exception {
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);

Map<String, List<PropertyPair>> properties = metadata.properties;
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());

//
Expand Down Expand Up @@ -265,7 +265,7 @@ public void testCreateMetaDataRetrieval() throws Exception {
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);

Map<String, List<PropertyPair>> properties = metadata.properties;
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());

//
Expand Down Expand Up @@ -306,7 +306,7 @@ public void testDeleteMetaDataRetrieval() throws Exception {
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);

Map<String, List<PropertyPair>> properties = metadata.properties;
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());

//
Expand Down Expand Up @@ -346,7 +346,7 @@ public void testUpdateMetaDataRetrieval() throws Exception {
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);

Map<String, List<PropertyPair>> properties = metadata.properties;
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());

//
Expand Down Expand Up @@ -393,7 +393,7 @@ public void testReadFromMetaDataRetrievalSSL() throws Exception {
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);

Map<String, List<PropertyPair>> properties = metadata.properties;
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());

//
Expand Down Expand Up @@ -434,7 +434,7 @@ public void testReadFromMetaDataRetrievalReferenceServerSSL() throws Exception {
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);

Map<String, List<PropertyPair>> properties = metadata.properties;
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());

//
Expand Down Expand Up @@ -476,7 +476,7 @@ public void testReadToMetaDataRetrieval() throws Exception {
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);

Map<String, List<PropertyPair>> properties = metadata.properties;
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());

//
Expand Down
Expand Up @@ -81,9 +81,9 @@ public void shouldAdaptObjectMetadataForProperties() {
final SyndesisMetadata metadata = adapter.adapt(null, null, null, properties,
MetaDataBuilder.on(CONTEXT).withAttribute("scope", "object").withPayload(payload).build());

assertThat(metadata.properties).containsKey("sObjectIdName");
assertThat(metadata.getProperties()).containsKey("sObjectIdName");

final List<PropertyPair> values = metadata.properties.get("sObjectIdName");
final List<PropertyPair> values = metadata.getProperties().get("sObjectIdName");

assertThat(values).containsOnly(new PropertyPair("uniqueProperty1", "Unique property 1"),
new PropertyPair("uniqueProperty2", "Unique property 2"));
Expand Down Expand Up @@ -116,9 +116,9 @@ public void shouldAdaptObjectTypesMetadataForProperties() {
final SyndesisMetadata metadata = adapter.adapt(null, null, null, NOT_USED,
MetaDataBuilder.on(CONTEXT).withPayload(globalObjectsPayload).build());

assertThat(metadata.properties).containsKey("sObjectName");
assertThat(metadata.getProperties()).containsKey("sObjectName");

final List<PropertyPair> values = metadata.properties.get("sObjectName");
final List<PropertyPair> values = metadata.getProperties().get("sObjectName");

assertThat(values).containsOnly(new PropertyPair("Object1", "Object1 Label"),
new PropertyPair("Object2", "Object2 Label"));
Expand All @@ -132,9 +132,9 @@ public void shouldAdaptObjectTypesMetadataForPropertiesLegacy() throws IOExcepti
final SyndesisMetadata metadata = adapter.adapt(null, null, null, NOT_USED,
MetaDataBuilder.on(CONTEXT).withAttribute("scope", "object_types").withPayload(payload).build());

assertThat(metadata.properties).containsKey("sObjectName");
assertThat(metadata.getProperties()).containsKey("sObjectName");

final List<PropertyPair> values = metadata.properties.get("sObjectName");
final List<PropertyPair> values = metadata.getProperties().get("sObjectName");

assertThat(values).containsOnly(new PropertyPair("Object1", "Object1 Label"),
new PropertyPair("Object2", "Object2 Label"));
Expand Down
11 changes: 11 additions & 0 deletions app/connector/support/verifier/pom.xml
Expand Up @@ -54,6 +54,17 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Expand Up @@ -38,6 +38,15 @@ public interface MetadataRetrieval {
*/
SyndesisMetadata fetch(CamelContext context, String componentId, String actionId, Map<String, Object> properties);

/**
* Provide all dynamic properties configured for the specific connector.
* It can use {@link CamelContext} to retrieve {@link MetaData} or use other Syndesis internal components
* to provide such properties.
*/
default SyndesisMetadataProperties fetchProperties(CamelContext context, String componentId, Map<String, Object> properties) {
return SyndesisMetadataProperties.EMPTY;
}

default RuntimeException handle(final Exception e) {
return new SyndesisServerException(e.getMessage() + ". Unable to fetch and process metadata", e);
}
Expand Down
Expand Up @@ -16,14 +16,13 @@
package io.syndesis.connector.support.verifier.api;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import io.syndesis.common.model.DataShape;
import org.apache.camel.util.ObjectHelper;

public final class SyndesisMetadata {
public final class SyndesisMetadata extends SyndesisMetadataProperties {
// The empty metadata instance
public static final SyndesisMetadata EMPTY = new SyndesisMetadata(Collections.emptyMap(), null, null);

Expand All @@ -37,22 +36,10 @@ public final class SyndesisMetadata {
*/
public final DataShape outputShape;

/**
* A Map keyed by action property name with a list of {@link PropertyPair}
* values that are applicable to for that property.
*/
public final Map<String, List<PropertyPair>> properties;

public SyndesisMetadata(final Map<String, List<PropertyPair>> properties, final DataShape inputShape, final DataShape outputShape) {
this.properties = properties;
super(properties);
this.inputShape = inputShape;
this.outputShape = outputShape;

if (properties != null) {
for (final List<PropertyPair> propertyPairs : properties.values()) {
Collections.sort(propertyPairs, Comparator.comparing(PropertyPair::getDisplayValue));
}
}
}

// *********************
Expand Down
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2016 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.syndesis.connector.support.verifier.api;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

public class SyndesisMetadataProperties {

public static final SyndesisMetadataProperties EMPTY = new SyndesisMetadataProperties(Collections.emptyMap());

/**
* A Map keyed by action property name with a list of {@link PropertyPair}
* values that are applicable to for that property.
*/
protected final Map<String, List<PropertyPair>> properties;

public SyndesisMetadataProperties(Map<String, List<PropertyPair>> properties) {
this.properties = properties;

if (properties != null && !properties.isEmpty()) {
for (final List<PropertyPair> propertyPairs : properties.values()) {
Collections.sort(propertyPairs, Comparator.comparing(PropertyPair::getDisplayValue));
}
}
}

public Map<String, List<PropertyPair>> getProperties() {
return properties;
}
}
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2016 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.syndesis.connector.support.verifier.api;

import java.util.HashMap;
import java.util.Map;

import io.syndesis.connector.support.verifier.api.sample.SampleConnectorMetaDataRetrieval;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class ConnectorMetadataTest {

@Test
public void verifyMetadataPropertyEchoed() {
SampleConnectorMetaDataRetrieval metaDataRetrieval = new SampleConnectorMetaDataRetrieval();
Map<String, Object> properties = new HashMap<>();
properties.put("brokers", null);
properties.put("anotherProperty", null);
SyndesisMetadataProperties dynamicProperties = metaDataRetrieval
.fetchProperties(null, "test", properties);

assertThat(dynamicProperties.getProperties().get("brokers"))
.containsOnly(new PropertyPair("brokers", "BROKERS"));
assertThat(dynamicProperties.getProperties().get("anotherProperty"))
.containsOnly(new PropertyPair("anotherProperty", "ANOTHERPROPERTY"));
}

}
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2016 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.syndesis.connector.support.verifier.api.sample;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.syndesis.connector.support.verifier.api.ComponentMetadataRetrieval;
import io.syndesis.connector.support.verifier.api.PropertyPair;
import io.syndesis.connector.support.verifier.api.SyndesisMetadata;
import io.syndesis.connector.support.verifier.api.SyndesisMetadataProperties;
import org.apache.camel.CamelContext;
import org.apache.camel.component.extension.MetaDataExtension;

public class SampleConnectorMetaDataRetrieval extends ComponentMetadataRetrieval {

@Override
protected SyndesisMetadata adapt(CamelContext context, String componentId, String actionId, Map<String, Object> properties, MetaDataExtension.MetaData metadata) {
return null;
}

@Override
public SyndesisMetadataProperties fetchProperties(CamelContext context, String componentId, Map<String, Object> properties) {
Map<String, List<PropertyPair>> echoProperties = SampleConnectorMetaDataRetrieval.echoProperties(properties);
return new SyndesisMetadataProperties(echoProperties);
}

private static Map<String, List<PropertyPair>> echoProperties(Map<String, Object> properties) {
Map<String, List<PropertyPair>> echoProperties = new HashMap<>();
for(Map.Entry<String, Object> x : properties.entrySet()){
List<PropertyPair> propertyPairs = new ArrayList<>();
propertyPairs.add(new PropertyPair(x.getKey(), x.getKey().toUpperCase()));
echoProperties.put(x.getKey(),propertyPairs);
}
return echoProperties;
}
}