Source:
<code>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) { 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()); } } List<String> projectIds = new ArrayList<String>(); List<String> regularAccounts = new ArrayList<String>(); final boolean isRootAdmin = _accountMgr.isRootAdmin(CallContext.current().getCallingAccountId()); for (String accountName : accountNames) { Account account = null; if (isRootAdmin) { List<AccountVO> accounts = accountDao.findAccountsLike(accountName); if (accounts != null && accounts.size() > 0) { <START> account = accounts.get(0); <END> } } if (account == null) { account = ApiDBUtils.findAccountByNameDomain(accountName, templateOwner.getDomainId()); } if (account == null) continue; if (account.getType() != Account.ACCOUNT_TYPE_PROJECT) { regularAccounts.add(accountName); } else { 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; }</code><technical_language>longer part of PR above</technical_language>

Target:
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) { 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()); } } 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 { 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; }