use of org.ovirt.engine.ui.uicommonweb.models.templates.ImportTemplateModel in project ovirt-engine by oVirt.
the class TemplateBackupModel method executeImport.
protected void executeImport() {
ImportTemplateModel model = (ImportTemplateModel) getWindow();
if (model.getProgress() != null) {
return;
}
if (!model.validate()) {
return;
}
List<ActionParametersBase> prms = new ArrayList<>();
for (Object object : importModel.getItems()) {
ImportTemplateData importData = (ImportTemplateData) object;
VmTemplate template = importData.getTemplate();
ImportVmTemplateParameters importVmTemplateParameters = new ImportVmTemplateParameters(model.getStoragePool().getId(), getEntity().getId(), Guid.Empty, model.getCluster().getSelectedItem().getId(), template);
if (importModel.getClusterQuota().getSelectedItem() != null && importModel.getClusterQuota().getIsAvailable()) {
importVmTemplateParameters.setQuotaId(importModel.getClusterQuota().getSelectedItem().getId());
}
CpuProfile cpuProfile = importModel.getCpuProfiles().getSelectedItem();
if (cpuProfile != null) {
importVmTemplateParameters.setCpuProfileId(cpuProfile.getId());
}
Map<Guid, Guid> map = new HashMap<>();
for (DiskImage disk : template.getDiskList()) {
map.put(disk.getId(), importModel.getDiskImportData(disk.getId()).getSelectedStorageDomain().getId());
if (importModel.getDiskImportData(disk.getId()).getSelectedQuota() != null) {
disk.setQuotaId(importModel.getDiskImportData(disk.getId()).getSelectedQuota().getId());
}
}
importVmTemplateParameters.setImageToDestinationDomainMap(map);
if (importData.isExistsInSystem() || importData.getClone().getEntity()) {
if (!cloneObjectMap.containsKey(template.getId())) {
continue;
}
importVmTemplateParameters.setImportAsNewEntity(true);
importVmTemplateParameters.getVmTemplate().setName(((ImportTemplateData) cloneObjectMap.get(template.getId())).getTemplate().getName());
}
prms.add(importVmTemplateParameters);
}
model.startProgress();
Frontend.getInstance().runMultipleAction(ActionType.ImportVmTemplate, prms, result -> {
TemplateBackupModel templateBackupModel = (TemplateBackupModel) result.getState();
templateBackupModel.getWindow().stopProgress();
templateBackupModel.cancel();
List<ActionReturnValue> retVals = result.getReturnValue();
if (retVals != null && templateBackupModel.getSelectedItems().size() == retVals.size()) {
StringBuilder importedTemplates = new StringBuilder();
int counter = 0;
boolean toShowConfirmWindow = false;
for (VmTemplate template : templateBackupModel.getSelectedItems()) {
if (retVals.get(counter) != null && retVals.get(counter).isValid()) {
// $NON-NLS-1$
importedTemplates.append(template.getName()).append(", ");
toShowConfirmWindow = true;
}
counter++;
}
if (toShowConfirmWindow) {
ConfirmationModel confirmModel = new ConfirmationModel();
templateBackupModel.setConfirmWindow(confirmModel);
confirmModel.setTitle(constants.importTemplatesTitle());
confirmModel.setHelpTag(HelpTag.import_template);
// $NON-NLS-1$
confirmModel.setHashName("import_template");
confirmModel.setMessage(messages.importProcessHasBegunForTemplates(StringHelper.trimEnd(importedTemplates.toString().trim(), ',')));
confirmModel.getCommands().add(// $NON-NLS-1$
new UICommand(CANCEL_CONFIRMATION_COMMAND, templateBackupModel).setTitle(constants.close()).setIsDefault(true).setIsCancel(true));
}
}
}, this);
}
use of org.ovirt.engine.ui.uicommonweb.models.templates.ImportTemplateModel in project ovirt-engine by oVirt.
the class TemplateBackupModel method restore.
@Override
protected void restore() {
if (getWindow() != null) {
return;
}
if (!validateSingleArchitecture()) {
return;
}
ImportTemplateModel model = importModelProvider.get();
model.setEntity(getEntity().getId());
setWindow(model);
model.startProgress();
model.setTitle(ConstantsManager.getInstance().getConstants().importTemplatesTitle());
// $NON-NLS-1$
model.getCommands().add(UICommand.createDefaultOkUiCommand("OnRestore", this));
// $NON-NLS-1$);
model.getCommands().add(UICommand.createCancelUiCommand(CANCEL_COMMAND, this));
model.init(getSelectedItems(), getEntity().getId());
model.setTargetArchitecture(getArchitectureFromItem(getSelectedItems().get(0)));
// Add 'Close' command
model.setCloseCommand(// $NON-NLS-1$
new UICommand(CANCEL_COMMAND, this).setTitle(ConstantsManager.getInstance().getConstants().close()).setIsDefault(true).setIsCancel(true));
((TemplateImportDiskListModel) ((ImportTemplateModel) getWindow()).getImportDiskListModel()).setExtendedItems(extendedItems);
}
Aggregations