use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-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 hub-alert by blackducksoftware.
the class AbstractJobResourceActions method getOne.
public final ActionResponse<JobFieldModel> getOne(UUID id) {
Set<String> descriptorNames = getDescriptorNames();
if (!authorizationManager.anyReadPermission(List.of(ConfigContextEnum.DISTRIBUTION), descriptorNames)) {
return ActionResponse.createForbiddenResponse();
}
Optional<JobFieldModel> optionalModel = findJobFieldModel(id);
if (optionalModel.isPresent()) {
JobFieldModel fieldModel = optionalModel.get();
boolean hasPermissions = hasRequiredPermissions(fieldModel.getFieldModels(), authorizationManager::hasReadPermission);
if (!hasPermissions) {
return ActionResponse.createForbiddenResponse();
}
return new ActionResponse<>(HttpStatus.OK, fieldModel);
}
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class AbstractJobResourceActions method delete.
public final ActionResponse<JobFieldModel> delete(UUID id) {
Optional<JobFieldModel> optionalModel = findJobFieldModel(id);
if (optionalModel.isPresent()) {
JobFieldModel jobFieldModel = optionalModel.get();
boolean hasPermissions = hasRequiredPermissions(jobFieldModel.getFieldModels(), authorizationManager::hasDeletePermission);
if (!hasPermissions) {
return ActionResponse.createForbiddenResponse();
}
} else {
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
return deleteWithoutChecks(id);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class ConfigurationCrudHelper method update.
public <T extends Obfuscated<T>> ActionResponse<T> update(Supplier<ValidationResponseModel> validator, BooleanSupplier existingModelSupplier, ThrowingSupplier<T, AlertConfigurationException> updateFunction) {
String actionName = "update";
logger.trace(ACTION_CALLED_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
if (!authorizationManager.hasWritePermission(context, descriptorKey)) {
logger.trace(ACTION_MISSING_PERMISSIONS_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
return ActionResponse.createForbiddenResponse();
}
boolean configurationExists = existingModelSupplier.getAsBoolean();
if (!configurationExists) {
logger.trace(ACTION_NOT_FOUND_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
ValidationResponseModel validationResponse = validator.get();
if (validationResponse.hasErrors()) {
logger.trace(ACTION_BAD_REQUEST_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
return new ActionResponse<>(HttpStatus.BAD_REQUEST, validationResponse.getMessage());
}
try {
return new ActionResponse<>(HttpStatus.OK, updateFunction.get().obfuscate());
} catch (AlertConfigurationException ex) {
logger.trace(ACTION_BAD_REQUEST_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
return new ActionResponse<>(HttpStatus.BAD_REQUEST, String.format("Error updating config: %s", ex.getMessage()));
} catch (Exception ex) {
logger.error("Error updating config:", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error updating config: %s", ex.getMessage()));
} finally {
logger.trace(ACTION_SUCCESS_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
}
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-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