Search in sources :

Example 1 with BasicGitConfiguration

use of net.nemerosa.ontrack.extension.git.model.BasicGitConfiguration in project ontrack by nemerosa.

the class GitProjectConfigurationPropertyType method fromStorage.

@Override
public GitProjectConfigurationProperty fromStorage(JsonNode node) {
    String configurationName = node.path("configuration").asText();
    // Looks the configuration up
    BasicGitConfiguration configuration = configurationService.getConfiguration(configurationName);
    // OK
    return new GitProjectConfigurationProperty(configuration);
}
Also used : BasicGitConfiguration(net.nemerosa.ontrack.extension.git.model.BasicGitConfiguration)

Example 2 with BasicGitConfiguration

use of net.nemerosa.ontrack.extension.git.model.BasicGitConfiguration in project ontrack by nemerosa.

the class GitConfigurationMigrationAction11 method migrate.

@Override
public void migrate(Connection connection) throws Exception {
    // For all Git configurations
    try (PreparedStatement ps = connection.prepareStatement("SELECT * FROM CONFIGURATIONS WHERE TYPE = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) {
        ps.setString(1, BasicGitConfiguration.class.getName());
        try (ResultSet rs = ps.executeQuery()) {
            while (rs.next()) {
                // Configuration as JSON
                String json = rs.getString("CONTENT");
                // Parses the configuration
                ObjectNode node = (ObjectNode) objectMapper.readTree(json);
                // Gets all fields of the node
                List<String> fieldNames = Lists.newArrayList(node.fieldNames());
                // Removes any field that does not belong to the BasicGitConfiguration class
                fieldNames.stream().filter(fieldName -> !validFields.contains(fieldName)).forEach(node::remove);
                // Updating
                rs.updateString("CONTENT", objectMapper.writeValueAsString(node));
                rs.updateRow();
            }
        }
    }
}
Also used : ObjectMapperFactory(net.nemerosa.ontrack.json.ObjectMapperFactory) Connection(java.sql.Connection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) PreparedStatement(java.sql.PreparedStatement) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Sets(com.google.common.collect.Sets) DBMigrationAction(net.nemerosa.ontrack.model.support.DBMigrationAction) Component(org.springframework.stereotype.Component) List(java.util.List) Lists(com.google.common.collect.Lists) ResultSet(java.sql.ResultSet) BasicGitConfiguration(net.nemerosa.ontrack.extension.git.model.BasicGitConfiguration) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BasicGitConfiguration(net.nemerosa.ontrack.extension.git.model.BasicGitConfiguration) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

BasicGitConfiguration (net.nemerosa.ontrack.extension.git.model.BasicGitConfiguration)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 List (java.util.List)1 Set (java.util.Set)1 ObjectMapperFactory (net.nemerosa.ontrack.json.ObjectMapperFactory)1 DBMigrationAction (net.nemerosa.ontrack.model.support.DBMigrationAction)1 Component (org.springframework.stereotype.Component)1