Search in sources :

Example 1 with ProjectComponent

use of com.synopsys.integration.jira.common.model.components.ProjectComponent in project hub-alert by blackducksoftware.

the class JiraServerIssueCreator method retrieveProjectComponent.

private ProjectComponent retrieveProjectComponent() throws AlertException {
    String jiraProjectName = distributionDetails.getProjectNameOrKey();
    List<ProjectComponent> foundProjectComponents;
    try {
        foundProjectComponents = projectService.getProjectsByName(jiraProjectName);
    } catch (IntegrationException e) {
        throw new AlertException("Failed to retrieve projects from Jira", e);
    }
    return foundProjectComponents.stream().findAny().orElseThrow(() -> new AlertException(String.format("Unable to find project matching '%s'", jiraProjectName)));
}
Also used : ProjectComponent(com.synopsys.integration.jira.common.model.components.ProjectComponent) IntegrationException(com.synopsys.integration.exception.IntegrationException) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 2 with ProjectComponent

use of com.synopsys.integration.jira.common.model.components.ProjectComponent in project hub-alert by blackducksoftware.

the class JiraCloudIssueCreator method createIssueCreationRequest.

@Override
protected IssueCreationRequestModel createIssueCreationRequest(IssueCreationModel alertIssueCreationModel, MessageReplacementValues replacementValues) throws AlertException {
    ProjectComponent jiraProject = retrieveProjectComponent();
    String issueSummary = distributionDetails.getIssueSummary();
    String title = alertIssueCreationModel.getTitle();
    if (StringUtils.isNotEmpty(issueSummary)) {
        MessageValueReplacementResolver messageValueReplacementResolver = new MessageValueReplacementResolver(replacementValues);
        title = messageValueReplacementResolver.createReplacedFieldValue(issueSummary);
    }
    IssueRequestModelFieldsMapBuilder fieldsBuilder = jiraIssueCreationRequestCreator.createIssueRequestModel(title, alertIssueCreationModel.getDescription(), jiraProject.getId(), distributionDetails.getIssueType(), replacementValues, distributionDetails.getCustomFields());
    return new IssueCreationRequestModel(distributionDetails.getIssueCreatorEmail(), distributionDetails.getIssueType(), distributionDetails.getProjectNameOrKey(), fieldsBuilder, List.of());
}
Also used : ProjectComponent(com.synopsys.integration.jira.common.model.components.ProjectComponent) IssueCreationRequestModel(com.synopsys.integration.jira.common.cloud.model.IssueCreationRequestModel) MessageValueReplacementResolver(com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageValueReplacementResolver) IssueRequestModelFieldsMapBuilder(com.synopsys.integration.jira.common.model.request.builder.IssueRequestModelFieldsMapBuilder)

Example 3 with ProjectComponent

use of com.synopsys.integration.jira.common.model.components.ProjectComponent in project hub-alert by blackducksoftware.

the class JiraCloudIssueCreatorTest method createTestJiraCloudIssueCreator.

private TestJiraCloudIssueCreator createTestJiraCloudIssueCreator(String projectNameOrKey, JiraCloudJobDetailsModel jiraCloudJobDetailsModel) throws IntegrationException {
    ProjectService projectService = Mockito.mock(ProjectService.class);
    Mockito.when(projectService.getProjectsByName(Mockito.anyString())).thenReturn(new PageOfProjectsResponseModel(List.of(new ProjectComponent("self", "id", "key", projectNameOrKey, null, null, null, null))));
    JiraCustomFieldResolver jiraCustomFieldResolver = new JiraCustomFieldResolver(() -> List.of());
    JiraIssueCreationRequestCreator jiraIssueCreationRequestCreator = new JiraIssueCreationRequestCreator(jiraCustomFieldResolver);
    IssueCategoryRetriever issueCategoryRetriever = new IssueCategoryRetriever();
    return new TestJiraCloudIssueCreator(jiraCloudJobDetailsModel, projectService, jiraIssueCreationRequestCreator, issueCategoryRetriever);
}
Also used : ProjectComponent(com.synopsys.integration.jira.common.model.components.ProjectComponent) JiraCustomFieldResolver(com.synopsys.integration.alert.api.channel.jira.distribution.custom.JiraCustomFieldResolver) JiraIssueCreationRequestCreator(com.synopsys.integration.alert.api.channel.jira.distribution.JiraIssueCreationRequestCreator) ProjectService(com.synopsys.integration.jira.common.cloud.service.ProjectService) PageOfProjectsResponseModel(com.synopsys.integration.jira.common.model.response.PageOfProjectsResponseModel) IssueCategoryRetriever(com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever)

Example 4 with ProjectComponent

use of com.synopsys.integration.jira.common.model.components.ProjectComponent in project hub-alert by blackducksoftware.

the class JiraServerIssueCreator method createIssueCreationRequest.

@Override
protected IssueCreationRequestModel createIssueCreationRequest(IssueCreationModel alertIssueCreationModel, MessageReplacementValues replacementValues) throws AlertException {
    ProjectComponent jiraProject = retrieveProjectComponent();
    String issueSummary = distributionDetails.getIssueSummary();
    String title = alertIssueCreationModel.getTitle();
    if (StringUtils.isNotEmpty(issueSummary)) {
        MessageValueReplacementResolver messageValueReplacementResolver = new MessageValueReplacementResolver(replacementValues);
        title = messageValueReplacementResolver.createReplacedFieldValue(issueSummary);
    }
    IssueRequestModelFieldsMapBuilder fieldsBuilder = jiraIssueCreationRequestCreator.createIssueRequestModel(title, alertIssueCreationModel.getDescription(), jiraProject.getId(), distributionDetails.getIssueType(), replacementValues, distributionDetails.getCustomFields());
    return new IssueCreationRequestModel(distributionDetails.getIssueCreatorUsername(), distributionDetails.getIssueType(), distributionDetails.getProjectNameOrKey(), fieldsBuilder);
}
Also used : ProjectComponent(com.synopsys.integration.jira.common.model.components.ProjectComponent) IssueCreationRequestModel(com.synopsys.integration.jira.common.server.model.IssueCreationRequestModel) MessageValueReplacementResolver(com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageValueReplacementResolver) IssueRequestModelFieldsMapBuilder(com.synopsys.integration.jira.common.model.request.builder.IssueRequestModelFieldsMapBuilder)

Aggregations

ProjectComponent (com.synopsys.integration.jira.common.model.components.ProjectComponent)4 MessageValueReplacementResolver (com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageValueReplacementResolver)2 IssueRequestModelFieldsMapBuilder (com.synopsys.integration.jira.common.model.request.builder.IssueRequestModelFieldsMapBuilder)2 IssueCategoryRetriever (com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever)1 JiraIssueCreationRequestCreator (com.synopsys.integration.alert.api.channel.jira.distribution.JiraIssueCreationRequestCreator)1 JiraCustomFieldResolver (com.synopsys.integration.alert.api.channel.jira.distribution.custom.JiraCustomFieldResolver)1 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 IssueCreationRequestModel (com.synopsys.integration.jira.common.cloud.model.IssueCreationRequestModel)1 ProjectService (com.synopsys.integration.jira.common.cloud.service.ProjectService)1 PageOfProjectsResponseModel (com.synopsys.integration.jira.common.model.response.PageOfProjectsResponseModel)1 IssueCreationRequestModel (com.synopsys.integration.jira.common.server.model.IssueCreationRequestModel)1