use of org.apache.cloudstack.acl.ProjectRole in project cloudstack by apache.
the class ListProjectRolePermissionsCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
List<ProjectRolePermission> projectRolePermissions = projRoleService.findAllProjectRolePermissions(getProjectId(), getProjectRoleId());
final ProjectRole projectRole = projRoleService.findProjectRole(getProjectRoleId(), getProjectId());
final ListResponse<ProjectRolePermissionResponse> response = new ListResponse<>();
final List<ProjectRolePermissionResponse> rolePermissionResponses = new ArrayList<>();
for (final ProjectRolePermission rolePermission : projectRolePermissions) {
ProjectRole role = projectRole;
if (role == null) {
role = projRoleService.findProjectRole(rolePermission.getProjectRoleId(), rolePermission.getProjectId());
}
rolePermissionResponses.add(setupResponse(role, rolePermission));
}
response.setResponses(rolePermissionResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.acl.ProjectRole in project cloudstack by apache.
the class CreateProjectRoleCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
CallContext.current().setEventDetails("Role: " + getProjectRoleName() + ", description: " + getProjectRoleDescription());
ProjectRole projectRole = projRoleService.createProjectRole(getProjectId(), getProjectRoleName(), getProjectRoleDescription());
if (projectRole == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create project role");
}
setupProjectRoleResponse(projectRole);
}
use of org.apache.cloudstack.acl.ProjectRole in project cloudstack by apache.
the class ListProjectRolesCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
List<ProjectRole> projectRoles;
if (getProjectId() != null && getProjectRoleId() != null) {
projectRoles = Collections.singletonList(projRoleService.findProjectRole(getProjectRoleId(), getProjectId()));
} else if (StringUtils.isNotBlank(getRoleName())) {
projectRoles = projRoleService.findProjectRolesByName(getProjectId(), getRoleName());
} else {
projectRoles = projRoleService.findProjectRoles(getProjectId());
}
final ListResponse<ProjectRoleResponse> response = new ListResponse<>();
final List<ProjectRoleResponse> roleResponses = new ArrayList<>();
for (ProjectRole role : projectRoles) {
if (role == null) {
continue;
}
roleResponses.add(setupProjectRoleResponse(role));
}
response.setResponses(roleResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.acl.ProjectRole in project cloudstack by apache.
the class UpdateProjectRolePermissionCmd method execute.
// ///////////////////////////////////////////////////
// ///////////////// API Implementation //////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
ProjectRole projectRole = projRoleService.findProjectRole(getProjectRoleId(), getProjectId());
boolean result = false;
if (projectRole == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role id provided");
}
if (getProjectRulePermissionOrder() != null) {
if (getProjectRuleId() != null || getProjectRolePermission() != null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Parameters permission and ruleid must be mutually exclusive with ruleorder");
}
CallContext.current().setEventDetails("Reordering permissions for role id: " + projectRole.getId());
result = updateProjectRolePermissionOrder(projectRole);
} else if (getProjectRuleId() != null || getProjectRolePermission() != null) {
if (getProjectRulePermissionOrder() != null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Parameters permission and ruleid must be mutually exclusive with ruleorder");
}
ProjectRolePermission rolePermission = getValidProjectRolePermission();
CallContext.current().setEventDetails("Updating project role permission for rule id: " + getProjectRuleId() + " to: " + getProjectRolePermission().toString());
result = projRoleService.updateProjectRolePermission(projectId, projectRole, rolePermission, getProjectRolePermission());
}
SuccessResponse response = new SuccessResponse(getCommandName());
response.setSuccess(result);
setResponseObject(response);
}
Aggregations