Search in sources :

Example 1 with ProjectResponse

use of org.apache.cloudstack.api.response.ProjectResponse in project cloudstack by apache.

the class ProjectJoinDaoImpl method newProjectResponse.

@Override
public ProjectResponse newProjectResponse(ProjectJoinVO proj) {
    ProjectResponse response = new ProjectResponse();
    response.setId(proj.getUuid());
    response.setName(proj.getName());
    response.setDisplaytext(proj.getDisplayText());
    if (proj.getState() != null) {
        response.setState(proj.getState().toString());
    }
    response.setDomainId(proj.getDomainUuid());
    response.setDomain(proj.getDomainName());
    response.setOwner(proj.getOwner());
    // update tag information
    Long tag_id = proj.getTagId();
    if (tag_id != null && tag_id.longValue() > 0) {
        ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    //set resource limit/count information for the project (by getting the info of the project's account)
    Account account = _accountDao.findByIdIncludingRemoved(proj.getProjectAccountId());
    AccountJoinVO accountJn = ApiDBUtils.newAccountView(account);
    _accountJoinDao.setResourceLimits(accountJn, false, response);
    response.setProjectAccountName(accountJn.getAccountName());
    response.setObjectName("project");
    return response;
}
Also used : Account(com.cloud.user.Account) ProjectResponse(org.apache.cloudstack.api.response.ProjectResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) AccountJoinVO(com.cloud.api.query.vo.AccountJoinVO)

Example 2 with ProjectResponse

use of org.apache.cloudstack.api.response.ProjectResponse in project cloudstack by apache.

the class UpdateProjectCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceAllocationException {
    CallContext.current().setEventDetails("Project id: " + getId());
    if (getAccountName() != null && getUserId() != null) {
        throw new InvalidParameterValueException("Account name and user ID are mutually exclusive. Provide either account name" + "to update account or user ID to update the user of the project");
    }
    Project project = null;
    if (isSwapOwner()) {
        project = _projectService.updateProject(getId(), getDisplayText(), getAccountName());
    } else {
        project = _projectService.updateProject(getId(), getDisplayText(), getAccountName(), getUserId(), getAccountRole());
    }
    if (project != null) {
        ProjectResponse response = _responseGenerator.createProjectResponse(project);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update a project");
    }
}
Also used : Project(com.cloud.projects.Project) ProjectResponse(org.apache.cloudstack.api.response.ProjectResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 3 with ProjectResponse

use of org.apache.cloudstack.api.response.ProjectResponse in project cloudstack by apache.

the class ViewResponseHelper method createProjectResponse.

public static List<ProjectResponse> createProjectResponse(ProjectJoinVO... projects) {
    Hashtable<Long, ProjectResponse> prjDataList = new Hashtable<Long, ProjectResponse>();
    // Initialise the prjdatalist with the input data
    for (ProjectJoinVO p : projects) {
        ProjectResponse pData = prjDataList.get(p.getId());
        if (pData == null) {
            // first time encountering this vm
            pData = ApiDBUtils.newProjectResponse(p);
        } else {
            // update those  1 to many mapping fields
            pData = ApiDBUtils.fillProjectDetails(pData, p);
        }
        prjDataList.put(p.getId(), pData);
    }
    return new ArrayList<ProjectResponse>(prjDataList.values());
}
Also used : ProjectResponse(org.apache.cloudstack.api.response.ProjectResponse) Hashtable(java.util.Hashtable) ProjectJoinVO(com.cloud.api.query.vo.ProjectJoinVO) ArrayList(java.util.ArrayList)

Example 4 with ProjectResponse

use of org.apache.cloudstack.api.response.ProjectResponse in project cloudstack by apache.

the class SuspendProjectCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
    CallContext.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(ApiErrorCode.INTERNAL_ERROR, "Failed to suspend a project");
    }
}
Also used : Project(com.cloud.projects.Project) ProjectResponse(org.apache.cloudstack.api.response.ProjectResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 5 with ProjectResponse

use of org.apache.cloudstack.api.response.ProjectResponse in project cloudstack by apache.

the class ActivateProjectCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    CallContext.current().setEventDetails("Project id: " + getId());
    Project project = _projectService.activateProject(getId());
    if (project != null) {
        ProjectResponse response = _responseGenerator.createProjectResponse(project);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to activate a project");
    }
}
Also used : Project(com.cloud.projects.Project) ProjectResponse(org.apache.cloudstack.api.response.ProjectResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Aggregations

ProjectResponse (org.apache.cloudstack.api.response.ProjectResponse)9 Project (com.cloud.projects.Project)4 ServerApiException (org.apache.cloudstack.api.ServerApiException)4 ArrayList (java.util.ArrayList)3 AccountJoinVO (com.cloud.api.query.vo.AccountJoinVO)2 ProjectJoinVO (com.cloud.api.query.vo.ProjectJoinVO)2 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)2 Account (com.cloud.user.Account)2 Hashtable (java.util.Hashtable)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ProjectAccount (com.cloud.projects.ProjectAccount)1 ProjectAccountVO (com.cloud.projects.ProjectAccountVO)1 ResourceIcon (com.cloud.server.ResourceIcon)1 User (com.cloud.user.User)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ResourceIconResponse (org.apache.cloudstack.api.response.ResourceIconResponse)1