Search in sources :

Example 26 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class BlackDuckProviderService method createBlackDuckProvider.

private String createBlackDuckProvider() {
    Map<String, FieldValueModel> keyToValues = new HashMap<>();
    keyToValues.put("provider.common.config.enabled", new FieldValueModel(List.of("true"), true));
    keyToValues.put("provider.common.config.name", new FieldValueModel(List.of(blackDuckProviderUniqueName), true));
    keyToValues.put("blackduck.url", new FieldValueModel(List.of(blackDuckProviderUrl), true));
    keyToValues.put("blackduck.api.key", new FieldValueModel(List.of(blackDuckApiToken), true));
    keyToValues.put("blackduck.timeout", new FieldValueModel(List.of(blackDuckTimeout), true));
    FieldModel blackDuckProviderConfiguration = new FieldModel(blackDuckProviderKey, ConfigContextEnum.GLOBAL.name(), keyToValues);
    String blackDuckConfigBody = gson.toJson(blackDuckProviderConfiguration);
    try {
        alertRequestUtility.executePostRequest("/api/configuration/validate", blackDuckConfigBody, "Validating the Black Duck provider failed.");
        alertRequestUtility.executePostRequest("/api/configuration/test", blackDuckConfigBody, "Testing the Black Duck provider failed.");
        String creationResponse = alertRequestUtility.executePostRequest("/api/configuration", blackDuckConfigBody, "Could not create the Black Duck provider.");
        JsonObject jsonObject = gson.fromJson(creationResponse, JsonObject.class);
        String blackDuckProviderID = jsonObject.get("id").getAsString();
        intLogger.info(String.format("Configured the Black Duck provider, ID %s.", blackDuckProviderID));
        return blackDuckProviderID;
    } catch (IntegrationException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 27 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class JiraCloudCustomFunctionAction method createActionResponse.

@Override
public ActionResponse<String> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper ignoredServletContent) {
    JiraCloudProperties jiraProperties = jiraCloudPropertiesFactory.createJiraProperties(fieldModel);
    try {
        JiraCloudServiceFactory jiraServicesCloudFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson);
        PluginManagerService jiraAppService = jiraServicesCloudFactory.createPluginManagerService();
        int statusCode = jiraAppService.installMarketplaceCloudApp(JiraConstants.JIRA_APP_KEY);
        if (!HttpStatusCodes.isSuccess(statusCode)) {
            return new ActionResponse<>(HttpStatus.BAD_REQUEST, "The Jira Cloud server responded with error code: " + statusCode);
        }
        boolean jiraPluginInstalled = JiraPluginCheckUtils.checkIsAppInstalledAndRetryIfNecessary(jiraAppService);
        if (!jiraPluginInstalled) {
            return new ActionResponse<>(HttpStatus.NOT_FOUND, String.format("Unable to confirm successful installation of the Jira Cloud '%s' plugin. Please verify the installation on your Jira Cloud server.", JiraConstants.JIRA_ALERT_APP_NAME));
        }
        return new ActionResponse<>(HttpStatus.OK, String.format("Successfully installed the '%s' plugin on Jira Cloud", JiraConstants.JIRA_ALERT_APP_NAME));
    } catch (IntegrationException e) {
        logger.error("There was an issue connecting to Jira Cloud", e);
        return new ActionResponse<>(HttpStatus.BAD_REQUEST, "The following error occurred when connecting to Jira Cloud: " + e.getMessage());
    } catch (InterruptedException e) {
        logger.error("Thread was interrupted while validating jira install.", e);
        Thread.currentThread().interrupt();
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Thread was interrupted while validating Jira '%s' plugin installation: %s", JiraConstants.JIRA_ALERT_APP_NAME, e.getMessage()));
    }
}
Also used : PluginManagerService(com.synopsys.integration.jira.common.rest.service.PluginManagerService) IntegrationException(com.synopsys.integration.exception.IntegrationException) JiraCloudServiceFactory(com.synopsys.integration.jira.common.cloud.service.JiraCloudServiceFactory) JiraCloudProperties(com.synopsys.integration.alert.channel.jira.cloud.JiraCloudProperties) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 28 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class JiraServerGlobalTestActionTest method testAppCheckDisabled.

