// TODO String userID, String category
throws AMException
{
envelope = checkEnvelopeIsValid(envelope);
TemplateDto diskInfo = null;
Map<String, VirtualDiskDescType> diskIdToDiskFormat =
new HashMap<String, VirtualDiskDescType>();
Map<String, FileType> fileIdToFileType = new HashMap<String, FileType>();
Map<String, List<String>> diskIdToVSs = new HashMap<String, List<String>>();
Map<String, TemplateDto> requiredByVSs = new HashMap<String, TemplateDto>();
DiskSectionType diskSectionType;
try
{
ContentType contentType = OVFEnvelopeUtils.getTopLevelVirtualSystemContent(envelope);
ProductSectionType product =
OVFEnvelopeUtils.getSection(contentType, ProductSectionType.class);
OperatingSystemSectionType ossection = null;
try
{
ossection =
OVFEnvelopeUtils.getSection(contentType, OperatingSystemSectionType.class);
}
catch (Exception e) // no such section
{
}
String description = null;
if (product.getInfo() != null && product.getInfo().getValue() != null)
{
description = product.getInfo().getValue();
}
String categoryName = null;
if (product.getOtherAttributes().containsKey(new QName("CategoryName")))
{
categoryName = product.getOtherAttributes().get(new QName("CategoryName"));
}
String iconPath = getIconPath(product, fileIdToFileType, ovfId);
diskSectionType = OVFEnvelopeUtils.getSection(envelope, DiskSectionType.class);
for (FileType fileType : envelope.getReferences().getFile())
{
fileIdToFileType.put(fileType.getId(), fileType);
}
// Create a hash
for (VirtualDiskDescType virtualDiskDescType : diskSectionType.getDisk())
{
diskIdToDiskFormat.put(virtualDiskDescType.getDiskId(), virtualDiskDescType);
}
if (contentType instanceof VirtualSystemType)
{
VirtualSystemType vs = (VirtualSystemType) contentType;
TemplateDto req = getDiskInfo(vs, diskIdToDiskFormat, diskIdToVSs);
requiredByVSs.put(vs.getId(), req);
}
else if (contentType instanceof VirtualSystemCollectionType)
{
List<VirtualSystemType> virtualSystems =
OVFEnvelopeUtils.getVirtualSystems((VirtualSystemCollectionType) contentType);
for (VirtualSystemType virtualSystemType : virtualSystems)
{
TemplateDto req =
getDiskInfo(virtualSystemType, diskIdToDiskFormat, diskIdToVSs);
requiredByVSs.put(virtualSystemType.getId(), req);
}
}
for (VirtualDiskDescType diskDescType : diskIdToDiskFormat.values())
{
String diskId = diskDescType.getDiskId();
String fileId = diskDescType.getFileRef();
if (!fileIdToFileType.containsKey(fileId))
{
String msg = "File Id [" + fileId + "] not found on the ReferencesSection";
throw new IdNotFoundException(msg);
}
FileType file = fileIdToFileType.get(fileId);
final String filePath = file.getHref();
final Long fileSize = file.getSize().longValue();
String format = diskDescType.getFormat(); // XXX using the same format on the OVF
// disk
if (!diskIdToVSs.containsKey(diskId))
{
throw new IdNotFoundException("Any virtualSystem is using diskId[" + diskId
+ "]"); // XXX warning ??
}
if (diskIdToVSs.size() != 1)
{
throw new AMException(AMError.TEMPLATE_INVALID, String.format(
"There are more than one virtual system on the OVF Envelope [%s]", ovfId));
}
for (String vssName : diskIdToVSs.get(diskId))
{
diskInfo = new TemplateDto();
diskInfo.setName(vssName);
diskInfo.setUrl(ovfId);
diskInfo.setLoginUser(getProductPropertyValue(product, "user"));
diskInfo.setLoginPassword(getProductPropertyValue(product, "password"));
diskInfo.setOsType(getOSType(ossection));
diskInfo.setOsVersion(getOSVersion(ossection));
DiskFormat diskFormat = DiskFormat.fromValue(format);
DiskFormatType ovfDiskFormat = DiskFormatType.valueOf(diskFormat.name());
diskInfo.setDiskFileFormat(ovfDiskFormat);
diskInfo.setDiskFileSize(fileSize);
// Note that getHRef() will now return the relative path
// of the file at the downloaded repository space
if (filePath.startsWith("http:"))
{
diskInfo.setDiskFilePath(FilenameUtils.getName(filePath));
}
else
{
diskInfo.setDiskFilePath(filePath);
}
diskInfo.setIconPath(iconPath);
diskInfo.setDescription(description);
diskInfo.setCategoryName(categoryName);
// XXX diskInfo.setSO(value);
if (!requiredByVSs.containsKey(vssName))
{
throw new IdNotFoundException("VirtualSystem id not found [" + vssName
+ "]");
}
TemplateDto requirement = requiredByVSs.get(vssName);
// XXX disk format ::: diskInfo.setImageType(requirement.getImageType());
diskInfo.setCpu(requirement.getCpu());
diskInfo.setRam(requirement.getRam());
diskInfo.setHd(requirement.getHd());
diskInfo.setRamSizeUnit(requirement.getRamSizeUnit());
diskInfo.setHdSizeUnit(requirement.getHdSizeUnit());
diskInfo.setEthernetDriverType(requirement.getEthernetDriverType());
diskInfo.setDiskControllerType(requirement.getDiskControllerType());
// TODO diskInfo.setEnterpriseId(enterpriseId);
// diskInfo.setUserId(userId); TODO user ID
// diskInfo.getCategories().add(category); TODO category