use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class PolicyNotificationFilterCustomFunctionAction method createPagedActionResponse.
@Override
public ActionResponse<NotificationFilterModelOptions> createPagedActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper, int pageNumber, int pageSize, String searchTerm) throws IntegrationException {
Optional<FieldValueModel> fieldValueModel = fieldModel.getFieldValueModel(ProviderDescriptor.KEY_NOTIFICATION_TYPES);
Collection<String> selectedNotificationTypes = fieldValueModel.map(FieldValueModel::getValues).orElse(List.of());
int totalPages = 1;
List<NotificationFilterModel> options = List.of();
if (isJobFilterableByPolicy(selectedNotificationTypes)) {
try {
Optional<BlackDuckServicesFactory> blackDuckServicesFactory = createBlackDuckServicesFactory(fieldModel);
if (blackDuckServicesFactory.isPresent()) {
BlackDuckPageResponse<PolicyRuleView> policyRulesPage = retrievePolicyRules(blackDuckServicesFactory.get(), pageNumber, pageSize, searchTerm);
totalPages = (policyRulesPage.getTotalCount() + (pageSize - 1)) / pageSize;
options = convertToNotificationFilterModel(policyRulesPage.getItems());
}
} catch (IntegrationException e) {
logger.errorAndDebug("There was an issue communicating with Black Duck. " + e.getMessage(), e);
throw new AlertException("Unable to communicate with Black Duck.", e);
}
}
NotificationFilterModelOptions notificationFilterModelOptions = new NotificationFilterModelOptions(totalPages, pageNumber, pageSize, options);
return new ActionResponse<>(HttpStatus.OK, notificationFilterModelOptions);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class VulnerabilityNotificationFilterCustomFunctionAction method createActionResponse.
@Override
public ActionResponse<LabelValueSelectOptions> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
Optional<FieldValueModel> fieldValueModel = fieldModel.getFieldValueModel(ProviderDescriptor.KEY_NOTIFICATION_TYPES);
Collection<String> selectedNotificationTypes = fieldValueModel.map(FieldValueModel::getValues).orElse(List.of());
List<LabelValueSelectOption> options = List.of();
if (isFilterableVulnerability(selectedNotificationTypes)) {
options = retrieveBlackDuckVulnerabilityOptions();
}
LabelValueSelectOptions optionList = new LabelValueSelectOptions(options);
return new ActionResponse<>(HttpStatus.OK, optionList);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class BlackDuckProjectCustomFunctionAction method getBlackDuckProjectsActionResponse.
private ActionResponse<ProviderProjectOptions> getBlackDuckProjectsActionResponse(Long blackDuckGlobalConfigId, int pageNumber, int pageSize, String searchTerm) {
AlertPagedModel<ProviderProject> providerProjectsPage = providerDataAccessor.getProjectsByProviderConfigId(blackDuckGlobalConfigId, pageNumber, pageSize, searchTerm);
List<ProviderProjectSelectOption> options = providerProjectsPage.getModels().stream().map(project -> new ProviderProjectSelectOption(project.getName(), project.getHref(), project.getDescription())).collect(Collectors.toList());
return new ActionResponse<>(HttpStatus.OK, new ProviderProjectOptions(providerProjectsPage.getTotalPages(), providerProjectsPage.getCurrentPage(), providerProjectsPage.getPageSize(), options));
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class UserActions method updateWithoutChecks.
@Override
protected ActionResponse<UserConfig> updateWithoutChecks(Long id, UserConfig resource) {
Optional<UserModel> userModel = userAccessor.getUser(id);
if (userModel.isPresent()) {
UserModel existingUser = userModel.get();
boolean passwordMissing = StringUtils.isBlank(resource.getPassword());
String userName = resource.getUsername();
String password = passwordMissing ? existingUser.getPassword() : resource.getPassword();
String emailAddress = resource.getEmailAddress();
UserModel newUserModel = UserModel.existingUser(existingUser.getId(), userName, password, emailAddress, existingUser.getAuthenticationType(), existingUser.getRoles(), existingUser.isEnabled());
try {
logger.debug(actionMessageCreator.updateStartMessage("user", userName));
userAccessor.updateUser(newUserModel, passwordMissing);
Set<String> configuredRoleNames = resource.getRoleNames();
if (null != configuredRoleNames && !configuredRoleNames.isEmpty()) {
Collection<UserRoleModel> roleNames = roleAccessor.getRoles().stream().filter(role -> configuredRoleNames.contains(role.getName())).collect(Collectors.toList());
authorizationManager.updateUserRoles(existingUser.getId(), roleNames);
}
userSystemValidator.validateDefaultAdminUser(id);
UserConfig user = userAccessor.getUser(id).map(this::convertDatabaseModelToRestModel).orElse(resource);
logger.debug(actionMessageCreator.updateSuccessMessage("User", userName));
return new ActionResponse<>(HttpStatus.NO_CONTENT);
} catch (AlertException ex) {
logger.error(actionMessageCreator.updateErrorMessage("User", userName));
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
logger.warn(actionMessageCreator.updateNotFoundMessage("User", id));
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class UserActions method createWithoutChecks.
@Override
protected ActionResponse<UserConfig> createWithoutChecks(UserConfig resource) {
try {
String userName = resource.getUsername();
String password = resource.getPassword();
String emailAddress = resource.getEmailAddress();
logger.debug(actionMessageCreator.createStartMessage("user", userName));
UserModel userModel = userAccessor.addUser(userName, password, emailAddress);
Long userId = userModel.getId();
Set<String> configuredRoleNames = resource.getRoleNames();
if (null != configuredRoleNames && !configuredRoleNames.isEmpty()) {
Collection<UserRoleModel> roleNames = roleAccessor.getRoles().stream().filter(role -> configuredRoleNames.contains(role.getName())).collect(Collectors.toList());
authorizationManager.updateUserRoles(userId, roleNames);
}
userModel = userAccessor.getUser(userId).orElse(userModel);
logger.debug(actionMessageCreator.createSuccessMessage("User", userName));
return new ActionResponse<>(HttpStatus.CREATED, convertDatabaseModelToRestModel(userModel));
} catch (AlertException ex) {
logger.error(actionMessageCreator.createErrorMessage("user", resource.getUsername()));
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("There was an issue creating the user. %s", ex.getMessage()));
}
}
Aggregations