@Test
void testAppCheckDisabled() throws IntegrationException {
    AuthorizationManager authorizationManager = createAuthorizationManager(255);
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
    JiraServerTestActionFactory jiraServerTestActionFactory = Mockito.mock(JiraServerTestActionFactory.class);
    JiraServerGlobalTestActionWrapper testActionWrapper = Mockito.mock(JiraServerGlobalTestActionWrapper.class);
    Mockito.when(jiraServerTestActionFactory.createTestActionWrapper(Mockito.any())).thenReturn(testActionWrapper);
    Mockito.when(testActionWrapper.canUserGetIssues()).thenReturn(true);
    Mockito.when(testActionWrapper.isAppCheckEnabled()).thenReturn(false);
    Mockito.when(testActionWrapper.isUserAdmin()).thenThrow(new IntegrationException("Test failure: This exception should not be thrown!"));
    JiraServerGlobalTestAction jiraServerGlobalTestAction = new JiraServerGlobalTestAction(authorizationManager, validator, jiraServerTestActionFactory);
    ConfigurationTestResult testResult = jiraServerGlobalTestAction.testConfigModelContent(jiraServerGlobalConfigModel);
    assertTrue(testResult.isSuccess());
}
Also used : JiraServerGlobalConfigurationValidator(com.synopsys.integration.alert.channel.jira.server.validator.JiraServerGlobalConfigurationValidator) IntegrationException(com.synopsys.integration.exception.IntegrationException) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigurationTestResult(com.synopsys.integration.alert.common.message.model.ConfigurationTestResult) Test(org.junit.jupiter.api.Test)

Example 29 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class JiraServerInstallPluginAction method installPlugin.

public ActionResponse<ValidationResponseModel> installPlugin(JiraServerGlobalConfigModel jiraServerGlobalConfigModel) {
    if (!authorizationManager.hasExecutePermission(ConfigContextEnum.GLOBAL, ChannelKeys.JIRA_SERVER)) {
        return new ActionResponse<>(HttpStatus.FORBIDDEN, ResponseFactory.UNAUTHORIZED_REQUEST_MESSAGE);
    }
    ActionResponse<ValidationResponseModel> validate = jiraServerGlobalValidationAction.validate(jiraServerGlobalConfigModel);
    Boolean validationHasErrors = validate.getContent().map(ValidationResponseModel::hasErrors).orElse(false);
    if (validationHasErrors) {
        return validate;
    }
    JiraServerProperties jiraProperties = jiraServerPropertiesFactory.createJiraProperties(jiraServerGlobalConfigModel);
    try {
        JiraServerServiceFactory jiraServicesFactory = jiraProperties.createJiraServicesServerFactory(logger, gson);
        PluginManagerService jiraAppService = jiraServicesFactory.createPluginManagerService();
        try {
            jiraAppService.installMarketplaceServerApp(JiraConstants.JIRA_APP_KEY);
        } catch (IntegrationRestException e) {
            if (RestConstants.NOT_FOUND_404 == e.getHttpStatusCode()) {
                return new ActionResponse<>(HttpStatus.NOT_FOUND, String.format("The marketplace listing of the '%s' app may not support your version of Jira. Please install the app manually or request a compatibility update. Error: %s", JiraConstants.JIRA_ALERT_APP_NAME, e.getMessage()));
            }
            return createBadRequestIntegrationException(e);
        }
        boolean jiraPluginInstalled = JiraPluginCheckUtils.checkIsAppInstalledAndRetryIfNecessary(jiraAppService);
        if (!jiraPluginInstalled) {
            return new ActionResponse<>(HttpStatus.NOT_FOUND, String.format("Unable to confirm Jira server successfully installed the '%s' plugin. Please verify the installation on you Jira server.", JiraConstants.JIRA_ALERT_APP_NAME));
        }
        return new ActionResponse<>(HttpStatus.OK, String.format("Successfully installed the '%s' plugin on Jira server.", JiraConstants.JIRA_ALERT_APP_NAME));
    } catch (IntegrationException e) {
        return createBadRequestIntegrationException(e);
    } catch (InterruptedException e) {
        logger.error("Thread was interrupted while validating Jira plugin installation.", e);
        Thread.currentThread().interrupt();
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Thread was interrupted while validating Jira '%s' plugin installation: %s", JiraConstants.JIRA_ALERT_APP_NAME, e.getMessage()));
    }
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) PluginManagerService(com.synopsys.integration.jira.common.rest.service.PluginManagerService) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) JiraServerServiceFactory(com.synopsys.integration.jira.common.server.service.JiraServerServiceFactory) IntegrationException(com.synopsys.integration.exception.IntegrationException) JiraServerProperties(com.synopsys.integration.alert.channel.jira.server.JiraServerProperties) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 30 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class JiraServerCustomFunctionAction method createActionResponse.

