use of net.nemerosa.ontrack.model.structure.ServiceConfiguration in project ontrack by nemerosa.
the class BuildGitCommitLinkMigrationAction method migrateBranchConfigurations.
private void migrateBranchConfigurations(Connection connection) throws SQLException, IOException {
// For all branches...
try (PreparedStatement psBranches = connection.prepareStatement("SELECT ID FROM BRANCHES")) {
try (ResultSet rsBranches = psBranches.executeQuery()) {
while (rsBranches.next()) {
int branchId = rsBranches.getInt("ID");
// For all the Git branch configurations
try (PreparedStatement psProperty = connection.prepareStatement("SELECT * FROM PROPERTIES WHERE TYPE = ? AND BRANCH = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) {
psProperty.setString(1, GitBranchConfigurationPropertyType.class.getName());
psProperty.setInt(2, branchId);
try (ResultSet rsProperty = psProperty.executeQuery()) {
while (rsProperty.next()) {
logger.info("Migrating Branch Git configuration: {}", branchId);
// Configuration as JSON
String json = rsProperty.getString("JSON");
// Parses the configuration
JsonNode node = objectMapper.readTree(json);
// Gets any existing tag pattern
String tagPattern = JsonUtils.get(node, "tagPattern", "*");
// Creates the commit link
ServiceConfiguration buildCommitLink;
if ("*".equals(tagPattern)) {
buildCommitLink = TagBuildNameGitCommitLink.DEFAULT.toServiceConfiguration();
} else {
buildCommitLink = new ServiceConfiguration("tagPattern", JsonUtils.object().with("pattern", tagPattern).end());
}
// Creates the new property
GitBranchConfigurationProperty property = new GitBranchConfigurationProperty(JsonUtils.get(node, "branch"), buildCommitLink, JsonUtils.getBoolean(node, "override"), JsonUtils.getInt(node, "buildTagInterval"));
// Saves the data back
rsProperty.updateString("json", objectMapper.writeValueAsString(property));
rsProperty.updateRow();
}
}
}
}
}
}
}
use of net.nemerosa.ontrack.model.structure.ServiceConfiguration in project ontrack by nemerosa.
the class BuildSvnRevisionLinkMigrationAction method migrateSvnBranchConfiguration.
protected void migrateSvnBranchConfiguration(ObjectNode node) {
// Gets the build path & branch path
String branchPath = node.get("branchPath").asText();
String buildPath = node.get("buildPath").asText();
// Removes the build path property
node.remove("buildPath");
// Converts to a service configuration
ConfiguredBuildSvnRevisionLink<?> configuredBuildSvnRevisionLink = toBuildSvnRevisionLinkConfiguration(buildPath);
// Gets the configuration representation
ServiceConfiguration serviceConfiguration = configuredBuildSvnRevisionLink.toServiceConfiguration();
// As json...
node.put("buildRevisionLink", (ObjectNode) objectMapper.valueToTree(serviceConfiguration));
// Logging
try {
logger.info("SVN branch config for {} with build expression {} has been converted to {}", branchPath, buildPath, objectMapper.writeValueAsString(serviceConfiguration));
} catch (IOException ex) {
throw new JsonClientMappingException(ex);
}
}
Aggregations