Search in sources :

Example 1 with AzureBoardsProperties

use of com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties in project hub-alert by blackducksoftware.

the class AzureBoardsProcessorFactory method createProcessor.

@Override
public IssueTrackerProcessor<Integer> createProcessor(AzureBoardsJobDetailsModel distributionDetails) throws AlertException {
    AzureBoardsProperties azureBoardsProperties = azureBoardsPropertiesFactory.createAzureBoardsProperties();
    String organizationName = azureBoardsProperties.getOrganizationName();
    azureBoardsProperties.validateProperties();
    // Initialize Http Service
    ProxyInfo proxy = proxyManager.createProxyInfoForHost(AzureHttpRequestCreatorFactory.DEFAULT_BASE_URL);
    AzureHttpRequestCreator azureHttpRequestCreator = azureBoardsProperties.createAzureHttpRequestCreator(proxy, gson);
    AzureHttpService azureHttpService = new AzureHttpService(gson, azureHttpRequestCreator);
    // Common Azure Boards Services
    AzureApiVersionAppender apiVersionAppender = new AzureApiVersionAppender();
    AzureProjectService projectService = new AzureProjectService(azureHttpService, apiVersionAppender);
    AzureWorkItemService workItemService = new AzureWorkItemService(azureHttpService, azureHttpRequestCreator);
    AzureWorkItemQueryService workItemQueryService = new AzureWorkItemQueryService(azureHttpService, apiVersionAppender);
    String projectNameOrId = distributionDetails.getProjectNameOrId();
    String teamProjectName = retrieveProjectNameIfNecessary(projectService, organizationName, projectNameOrId);
    installCustomFieldsIfNecessary(organizationName, teamProjectName, distributionDetails.getWorkItemType(), projectService, new AzureProcessService(azureHttpService, apiVersionAppender));
    // Searcher Requirements
    AzureBoardsIssueStatusResolver azureBoardsIssueStatusResolver = new AzureBoardsIssueStatusResolver(distributionDetails.getWorkItemCompletedState(), distributionDetails.getWorkItemReopenState());
    AzureBoardsIssueTrackerQueryManager queryManager = new AzureBoardsIssueTrackerQueryManager(organizationName, distributionDetails, workItemService, workItemQueryService);
    // Extractor Requirements
    AzureBoardsExistingIssueDetailsCreator issueDetailsCreator = new AzureBoardsExistingIssueDetailsCreator(organizationName, issueCategoryRetriever, azureBoardsIssueStatusResolver);
    AzureBoardsWorkItemFinder workItemFinder = new AzureBoardsWorkItemFinder(queryManager, teamProjectName);
    AzureBoardsProjectAndVersionIssueFinder projectAndVersionIssueFinder = new AzureBoardsProjectAndVersionIssueFinder(gson, issueDetailsCreator, workItemFinder);
    AzureBoardsComponentIssueFinder componentIssueFinder = new AzureBoardsComponentIssueFinder(gson, workItemFinder, issueDetailsCreator);
    IssueTrackerSearcher<Integer> azureBoardsSearcher = new IssueTrackerSearcher<>(projectAndVersionIssueFinder, projectAndVersionIssueFinder, componentIssueFinder, componentIssueFinder, modelTransformer);
    IssueTrackerModelExtractor<Integer> extractor = new IssueTrackerModelExtractor<>(formatter, azureBoardsSearcher);
    // Message Sender Requirements
    AzureWorkItemTypeStateService workItemTypeStateService = new AzureWorkItemTypeStateService(azureHttpService, apiVersionAppender);
    AzureWorkItemCommentService workItemCommentService = new AzureWorkItemCommentService(azureHttpService, apiVersionAppender);
    IssueTrackerMessageSender<Integer> messageSender = azureBoardsMessageSenderFactory.createMessageSender(workItemService, workItemTypeStateService, workItemCommentService, organizationName, distributionDetails);
    return new IssueTrackerProcessor<>(extractor, messageSender);
}
Also used : AzureBoardsProjectAndVersionIssueFinder(com.synopsys.integration.alert.channel.azure.boards.distribution.search.AzureBoardsProjectAndVersionIssueFinder) AzureBoardsWorkItemFinder(com.synopsys.integration.alert.channel.azure.boards.distribution.search.AzureBoardsWorkItemFinder) AzureWorkItemTypeStateService(com.synopsys.integration.azure.boards.common.service.state.AzureWorkItemTypeStateService) AzureWorkItemQueryService(com.synopsys.integration.azure.boards.common.service.query.AzureWorkItemQueryService) ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) IssueTrackerModelExtractor(com.synopsys.integration.alert.api.channel.issue.IssueTrackerModelExtractor) AzureWorkItemCommentService(com.synopsys.integration.azure.boards.common.service.comment.AzureWorkItemCommentService) AzureHttpRequestCreator(com.synopsys.integration.azure.boards.common.http.AzureHttpRequestCreator) AzureHttpService(com.synopsys.integration.azure.boards.common.http.AzureHttpService) AzureBoardsExistingIssueDetailsCreator(com.synopsys.integration.alert.channel.azure.boards.distribution.search.AzureBoardsExistingIssueDetailsCreator) AzureBoardsProperties(com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties) IssueTrackerProcessor(com.synopsys.integration.alert.api.channel.issue.IssueTrackerProcessor) IssueTrackerSearcher(com.synopsys.integration.alert.api.channel.issue.search.IssueTrackerSearcher) AzureProjectService(com.synopsys.integration.azure.boards.common.service.project.AzureProjectService) AzureApiVersionAppender(com.synopsys.integration.azure.boards.common.http.AzureApiVersionAppender) AzureBoardsComponentIssueFinder(com.synopsys.integration.alert.channel.azure.boards.distribution.search.AzureBoardsComponentIssueFinder) AzureBoardsIssueStatusResolver(com.synopsys.integration.alert.channel.azure.boards.distribution.search.AzureBoardsIssueStatusResolver) AzureWorkItemService(com.synopsys.integration.azure.boards.common.service.workitem.AzureWorkItemService) AzureProcessService(com.synopsys.integration.azure.boards.common.service.process.AzureProcessService)

