Search in sources :

Example 36 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse 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)

Example 37 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testGetOneEmpty.

@Test
public void testGetOneEmpty() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, 255);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.getOne(() -> createEmptyOptional());
    assertEquals(HttpStatus.NOT_FOUND, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

Example 38 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testCreateForbidden.

@Test
public void testCreateForbidden() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.NO_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.create(() -> ValidationResponseModel.success(), () -> Boolean.FALSE, () -> createDefault());
    assertEquals(HttpStatus.FORBIDDEN, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

Example 39 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testUpdateException.

@Test
public void testUpdateException() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ThrowingSupplier createdModelSupplier = () -> {
        throw new AlertException("error getting test message");
    };
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.update(() -> ValidationResponseModel.success(), () -> true, createdModelSupplier);
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ThrowingSupplier(com.synopsys.integration.function.ThrowingSupplier) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

Example 40 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testUpdateModelNotFound.

@Test
public void testUpdateModelNotFound() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.update(() -> ValidationResponseModel.success(), () -> false, () -> createDefault());
    assertEquals(HttpStatus.NOT_FOUND, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

Aggregations

ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)66 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)23 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)20 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)19 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)17 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)16 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)15 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)15 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)15 Test (org.junit.jupiter.api.Test)15 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)12 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)8 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)6 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)6 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)5 MultiFieldModel (com.synopsys.integration.alert.common.rest.model.MultiFieldModel)5 Collection (java.util.Collection)5 Optional (java.util.Optional)5 Set (java.util.Set)5