Search in sources :

Example 21 with AlertException

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);
    }
}
Also used : HttpServiceException(com.synopsys.integration.azure.boards.common.http.HttpServiceException) ProcessWorkItemTypesResponseModel(com.synopsys.integration.azure.boards.common.service.process.ProcessWorkItemTypesResponseModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 22 with AlertException

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;
}
Also used : DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) DistributionChannelTestAction(com.synopsys.integration.alert.common.channel.DistributionChannelTestAction) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DataStructureUtils(com.synopsys.integration.alert.common.util.DataStructureUtils) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) AbstractJobResourceActions(com.synopsys.integration.alert.common.action.api.AbstractJobResourceActions) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) ProviderProjectExistencePopulator(com.synopsys.integration.alert.api.provider.ProviderProjectExistencePopulator) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) BlackDuckProjectDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.BlackDuckProjectDetailsModel) Map(java.util.Map) ListUtils(org.apache.commons.collections4.ListUtils) DateUtils(com.synopsys.integration.alert.common.util.DateUtils) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) JobPagedModel(com.synopsys.integration.alert.common.rest.model.JobPagedModel) Collection(java.util.Collection) Set(java.util.Set) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) UUID(java.util.UUID) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) Collectors(java.util.stream.Collectors) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Stream(java.util.stream.Stream) FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) Optional(java.util.Optional) JobFieldStatuses(com.synopsys.integration.alert.common.rest.model.JobFieldStatuses) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) HashMap(java.util.HashMap) PKIXErrorResponseFactory(com.synopsys.integration.alert.component.certificates.web.PKIXErrorResponseFactory) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DescriptorActionMap(com.synopsys.integration.alert.common.descriptor.action.DescriptorActionMap) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) LinkedList(java.util.LinkedList) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobIdsRequestModel(com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Logger(org.slf4j.Logger) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) GlobalConfigExistsValidator(com.synopsys.integration.alert.common.descriptor.config.GlobalConfigExistsValidator) FieldModelTestAction(com.synopsys.integration.alert.common.action.FieldModelTestAction) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel)

Example 23 with AlertException

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());
    }
}
Also used : JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) HashSet(java.util.HashSet)

Example 24 with AlertException

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);
}
Also used : JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) LinkedList(java.util.LinkedList) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 25 with AlertException

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());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Aggregations

AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)101 Test (org.junit.jupiter.api.Test)35 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)22 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)18 List (java.util.List)18 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)17 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)16 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)16 Optional (java.util.Optional)13 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)12 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)12 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)11 HashMap (java.util.HashMap)11 IntegrationException (com.synopsys.integration.exception.IntegrationException)10 ArrayList (java.util.ArrayList)9 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)8 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)8 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)8 UUID (java.util.UUID)8 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)7