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;
}
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);
}
Aggregations