if (templateOwner != null) {
templateOwnerDomain = templateOwner.getDomainId();
}
}
TemplatePermissionsResponse response = new TemplatePermissionsResponse();
response.setId(template.getId());
response.setPublicTemplate(template.isPublicTemplate());
if (isAdmin && (templateOwnerDomain != null)) {
response.setDomainId(templateOwnerDomain);
}
// 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.getType() != Account.ACCOUNT_TYPE_PROJECT) {
regularAccounts.add(accountName);
} else {
// convert account to projectIds
Project project = ApiDBUtils.findProjectByProjectAccountIdIncludingRemoved(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;
}