use of net.nemerosa.ontrack.tx.Transaction in project ontrack by nemerosa.
the class JIRAServiceExtension method followLinks.
/**
* Given an issue seed, and a list of link names, follows the given links recursively and
* puts the associated issues into the {@code collectedIssues} map.
*
* @param configuration JIRA configuration to use to load the issues
* @param seed Issue to start from.
* @param linkNames Links to follow
* @param collectedIssues Collected issues, indexed by their key
*/
public void followLinks(JIRAConfiguration configuration, JIRAIssue seed, Set<String> linkNames, Map<String, JIRAIssue> collectedIssues) {
try (Transaction tx = transactionService.start()) {
JIRASession session = getJIRASession(tx, configuration);
// Gets the client from the current session
JIRAClient client = session.getClient();
// Puts the seed into the list
collectedIssues.put(seed.getKey(), seed);
// Gets the linked issue keys
seed.getLinks().stream().filter(linkedIssue -> linkNames.contains(linkedIssue.getLinkName())).filter(linkedIssue -> !collectedIssues.containsKey(linkedIssue.getKey())).map(linkedIssue -> client.getIssue(linkedIssue.getKey(), configuration)).forEach(linkedIssue -> followLinks(configuration, linkedIssue, linkNames, collectedIssues));
}
}
use of net.nemerosa.ontrack.tx.Transaction in project ontrack by nemerosa.
the class SVNServiceImpl method download.
@Override
public Optional<String> download(Branch branch, String path) {
// Security check
securityService.checkProjectFunction(branch, ProjectConfig.class);
// If project configured...
Optional<SVNRepository> oSvnRepository = getSVNRepository(branch);
if (oSvnRepository.isPresent()) {
// SVN Branch configuration
Optional<SVNBranchConfigurationProperty> oSvnBranchConfigurationProperty = propertyService.getProperty(branch, SVNBranchConfigurationPropertyType.class).option();
if (oSvnBranchConfigurationProperty.isPresent()) {
String pathInBranch = oSvnBranchConfigurationProperty.get().getCuredBranchPath() + "/" + StringUtils.stripStart(path, "/");
try (Transaction ignored = transactionService.start()) {
return svnClient.download(oSvnRepository.get(), pathInBranch);
}
} else {
return Optional.empty();
}
} else {
return Optional.empty();
}
}
use of net.nemerosa.ontrack.tx.Transaction in project ontrack by nemerosa.
the class IndexationServiceImpl method indexFromLatest.
protected void indexFromLatest(SVNRepository repository, JobRunListener runListener) {
securityService.checkGlobalFunction(GlobalSettings.class);
try (Transaction ignored = transactionService.start()) {
// Loads the repository information
SVNURL url = SVNUtils.toURL(repository.getConfiguration().getUrl());
// Last scanned revision
long lastScannedRevision = revisionDao.getLast(repository.getId());
if (lastScannedRevision <= 0) {
lastScannedRevision = repository.getConfiguration().getIndexationStart();
}
// HEAD revision
long repositoryRevision = svnClient.getRepositoryRevision(repository, url);
// Logging
logger.info("[svn-indexation] Repository={}, LastScannedRevision={}", repository.getId(), lastScannedRevision);
// Range
long from = lastScannedRevision + 1;
// Request index of the range
indexRange(repository, from, repositoryRevision, runListener);
}
}
use of net.nemerosa.ontrack.tx.Transaction in project ontrack by nemerosa.
the class IndexationServiceImpl method indexInTransaction.
/**
* This method is executed within a transaction
*/
private void indexInTransaction(SVNRepository repository, SVNLogEntry logEntry) throws SVNException {
// Log values
long revision = logEntry.getRevision();
String author = logEntry.getAuthor();
String message = logEntry.getMessage();
Date date = logEntry.getDate();
// Sanitizes the possible null values
author = Objects.toString(author, "");
message = Objects.toString(message, "");
// Date to date time
LocalDateTime dateTime = Time.from(date, Time.now());
// Branch for the revision
String branch = getBranchForRevision(repository, logEntry);
// Logging
logger.info(String.format("Indexing revision %d", revision));
// Inserting or updating the revision
revisionDao.addRevision(repository.getId(), revision, author, dateTime, message, branch);
// Merge relationships (using a nested SVN client)
try (Transaction ignored = transactionService.start(true)) {
List<Long> mergedRevisions = svnClient.getMergedRevisions(repository, SVNUtils.toURL(repository.getConfiguration().getUrl(), branch), revision);
// Unique revisions
List<Long> uniqueMergedRevisions = mergedRevisions.stream().distinct().collect(Collectors.toList());
revisionDao.addMergedRevisions(repository.getId(), revision, uniqueMergedRevisions);
}
// Subversion events
indexSVNEvents(repository, logEntry);
// Indexes the issues
indexIssues(repository, logEntry);
}
use of net.nemerosa.ontrack.tx.Transaction in project ontrack by nemerosa.
the class IndexationServiceImpl method getLastRevisionInfo.
@Override
public LastRevisionInfo getLastRevisionInfo(String name) {
try (Transaction ignored = transactionService.start()) {
SVNRepository repository = getRepositoryByName(name);
SVNURL url = SVNUtils.toURL(repository.getConfiguration().getUrl());
long repositoryRevision = svnClient.getRepositoryRevision(repository, url);
TRevision r = revisionDao.getLastRevision(repository.getId());
if (r != null) {
return new LastRevisionInfo(r.getRevision(), r.getMessage(), repositoryRevision);
} else {
return LastRevisionInfo.none(repositoryRevision);
}
}
}
Aggregations