@Override public void ExecuteCommand(UICommand command) { super.ExecuteCommand(command); if (StringHelper.stringsEqual(command.getName(), "AddHost")) { AddHost(); } if (StringHelper.stringsEqual(command.getName(), "OnConfirmPMHost")) { OnConfirmPMHost(); } if (StringHelper.stringsEqual(command.getName(), "OnAddHost")) { OnAddHost(); } if (StringHelper.stringsEqual(command.getName(), "SelectHost")) { SelectHost(); } if (StringHelper.stringsEqual(command.getName(), "OnSelectHost")) { OnSelectHost(); } if (StringHelper.stringsEqual(command.getName(), "Cancel")) { Cancel(); } if (StringHelper.stringsEqual(command.getName(), "CancelConfirm")) { CancelConfirm(); } if (StringHelper.stringsEqual(command.getName(), "CancelConfirmWithFocus")) { CancelConfirmWithFocus(); } }
private String AvailableName(java.util.ArrayList<String> list) { String retVal = getCommonName(); java.util.ArrayList<Integer> notAvialbleNumberList = new java.util.ArrayList<Integer>(); String temp; for (String str : list) { temp = str.replace(getCommonName(), ""); if (StringHelper.isNullOrEmpty(temp)) { temp = "0"; } int tempInt = 0; RefObject<Integer> tempRef_tempInt = new RefObject<Integer>(tempInt); boolean tempVar = IntegerCompat.TryParse(temp, tempRef_tempInt); tempInt = tempRef_tempInt.argvalue; if (tempVar) { notAvialbleNumberList.add(tempInt); } } Collections.sort(notAvialbleNumberList); int i = 0; for (i = 0; i < notAvialbleNumberList.size(); i++) { if (notAvialbleNumberList.get(i) == i) { continue; } break; } if (i > 0) { retVal = getCommonName() + (new Integer(i)).toString(); } return retVal; }
protected void updateTimeZone(final String selectedTimeZone) { if (StringHelper.isNullOrEmpty(selectedTimeZone)) { updateDefaultTimeZone(); } else { doUpdateTimeZone(selectedTimeZone); } }
private void host_SelectedItemChanged() { VDS host = getHost().getSelectedItem(); if (getCurrentStorageItem() != null) { // When changing host clear items for san storage model. if (getCurrentStorageItem() instanceof SanStorageModelBase) { SanStorageModelBase sanStorageModel = (SanStorageModelBase) getCurrentStorageItem(); if (getStorage() == null) { sanStorageModel.setItems(null); } } if (host != null) { getCurrentStorageItem().getUpdateCommand().execute(); String prefix = host.isOvirtNode() ? localFSPath : ""; // $NON-NLS-1$ if (!StringHelper.isNullOrEmpty(prefix)) { for (Object item : getStorageModels()) { if (item instanceof LocalStorageModel) { LocalStorageModel model = (LocalStorageModel) item; model.getPath().setEntity(prefix); model.getPath().setIsChangeable(false); } } } } } }
public static Network FindNetworkByName(ArrayList<Network> items, String name) { for (Network n : items) { if (StringHelper.stringsEqual(n.getname(), name)) { return n; } } return null; }
@Override public void ExecuteCommand(UICommand command) { super.ExecuteCommand(command); if (command == getManageCommand()) { Manage(); } else if (command == getSetAsDisplayCommand()) { SetAsDisplay(); } else if (StringHelper.stringsEqual(command.getName(), "OnManage")) { OnManage(); } else if (StringHelper.stringsEqual(command.getName(), "New")) { New(); } else if (StringHelper.stringsEqual(command.getName(), "OnSave")) { OnSave(); } else if (StringHelper.stringsEqual(command.getName(), "Cancel")) { Cancel(); } }
public static NetworkInterface FindInterfaceNetworkNameNotEmpty( ArrayList<NetworkInterface> items) { for (NetworkInterface i : items) { if (!StringHelper.isNullOrEmpty(i.getNetworkName())) { return i; } } return null; }
public static NetworkInterface FindInterfaceByNetworkName( ArrayList<NetworkInterface> items, String name) { for (NetworkInterface i : items) { if (StringHelper.stringsEqual(i.getNetworkName(), name)) { return i; } } return null; }
@Override public void ExecuteCommand(UICommand command) { super.ExecuteCommand(command); if (command == getNewCommand()) { New(); } else if (command == getEditCommand()) { Edit(); } else if (command == getRemoveCommand()) { remove(); } else if (StringHelper.stringsEqual(command.getName(), "OnSave")) { OnSave(); } else if (StringHelper.stringsEqual(command.getName(), "Cancel")) { Cancel(); } else if (StringHelper.stringsEqual(command.getName(), "OnRemove")) { OnRemove(); } }
public static VdcReturnValueBase FindVdcReturnValueByDescription( ArrayList<VdcReturnValueBase> items, String description) { for (VdcReturnValueBase i : items) { if (StringHelper.stringsEqual(i.getDescription(), description)) { return i; } } return null; }
public static ArrayList<VdsNetworkInterface> FindAllInterfaceBondNameIsEmpty( ArrayList<VdsNetworkInterface> items) { ArrayList<VdsNetworkInterface> ret = new ArrayList<VdsNetworkInterface>(); for (VdsNetworkInterface i : items) { if (StringHelper.isNullOrEmpty(i.getBondName())) { ret.add(i); } } return ret; }
public static ArrayList<NetworkInterface> FindAllInterfaceNetworkNameNotEmpty( ArrayList<NetworkInterface> items) { ArrayList<NetworkInterface> ret = new ArrayList<NetworkInterface>(); for (NetworkInterface i : items) { if (!StringHelper.isNullOrEmpty(i.getNetworkName())) { ret.add(i); } } return ret; }
public String changeCaseDisplay(String text) { for (String s : EnumCompat.GetNames(DayOfWeek.class)) { if (StringHelper.EqOp(text, s)) // days of the begin with capital // letter { return text; } } return text.toLowerCase(); }
/** * Handle a BackendFailureException or an exception thrown from a backend query/action and * re-throw as a WebApplicationException. * * <p>If the exception indicates that the referenced backend entity does not exist * and @notFoundAs404 is true, then throw a WebApplicationException which wraps a 404 HTTP * response. * * @param clz dummy explicit type parameter for use when type inference is not possible * (irrelevant in any case as a value is never returned, rather an exception is always thrown) * @param e the exception to handle * @param notFoundAs404 whether to return a 404 if appropriate * @returns the result of the operation */ protected <T> T handleError(Class<T> clz, Exception e, boolean notFoundAs404) { if ((e instanceof EntityNotFoundException) && (notFoundAs404)) { throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build()); } else if ((e instanceof BackendFailureException) && (!StringHelper.isNullOrEmpty(e.getMessage()))) { LOG.errorFormat(localize(Messages.BACKEND_FAILED_TEMPLATE), e.getMessage(), null); throw new WebFaultException(null, e.getMessage(), Response.Status.BAD_REQUEST); } else { LOG.errorFormat(localize(Messages.BACKEND_FAILED_TEMPLATE), detail(e), e); throw new WebFaultException(e, detail(e), Response.Status.INTERNAL_SERVER_ERROR); } }
/** * Converts properties from string to map. Method assumes, that properties are syntactically valid * * @param properties specified properties * @return map containing all properties ({@code LinkedHashMap} is used to ensure properties order * is constant) */ public static Map<String, String> convertProperties(String properties) { Map<String, String> map = new LinkedHashMap<>(); if (!StringHelper.isNullOrEmpty(properties)) { String[] keyValuePairs = properties.split(PROPERTIES_DELIMETER); for (String keyValuePairStr : keyValuePairs) { String[] pairParts = keyValuePairStr.split(KEY_VALUE_DELIMETER, 2); String key = pairParts[0]; // property value may be null String value = pairParts[1]; map.put(key, value); } } return map; }
/** * Generate a string containing the given VM's configuration. * * @param vm The VM to generate configuration from. * @return A String containing the VM configuration. */ protected String generateVmConfiguration(VM vm) { if (vm.getInterfaces() == null || vm.getInterfaces().isEmpty()) { vm.setInterfaces(getVmNetworkInterfaceDao().getAllForVm(vm.getId())); } if (StringHelper.isNullOrEmpty(vm.getvmt_name())) { VmTemplate t = getVmTemplateDao().get(vm.getvmt_guid()); vm.setvmt_name(t.getname()); } RefObject<String> tempRefObject = new RefObject<String>(""); new OvfManager() .ExportVm( tempRefObject, vm, new ArrayList<DiskImage>(getDiskImageDao().getAllForVm(vm.getId()))); return tempRefObject.argvalue; }
public void PostGetClusterNetworkList_Edit(java.util.ArrayList<network> network_list) { VmNetworkInterface nic = (VmNetworkInterface) getSelectedItem(); int nicCount = Linq.<VmNetworkInterface>Cast(getItems()).size(); java.util.ArrayList<network> networks = new java.util.ArrayList<network>(); for (network a : network_list) { if (a.getStatus() == NetworkStatus.Operational) { networks.add(a); } } VmInterfaceModel model = (VmInterfaceModel) getWindow(); model.getNetwork().setItems(networks); network network = null; for (network a : networks) { if (StringHelper.stringsEqual(a.getname(), nic.getNetworkName())) { network = a; break; } } model.getNetwork().setSelectedItem(network); Integer selectedNicType = nic.getType(); java.util.ArrayList<VmInterfaceType> nicTypes = DataProvider.GetNicTypeList( getEntityStronglyTyped().getos(), VmInterfaceType.forValue(selectedNicType) == VmInterfaceType.rtl8139_pv); model.getNicType().setItems(nicTypes); if (selectedNicType == null || !nicTypes.contains(VmInterfaceType.forValue(selectedNicType))) { selectedNicType = DataProvider.GetDefaultNicType(getEntityStronglyTyped().getos()).getValue(); } model.getNicType().setSelectedItem(VmInterfaceType.forValue(selectedNicType)); model.getName().setEntity(nic.getName()); model.getMAC().setIsAvailable(false); UICommand tempVar = new UICommand("OnSave", this); tempVar.setTitle("OK"); tempVar.setIsDefault(true); model.getCommands().add(tempVar); UICommand tempVar2 = new UICommand("Cancel", this); tempVar2.setTitle("Cancel"); tempVar2.setIsCancel(true); model.getCommands().add(tempVar2); }
public void setTemplate(String value) { if (!StringHelper.stringsEqual(template, value)) { template = value; OnPropertyChanged(new PropertyChangedEventArgs("Template")); } }
protected void updateSelectedCdImage(VmBase vmBase) { getModel().getCdImage().setSelectedItem(vmBase.getIsoPath()); boolean hasCd = !StringHelper.isNullOrEmpty(vmBase.getIsoPath()); getModel().getCdImage().setIsChangable(hasCd); getModel().getCdAttached().setEntity(hasCd); }
public void setParticipantDisks(String value) { if (!StringHelper.stringsEqual(participantDisks, value)) { participantDisks = value; OnPropertyChanged(new PropertyChangedEventArgs("ParticipantDisks")); } }
public void setApps(String value) { if (!StringHelper.stringsEqual(apps, value)) { apps = value; OnPropertyChanged(new PropertyChangedEventArgs("Apps")); } }
@Override public boolean Match(SanTargetModel source) { return StringHelper.stringsEqual(source.getName(), target.getName()) && StringHelper.stringsEqual(source.getAddress(), target.getAddress()) && StringHelper.stringsEqual(source.getPort(), target.getPort()); }
public void setName(String value) { if (!StringHelper.stringsEqual(name, value)) { name = value; OnPropertyChanged(new PropertyChangedEventArgs("Name")); // $NON-NLS-1$ } }
@Override public boolean Match(LunModel source) { return StringHelper.stringsEqual(source.getLunId(), lun.getLunId()); }
public void setGetLUNsFailure(String value) { if (!StringHelper.stringsEqual(getLUNsFailure, value)) { getLUNsFailure = value; OnPropertyChanged(new PropertyChangedEventArgs("GetLUNsFailure")); } }
@Override public boolean Match(ServerCpu source) { return StringHelper.stringsEqual(source.getCpuName(), cpuName); }
public void setDescription(String value) { if (!StringHelper.stringsEqual(description, value)) { description = value; OnPropertyChanged(new PropertyChangedEventArgs("Description")); } }
public void SetDefaultNames(VDS host, RefObject<String> message) { message.argvalue = null; setCommonName(StringFormat.format("%1$s-Local", host.getvds_name().replace('.', '-'))); storage_pool candidate = null; // selecet all possible DCs VdcQueryReturnValue returnValue = Frontend.RunQuery( VdcQueryType.Search, new SearchParameters( StringFormat.format("DataCenter: name=%1$s", getCommonName() + "*"), SearchType.StoragePool)); java.util.ArrayList<storage_pool> dataCenterList = new java.util.ArrayList<storage_pool>(); java.util.ArrayList<VDSGroup> clusterList = null; if (returnValue != null && returnValue.getSucceeded() && returnValue.getReturnValue() != null) { dataCenterList = Linq.<storage_pool>Cast( (java.util.ArrayList<IVdcQueryable>) returnValue.getReturnValue()); } // check if current settings suitable for local setup (in case just SD creation failed - // re-using the same setup) boolean useCurrentSettings = false; if (host.getstorage_pool_id() != null) { storage_pool tempCandidate = DataProvider.GetDataCenterById(host.getstorage_pool_id()); if (IsLocalDataCenterEmpty(tempCandidate)) { candidate = tempCandidate; useCurrentSettings = true; } else { if (tempCandidate != null && tempCandidate.getstorage_pool_type() == StorageType.LOCALFS) { message.argvalue = "Note: Local Storage is already configured for this Host. The Host belongs to " + host.getstorage_pool_name() + " with local Storage Domain. If OK is clicked - this Host will be moved to a new Data Center, and a new Local Storage Domain will be created. Hit Cancel to abort the operation."; } } } // check if there is other DC suitable for re-use if (candidate == null) { for (storage_pool dataCenter : dataCenterList) { // need to check if the new DC is without host. if (IsLocalDataCenterEmpty(dataCenter) && DataProvider.GetLocalStorageHost(dataCenter.getname()) == null) { candidate = dataCenter; break; } } } java.util.ArrayList<String> listNames = new java.util.ArrayList<String>(); // in case we found a suitable candidte for re-use: if (candidate != null) { getDataCenter().setDataCenterId(candidate.getId()); getDataCenter().getName().setEntity(candidate.getname()); getDataCenter().getDescription().setEntity(candidate.getdescription()); Version compVersion = candidate.getcompatibility_version(); getDataCenter().getVersion().setSelectedItem(compVersion); getCluster().getVersion().setSelectedItem(compVersion); setDontCreateDataCenter(true); // if we use current settings there is no need to create cluster. if (useCurrentSettings) { getCluster().setClusterId(host.getvds_group_id().getValue()); getCluster().getName().setEntity(host.getvds_group_name()); VDSGroup cluster = DataProvider.GetClusterById(host.getvds_group_id().getValue()); if (cluster != null) { getCluster().getDescription().setEntity(cluster.getdescription()); ServerCpu tempVar = new ServerCpu(); tempVar.setCpuName(cluster.getcpu_name()); getCluster().getCPU().setSelectedItem(tempVar); } setDontCreateCluster(true); setDontChangeHostCluster(true); } // use differnt cluster else { // check the DC cluster list (for re-use) clusterList = DataProvider.GetClusterList(candidate.getId()); // no clusters avilable - pick up new name. if (clusterList.isEmpty()) { java.util.ArrayList<VDSGroup> listClusters = DataProvider.GetClusterList(); listNames = new java.util.ArrayList<String>(); for (VDSGroup cluster : listClusters) { listNames.add(cluster.getname()); } getCluster().getName().setEntity(AvailableName(listNames)); } else { // use the DC cluster. getCluster().setClusterId(clusterList.get(0).getId()); getCluster().getName().setEntity(clusterList.get(0).getname()); getCluster().getDescription().setEntity(clusterList.get(0).getdescription()); VDSGroup cluster = DataProvider.GetClusterById(getCluster().getClusterId().getValue()); if (cluster != null) { ServerCpu tempVar2 = new ServerCpu(); tempVar2.setCpuName(cluster.getcpu_name()); getCluster().getCPU().setSelectedItem(tempVar2); } setDontCreateCluster(true); if (host.getvds_group_id().getValue().equals(getCluster().getClusterId())) { setDontChangeHostCluster(true); } } } } else { // didn't found DC to re-use, so we select new names: listNames = new java.util.ArrayList<String>(); for (storage_pool storagePool : dataCenterList) { listNames.add(storagePool.getname()); } getDataCenter().getName().setEntity(AvailableName(listNames)); // Choose a Data Center version corresponding to the host. if (!StringHelper.isNullOrEmpty(host.getsupported_cluster_levels())) { // the supported_cluster_levels are sorted. String[] array = host.getsupported_cluster_levels().split("[,]", -1); Version maxCombindVersion = null; for (int i = 0; i < array.length; i++) { Version vdsVersion = new Version(array[i]); for (Version version : (java.util.List<Version>) getDataCenter().getVersion().getItems()) { if (version.equals(vdsVersion) && version.compareTo(maxCombindVersion) > 0) { maxCombindVersion = version; } } } if (maxCombindVersion != null) { getDataCenter().getVersion().setSelectedItem(maxCombindVersion); getCluster().getVersion().setSelectedItem(maxCombindVersion); } } listNames = new java.util.ArrayList<String>(); if (clusterList == null) { clusterList = DataProvider.GetClusterList(); } for (VDSGroup cluster : clusterList) { listNames.add(cluster.getname()); } getCluster().getName().setEntity(AvailableName(listNames)); } // Choose default CPU name to match host. if (host.getCpuName() != null && getCluster().getCPU().getSelectedItem() != null) { getCluster() .getCPU() .setSelectedItem( Linq.FirstOrDefault( (java.util.List<ServerCpu>) getCluster().getCPU().getItems(), new Linq.ServerCpuPredicate(host.getCpuName().getCpuName()))); } // always choose a avialable storage name. java.util.ArrayList<storage_domains> listStorageDomains = DataProvider.GetStorageDomainList(); listNames = new java.util.ArrayList<String>(); for (storage_domains storageDomain : listStorageDomains) { listNames.add(storageDomain.getstorage_name()); } getFormattedStorageName().setEntity(AvailableName(listNames)); }
@Override public boolean Match(Map.Entry<String, String> source) { return StringHelper.stringsEqual(source.getKey(), timeZone); }
public void setDefinedMemory(String value) { if (!StringHelper.stringsEqual(definedMemory, value)) { definedMemory = value; OnPropertyChanged(new PropertyChangedEventArgs("DefinedMemory")); } }