use of com.synopsys.integration.alert.common.rest.model.FieldModel 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);
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class JobFieldModelPopulationUtils method createJobFieldModel.
public static JobFieldModel createJobFieldModel(DistributionJobModel jobModel, List<JobProviderProjectFieldModel> jobProviderProjects) {
FieldModel providerFieldModel = new FieldModel(DEFAULT_PROVIDER_NAME, ConfigContextEnum.DISTRIBUTION.name(), new HashMap<>());
populateProviderFields(providerFieldModel, jobModel, jobProviderProjects);
FieldModel channelFieldModel = new FieldModel(jobModel.getChannelDescriptorName(), ConfigContextEnum.DISTRIBUTION.name(), new HashMap<>());
populateChannelFields(channelFieldModel, jobModel);
String jobIdString = Optional.ofNullable(jobModel.getJobId()).map(UUID::toString).orElse(null);
return new JobFieldModel(jobIdString, Set.of(providerFieldModel, channelFieldModel), jobProviderProjects);
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class JobConfigActionsTest method createFieldModel.
private FieldModel createFieldModel() {
String value = "testValue";
Map<String, FieldValueModel> keyToValues = new HashMap<>();
keyToValues.put(FieldModelTestAction.KEY_CUSTOM_TOPIC, new FieldValueModel(List.of(value), false));
keyToValues.put(ChannelDescriptor.KEY_NAME, new FieldValueModel(List.of(value), false));
return new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.DISTRIBUTION.name(), keyToValues);
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class ConfigActions method convertConfigurationModelList.
private List<FieldModel> convertConfigurationModelList(String descriptorName, String context, List<ConfigurationModel> configurationModels) {
List<FieldModel> responseFieldModels = new LinkedList<>();
List<FieldModel> fieldModelList = new LinkedList<>();
if (null != configurationModels) {
for (ConfigurationModel configurationModel : configurationModels) {
FieldModel fieldModel = modelConverter.convertToFieldModel(configurationModel);
fieldModelList.add(fieldModel);
}
}
if (fieldModelList.isEmpty()) {
fieldModelList.add(new FieldModel(descriptorName, context, new HashMap<>()));
}
for (FieldModel fieldModel : fieldModelList) {
try {
responseFieldModels.add(fieldModelProcessor.performAfterReadAction(fieldModel));
} catch (AlertException ex) {
logger.error("Error performing after read action", ex);
}
}
return responseFieldModels;
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class ConfigActions method readAllByContextAndDescriptorWithoutChecks.
@Override
protected ActionResponse<MultiFieldModel> readAllByContextAndDescriptorWithoutChecks(String context, String descriptorName) {
ConfigContextEnum configContext = ConfigContextEnum.valueOf(context);
Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(descriptorName);
if (!descriptorKey.isPresent()) {
return new ActionResponse<>(HttpStatus.BAD_REQUEST, String.format("Unknown descriptor: %s", descriptorName));
}
List<ConfigurationModel> configurationModels = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey.get(), configContext);
List<FieldModel> fieldModels = convertConfigurationModelList(descriptorName, context, configurationModels);
return new ActionResponse<>(HttpStatus.OK, new MultiFieldModel(fieldModels));
}
Aggregations