use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class AuditEntryActions method queryForAuditInfoInJobs.
public ActionResponse<AuditJobStatusesModel> queryForAuditInfoInJobs(JobIdsRequestModel queryRequestModel) {
if (!authorizationManager.hasReadPermission(ConfigContextEnum.GLOBAL, descriptorKey)) {
return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
}
List<UUID> jobIds = queryRequestModel.getJobIds();
for (UUID jobId : jobIds) {
if (null == jobId) {
return new ActionResponse<>(HttpStatus.BAD_REQUEST, "The field 'jobIds' cannot contain null values");
}
}
List<AuditJobStatusModel> auditJobStatusModels = auditAccessor.findByJobIds(jobIds);
return new ActionResponse<>(HttpStatus.OK, new AuditJobStatusesModel(auditJobStatusModels));
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class JiraServerCustomFunctionAction method createActionResponse.
@Override
public ActionResponse<String> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper ignoredServletContent) {
try {
JiraServerProperties jiraProperties = jiraServerPropertiesFactory.createJiraPropertiesWithJobId(UUID.fromString(fieldModel.getId()));
JiraServerServiceFactory jiraServicesFactory = jiraProperties.createJiraServicesServerFactory(logger, gson);
PluginManagerService jiraAppService = jiraServicesFactory.createPluginManagerService();
try {
jiraAppService.installMarketplaceServerApp(JiraConstants.JIRA_APP_KEY);
} catch (IntegrationRestException e) {
if (RestConstants.NOT_FOUND_404 == e.getHttpStatusCode()) {
return new ActionResponse<>(HttpStatus.NOT_FOUND, String.format("The marketplace listing of the '%s' app may not support your version of Jira. Please install the app manually or request a compatibility update. Error: %s", JiraConstants.JIRA_ALERT_APP_NAME, e.getMessage()));
}
return createBadRequestIntegrationException(e);
}
boolean jiraPluginInstalled = JiraPluginCheckUtils.checkIsAppInstalledAndRetryIfNecessary(jiraAppService);
if (!jiraPluginInstalled) {
return new ActionResponse<>(HttpStatus.NOT_FOUND, String.format("Unable to confirm Jira server successfully installed the '%s' plugin. Please verify the installation on you Jira server.", JiraConstants.JIRA_ALERT_APP_NAME));
}
return new ActionResponse<>(HttpStatus.OK, String.format("Successfully installed the '%s' plugin on Jira server.", JiraConstants.JIRA_ALERT_APP_NAME));
} catch (IntegrationException e) {
return createBadRequestIntegrationException(e);
} catch (InterruptedException e) {
logger.error("Thread was interrupted while validating Jira plugin installation.", e);
Thread.currentThread().interrupt();
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Thread was interrupted while validating Jira '%s' plugin installation: %s", JiraConstants.JIRA_ALERT_APP_NAME, e.getMessage()));
}
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-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()));
}
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class RoleActions method updateWithoutChecks.
@Override
protected ActionResponse<RolePermissionModel> updateWithoutChecks(Long id, RolePermissionModel resource) {
try {
String roleName = resource.getRoleName();
Optional<UserRoleModel> existingRole = roleAccessor.getRoles(List.of(id)).stream().findFirst();
if (existingRole.isPresent()) {
logger.debug(actionMessageCreator.updateStartMessage("role", existingRole.get().getName()));
if (!existingRole.get().getName().equals(roleName)) {
authorizationManager.updateRoleName(id, roleName);
}
Set<PermissionModel> permissions = resource.getPermissions();
PermissionMatrixModel permissionMatrixModel = PermissionModelUtil.convertToPermissionMatrixModel(permissions);
authorizationManager.updatePermissionsForRole(roleName, permissionMatrixModel);
logger.debug(actionMessageCreator.updateSuccessMessage("Role", roleName));
return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
logger.warn(actionMessageCreator.updateNotFoundMessage("Role", id));
return new ActionResponse<>(HttpStatus.NOT_FOUND, "Role not found.");
} catch (AlertException ex) {
logger.error(actionMessageCreator.updateErrorMessage("role", resource.getRoleName()));
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class RoleActions method createWithoutChecks.
@Override
protected ActionResponse<RolePermissionModel> createWithoutChecks(RolePermissionModel resource) {
String roleName = resource.getRoleName();
Set<PermissionModel> permissions = resource.getPermissions();
PermissionMatrixModel permissionMatrixModel = PermissionModelUtil.convertToPermissionMatrixModel(permissions);
logger.debug(actionMessageCreator.createStartMessage("role", roleName));
UserRoleModel userRoleModel = authorizationManager.createRoleWithPermissions(roleName, permissionMatrixModel);
logger.debug(actionMessageCreator.createSuccessMessage("Role", roleName));
return new ActionResponse<>(HttpStatus.OK, convertDatabaseModelToRestModel(userRoleModel));
}
Aggregations