Search in sources :

Example 1 with TemplatePermissionsResponse

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

the class ApiResponseHelper method createTemplatePermissionsResponse.

@Override
public TemplatePermissionsResponse createTemplatePermissionsResponse(ResponseView view, List<String> accountNames, Long id) {
    Long templateOwnerDomain = null;
    VirtualMachineTemplate template = ApiDBUtils.findTemplateById(id);
    Account templateOwner = ApiDBUtils.findAccountById(template.getAccountId());
    if (view == ResponseView.Full) {
        // from that
        if (templateOwner != null) {
            templateOwnerDomain = templateOwner.getDomainId();
        }
    }
    TemplatePermissionsResponse response = new TemplatePermissionsResponse();
    response.setId(template.getUuid());
    response.setPublicTemplate(template.isPublicTemplate());
    if ((view == ResponseView.Full) && (templateOwnerDomain != null)) {
        Domain domain = ApiDBUtils.findDomainById(templateOwnerDomain);
        if (domain != null) {
            response.setDomainId(domain.getUuid());
        }
    }
    // Set accounts
    List<String> projectIds = new ArrayList<String>();
    List<String> regularAccounts = new ArrayList<String>();
    for (String accountName : accountNames) {
        Account account = ApiDBUtils.findAccountByNameDomain(accountName, templateOwner.getDomainId());
        if (account == null) {
            s_logger.error("Missing Account " + accountName + " in domain " + templateOwner.getDomainId());
            continue;
        }
        if (account.getType() != Account.ACCOUNT_TYPE_PROJECT) {
            regularAccounts.add(accountName);
        } else {
            // convert account to projectIds
            Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
            if (project.getUuid() != null && !project.getUuid().isEmpty()) {
                projectIds.add(project.getUuid());
            } else {
                projectIds.add(String.valueOf(project.getId()));
            }
        }
    }
    if (!projectIds.isEmpty()) {
        response.setProjectIds(projectIds);
    }
    if (!regularAccounts.isEmpty()) {
        response.setAccountNames(regularAccounts);
    }
    response.setObjectName("templatepermission");
    return response;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) Project(com.cloud.projects.Project) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ArrayList(java.util.ArrayList) Domain(com.cloud.domain.Domain) TemplatePermissionsResponse(org.apache.cloudstack.api.response.TemplatePermissionsResponse)

Example 2 with TemplatePermissionsResponse

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

the class BaseListTemplateOrIsoPermissionsCmd method executeWithView.

protected void executeWithView(ResponseView view) {
    List<String> accountNames = _templateService.listTemplatePermissions(this);
    TemplatePermissionsResponse response = _responseGenerator.createTemplatePermissionsResponse(view, accountNames, id);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : TemplatePermissionsResponse(org.apache.cloudstack.api.response.TemplatePermissionsResponse)

Aggregations

TemplatePermissionsResponse (org.apache.cloudstack.api.response.TemplatePermissionsResponse)2 Domain (com.cloud.domain.Domain)1 Project (com.cloud.projects.Project)1 ProjectAccount (com.cloud.projects.ProjectAccount)1 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)1 Account (com.cloud.user.Account)1 UserAccount (com.cloud.user.UserAccount)1 ArrayList (java.util.ArrayList)1