use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class JobConfigActionsTest method createServerErrorTest.
@Test
public void createServerErrorTest() throws Exception {
Mockito.doThrow(new AlertException("Exception for test")).when(mockedFieldModelProcessor).performBeforeSaveAction(Mockito.any());
ActionResponse<JobFieldModel> jobFieldModelActionResponse = defaultJobConfigActions.create(jobFieldModel);
assertTrue(jobFieldModelActionResponse.isError());
assertFalse(jobFieldModelActionResponse.hasContent());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, jobFieldModelActionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class JobConfigActionsTest method getOneErrorTest.
@Test
public void getOneErrorTest() throws Exception {
Mockito.doThrow(new AlertException("Exception for Alert")).when(mockedFieldModelProcessor).performAfterReadAction(Mockito.any());
ActionResponse<JobFieldModel> jobFieldModelActionResponse = defaultJobConfigActions.getOne(jobId);
assertTrue(jobFieldModelActionResponse.isError());
assertFalse(jobFieldModelActionResponse.hasContent());
assertEquals(HttpStatus.NOT_FOUND, jobFieldModelActionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class ConfigActions method convertConfigurationModelList.
private List<FieldModel> convertConfigurationModelList(String descriptorName, String context, List<ConfigurationModel> configurationModels) {
List<FieldModel> responseFieldModels = new LinkedList<>();
List<FieldModel> fieldModelList = new LinkedList<>();
if (null != configurationModels) {
for (ConfigurationModel configurationModel : configurationModels) {
FieldModel fieldModel = modelConverter.convertToFieldModel(configurationModel);
fieldModelList.add(fieldModel);
}
}
if (fieldModelList.isEmpty()) {
fieldModelList.add(new FieldModel(descriptorName, context, new HashMap<>()));
}
for (FieldModel fieldModel : fieldModelList) {
try {
responseFieldModels.add(fieldModelProcessor.performAfterReadAction(fieldModel));
} catch (AlertException ex) {
logger.error("Error performing after read action", ex);
}
}
return responseFieldModels;
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class JobConfigActions method updateWithoutChecks.
@Override
protected ActionResponse<JobFieldModel> updateWithoutChecks(UUID id, JobFieldModel resource) {
try {
Optional<DistributionJobModel> jobModel = jobAccessor.getJobById(id);
if (jobModel.isPresent()) {
DistributionJobModel previousJob = jobModel.get();
JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(previousJob);
Map<String, FieldModel> descriptorAndContextToPreviousFieldModel = new HashMap<>();
for (FieldModel previousJobFieldModel : jobFieldModel.getFieldModels()) {
descriptorAndContextToPreviousFieldModel.put(previousJobFieldModel.getDescriptorName() + previousJobFieldModel.getContext(), previousJobFieldModel);
}
Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
for (FieldModel fieldModel : resource.getFieldModels()) {
FieldModel beforeUpdateEventFieldModel = fieldModelProcessor.performBeforeUpdateAction(fieldModel);
String beforeFieldModelId = beforeUpdateEventFieldModel.getId();
Long fieldModelId = (StringUtils.isNotBlank(beforeFieldModelId)) ? Long.parseLong(beforeFieldModelId) : null;
Collection<ConfigurationFieldModel> updatedFieldModels = fieldModelProcessor.fillFieldModelWithExistingData(fieldModelId, beforeUpdateEventFieldModel);
configurationFieldModels.addAll(updatedFieldModels);
}
List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, previousJob.getCreatedAt(), DateUtils.createCurrentDateTimestamp());
DistributionJobModel savedJob = jobAccessor.updateJob(previousJob.getJobId(), jobRequestModel);
JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
Set<FieldModel> updatedFieldModels = new HashSet<>();
for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
FieldModel previousFieldModel = descriptorAndContextToPreviousFieldModel.get(fieldModel.getDescriptorName() + fieldModel.getContext());
FieldModel updatedModel = fieldModelProcessor.performAfterUpdateAction(previousFieldModel, fieldModel);
updatedFieldModels.add(updatedModel);
}
savedJobFieldModel.setFieldModels(updatedFieldModels);
return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
} else {
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
} catch (AlertException ex) {
logger.error("Error creating job", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class IssueTrackerTransitionTestAction method transitionTestIssueOrReturnFailureResult.
public Optional<MessageResult> transitionTestIssueOrReturnFailureResult(IssueOperation operation, ExistingIssueDetails<T> existingIssueDetails, ProjectIssueModel testProjectIssueModel) {
String postTransitionComment = String.format("Successfully tested the %s operation", operation.name());
IssueTransitionModel<T> resolveRequest = new IssueTransitionModel<>(existingIssueDetails, operation, List.of(postTransitionComment), testProjectIssueModel);
IssueTrackerModelHolder<T> resolveRequestModelHolder = new IssueTrackerModelHolder<>(List.of(), List.of(resolveRequest), List.of());
List<IssueTrackerIssueResponseModel<T>> transitionedIssues;
try {
transitionedIssues = messageSender.sendMessages(resolveRequestModelHolder);
} catch (IssueMissingTransitionException e) {
MessageResult issueMissingResult = handleIssueMessingTransitionException(e);
return Optional.of(issueMissingResult);
} catch (AlertException e) {
MessageResult alertExceptionResult = handleAlertException(e, operation);
return Optional.of(alertExceptionResult);
}
int transitionedIssuesSize = transitionedIssues.size();
if (transitionedIssuesSize != 1) {
String errorMessage = String.format("Expected [1] issue to be transitioned, but there were actually [%d]", transitionedIssuesSize);
return Optional.of(new MessageResult(errorMessage, fieldStatusCreator.createWithoutField(errorMessage)));
}
return Optional.empty();
}
Aggregations