use of org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork in project ovirt-engine by oVirt.
the class BaseImportNetworksModel method onProviderChosen.
private void onProviderChosen() {
final Provider<?> provider = providers.getSelectedItem();
if (provider == null) {
return;
}
startProgress();
AsyncQuery<List<StoragePool>> dataCenterQuery = new AsyncQuery<>(returnValue -> {
final List<StoragePool> dataCenters = new LinkedList<>(returnValue);
Collections.sort(dataCenters, new NameableComparator());
AsyncQuery<QueryReturnValue> externalNetworksQuery = new AsyncQuery<>(queryReturnValue -> {
if (queryReturnValue.getSucceeded()) {
Map<Network, Set<Guid>> externalNetworkToDataCenters = queryReturnValue.getReturnValue();
providerNetworks.setItems(getExternalNetworks(externalNetworkToDataCenters, dataCenters));
importedNetworks.setItems(new LinkedList<ExternalNetwork>());
} else {
final ErrorPopupManager popupManager = (ErrorPopupManager) TypeResolver.getInstance().resolve(ErrorPopupManager.class);
popupManager.show(ConstantsManager.getInstance().getMessages().failedToListExternalNetworks(queryReturnValue.getExceptionMessage()));
}
stopProgress();
}, true);
AsyncDataProvider.getInstance().getExternalNetworksByProviderId(externalNetworksQuery, provider.getId());
});
AsyncDataProvider.getInstance().getDataCenterList(dataCenterQuery);
}
use of org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork in project ovirt-engine by oVirt.
the class BaseImportNetworksModel method getExternalNetwork.
private ExternalNetwork getExternalNetwork(Network network, Set<Guid> attachedDataCenters, List<StoragePool> dataCenters) {
ExternalNetwork externalNetwork = new ExternalNetwork();
externalNetwork.setNetwork(network);
externalNetwork.setDisplayName(network.getName());
externalNetwork.setPublicUse(true);
List<StoragePool> availableDataCenters = getAvailableDataCenters(dataCenters, attachedDataCenters);
externalNetwork.getDataCenters().setItems(availableDataCenters);
externalNetwork.getDataCenters().setSelectedItem(dataCenterListModel.getSelectedItem() != null && availableDataCenters.contains(dataCenterListModel.getSelectedItem()) ? dataCenterListModel.getSelectedItem() : Linq.firstOrNull(availableDataCenters));
return externalNetwork;
}
use of org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork in project ovirt-engine by oVirt.
the class BaseImportNetworksModel method cancelImport.
private void cancelImport() {
Collection<ExternalNetwork> selectedNetworks = getImportedNetworks().getSelectedItems();
Collection<ExternalNetwork> importedNetworks = getImportedNetworks().getItems();
getDefaultCommand().setIsExecutionAllowed(selectedNetworks.size() < importedNetworks.size());
for (ExternalNetwork externalNetwork : selectedNetworks) {
externalNetwork.setDisplayName(externalNetwork.getNetwork().getName());
}
}
use of org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork in project ovirt-engine by oVirt.
the class BaseImportNetworksModel method onImport.
public void onImport() {
if (!validate()) {
return;
}
List<ActionParametersBase> multipleActionParameters = new LinkedList<>();
for (final ExternalNetwork externalNetwork : importedNetworks.getItems()) {
final Network network = externalNetwork.getNetwork();
final Guid dcId = externalNetwork.getDataCenters().getSelectedItem().getId();
ImportExternalNetworkParameters params = new ImportExternalNetworkParameters(network.getProvidedBy().getProviderId(), network.getProvidedBy().getExternalId(), dcId, externalNetwork.isPublicUse(), true);
multipleActionParameters.add(params);
}
Frontend.getInstance().runMultipleActions(ActionType.ImportExternalNetwork, multipleActionParameters, result -> sourceListModel.getSearchCommand().execute());
cancel();
}
use of org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork in project ovirt-engine by oVirt.
the class BaseImportNetworksModel method validate.
private boolean validate() {
String errorDuplicate = ConstantsManager.getInstance().getConstants().importDuplicateName();
boolean valid = true;
Collection<ExternalNetwork> networks = importedNetworks.getItems();
List<String> errors = new ArrayList<>(networks.size());
Map<String, Integer> nameToIndex = new HashMap<>();
int i = 0;
for (ExternalNetwork network : networks) {
String networkName = network.getDisplayName();
Integer encounteredIndex = nameToIndex.get(networkName);
// if this name has been encountered, invalidate that entry; else store it for future invalidation
if (encounteredIndex != null) {
errors.set(encounteredIndex, errorDuplicate);
valid = false;
} else {
nameToIndex.put(networkName, i);
}
// invalidate current entry
errors.add(encounteredIndex == null ? null : errorDuplicate);
++i;
}
getErrors().setItems(errors);
return valid;
}
Aggregations