Example 2 with AzureBoardsProperties

use of com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties in project hub-alert by blackducksoftware.

the class AzureBoardsGlobalFieldModelTestAction method testConfig.

@Override
public MessageResult testConfig(String configId, FieldModel fieldModel, FieldUtility registeredFieldValues) throws IntegrationException {
    try {
        Optional<ConfigurationFieldModel> configurationFieldModel = registeredFieldValues.getField(AzureBoardsDescriptor.KEY_ORGANIZATION_NAME);
        String organizationName = configurationFieldModel.flatMap(ConfigurationFieldModel::getFieldValue).orElse(null);
        AzureBoardsProperties azureBoardsProperties = AzureBoardsProperties.fromFieldAccessor(azureBoardsCredentialDataStoreFactory, azureRedirectUrlCreator.createOAuthRedirectUri(), registeredFieldValues);
        AzureHttpService azureHttpService = createAzureHttpService(azureBoardsProperties);
        AzureProjectService azureProjectService = new AzureProjectService(azureHttpService, new AzureApiVersionAppender());
        azureProjectService.getProjects(organizationName);
        return new MessageResult("Successfully connected to Azure instance.");
    } catch (HttpServiceException ex) {
        logger.error("Global Test Action failed testing Azure Boards connection.", ex);
        throw (ex);
    }
}
Also used : HttpServiceException(com.synopsys.integration.azure.boards.common.http.HttpServiceException) AzureApiVersionAppender(com.synopsys.integration.azure.boards.common.http.AzureApiVersionAppender) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AzureHttpService(com.synopsys.integration.azure.boards.common.http.AzureHttpService) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) AzureProjectService(com.synopsys.integration.azure.boards.common.service.project.AzureProjectService) AzureBoardsProperties(com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties)

