use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class ConfigActions method findFieldModel.
@Override
protected Optional<FieldModel> findFieldModel(Long id) {
Optional<FieldModel> optionalModel = Optional.empty();
Optional<ConfigurationModel> configurationModel = configurationModelConfigurationAccessor.getConfigurationById(id);
if (configurationModel.isPresent()) {
try {
FieldModel configurationFieldModel = modelConverter.convertToFieldModel(configurationModel.get());
FieldModel fieldModel = fieldModelProcessor.performAfterReadAction(configurationFieldModel);
optionalModel = Optional.of(fieldModel);
} catch (AlertException ex) {
logger.error(String.format("Error finding configuration for id: %d", id), ex);
}
}
return optionalModel;
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class ConfigActions method createWithoutChecks.
@Override
protected ActionResponse<FieldModel> createWithoutChecks(FieldModel resource) {
Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(resource.getDescriptorName());
if (descriptorKey.isPresent()) {
try {
FieldModel modifiedFieldModel = fieldModelProcessor.performBeforeSaveAction(resource);
String context = modifiedFieldModel.getContext();
Map<String, ConfigurationFieldModel> configurationFieldModelMap = modelConverter.convertToConfigurationFieldModelMap(modifiedFieldModel);
ConfigurationModel configuration = configurationModelConfigurationAccessor.createConfiguration(descriptorKey.get(), EnumUtils.getEnum(ConfigContextEnum.class, context), configurationFieldModelMap.values());
globalConfigurationModelToConcreteConversionService.createDefaultConcreteModel(modifiedFieldModel.getDescriptorName(), configuration);
FieldModel dbSavedModel = modelConverter.convertToFieldModel(configuration);
FieldModel afterSaveAction = fieldModelProcessor.performAfterSaveAction(dbSavedModel);
FieldModel responseModel = dbSavedModel.fill(afterSaveAction);
return new ActionResponse<>(HttpStatus.OK, responseModel);
} catch (AlertException ex) {
logger.error("Error creating configuration", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error creating config: %s", ex.getMessage()));
}
}
return new ActionResponse<>(HttpStatus.BAD_REQUEST, "descriptorName is missing or invalid");
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class ConfigActions method deleteWithoutChecks.
@Override
protected ActionResponse<FieldModel> deleteWithoutChecks(Long id) {
Optional<ConfigurationModel> configuration = configurationModelConfigurationAccessor.getConfigurationById(id);
if (configuration.isPresent()) {
try {
ConfigurationModel configurationModel = configuration.get();
FieldModel convertedFieldModel = modelConverter.convertToFieldModel(configurationModel);
FieldModel fieldModel = fieldModelProcessor.performBeforeDeleteAction(convertedFieldModel);
configurationModelConfigurationAccessor.deleteConfiguration(Long.parseLong(fieldModel.getId()));
globalConfigurationModelToConcreteConversionService.deleteDefaultConcreteModel(fieldModel.getDescriptorName(), configurationModel);
fieldModelProcessor.performAfterDeleteAction(fieldModel);
} catch (AlertException ex) {
logger.error(String.format("Error deleting config id: %d", id), ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class IssueTrackerTestAction method testConfig.
@Override
public MessageResult testConfig(DistributionJobModel testJobModel, String jobName, @Nullable String customTopic, @Nullable String customMessage) throws AlertException {
D distributionDetails = (D) testJobModel.getDistributionJobDetails();
IssueTrackerMessageSender<T> messageSender = messageSenderFactory.createMessageSender(distributionDetails);
String topicString = Optional.ofNullable(customTopic).orElse("Alert Test Topic");
String messageString = Optional.ofNullable(customMessage).orElse("Alert Test Message");
// TODO determine if source should be required everywhere
ProjectIssueModel testProjectIssueModel = createPlaceholderProjectIssueModel(testJobModel.getBlackDuckGlobalConfigId());
String postCreateComment = String.format("Created by [ Test Configuration ] in the Alert Distribution Job: %s", testJobModel.getName());
IssueCreationModel creationRequest = IssueCreationModel.simple(topicString, messageString, List.of(postCreateComment), testProjectIssueModel.getProvider());
IssueTrackerModelHolder<T> creationRequestModelHolder = new IssueTrackerModelHolder<>(List.of(creationRequest), List.of(), List.of());
IssueTrackerTestActionFieldStatusCreator fieldStatusCreator = new IssueTrackerTestActionFieldStatusCreator();
List<IssueTrackerIssueResponseModel<T>> createdIssues;
try {
createdIssues = messageSender.sendMessages(creationRequestModelHolder);
} catch (AlertFieldException e) {
logger.error("Failed to create test issue", e);
return new MessageResult("Failed to create issue: " + e.getMessage(), e.getFieldErrors());
} catch (AlertException e) {
logger.error("Failed to create test issue", e);
return new MessageResult("Failed to create issue: " + e.getMessage(), fieldStatusCreator.createWithoutField(e.getMessage()));
}
int createdIssuesSize = createdIssues.size();
if (createdIssuesSize != 1) {
String errorMessage = String.format("Expected [1] issue to be created, but there were actually [%d]", createdIssuesSize);
return new MessageResult(errorMessage, fieldStatusCreator.createWithoutField(errorMessage));
}
IssueTrackerIssueResponseModel<T> createdIssue = createdIssues.get(0);
ExistingIssueDetails<T> existingIssueDetails = new ExistingIssueDetails<>(createdIssue.getIssueId(), createdIssue.getIssueKey(), createdIssue.getIssueTitle(), createdIssue.getIssueLink(), IssueStatus.RESOLVABLE, IssueCategory.BOM);
if (!hasResolveTransition(distributionDetails)) {
return createSuccessMessageResult(existingIssueDetails);
}
IssueTrackerTransitionTestAction<T> transitionTestAction = new IssueTrackerTransitionTestAction<>(messageSender, fieldStatusCreator);
Optional<MessageResult> optionalResolveFailure = transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel);
if (optionalResolveFailure.isPresent()) {
return optionalResolveFailure.get();
}
if (!hasReopenTransition(distributionDetails)) {
return createSuccessMessageResult(existingIssueDetails);
}
return transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.OPEN, existingIssueDetails, testProjectIssueModel).orElseGet(() -> transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel).orElse(createSuccessMessageResult(existingIssueDetails)));
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class RestChannelUtilityTest method sendMessageSuccessTest.
@Test
public void sendMessageSuccessTest() throws IntegrationException {
Response response = createMockResponse(HttpStatus.OK);
IntHttpClient intHttpClient = createMockHttpClientWithResponse(response);
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
try {
restChannelUtility.sendMessage(List.of(TEST_REQUEST, TEST_REQUEST), CLASS_NAME);
} catch (AlertException e) {
fail("Expected no exception to be thrown", e);
}
}
Aggregations