Search in sources :

Example 6 with ProjectResponse

use of com.cloud.api.response.ProjectResponse 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 7 with ProjectResponse

use of com.cloud.api.response.ProjectResponse 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 8 with ProjectResponse

use of com.cloud.api.response.ProjectResponse in project cosmic by MissionCriticalCloud.

the class ViewResponseHelper method createProjectResponse.

public static List<ProjectResponse> createProjectResponse(final ProjectJoinVO... projects) {
    final Hashtable<Long, ProjectResponse> prjDataList = new Hashtable<>();
    // Initialise the prjdatalist with the input data
    for (final 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<>(prjDataList.values());
}
Also used : ProjectResponse(com.cloud.api.response.ProjectResponse) Hashtable(java.util.Hashtable) ProjectJoinVO(com.cloud.api.query.vo.ProjectJoinVO) ArrayList(java.util.ArrayList)

Example 9 with ProjectResponse

use of com.cloud.api.response.ProjectResponse in project cosmic by MissionCriticalCloud.

the class ProjectJoinDaoImpl method newProjectResponse.

@Override
public ProjectResponse newProjectResponse(final ProjectJoinVO proj) {
    final 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
    final Long tag_id = proj.getTagId();
    if (tag_id != null && tag_id.longValue() > 0) {
        final 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)
    final Account account = _accountDao.findByIdIncludingRemoved(proj.getProjectAccountId());
    final AccountJoinVO accountJn = ApiDBUtils.newAccountView(account);
    _accountJoinDao.setResourceLimits(accountJn, false, response);
    response.setObjectName("project");
    return response;
}
Also used : Account(com.cloud.legacymodel.user.Account) ProjectResponse(com.cloud.api.response.ProjectResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) AccountJoinVO(com.cloud.api.query.vo.AccountJoinVO)

Example 10 with ProjectResponse

use of com.cloud.api.response.ProjectResponse in project cosmic by MissionCriticalCloud.

the class SuspendProjectCmd method execute.

@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
    CallContext.current().setEventDetails("Project Id: " + id);
    final Project project = _projectService.suspendProject(id);
    if (project != null) {
        final 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(com.cloud.api.response.ProjectResponse) ServerApiException(com.cloud.api.ServerApiException)

Aggregations

ProjectResponse (com.cloud.api.response.ProjectResponse)11 Project (com.cloud.projects.Project)9 ServerApiException (com.cloud.api.ServerApiException)8 ArrayList (java.util.ArrayList)2 AccountJoinVO (com.cloud.api.query.vo.AccountJoinVO)1 ProjectJoinVO (com.cloud.api.query.vo.ProjectJoinVO)1 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)1 ListResponse (com.cloud.api.response.ListResponse)1 Account (com.cloud.legacymodel.user.Account)1 Hashtable (java.util.Hashtable)1