Example 3 with AzureBoardsProperties

use of com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties in project hub-alert by blackducksoftware.

the class AzureOAuthCallbackController method oauthCallback.

@GetMapping
public ResponseEntity<String> oauthCallback(HttpServletRequest request) {
    logger.debug("Azure OAuth callback method called");
    if (!authorizationManager.hasExecutePermission(ConfigContextEnum.GLOBAL.name(), ChannelKeys.AZURE_BOARDS.getUniversalKey())) {
        logger.debug("Azure OAuth callback user does not have permission to call the controller.");
        return responseFactory.createForbiddenResponse();
    }
    String state = request.getParameter("state");
    String oAuthRequestId = oAuthRequestValidator.parseRequestIdString(state);
    try {
        String requestURI = request.getRequestURI();
        String requestQueryString = request.getQueryString();
        logger.debug("Request URI {}?{}", requestURI, requestQueryString);
        String authorizationCode = request.getParameter("code");
        if (!oAuthRequestValidator.hasRequestKey(state)) {
            logger.info("OAuth request with id {}: not found.", oAuthRequestId);
        } else {
            logger.info("OAuth request with id {}: Processing...", oAuthRequestId);
            oAuthRequestValidator.removeAuthorizationRequest(state);
            FieldUtility fieldUtility = createFieldAccessor();
            if (fieldUtility.getFields().isEmpty()) {
                logger.error("OAuth request with id {}: Azure oauth callback: Channel global configuration missing", oAuthRequestId);
            } else {
                if (StringUtils.isBlank(authorizationCode)) {
                    logger.error("OAuth request with id {}: Azure oauth callback: Authorization code isn't valid. Stop processing", oAuthRequestId);
                } else {
                    String oAuthRedirectUri = azureRedirectUrlCreator.createOAuthRedirectUri();
                    AzureBoardsProperties properties = AzureBoardsProperties.fromFieldAccessor(azureBoardsCredentialDataStoreFactory, oAuthRedirectUri, fieldUtility);
                    testOAuthConnection(properties, authorizationCode, oAuthRequestId);
                }
            }
        }
    } catch (Exception ex) {
        // catch any exceptions so the redirect back to the UI happens and doesn't display the URL with the authorization code to the user.
        logger.error("OAuth request with id {}: Azure OAuth callback error occurred", oAuthRequestId, ex);
    }
    // redirect back to the global channel configuration URL in the Alert UI.
    return responseFactory.createFoundRedirectResponse(azureRedirectUrlCreator.createUIRedirectLocation());
}
Also used : FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) AzureBoardsProperties(com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties) HttpServiceException(com.synopsys.integration.azure.boards.common.http.HttpServiceException) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with AzureBoardsProperties

use of com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties in project hub-alert by blackducksoftware.

the class AzureBoardsMessageSenderFactory method createMessageSender.

@Override
public IssueTrackerMessageSender<Integer> createMessageSender(AzureBoardsJobDetailsModel distributionDetails) throws AlertException {
    AzureBoardsProperties azureBoardsProperties = azureBoardsPropertiesFactory.createAzureBoardsProperties();
    azureBoardsProperties.validateProperties();
    // Initialize Http Service
    ProxyInfo proxy = proxyManager.createProxyInfoForHost(AzureHttpRequestCreatorFactory.DEFAULT_BASE_URL);
    AzureHttpRequestCreator azureHttpRequestCreator = azureBoardsProperties.createAzureHttpRequestCreator(proxy, gson);
    AzureHttpService azureHttpService = new AzureHttpService(gson, azureHttpRequestCreator);
    // Azure Boards Services
    AzureApiVersionAppender apiVersionAppender = new AzureApiVersionAppender();
    AzureWorkItemService workItemService = new AzureWorkItemService(azureHttpService, azureHttpRequestCreator);
    AzureWorkItemTypeStateService workItemTypeStateService = new AzureWorkItemTypeStateService(azureHttpService, apiVersionAppender);
    AzureWorkItemCommentService workItemCommentService = new AzureWorkItemCommentService(azureHttpService, apiVersionAppender);
    return createMessageSender(workItemService, workItemTypeStateService, workItemCommentService, azureBoardsProperties.getOrganizationName(), distributionDetails);
}
Also used : ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) AzureApiVersionAppender(com.synopsys.integration.azure.boards.common.http.AzureApiVersionAppender) AzureWorkItemCommentService(com.synopsys.integration.azure.boards.common.service.comment.AzureWorkItemCommentService) AzureWorkItemService(com.synopsys.integration.azure.boards.common.service.workitem.AzureWorkItemService) AzureWorkItemTypeStateService(com.synopsys.integration.azure.boards.common.service.state.AzureWorkItemTypeStateService) AzureHttpRequestCreator(com.synopsys.integration.azure.boards.common.http.AzureHttpRequestCreator) AzureHttpService(com.synopsys.integration.azure.boards.common.http.AzureHttpService) AzureBoardsProperties(com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties)