@Override
public ActionResponse<String> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper ignoredServletContent) {
    try {
        JiraServerProperties jiraProperties = jiraServerPropertiesFactory.createJiraPropertiesWithJobId(UUID.fromString(fieldModel.getId()));
        JiraServerServiceFactory jiraServicesFactory = jiraProperties.createJiraServicesServerFactory(logger, gson);
        PluginManagerService jiraAppService = jiraServicesFactory.createPluginManagerService();
        try {
            jiraAppService.installMarketplaceServerApp(JiraConstants.JIRA_APP_KEY);
        } catch (IntegrationRestException e) {
            if (RestConstants.NOT_FOUND_404 == e.getHttpStatusCode()) {
                return new ActionResponse<>(HttpStatus.NOT_FOUND, String.format("The marketplace listing of the '%s' app may not support your version of Jira. Please install the app manually or request a compatibility update. Error: %s", JiraConstants.JIRA_ALERT_APP_NAME, e.getMessage()));
            }
            return createBadRequestIntegrationException(e);
        }
        boolean jiraPluginInstalled = JiraPluginCheckUtils.checkIsAppInstalledAndRetryIfNecessary(jiraAppService);
        if (!jiraPluginInstalled) {
            return new ActionResponse<>(HttpStatus.NOT_FOUND, String.format("Unable to confirm Jira server successfully installed the '%s' plugin. Please verify the installation on you Jira server.", JiraConstants.JIRA_ALERT_APP_NAME));
        }
        return new ActionResponse<>(HttpStatus.OK, String.format("Successfully installed the '%s' plugin on Jira server.", JiraConstants.JIRA_ALERT_APP_NAME));
    } catch (IntegrationException e) {
        return createBadRequestIntegrationException(e);
    } catch (InterruptedException e) {
        logger.error("Thread was interrupted while validating Jira plugin installation.", e);
        Thread.currentThread().interrupt();
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Thread was interrupted while validating Jira '%s' plugin installation: %s", JiraConstants.JIRA_ALERT_APP_NAME, e.getMessage()));
    }
}
Also used : PluginManagerService(com.synopsys.integration.jira.common.rest.service.PluginManagerService) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) JiraServerServiceFactory(com.synopsys.integration.jira.common.server.service.JiraServerServiceFactory) IntegrationException(com.synopsys.integration.exception.IntegrationException) JiraServerProperties(com.synopsys.integration.alert.channel.jira.server.JiraServerProperties) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Aggregations

IntegrationException (com.synopsys.integration.exception.IntegrationException)53 HttpUrl (com.synopsys.integration.rest.HttpUrl)19 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)14 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)13 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)12 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)11 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)10 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)9 ArrayList (java.util.ArrayList)9 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)8 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)8 Set (java.util.Set)8 Test (org.junit.jupiter.api.Test)8 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)7 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)7 List (java.util.List)7 Optional (java.util.Optional)7 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)6 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)6 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)6