Search in sources :

Example 1 with HttpServiceException

use of com.synopsys.integration.azure.boards.common.http.HttpServiceException 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 2 with HttpServiceException

use of com.synopsys.integration.azure.boards.common.http.HttpServiceException in project hub-alert by blackducksoftware.

the class AzureCustomFieldManager method findOrCreateAlertCustomProjectField.

private ProjectWorkItemFieldModel findOrCreateAlertCustomProjectField(String projectName, String fieldName, String fieldReferenceName, String fieldDescription) throws AlertException {
    ProjectWorkItemFieldModel fieldRequestModel = ProjectWorkItemFieldModel.workItemStringField(fieldName, fieldReferenceName, fieldDescription);
    Optional<ProjectWorkItemFieldModel> customField = getAlertCustomProjectField(projectName, fieldRequestModel.getReferenceName());
    if (customField.isPresent()) {
        return customField.get();
    }
    // custom field not found so create it
    try {
        return projectService.createProjectField(organizationName, projectName, fieldRequestModel);
    } catch (IOException e) {
        throw new AlertException(String.format("There was a problem creating the request to create the Alert Custom Field (%s) in the Azure project: %s", fieldReferenceName, projectName), e);
    } catch (HttpServiceException e) {
        throw new AlertException(String.format("There was a problem creating the Alert Custom Field (%s) in the Azure project: %s", fieldReferenceName, projectName), e);
    }
}
Also used : HttpServiceException(com.synopsys.integration.azure.boards.common.http.HttpServiceException) ProjectWorkItemFieldModel(com.synopsys.integration.azure.boards.common.service.project.ProjectWorkItemFieldModel) IOException(java.io.IOException) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 3 with HttpServiceException

use of com.synopsys.integration.azure.boards.common.http.HttpServiceException in project hub-alert by blackducksoftware.

the class AzureCustomFieldManager method getWorkItemTypeRefName.

private String getWorkItemTypeRefName(String processId, String workItemTypeName) throws AlertException {
    try {
        AzureArrayResponseModel<ProcessWorkItemTypesResponseModel> processWorkItemTypes = processService.getWorkItemTypes(organizationName, processId);
        ProcessWorkItemTypesResponseModel matchingWorkItemType = processWorkItemTypes.getValue().stream().filter(workItemType -> workItemType.getName().equals(workItemTypeName)).findFirst().orElseThrow(() -> new AlertException(String.format("No work item type '%s' exists for the Azure process with id: '%s'", workItemTypeName, processId)));
        if (matchingWorkItemType.getReferenceName().startsWith(UNMODIFIABLE_WORK_ITEM_PREFIX)) {
            // if the reference name starts with this prefix, we know it is a system default so it can not be modified and fields can not be added to it, so we need to create a "copy" of it
            matchingWorkItemType = copyWorkItem(processId, matchingWorkItemType);
        }
        return matchingWorkItemType.getReferenceName();
    } catch (HttpServiceException e) {
        throw new AlertException(String.format("There was a problem trying to get the work item types for the Azure process with id: %s", processId), e);
    }
}
Also used : HttpServiceException(com.synopsys.integration.azure.boards.common.http.HttpServiceException) ProcessWorkItemTypesResponseModel(com.synopsys.integration.azure.boards.common.service.process.ProcessWorkItemTypesResponseModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 4 with HttpServiceException

use of com.synopsys.integration.azure.boards.common.http.HttpServiceException in project hub-alert by blackducksoftware.

the class AzureOAuthCallbackController method testGetProjects.

private void testGetProjects(AzureHttpService azureHttpService, String organizationName, String oAuthRequestKey) {
    try {
        AzureProjectService azureProjectService = new AzureProjectService(azureHttpService, new AzureApiVersionAppender());
        AzureArrayResponseModel<TeamProjectReferenceResponseModel> projects = azureProjectService.getProjects(organizationName);
        Integer projectCount = projects.getCount();
        logger.info("OAuth request with id {}: Azure Boards project count: {}", oAuthRequestKey, projectCount);
    } catch (HttpServiceException ex) {
        logger.error("OAuth request with id {}: Error in azure oauth get projects validation test ", oAuthRequestKey, ex);
    }
}
Also used : HttpServiceException(com.synopsys.integration.azure.boards.common.http.HttpServiceException) AzureApiVersionAppender(com.synopsys.integration.azure.boards.common.http.AzureApiVersionAppender) TeamProjectReferenceResponseModel(com.synopsys.integration.azure.boards.common.service.project.TeamProjectReferenceResponseModel) AzureProjectService(com.synopsys.integration.azure.boards.common.service.project.AzureProjectService)

Example 5 with HttpServiceException

use of com.synopsys.integration.azure.boards.common.http.HttpServiceException in project hub-alert by blackducksoftware.

the class AzureBoardsIssueTransitioner method findAndPerformTransition.

@Override
protected void findAndPerformTransition(ExistingIssueDetails<Integer> existingIssueDetails, String transitionName) throws AlertException {
    WorkItemElementOperationModel replaceSystemStateField = WorkItemElementOperationModel.fieldElement(WorkItemElementOperation.REPLACE, WorkItemResponseFields.System_State, transitionName);
    WorkItemRequest request = new WorkItemRequest(List.of(replaceSystemStateField));
    Integer issueId = existingIssueDetails.getIssueId();
    try {
        workItemService.updateWorkItem(organizationName, distributionDetails.getProjectNameOrId(), issueId, request);
    } catch (HttpServiceException e) {
        List<String> availableStates = retrieveAvailableStates(existingIssueDetails.getIssueId()).stream().map(WorkItemTypeStateResponseModel::getName).collect(Collectors.toList());
        throw new IssueMissingTransitionException(existingIssueDetails.getIssueKey(), transitionName, availableStates);
    }
}
Also used : HttpServiceException(com.synopsys.integration.azure.boards.common.http.HttpServiceException) WorkItemRequest(com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemRequest) IssueMissingTransitionException(com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException) List(java.util.List) WorkItemElementOperationModel(com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemElementOperationModel) WorkItemTypeStateResponseModel(com.synopsys.integration.azure.boards.common.service.state.WorkItemTypeStateResponseModel)

Aggregations

HttpServiceException (com.synopsys.integration.azure.boards.common.http.HttpServiceException)5 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 AzureApiVersionAppender (com.synopsys.integration.azure.boards.common.http.AzureApiVersionAppender)2 AzureProjectService (com.synopsys.integration.azure.boards.common.service.project.AzureProjectService)2 AzureBoardsProperties (com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties)1 IssueMissingTransitionException (com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException)1 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)1 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)1 AzureHttpService (com.synopsys.integration.azure.boards.common.http.AzureHttpService)1 ProcessWorkItemTypesResponseModel (com.synopsys.integration.azure.boards.common.service.process.ProcessWorkItemTypesResponseModel)1 ProjectWorkItemFieldModel (com.synopsys.integration.azure.boards.common.service.project.ProjectWorkItemFieldModel)1 TeamProjectReferenceResponseModel (com.synopsys.integration.azure.boards.common.service.project.TeamProjectReferenceResponseModel)1 WorkItemTypeStateResponseModel (com.synopsys.integration.azure.boards.common.service.state.WorkItemTypeStateResponseModel)1 WorkItemElementOperationModel (com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemElementOperationModel)1 WorkItemRequest (com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemRequest)1 IOException (java.io.IOException)1 List (java.util.List)1