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));
}
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);
}
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());
}
Aggregations