use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class ProviderConfigSelectCustomFunctionAction method createActionResponse.
@Override
public ActionResponse<LabelValueSelectOptions> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
String providerName = fieldModel.getDescriptorName();
Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(providerName);
List<LabelValueSelectOption> options = List.of();
if (descriptorKey.isPresent()) {
List<ConfigurationModel> configurationModels = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey.get(), ConfigContextEnum.GLOBAL);
options = configurationModels.stream().map(this::createNameToIdOption).flatMap(Optional::stream).collect(Collectors.toList());
}
LabelValueSelectOptions optionList = new LabelValueSelectOptions(options);
return new ActionResponse<>(HttpStatus.OK, optionList);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class AbstractConfigResourceActions method update.
@Override
public final ActionResponse<FieldModel> update(Long id, FieldModel resource) {
if (!authorizationManager.hasWritePermission(resource.getContext(), resource.getDescriptorName())) {
return ActionResponse.createForbiddenResponse();
}
Optional<FieldModel> existingModel = findFieldModel(id);
if (existingModel.isEmpty()) {
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
ValidationActionResponse validationResponse = validateWithoutChecks(resource);
if (validationResponse.isError()) {
return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
}
return updateWithoutChecks(id, resource);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class AbstractJobResourceActions method update.
public final ActionResponse<JobFieldModel> update(UUID id, JobFieldModel resource) {
boolean hasPermissions = hasRequiredPermissions(resource.getFieldModels(), authorizationManager::hasWritePermission);
if (!hasPermissions) {
return ActionResponse.createForbiddenResponse();
}
Optional<JobFieldModel> existingJob = findJobFieldModel(id);
if (existingJob.isEmpty()) {
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
// Clean input
correctProjectsField(resource);
ValidationActionResponse validationResponse = validateWithoutChecks(resource);
if (validationResponse.isError()) {
return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
}
return updateWithoutChecks(id, resource);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class AbstractResourceActions method update.
public final ActionResponse<T> update(Long id, T resource) {
if (!authorizationManager.hasWritePermission(context, descriptorKey)) {
logger.debug(String.format(FORBIDDEN_ACTION_FORMAT, "Update"));
return ActionResponse.createForbiddenResponse();
}
Optional<T> existingItem = findExisting(id);
if (existingItem.isEmpty()) {
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
ValidationActionResponse validationResponse = validateWithoutChecks(resource);
if (validationResponse.isError()) {
return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
}
return updateWithoutChecks(id, resource);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class AbstractUploadAction method uploadFileExists.
public ActionResponse<ExistenceModel> uploadFileExists() {
if (isTargetUndefined()) {
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, META_DATA_MISSING);
}
if (!authorizationManager.hasUploadReadPermission(target.getContext(), target.getDescriptorKey())) {
return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
}
String targetFilename = target.getFilename();
Boolean exists = filePersistenceUtil.uploadFileExists(targetFilename);
ExistenceModel content = new ExistenceModel(exists);
return new ActionResponse<>(HttpStatus.OK, content);
}
Aggregations