Search in sources :

Example 1 with FieldValueModel

use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.

the class SchedulingGlobalApiAction method calculateNextRuntime.

private FieldModel calculateNextRuntime(FieldModel fieldModel) {
    fieldModel.putField(SchedulingDescriptor.KEY_DAILY_PROCESSOR_NEXT_RUN, new FieldValueModel(List.of(taskManager.getNextRunTime(ScheduledTask.computeTaskName(DailyTask.class)).orElse("")), true));
    String processFrequency = fieldModel.getFieldValue(SchedulingDescriptor.KEY_DAILY_PROCESSOR_HOUR_OF_DAY).orElse(String.valueOf(DailyTask.DEFAULT_HOUR_OF_DAY));
    fieldModel.putField(SchedulingDescriptor.KEY_DAILY_PROCESSOR_HOUR_OF_DAY, new FieldValueModel(List.of(processFrequency), true));
    fieldModel.putField(SchedulingDescriptor.KEY_PURGE_DATA_NEXT_RUN, new FieldValueModel(List.of(taskManager.getNextRunTime(ScheduledTask.computeTaskName(PurgeTask.class)).orElse("")), true));
    String purgeFrequency = fieldModel.getFieldValue(SchedulingDescriptor.KEY_PURGE_DATA_FREQUENCY_DAYS).orElse(String.valueOf(PurgeTask.DEFAULT_FREQUENCY));
    fieldModel.putField(SchedulingDescriptor.KEY_PURGE_DATA_FREQUENCY_DAYS, new FieldValueModel(List.of(purgeFrequency), true));
    return fieldModel;
}
Also used : DailyTask(com.synopsys.integration.alert.component.scheduling.workflow.DailyTask) PurgeTask(com.synopsys.integration.alert.component.scheduling.workflow.PurgeTask) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 2 with FieldValueModel

use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.

the class SettingsGlobalApiAction method afterGetAction.

@Override
public FieldModel afterGetAction(FieldModel fieldModel) {
    FieldModel fieldModelCopy = createFieldModelCopy(fieldModel);
    fieldModelCopy.putField(SettingsDescriptor.KEY_ENCRYPTION_PWD, new FieldValueModel(null, encryptionUtility.isPasswordSet()));
    fieldModelCopy.putField(SettingsDescriptor.KEY_ENCRYPTION_GLOBAL_SALT, new FieldValueModel(null, encryptionUtility.isGlobalSaltSet()));
    return fieldModelCopy;
}
Also used : FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 3 with FieldValueModel

use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.

the class ConfigurationManager method createJob.

public String createJob(Map<String, FieldValueModel> channelFields, String jobName, String blackDuckProviderId, String blackDuckProjectName, List<NotificationType> notificationTypes) throws IntegrationException {
    List<String> notificationTypeNames = notificationTypes.stream().map(Enum::name).collect(Collectors.toList());
    Map<String, FieldValueModel> providerKeyToValues = new HashMap<>();
    providerKeyToValues.put(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, new FieldValueModel(List.of(blackDuckProviderId), true));
    providerKeyToValues.put(ProviderDescriptor.KEY_NOTIFICATION_TYPES, new FieldValueModel(notificationTypeNames, true));
    providerKeyToValues.put(ProviderDescriptor.KEY_PROCESSING_TYPE, new FieldValueModel(List.of(ProcessingType.DEFAULT.name()), true));
    providerKeyToValues.put(ProviderDescriptor.KEY_FILTER_BY_PROJECT, new FieldValueModel(List.of("true"), true));
    providerKeyToValues.put(ProviderDescriptor.KEY_CONFIGURED_PROJECT, new FieldValueModel(List.of(blackDuckProjectName), true));
    FieldModel jobProviderConfiguration = new FieldModel(blackDuckProviderKey, ConfigContextEnum.DISTRIBUTION.name(), providerKeyToValues);
    FieldModel jobConfiguration = new FieldModel(channelKey, ConfigContextEnum.DISTRIBUTION.name(), channelFields);
    JobFieldModel jobFieldModel = new JobFieldModel(null, Set.of(jobConfiguration, jobProviderConfiguration), List.of(new JobProviderProjectFieldModel(blackDuckProjectName, "href", false)));
    String jobConfigBody = gson.toJson(jobFieldModel);
    alertRequestUtility.executePostRequest("/api/configuration/job/validate", jobConfigBody, String.format("Validating the Job %s failed.", jobName));
    alertRequestUtility.executePostRequest("/api/configuration/job/test", jobConfigBody, String.format("Testing the Job %s failed.", jobName));
    String creationResponse = alertRequestUtility.executePostRequest("/api/configuration/job", jobConfigBody, String.format("Could not create the Job %s.", jobName));
    JsonObject jsonObject = gson.fromJson(creationResponse, JsonObject.class);
    return jsonObject.get("jobId").getAsString();
}
Also used : HashMap(java.util.HashMap) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) JsonObject(com.google.gson.JsonObject) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) 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 4 with FieldValueModel

use of com.synopsys.integration.alert.common.rest.model.FieldValueModel 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 5 with FieldValueModel

use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.

the class JiraServerPerformanceTest method jiraServerJobTest.

@Test
@Disabled
public void jiraServerJobTest() throws Exception {
    TestProperties testProperties = new TestProperties();
    FieldModel globalConfig = createGlobalConfig(testProperties);
    // Install plugin
    ActionResponse<String> actionResponse = jiraServerCustomFunctionAction.createActionResponse(globalConfig, null);
    if (actionResponse.isError()) {
        fail("Unable to install the Alert plugin for Jira Server. Exiting test...");
    }
    Map<String, FieldValueModel> channelFieldsMap = createChannelFieldsMap(testProperties);
    IntegrationPerformanceTestRunner testRunner = createTestRunner();
    testRunner.runTest(globalConfig, channelFieldsMap, PERFORMANCE_JOB_NAME);
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) IntegrationPerformanceTestRunner(com.synopsys.integration.alert.performance.utility.IntegrationPerformanceTestRunner) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)58 HashMap (java.util.HashMap)27 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)24 Test (org.junit.jupiter.api.Test)18 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)12 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)6 GlobalConfigurationValidatorAsserter (com.synopsys.integration.alert.test.common.channel.GlobalConfigurationValidatorAsserter)6 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)5 JobProviderProjectFieldModel (com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel)4 ConfigurationManager (com.synopsys.integration.alert.performance.utility.ConfigurationManager)4 IntegrationPerformanceTestRunner (com.synopsys.integration.alert.performance.utility.IntegrationPerformanceTestRunner)4 Disabled (org.junit.jupiter.api.Disabled)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)3 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)3 AlertRequestUtility (com.synopsys.integration.alert.performance.utility.AlertRequestUtility)3 BlackDuckProviderService (com.synopsys.integration.alert.performance.utility.BlackDuckProviderService)3 List (java.util.List)3