Search in sources :

Example 21 with Project

use of com.cloud.projects.Project in project CloudStack-archive by CloudStack-extras.

the class ListProjectsCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() {
    List<? extends Project> projects = _projectService.listProjects(id, name, displayText, state, this.getAccountName(), this.getDomainId(), this.getKeyword(), this.getStartIndex(), this.getPageSizeVal(), this.listAll(), this.isRecursive());
    ListResponse<ProjectResponse> response = new ListResponse<ProjectResponse>();
    List<ProjectResponse> projectResponses = new ArrayList<ProjectResponse>();
    for (Project project : projects) {
        ProjectResponse projectResponse = _responseGenerator.createProjectResponse(project);
        projectResponses.add(projectResponse);
    }
    response.setResponses(projectResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : Project(com.cloud.projects.Project) ProjectResponse(com.cloud.api.response.ProjectResponse) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList)

Example 22 with Project

use of com.cloud.projects.Project in project CloudStack-archive by CloudStack-extras.

the class SuspendProjectCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
    UserContext.current().setEventDetails("Project Id: " + id);
    Project project = _projectService.suspendProject(id);
    if (project != null) {
        ProjectResponse response = _responseGenerator.createProjectResponse(project);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to suspend a project");
    }
}
Also used : Project(com.cloud.projects.Project) ProjectResponse(com.cloud.api.response.ProjectResponse) ServerApiException(com.cloud.api.ServerApiException)

Example 23 with Project

use of com.cloud.projects.Project in project CloudStack-archive by CloudStack-extras.

the class UpdateProjectCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceAllocationException {
    UserContext.current().setEventDetails("Project id: " + getId());
    Project project = _projectService.updateProject(getId(), getDisplayText(), getAccountName());
    if (project != null) {
        ProjectResponse response = _responseGenerator.createProjectResponse(project);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update a project");
    }
}
Also used : Project(com.cloud.projects.Project) ProjectResponse(com.cloud.api.response.ProjectResponse) ServerApiException(com.cloud.api.ServerApiException)

Example 24 with Project

use of com.cloud.projects.Project in project CloudStack-archive by CloudStack-extras.

the class BaseCmd method finalyzeAccountId.

public Long finalyzeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly) {
    if (accountName != null) {
        if (domainId == null) {
            throw new InvalidParameterValueException("Account must be specified with domainId parameter");
        }
        Domain domain = _domainService.getDomain(domainId);
        if (domain == null) {
            throw new InvalidParameterValueException("Unable to find domain by id=" + domainId);
        }
        Account account = _accountService.getActiveAccountByName(accountName, domainId);
        if (account != null && account.getType() != Account.ACCOUNT_TYPE_PROJECT) {
            if (!enabledOnly || account.getState() == Account.State.enabled) {
                return account.getId();
            } else {
                throw new PermissionDeniedException("Can't add resources to the account id=" + account.getId() + " in state=" + account.getState() + " as it's no longer active");
            }
        } else {
            throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain id=" + domainId);
        }
    }
    if (projectId != null) {
        Project project = _projectService.getProject(projectId);
        if (project != null) {
            if (!enabledOnly || project.getState() == Project.State.Active) {
                return project.getProjectAccountId();
            } else {
                PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
                ex.addProxyObject(project, projectId, "projectId");
                throw ex;
            }
        } else {
            InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified projectId");
            ex.addProxyObject(project, projectId, "projectId");
            throw ex;
        }
    }
    return null;
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) Domain(com.cloud.domain.Domain)

Example 25 with Project

use of com.cloud.projects.Project in project CloudStack-archive by CloudStack-extras.

the class AddAccountToProjectCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    Project project = _projectService.getProject(projectId);
    //verify input parameters
    if (project == null) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id");
        ex.addProxyObject(project, projectId, "projectId");
        throw ex;
    }
    return _projectService.getProjectOwner(projectId).getId();
}
Also used : Project(com.cloud.projects.Project) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Aggregations

Project (com.cloud.projects.Project)48 Account (com.cloud.user.Account)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)25 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)16 Domain (com.cloud.domain.Domain)10 ArrayList (java.util.ArrayList)10 DomainVO (com.cloud.domain.DomainVO)7 Volume (com.cloud.storage.Volume)7 Pair (com.cloud.utils.Pair)6 List (java.util.List)6 ServerApiException (com.cloud.api.ServerApiException)5 ProjectResponse (com.cloud.api.response.ProjectResponse)5 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)5 ProjectAccount (com.cloud.projects.ProjectAccount)5 UserAccount (com.cloud.user.UserAccount)5 ServerApiException (org.apache.cloudstack.api.ServerApiException)5 DataCenterVO (com.cloud.dc.DataCenterVO)4 DB (com.cloud.utils.db.DB)4 Filter (com.cloud.utils.db.Filter)4 VlanVO (com.cloud.dc.VlanVO)3