Search in sources :

Example 1 with Transaction

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));
    }
}
Also used : PropertyService(net.nemerosa.ontrack.model.structure.PropertyService) java.util(java.util) Autowired(org.springframework.beans.factory.annotation.Autowired) JIRAIssue(net.nemerosa.ontrack.extension.jira.model.JIRAIssue) JIRAClient(net.nemerosa.ontrack.extension.jira.client.JIRAClient) StringUtils(org.apache.commons.lang3.StringUtils) Issue(net.nemerosa.ontrack.extension.issues.model.Issue) Transaction(net.nemerosa.ontrack.tx.Transaction) Matcher(java.util.regex.Matcher) MessageAnnotation(net.nemerosa.ontrack.model.support.MessageAnnotation) JIRASessionFactory(net.nemerosa.ontrack.extension.jira.tx.JIRASessionFactory) JIRASession(net.nemerosa.ontrack.extension.jira.tx.JIRASession) AbstractIssueServiceExtension(net.nemerosa.ontrack.extension.issues.support.AbstractIssueServiceExtension) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) Component(org.springframework.stereotype.Component) URLEncoder(java.net.URLEncoder) Validate(org.apache.commons.lang3.Validate) IssueExportServiceFactory(net.nemerosa.ontrack.extension.issues.export.IssueExportServiceFactory) MessageAnnotator(net.nemerosa.ontrack.model.support.MessageAnnotator) RegexMessageAnnotator(net.nemerosa.ontrack.model.support.RegexMessageAnnotator) TransactionService(net.nemerosa.ontrack.tx.TransactionService) Project(net.nemerosa.ontrack.model.structure.Project) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IssueServiceConfiguration(net.nemerosa.ontrack.extension.issues.model.IssueServiceConfiguration) JIRAClient(net.nemerosa.ontrack.extension.jira.client.JIRAClient) Transaction(net.nemerosa.ontrack.tx.Transaction) JIRASession(net.nemerosa.ontrack.extension.jira.tx.JIRASession)

Example 2 with Transaction

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();
    }
}
Also used : Transaction(net.nemerosa.ontrack.tx.Transaction)

Example 3 with Transaction

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);
    }
}
Also used : Transaction(net.nemerosa.ontrack.tx.Transaction)

Example 4 with Transaction

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) Transaction(net.nemerosa.ontrack.tx.Transaction)

Example 5 with Transaction

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);
        }
    }
}
Also used : LastRevisionInfo(net.nemerosa.ontrack.extension.svn.model.LastRevisionInfo) Transaction(net.nemerosa.ontrack.tx.Transaction)

Aggregations

Transaction (net.nemerosa.ontrack.tx.Transaction)15 SVNRepository (net.nemerosa.ontrack.extension.svn.db.SVNRepository)7 Transactional (org.springframework.transaction.annotation.Transactional)5 ConfiguredIssueService (net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService)3 Issue (net.nemerosa.ontrack.extension.issues.model.Issue)3 IssueServiceConfigurationRepresentation (net.nemerosa.ontrack.extension.issues.model.IssueServiceConfigurationRepresentation)3 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 SVNBranchConfigurationProperty (net.nemerosa.ontrack.extension.svn.property.SVNBranchConfigurationProperty)2 SVNProjectConfigurationProperty (net.nemerosa.ontrack.extension.svn.property.SVNProjectConfigurationProperty)2 SVNLogEntryCollector (net.nemerosa.ontrack.extension.svn.support.SVNLogEntryCollector)2 TransactionService (net.nemerosa.ontrack.tx.TransactionService)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 SVNLogEntry (org.tmatesoft.svn.core.SVNLogEntry)2 SVNURL (org.tmatesoft.svn.core.SVNURL)2 SVNRevision (org.tmatesoft.svn.core.wc.SVNRevision)2 Sets (com.google.common.collect.Sets)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 String.format (java.lang.String.format)1