Search in sources :

Example 1 with JIRASession

use of net.nemerosa.ontrack.extension.jira.tx.JIRASession 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 JIRASession

use of net.nemerosa.ontrack.extension.jira.tx.JIRASession in project ontrack by nemerosa.

the class JIRAServiceTest method before.

@Before
public void before() {
    SecurityService securityService = mock(SecurityService.class);
    configurationRepository = mock(ConfigurationRepository.class);
    encryptionService = mock(EncryptionService.class);
    JIRASession jiraSession = mock(JIRASession.class);
    when(jiraSession.getClient()).thenReturn(mock(JIRAClient.class));
    JIRASessionFactory jiraSessionFactory = mock(JIRASessionFactory.class);
    when(jiraSessionFactory.create(any(JIRAConfiguration.class))).thenReturn(jiraSession);
    OntrackConfigProperties ontrackConfigProperties = new OntrackConfigProperties();
    jiraService = new JIRAConfigurationServiceImpl(configurationRepository, securityService, encryptionService, mock(EventPostService.class), mock(EventFactory.class), jiraSessionFactory, ontrackConfigProperties);
}
Also used : JIRAClient(net.nemerosa.ontrack.extension.jira.client.JIRAClient) JIRASession(net.nemerosa.ontrack.extension.jira.tx.JIRASession) SecurityService(net.nemerosa.ontrack.model.security.SecurityService) EncryptionService(net.nemerosa.ontrack.model.security.EncryptionService) ConfigurationRepository(net.nemerosa.ontrack.model.support.ConfigurationRepository) JIRASessionFactory(net.nemerosa.ontrack.extension.jira.tx.JIRASessionFactory) OntrackConfigProperties(net.nemerosa.ontrack.model.support.OntrackConfigProperties) Before(org.junit.Before)

Aggregations

JIRAClient (net.nemerosa.ontrack.extension.jira.client.JIRAClient)2 JIRASession (net.nemerosa.ontrack.extension.jira.tx.JIRASession)2 JIRASessionFactory (net.nemerosa.ontrack.extension.jira.tx.JIRASessionFactory)2 Sets (com.google.common.collect.Sets)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 String.format (java.lang.String.format)1 URLEncoder (java.net.URLEncoder)1 java.util (java.util)1 Matcher (java.util.regex.Matcher)1 Collectors (java.util.stream.Collectors)1 IssueExportServiceFactory (net.nemerosa.ontrack.extension.issues.export.IssueExportServiceFactory)1 Issue (net.nemerosa.ontrack.extension.issues.model.Issue)1 IssueServiceConfiguration (net.nemerosa.ontrack.extension.issues.model.IssueServiceConfiguration)1 AbstractIssueServiceExtension (net.nemerosa.ontrack.extension.issues.support.AbstractIssueServiceExtension)1 JIRAIssue (net.nemerosa.ontrack.extension.jira.model.JIRAIssue)1 EncryptionService (net.nemerosa.ontrack.model.security.EncryptionService)1 SecurityService (net.nemerosa.ontrack.model.security.SecurityService)1 Project (net.nemerosa.ontrack.model.structure.Project)1 PropertyService (net.nemerosa.ontrack.model.structure.PropertyService)1 ConfigurationRepository (net.nemerosa.ontrack.model.support.ConfigurationRepository)1