EquivContext context = identifier(parentContext, another.getName(), another.getClass()); context.setFail(ONE_NULL, NULL, NOT_NULL); return false; EquivContext context = identifier(parentContext, one.getName(), one.getClass()); if (another == null) { context.setFail(ANOTHER_NULL, NOT_NULL, NULL); Connector myConnector = one.getConnector().orElse(null); Connector anotherConnector = another.getConnector().orElse(null); pair(one.getId(), another.getId(), "id"), pair(one.getOrganization(), another.getOrganization(), "organization"), pair(one.getOrganizationId(), another.getOrganizationId(), "organization-id"), pair(one.getConnectorId(), another.getConnectorId(), "connector-id"), pair(one.getOptions(), another.getOptions(), "options"), pair(one.getIcon(), another.getIcon(), "icon"), pair(one.getDescription(), another.getDescription(), "description"), pair(one.getUserId(), another.getUserId(), "user-id"), pair(one.isDerived(), another.isDerived(), "is-derived"), pair(one.getTags(), another.getTags(), "tags"), pair(one.getName(), another.getName(), "name"), pair(one.getConfiguredProperties(), another.getConfiguredProperties(), "configured-properties"));
@Override public Optional<Date> getLastUpdated() { return getTarget().getLastUpdated(); }
/** * Load a connector from the give connection or from the underlying storage * if the connector is referenced by id. */ default Optional<Connector> loadConnector(Connection connection) { final Optional<Connector> connector; if (connection.getConnector().isPresent()) { connector = connection.getConnector(); } else { connector = loadConnector(connection.getConnectorId()); } return connector; }
public Connection apply(final Connection updatedConnection, final CredentialFlowState flowState) { final CredentialProvider credentialProvider = providerFrom(flowState); final Connection withDerivedFlag = new Connection.Builder().createFrom(updatedConnection).isDerived(true).build(); final Connection appliedConnection = credentialProvider.applyTo(withDerivedFlag, flowState); final Map<String, String> configuredProperties = appliedConnection.getConfiguredProperties(); final Map<String, ConfigurationProperty> properties = updatedConnection.getConnector() .orElseGet(() -> dataManager.fetch(Connector.class, updatedConnection.getConnectorId())).getProperties(); final Map<String, String> encryptedConfiguredProperties = encryptionComponent.encryptPropertyValues(configuredProperties, properties); return new Connection.Builder().createFrom(appliedConnection).configuredProperties(encryptedConfiguredProperties).build(); }
@Override public Optional<Connector> getConnector() { return getTarget().getConnector(); }
final Connector connector = connection.getConnector().get(); final ConnectorAction action = step.getActionAs(ConnectorAction.class).get(); final ConnectorDescriptor descriptor = action.getDescriptor(); final Map<String, String> configuredProperties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties()); final Map<String, String> properties = CollectionsUtils.aggregate(connector.filterEndpointProperties(configuredProperties), action.filterEndpointProperties(configuredProperties));
if (connection.getId().isPresent()) { Connector newConnector = dataManager.fetch(Connector.class, connection.getConnectorId()); if (newConnector == null) { messages.add( ); } else { Map<String, String> configuredProperties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties());
ConnectionBulletinBoard computeBoard(Connection connection, Connector oldConnector, Connector newConnector) { final DataManager dataManager = getDataManager(); final String id = connection.getId().get(); final ConnectionBulletinBoard board = dataManager.fetchByPropertyValue(ConnectionBulletinBoard.class, "targetResourceId", id).orElse(null); final ConnectionBulletinBoard.Builder builder; messages.addAll(computeValidatorMessages(LeveledMessage.Builder::new, connection)); messages.addAll(computePropertiesDiffMessages(LeveledMessage.Builder::new, oldConnector.getProperties(), newConnector.getProperties())); if (!connection.isDerived()) { messages.addAll(computeMissingMandatoryPropertiesMessages( LeveledMessage.Builder::new, newConnector.getProperties(), merge(newConnector.getConfiguredProperties(), connection.getConfiguredProperties())) ); messages.addAll(computeSecretsUpdateMessages(LeveledMessage.Builder::new, newConnector.getProperties(), connection.getConfiguredProperties()));
private Map<String, String> getConfiguredPropertiesInitialize() { return Connection.super.getConfiguredProperties(); }
@Test public void shouldApplyReceivedCredentialsToConnections() { final CredentialProvider credentialProvider = mock(CredentialProvider.class); when(locator.providerWithId("providerId")).thenReturn(credentialProvider); final CredentialFlowState flowState = new OAuth2CredentialFlowState.Builder().providerId("providerId") .returnUrl(URI.create("/ui#state")).code("code").state("state").build(); final Connection connection = new Connection.Builder() .connector(new Connector.Builder().putProperty("key", new ConfigurationProperty.Builder().build()).build()) .build(); when(credentialProvider.applyTo(new Connection.Builder().createFrom(connection).isDerived(true).build(), flowState)) .then(a -> new Connection.Builder().createFrom(a.getArgument(0)) .putConfiguredProperty("key", "value").build()); final Connection finishedConnection = credentials.apply(connection, flowState); assertThat(finishedConnection).isNotNull(); assertThat(finishedConnection.getConfiguredProperties()).contains(entry("key", "value")); assertThat(finishedConnection.isDerived()).isTrue(); }
default Optional<Connection> findConnectionById(String connectionId) { if (getConnections() == null) { return Optional.empty(); } return getConnections().stream() .filter(WithId.class::isInstance) .filter(connection -> connection.getId().isPresent()) .filter(connection -> connectionId.equals(connection.getId().get())) .findFirst(); }
@Override public String getConnectorId() { return getTarget().getConnectorId(); }
@Override public boolean isDerived() { return getTarget().isDerived(); }
Optional<? extends Action> getAction(final String id) { return Optionals.asStream(this.connection.getConnector()) .flatMap(c -> c.getActions().stream()) .filter(a -> a.getId().equals(Optional.of(id))) .findFirst(); } }
final Connector connector = connection.getConnector().get(); final ConnectorAction action = step.getActionAs(ConnectorAction.class).get(); final ConnectorDescriptor descriptor = action.getDescriptor(); final String componentId = scheme + "-" + flowIndex + "-" + stepIndex; final ComponentProxyComponent component = resolveComponent(componentId, scheme, context, connector, descriptor); final Map<String, String> properties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties()); final Map<String, ConfigurationProperty> configurationProperties = CollectionsUtils.aggregate(connector.getProperties(), action.getProperties());
private Connection includeConnector(Connection connection) { if (connection == null) { return connection; } Optional<Connector> connectorOptional = connection.getConnector(); if (connectorOptional != null && connectorOptional.isPresent()) { return connection; } Connector connector = getDataManager().fetch(Connector.class, connection.getConnectorId()); if (connector == null) { return connection; } Connection.Builder builder = new Connection.Builder(); return builder.createFrom(connection) .connector(connector) .build(); }
@Test public void shouldApplyPropertyValues() { final Connection.Builder connection = new Connection.Builder(); Applicator.applyProperty(connection, "property", "value"); final Connection built = connection.build(); assertThat(built.getConfiguredProperties()).containsEntry("property", "value"); }
LeveledMessage.Code differenceCode) { Connection newConnection = getDataManager().fetch(Connection.class, connection.getId().get());
@Override protected List<ConnectionBulletinBoard> compute(ChangeEvent event) { final List<ConnectionBulletinBoard> boards = new ArrayList<>(); final DataManager dataManager = getDataManager(); final List<Connector> connectors = dataManager.fetchAll(Connector.class).getItems(); for (int i = 0; i < connectors.size(); i++) { final Connector connector = connectors.get(i); final String id = connector.getId().get(); dataManager.fetchAllByPropertyValue(Connection.class, "connectorId", id) .filter(connection -> connection.getConnector().isPresent()) .map(connection -> computeBoard(connection, connection.getConnector().get(), connector)) .filter(Objects::nonNull) .forEach(boards::add); } return boards; }
@Test public void shouldApplyAdditionalProperties() { final SalesforceProperties properties = new SalesforceProperties(); properties.setAppId("appId"); properties.setAppSecret("appSecret"); final AccessGrant accessGrant = new AccessGrant("accessToken", "scope", "refreshToken", 1L); final SalesforceConnectionFactory salesforce = mock(SalesforceConnectionFactory.class); @SuppressWarnings("unchecked") final org.springframework.social.connect.Connection<Salesforce> salesforceConnection = mock( org.springframework.social.connect.Connection.class); final Salesforce salesforceApi = mock(Salesforce.class); when(salesforceConnection.getApi()).thenReturn(salesforceApi); when(salesforceApi.getInstanceUrl()).thenReturn("https://instance.salesforce.com"); when(salesforce.createConnection(accessGrant)).thenReturn(salesforceConnection); final Connection.Builder mutableConnection = new Connection.Builder(); final SalesforceApplicator applicator = new SalesforceApplicator(salesforce, properties); applicator.additionalApplication(mutableConnection, accessGrant); assertThat(mutableConnection.build().getConfiguredProperties()) .containsExactly(entry("instanceUrl", "https://instance.salesforce.com")); }