Example 5 with AzureBoardsProperties

use of com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties in project hub-alert by blackducksoftware.

the class AzureBoardsCustomFunctionAction method isAuthenticated.

private boolean isAuthenticated(FieldUtility fieldUtility) {
    AzureBoardsProperties properties = AzureBoardsProperties.fromFieldAccessor(azureBoardsCredentialDataStoreFactory, azureRedirectUrlCreator.createOAuthRedirectUri(), fieldUtility);
    ProxyInfo proxy = proxyManager.createProxyInfoForHost(AzureHttpRequestCreatorFactory.DEFAULT_BASE_URL);
    return properties.hasOAuthCredentials(proxy);
}
Also used : ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) AzureBoardsProperties(com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties)

Aggregations

AzureBoardsProperties (com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties)5 AzureApiVersionAppender (com.synopsys.integration.azure.boards.common.http.AzureApiVersionAppender)3 AzureHttpService (com.synopsys.integration.azure.boards.common.http.AzureHttpService)3 ProxyInfo (com.synopsys.integration.rest.proxy.ProxyInfo)3 AzureHttpRequestCreator (com.synopsys.integration.azure.boards.common.http.AzureHttpRequestCreator)2 HttpServiceException (com.synopsys.integration.azure.boards.common.http.HttpServiceException)2 AzureWorkItemCommentService (com.synopsys.integration.azure.boards.common.service.comment.AzureWorkItemCommentService)2 AzureProjectService (com.synopsys.integration.azure.boards.common.service.project.AzureProjectService)2 AzureWorkItemTypeStateService (com.synopsys.integration.azure.boards.common.service.state.AzureWorkItemTypeStateService)2 AzureWorkItemService (com.synopsys.integration.azure.boards.common.service.workitem.AzureWorkItemService)2 IssueTrackerModelExtractor (com.synopsys.integration.alert.api.channel.issue.IssueTrackerModelExtractor)1 IssueTrackerProcessor (com.synopsys.integration.alert.api.channel.issue.IssueTrackerProcessor)1 IssueTrackerSearcher (com.synopsys.integration.alert.api.channel.issue.search.IssueTrackerSearcher)1 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 AzureBoardsComponentIssueFinder (com.synopsys.integration.alert.channel.azure.boards.distribution.search.AzureBoardsComponentIssueFinder)1 AzureBoardsExistingIssueDetailsCreator (com.synopsys.integration.alert.channel.azure.boards.distribution.search.AzureBoardsExistingIssueDetailsCreator)1 AzureBoardsIssueStatusResolver (com.synopsys.integration.alert.channel.azure.boards.distribution.search.AzureBoardsIssueStatusResolver)1 AzureBoardsProjectAndVersionIssueFinder (com.synopsys.integration.alert.channel.azure.boards.distribution.search.AzureBoardsProjectAndVersionIssueFinder)1 AzureBoardsWorkItemFinder (com.synopsys.integration.alert.channel.azure.boards.distribution.search.AzureBoardsWorkItemFinder)1 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)1