Search in sources :

Example 1 with ConnectionBulletinBoard

use of io.syndesis.common.model.bulletin.ConnectionBulletinBoard in project syndesis by syndesisio.

the class ConnectionUpdateHandler method compute.

@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)).forEach(boards::add);
    }
    return boards;
}
Also used : LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage) Arrays(java.util.Arrays) KeyGenerator(io.syndesis.common.util.KeyGenerator) Kind(io.syndesis.common.model.Kind) Validator(javax.validation.Validator) Connector(io.syndesis.common.model.connection.Connector) ArrayList(java.util.ArrayList) List(java.util.List) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) Connection(io.syndesis.common.model.connection.Connection) ConnectionBulletinBoard(io.syndesis.common.model.bulletin.ConnectionBulletinBoard) DataManager(io.syndesis.server.dao.manager.DataManager) ChangeEvent(io.syndesis.common.model.ChangeEvent) Connector(io.syndesis.common.model.connection.Connector) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) DataManager(io.syndesis.server.dao.manager.DataManager) ConnectionBulletinBoard(io.syndesis.common.model.bulletin.ConnectionBulletinBoard)

Example 2 with ConnectionBulletinBoard

use of io.syndesis.common.model.bulletin.ConnectionBulletinBoard in project syndesis by syndesisio.

the class ConnectionUpdateHandler method computeBoard.

private 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;
    if (board != null) {
        builder = new ConnectionBulletinBoard.Builder().createFrom(board).updatedAt(System.currentTimeMillis());
    } else {
        builder = new ConnectionBulletinBoard.Builder().id(KeyGenerator.createKey()).targetResourceId(id).createdAt(System.currentTimeMillis());
    }
    List<LeveledMessage> messages = new ArrayList<>();
    messages.addAll(computeValidatorMessages(LeveledMessage.Builder::new, connection));
    messages.addAll(computePropertiesDiffMessages(LeveledMessage.Builder::new, oldConnector.getProperties(), newConnector.getProperties()));
    messages.addAll(computeMissingMandatoryPropertiesMessages(LeveledMessage.Builder::new, newConnector.getProperties(), connection.getConfiguredProperties()));
    messages.addAll(computeSecretsUpdateMessages(LeveledMessage.Builder::new, newConnector.getProperties(), connection.getConfiguredProperties()));
    builder.errors(countMessagesWithLevel(LeveledMessage.Level.ERROR, messages));
    builder.warnings(countMessagesWithLevel(LeveledMessage.Level.WARN, messages));
    builder.notices(countMessagesWithLevel(LeveledMessage.Level.INFO, messages));
    builder.putMetadata("connector-id", newConnector.getId().get());
    builder.putMetadata("connector-version-latest", Integer.toString(newConnector.getVersion()));
    builder.putMetadata("connector-version-connection", Integer.toString(oldConnector.getVersion()));
    builder.messages(messages);
    return builder.build();
}
Also used : ArrayList(java.util.ArrayList) DataManager(io.syndesis.server.dao.manager.DataManager) ConnectionBulletinBoard(io.syndesis.common.model.bulletin.ConnectionBulletinBoard) LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage)

Aggregations

ConnectionBulletinBoard (io.syndesis.common.model.bulletin.ConnectionBulletinBoard)2 LeveledMessage (io.syndesis.common.model.bulletin.LeveledMessage)2 DataManager (io.syndesis.server.dao.manager.DataManager)2 ArrayList (java.util.ArrayList)2 ChangeEvent (io.syndesis.common.model.ChangeEvent)1 Kind (io.syndesis.common.model.Kind)1 Connection (io.syndesis.common.model.connection.Connection)1 Connector (io.syndesis.common.model.connection.Connector)1 KeyGenerator (io.syndesis.common.util.KeyGenerator)1 EncryptionComponent (io.syndesis.server.dao.manager.EncryptionComponent)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Validator (javax.validation.Validator)1