Search in sources :

Example 1 with JobPagedModel

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

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

the class JobConfigActions method readPageWithoutChecks.

@Override
public final ActionResponse<JobPagedModel> readPageWithoutChecks(Integer pageNumber, Integer pageSize, String searchTerm, Collection<String> permittedDescriptorsForSession) {
    AlertPagedModel<DistributionJobModel> pageOfJobs = jobAccessor.getPageOfJobs(pageNumber, pageSize, searchTerm, permittedDescriptorsForSession);
    List<DistributionJobModel> distributionJobModels = pageOfJobs.getModels();
    List<JobFieldModel> jobFieldModels = new ArrayList<>(distributionJobModels.size());
    for (DistributionJobModel distributionJobModel : distributionJobModels) {
        JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(distributionJobModel);
        jobFieldModels.add(jobFieldModel);
    }
    JobPagedModel jobPagedModel = new JobPagedModel(pageOfJobs.getTotalPages(), pageOfJobs.getCurrentPage(), pageOfJobs.getPageSize(), jobFieldModels);
    return new ActionResponse<>(HttpStatus.OK, jobPagedModel);
}
Also used : ArrayList(java.util.ArrayList) JobPagedModel(com.synopsys.integration.alert.common.rest.model.JobPagedModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) 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)

Example 3 with JobPagedModel

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

the class JobConfigActionsTest method getPageTest.

@Test
public void getPageTest() throws Exception {
    int totalPages = 1;
    int pageNumber = 0;
    int pageSize = 10;
    RegisteredDescriptorModel registeredDescriptorModel = new RegisteredDescriptorModel(1L, "descriptorName", DESCRIPTOR_TYPE.name());
    AlertPagedModel<DistributionJobModel> pageOfJobs = new AlertPagedModel<>(totalPages, pageNumber, pageSize, List.of(distributionJobModel));
    Mockito.when(mockedDescriptorAccessor.getRegisteredDescriptors()).thenReturn(List.of(registeredDescriptorModel));
    Mockito.when(mockedJobAccessor.getPageOfJobs(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString(), Mockito.anyCollection())).thenReturn(pageOfJobs);
    Mockito.when(mockedConfigurationFieldModelConverter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
    ActionResponse<JobPagedModel> jobPagedModelActionResponse = defaultJobConfigActions.getPage(pageNumber, pageSize, "");
    assertTrue(jobPagedModelActionResponse.isSuccessful());
    assertTrue(jobPagedModelActionResponse.hasContent());
    assertEquals(HttpStatus.OK, jobPagedModelActionResponse.getHttpStatus());
}
Also used : JobPagedModel(com.synopsys.integration.alert.common.rest.model.JobPagedModel) RegisteredDescriptorModel(com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Aggregations

JobPagedModel (com.synopsys.integration.alert.common.rest.model.JobPagedModel)3 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)2 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)2 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)1 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)1 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)1 RegisteredDescriptorModel (com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel)1 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)1 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)1 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)1 JobProviderProjectFieldModel (com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1