Search in sources :

Example 1 with AlertRuntimeException

use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException in project hub-alert by blackducksoftware.

the class ConfigurationManager method copyJob.

public void copyJob(String jobToCopy, String newJobName) throws IntegrationException {
    String response = alertRequestUtility.executeGetRequest(String.format("/api/configuration/job?searchTerm=%s", jobToCopy), String.format("Could not copy the Job %s.", jobToCopy));
    JobPagedModel jobModel = gson.fromJson(response, JobPagedModel.class);
    JobFieldModel jobFieldModel = jobModel.getJobs().stream().findFirst().orElseThrow(() -> new AlertRuntimeException(String.format("Cannot find job %s", jobToCopy), null));
    jobFieldModel.setJobId(null);
    FieldModel channelFieldModel = jobFieldModel.getFieldModels().stream().filter(model -> ChannelKeys.getChannelKey(model.getDescriptorName()) != null).findFirst().orElseThrow(() -> new AlertRuntimeException("Cannot find channel field model", null));
    Map<String, FieldValueModel> channelKeyToValues = new HashMap<>();
    channelKeyToValues.putAll(channelFieldModel.getKeyToValues());
    channelKeyToValues.put(ChannelDescriptor.KEY_NAME, new FieldValueModel(List.of(newJobName), true));
    channelFieldModel.setKeyToValues(channelKeyToValues);
    String jobConfigBody = gson.toJson(jobFieldModel);
    alertRequestUtility.executePostRequest("/api/configuration/job", jobConfigBody, String.format("Could not create the Job %s.", newJobName));
}
Also used : HashMap(java.util.HashMap) JobPagedModel(com.synopsys.integration.alert.common.rest.model.JobPagedModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) 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) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 2 with AlertRuntimeException

use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessor method createConfigModel.

private ConfigurationModelMutable createConfigModel(Long descriptorId, Long configId, OffsetDateTime createdAt, OffsetDateTime lastUpdated, Long contextId) {
    String configContext = getContextById(contextId);
    String createdAtFormatted = DateUtils.formatDate(createdAt, DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
    String lastUpdatedFormatted = DateUtils.formatDate(lastUpdated, DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
    ConfigurationModelMutable newModel = new ConfigurationModelMutable(descriptorId, configId, createdAtFormatted, lastUpdatedFormatted, configContext);
    List<FieldValueEntity> fieldValueEntities = fieldValueRepository.findByConfigId(configId);
    for (FieldValueEntity fieldValueEntity : fieldValueEntities) {
        DefinedFieldEntity definedFieldEntity = definedFieldRepository.findById(fieldValueEntity.getFieldId()).orElseThrow(() -> new AlertRuntimeException("Field Id missing from the database"));
        String fieldKey = definedFieldEntity.getKey();
        ConfigurationFieldModel fieldModel = BooleanUtils.isTrue(definedFieldEntity.getSensitive()) ? ConfigurationFieldModel.createSensitive(fieldKey) : ConfigurationFieldModel.create(fieldKey);
        String decryptedValue = decrypt(fieldValueEntity.getValue(), fieldModel.isSensitive());
        fieldModel.setFieldValue(decryptedValue);
        newModel.put(fieldModel);
    }
    return newModel;
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity)

Example 3 with AlertRuntimeException

use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException in project hub-alert by blackducksoftware.

the class DefaultUserAccessor method addUser.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public UserModel addUser(UserModel user, boolean passwordEncoded) throws AlertConfigurationException {
    String username = user.getName();
    Optional<UserEntity> userWithSameUsername = userRepository.findByUserName(username);
    if (userWithSameUsername.isPresent()) {
        throw new AlertConfigurationException(String.format("A user with username '%s' is already present", username));
    }
    String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword());
    AuthenticationTypeDetails authenticationType = authenticationTypeAccessor.getAuthenticationTypeDetails(user.getAuthenticationType()).orElseThrow(() -> new AlertRuntimeException("Cannot find Authentication Type."));
    UserEntity newEntity = new UserEntity(username, password, user.getEmailAddress(), authenticationType.getId());
    UserEntity savedEntity = userRepository.save(newEntity);
    UserModel model = createModel(savedEntity);
    roleAccessor.updateUserRoles(model.getId(), user.getRoles());
    return model;
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) AuthenticationTypeDetails(com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails) UserEntity(com.synopsys.integration.alert.database.user.UserEntity) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with AlertRuntimeException

use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException in project hub-alert by blackducksoftware.

the class AbstractJobResourceActions method checkContextAndDescriptorKey.

private boolean checkContextAndDescriptorKey(FieldModel fieldModel, BiFunction<ConfigContextEnum, DescriptorKey, Boolean> permissionChecker) {
    ConfigContextEnum configContextEnum = ConfigContextEnum.valueOf(fieldModel.getContext());
    DescriptorKey descriptorKey = descriptorMap.getDescriptorKey(fieldModel.getDescriptorName()).orElseThrow(() -> new AlertRuntimeException("Could not find DescriptorKey for: " + fieldModel.getDescriptorName()));
    return permissionChecker.apply(configContextEnum, descriptorKey);
}
Also used : DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)

Example 5 with AlertRuntimeException

use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method testTest.

@Test
public void testTest() throws Exception {
    JobConfigActions jobConfigActionsForTest = new JobConfigActions(mockedAuthorizationManager, mockedDescriptorAccessor, mockedConfigurationModelConfigurationAccessor, mockedJobAccessor, mockedFieldModelProcessor, mockedDescriptorProcessor, mockedConfigurationFieldModelConverter, mockedGlobalConfigExistsValidator, mockedPkixErrorResponseFactory, descriptorMap, (id, list) -> {
    }, List.of(createChannelDistributionTestAction()), mockedJobModelExtractor);
    fieldModel.setId("testID");
    Mockito.when(mockedDescriptorProcessor.retrieveDescriptor(Mockito.any())).thenReturn(Optional.of(descriptor));
    Mockito.when(mockedFieldModelProcessor.createCustomMessageFieldModel(Mockito.any())).thenReturn(fieldModel);
    ValidationActionResponse validationActionResponse = jobConfigActionsForTest.test(jobFieldModel);
    assertTrue(validationActionResponse.isSuccessful(), "Validation response was not successful");
    assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
    assertTrue(validationActionResponse.hasContent(), "Missing content");
    ValidationResponseModel validationResponseModel = validationActionResponse.getContent().orElseThrow(() -> new AlertRuntimeException("Missing validation response"));
    assertFalse(validationResponseModel.hasErrors(), "Validation response had errors");
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) Test(org.junit.jupiter.api.Test)

Aggregations

AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)22 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)4 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)3 RegisteredDescriptorModel (com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel)3 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)3 IntegrationException (com.synopsys.integration.exception.IntegrationException)3 ArrayList (java.util.ArrayList)3 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)2 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)2 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)2 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)2 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)2 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)2 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)2 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)2 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)2 HashMap (java.util.HashMap)2 List (java.util.List)2