use of com.synopsys.integration.alert.api.common.model.exception.AlertException 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);
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class JobConfigActions method getChannelFieldModelAndPopulateOtherJobModels.
private FieldModel getChannelFieldModelAndPopulateOtherJobModels(JobFieldModel jobFieldModel, Collection<FieldModel> otherJobModels) throws AlertException {
FieldModel channelFieldModel = null;
for (FieldModel fieldModel : jobFieldModel.getFieldModels()) {
Optional<Descriptor> descriptor = descriptorProcessor.retrieveDescriptor(fieldModel.getDescriptorName());
FieldModel updatedFieldModel = fieldModelProcessor.createCustomMessageFieldModel(fieldModel);
if (descriptor.filter(foundDescriptor -> DescriptorType.CHANNEL.equals(foundDescriptor.getType())).isPresent()) {
channelFieldModel = updatedFieldModel;
} else {
otherJobModels.add(updatedFieldModel);
}
}
return channelFieldModel;
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class JobConfigActions method createWithoutChecks.
@Override
protected ActionResponse<JobFieldModel> createWithoutChecks(JobFieldModel resource) {
try {
Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
for (FieldModel fieldModel : resource.getFieldModels()) {
FieldModel beforeSaveEventFieldModel = fieldModelProcessor.performBeforeSaveAction(fieldModel);
Collection<ConfigurationFieldModel> savedFieldsModels = modelConverter.convertToConfigurationFieldModelMap(beforeSaveEventFieldModel).values();
configurationFieldModels.addAll(savedFieldsModels);
}
List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, DateUtils.createCurrentDateTimestamp(), null);
DistributionJobModel savedJob = jobAccessor.createJob(jobRequestModel);
JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
Set<FieldModel> updatedFieldModels = new HashSet<>();
for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
FieldModel updatedModel = fieldModelProcessor.performAfterSaveAction(fieldModel);
updatedFieldModels.add(updatedModel);
}
savedJobFieldModel.setFieldModels(updatedFieldModels);
return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
} 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 JobConfigActions method deleteWithoutChecks.
@Override
protected ActionResponse<JobFieldModel> deleteWithoutChecks(UUID id) {
try {
Optional<DistributionJobModel> job = jobAccessor.getJobById(id);
if (job.isPresent()) {
LinkedList<FieldModel> processedFieldModels = new LinkedList<>();
DistributionJobModel distributionJobModel = job.get();
JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(distributionJobModel);
for (FieldModel fieldModel : jobFieldModel.getFieldModels()) {
FieldModel preProcessedFieldModel = fieldModelProcessor.performBeforeDeleteAction(fieldModel);
processedFieldModels.add(preProcessedFieldModel);
}
jobAccessor.deleteJob(distributionJobModel.getJobId());
for (FieldModel preProcessedFieldModel : processedFieldModels) {
fieldModelProcessor.performAfterDeleteAction(preProcessedFieldModel);
}
} else {
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
} catch (AlertException ex) {
logger.error("Error reading job", 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 JobConfigActionsTest method testIntegrationExceptionTest.
@Test
public void testIntegrationExceptionTest() throws Exception {
Mockito.when(mockedDescriptorProcessor.retrieveDescriptor(Mockito.any())).thenReturn(Optional.of(descriptor));
Mockito.doThrow(new AlertException("IntegrationException for Alert test")).when(mockedFieldModelProcessor).createCustomMessageFieldModel(Mockito.any());
ValidationActionResponse validationActionResponse = defaultJobConfigActions.test(jobFieldModel);
assertTrue(validationActionResponse.isSuccessful());
assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
assertTrue(validationActionResponse.hasContent());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertTrue(validationResponseModel.hasErrors());
}
Aggregations