}
private List<TemplateResponse> createSwiftTemplateResponses(long templateId) {
VirtualMachineTemplate template = findTemplateById(templateId);
List<TemplateResponse> responses = new ArrayList<TemplateResponse>();
VMTemplateSwiftVO templateSwiftRef = ApiDBUtils.findTemplateSwiftRef(templateId);
if (templateSwiftRef == null) {
return responses;
}
TemplateResponse templateResponse = new TemplateResponse();
templateResponse.setId(template.getId());
templateResponse.setName(template.getName());
templateResponse.setDisplayText(template.getDisplayText());
templateResponse.setPublic(template.isPublicTemplate());
templateResponse.setCreated(templateSwiftRef.getCreated());
templateResponse.setReady(true);
templateResponse.setFeatured(template.isFeatured());
templateResponse.setExtractable(template.isExtractable() && !(template.getTemplateType() == TemplateType.SYSTEM));
templateResponse.setPasswordEnabled(template.getEnablePassword());
templateResponse.setCrossZones(template.isCrossZones());
templateResponse.setFormat(template.getFormat());
templateResponse.setDetails(template.getDetails());
if (template.getTemplateType() != null) {
templateResponse.setTemplateType(template.getTemplateType().toString());
}
templateResponse.setHypervisor(template.getHypervisorType().toString());
GuestOS os = ApiDBUtils.findGuestOSById(template.getGuestOSId());
if (os != null) {
templateResponse.setOsTypeId(os.getId());
templateResponse.setOsTypeName(os.getDisplayName());
} else {
templateResponse.setOsTypeId(-1L);
templateResponse.setOsTypeName("");
}
Account account = ApiDBUtils.findAccountByIdIncludingRemoved(template.getAccountId());
populateAccount(templateResponse, account.getId());
populateDomain(templateResponse, account.getDomainId());
Account caller = UserContext.current().getCaller();
boolean isAdmin = false;
if (BaseCmd.isAdmin(caller.getType())) {
isAdmin = true;
}
// If the user is an Admin, add the template download status
if (isAdmin || caller.getId() == template.getAccountId()) {
// add download status
templateResponse.setStatus("Successfully Installed");
}
Long templateSize = templateSwiftRef.getSize();
if (templateSize > 0) {
templateResponse.setSize(templateSize);
}
templateResponse.setChecksum(template.getChecksum());