List of usage examples for org.apache.commons.lang StringUtils defaultString
public static String defaultString(String str)
Returns either the passed in String, or if the String is null
, an empty String ("").
From source file:com.redhat.rhn.frontend.taglibs.list.DataSetManipulator.java
/** * Sorts the dataset in place//from w w w . j a va 2 s . co m */ public void sort() { String sortKey = ListTagUtil.makeSortByLabel(uniqueName); String sortDirectionKey = ListTagUtil.makeSortDirLabel(uniqueName); String sortAttribute = StringUtils.defaultString(request.getParameter(sortKey)); String sortDir = StringUtils.defaultString(request.getParameter(sortDirectionKey)); if (!sortDir.equals(RequestContext.SORT_ASC) && !sortDir.equals(RequestContext.SORT_DESC)) { sortDir = ascending ? RequestContext.SORT_ASC : RequestContext.SORT_DESC; } if (AlphaBarHelper.getInstance().isSelected(uniqueName, request)) { Collections.sort(dataset, new DynamicComparator(alphaCol, RequestContext.SORT_ASC)); } else if (!StringUtils.isBlank(sortAttribute)) { try { Collections.sort(dataset, new DynamicComparator(sortAttribute, sortDir)); } catch (IllegalArgumentException iae) { Collections.sort(dataset, new DynamicComparator(defaultSortAttribute, sortDir)); } } else if (!StringUtils.isBlank(defaultSortAttribute)) { Collections.sort(dataset, new DynamicComparator(defaultSortAttribute, ascending ? RequestContext.SORT_ASC : RequestContext.SORT_DESC)); } }
From source file:com.redhat.rhn.frontend.action.kickstart.KickstartDetailsEditAction.java
/** * Proccess Cobbler form values, pulling in the form * and pushing the values to cobbler * @param ksdata the kickstart data/*from w w w .j a va2 s. c o m*/ * @param form the form * @param user the user * @throws ValidatorException if there is not enough ram */ public static void processCobblerFormValues(KickstartData ksdata, DynaActionForm form, User user) throws ValidatorException { if (KickstartDetailsEditAction.canSaveVirtOptions(ksdata, form)) { int virtMemory = (Integer) form.get(VIRT_MEMORY); if (ksdata.isRhel7OrGreater() && virtMemory < 1024) { ValidatorException.raiseException("kickstart.cobbler.profile.notenoughmemory"); } else if (ksdata.isSUSE() && virtMemory < 512) { ValidatorException.raiseException("kickstart.cobbler.profile.notenoughmemorysuse"); } } CobblerProfileEditCommand cmd = new CobblerProfileEditCommand(ksdata, user); cmd.setKernelOptions(StringUtils.defaultString(form.getString(KERNEL_OPTIONS))); cmd.setPostKernelOptions(StringUtils.defaultString(form.getString(POST_KERNEL_OPTIONS))); cmd.store(); Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), ksdata.getCobblerId()); if (prof == null) { return; } if (KickstartDetailsEditAction.canSaveVirtOptions(ksdata, form)) { prof.setVirtRam((Integer) form.get(VIRT_MEMORY)); prof.setVirtCpus((Integer) form.get(VIRT_CPU)); prof.setVirtFileSize((Integer) form.get(VIRT_DISK_SIZE)); prof.setVirtBridge(form.getString(VIRT_BRIDGE)); } prof.save(); }
From source file:gov.nih.nci.caarray.dao.ProjectDaoImpl.java
private Query getSearchQuery(boolean count, PageSortParams<Project> params, String keyword, SearchCategory... categories) {//from w w w . jav a2 s. c o m @SuppressWarnings("deprecation") final SortCriterion<Project> sortCrit = params != null ? params.getSortCriterion() : null; final StringBuffer sb = new StringBuffer(); if (count) { sb.append("SELECT COUNT(DISTINCT p)"); } else { sb.append("SELECT DISTINCT p"); } sb.append(" FROM ").append(Project.class.getName()).append(" p"); if (!count) { sb.append(" left join fetch p.experiment e left join fetch e.organism"); } sb.append(getJoinClause(categories)); sb.append(getWhereClause(categories)); if (!count && sortCrit != null) { sb.append(" ORDER BY p.").append(sortCrit.getOrderField()); if (params.isDesc()) { sb.append(" desc"); } } final Query q = getCurrentSession().createQuery(sb.toString()); q.setString("keyword", "%" + StringUtils.defaultString(keyword) + "%"); return q; }
From source file:com.redhat.rhn.frontend.xmlrpc.errata.ErrataHandler.java
/** * GetDetails - Retrieves the details for a given errata. * @param loggedInUser The current user/* w w w. j a v a 2 s .c o m*/ * @param advisoryName The advisory name of the errata * @return Returns a map containing the details of the errata * @throws FaultException A FaultException is thrown if the errata * corresponding to advisoryName cannot be found. * * @xmlrpc.doc Retrieves the details for the erratum matching the given * advisory name. * @xmlrpc.param #session_key() * @xmlrpc.param #param("string", "advisoryName") * @xmlrpc.returntype * #struct("erratum") * #prop("int", "id") * #prop("string", "issue_date") * #prop("string", "update_date") * #prop_desc("string", "last_modified_date", "This date is only included for * published erratum and it represents the last time the erratum was * modified.") * #prop("string", "synopsis") * #prop("int", "release") * #prop("string", "type") * #prop("string", "product") * #prop("string", "errataFrom") * #prop("string", "topic") * #prop("string", "description") * #prop("string", "references") * #prop("string", "notes") * #prop("string", "solution") * #struct_end() */ public Map<String, Object> getDetails(User loggedInUser, String advisoryName) throws FaultException { // Get the logged in user. We don't care what roles this user has, we // just want to make sure the caller is logged in. Errata errata = lookupErrataReadOnly(advisoryName, loggedInUser.getOrg()); Map<String, Object> errataMap = new HashMap<String, Object>(); errataMap.put("id", errata.getId()); if (errata.getIssueDate() != null) { errataMap.put("issue_date", LocalizationService.getInstance().formatShortDate(errata.getIssueDate())); } if (errata.getUpdateDate() != null) { errataMap.put("update_date", LocalizationService.getInstance().formatShortDate(errata.getUpdateDate())); } if (errata.getLastModified() != null) { errataMap.put("last_modified_date", errata.getLastModified().toString()); } if (errata.getAdvisoryRel() != null) { errataMap.put("release", errata.getAdvisoryRel()); } errataMap.put("product", StringUtils.defaultString(errata.getProduct())); errataMap.put("errataFrom", StringUtils.defaultString(errata.getErrataFrom())); errataMap.put("solution", StringUtils.defaultString(errata.getSolution())); errataMap.put("description", StringUtils.defaultString(errata.getDescription())); errataMap.put("synopsis", StringUtils.defaultString(errata.getSynopsis())); errataMap.put("topic", StringUtils.defaultString(errata.getTopic())); errataMap.put("references", StringUtils.defaultString(errata.getRefersTo())); errataMap.put("notes", StringUtils.defaultString(errata.getNotes())); errataMap.put("type", StringUtils.defaultString(errata.getAdvisoryType())); return errataMap; }
From source file:de.cosmocode.collections.utility.Convert.java
private static Locale doIntoLocale(Object value) { if (value == null) return null; if (value instanceof Locale) return Locale.class.cast(value); final String string = doIntoString(value); final Matcher matcher = Patterns.LOCALE.matcher(string); if (matcher.matches()) { final String language = StringUtils.defaultString(matcher.group(1)); final String country = StringUtils.defaultString(matcher.group(2)); final String variant = StringUtils.defaultString(matcher.group(3)); return new Locale(language, country, variant); } else {// w w w . j av a2 s . c o m return null; } }
From source file:mitm.application.djigzo.ws.impl.MailRepositoryWSImpl.java
@Override @StartTransaction//from w ww. j a v a 2 s .co m public int getSearchCount(MailRepositorySearchField searchField, String key) throws WebServiceCheckedException { if (searchField == null) { throw new WebServiceCheckedException("searchField is missing."); } key = StringUtils.defaultString(key); return mailRepository.getSearchCount(searchField, key); }
From source file:br.com.ingenieux.mojo.beanstalk.env.ReplaceEnvironmentMojo.java
/** * Prior to Launching a New Environment, lets look and copy the most we can * * @param curEnv current environment//from w ww . j a v a2 s .c o m */ private void copyOptionSettings(EnvironmentDescription curEnv) throws Exception { /** * Skip if we don't have anything */ if (null != this.optionSettings && this.optionSettings.length > 0) { return; } DescribeConfigurationSettingsResult configSettings = getService() .describeConfigurationSettings(new DescribeConfigurationSettingsRequest() .withApplicationName(applicationName).withEnvironmentName(curEnv.getEnvironmentName())); List<ConfigurationOptionSetting> newOptionSettings = new ArrayList<ConfigurationOptionSetting>( configSettings.getConfigurationSettings().get(0).getOptionSettings()); ListIterator<ConfigurationOptionSetting> listIterator = newOptionSettings.listIterator(); while (listIterator.hasNext()) { ConfigurationOptionSetting curOptionSetting = listIterator.next(); boolean bInvalid = harmfulOptionSettingP(curEnv.getEnvironmentId(), curOptionSetting); if (bInvalid) { getLog().info(format("Excluding Option Setting: %s:%s['%s']", curOptionSetting.getNamespace(), curOptionSetting.getOptionName(), CredentialsUtil.redact(curOptionSetting.getValue()))); listIterator.remove(); } else { getLog().info(format("Including Option Setting: %s:%s['%s']", curOptionSetting.getNamespace(), curOptionSetting.getOptionName(), CredentialsUtil.redact(curOptionSetting.getValue()))); } } Object __secGroups = project.getProperties().get("beanstalk.securityGroups"); if (null != __secGroups) { String securityGroups = StringUtils.defaultString(__secGroups.toString()); if (!StringUtils.isBlank(securityGroups)) { ConfigurationOptionSetting newOptionSetting = new ConfigurationOptionSetting( "aws:autoscaling:launchconfiguration", "SecurityGroups", securityGroups); newOptionSettings.add(newOptionSetting); getLog().info(format("Including Option Setting: %s:%s['%s']", newOptionSetting.getNamespace(), newOptionSetting.getOptionName(), newOptionSetting.getValue())); } } /* * Then copy it back */ this.optionSettings = newOptionSettings.toArray(new ConfigurationOptionSetting[newOptionSettings.size()]); }
From source file:net.ageto.gyrex.impex.persistence.cassandra.storage.CassandraRepositoryImpl.java
/** * Find all logging messages by the give process run id. * /*w w w . j av a 2 s . co m*/ * @param processRunId * * @return */ public List<ILoggingMessage> findAllLoggingMessages(String processRunId) { SuperSliceQuery<String, UUID, String, String> superSlicesQuery = HFactory.createSuperSliceQuery( getImpexKeyspace(), StringSerializer.get(), UUIDSerializer.get(), StringSerializer.get(), StringSerializer.get()); superSlicesQuery.setColumnFamily(supercolumnFamilyProcessLogging); superSlicesQuery.setKey(processRunId); superSlicesQuery.setRange(null, null, false, 999); QueryResult<SuperSlice<UUID, String, String>> result = superSlicesQuery.execute(); SuperSlice<UUID, String, String> superSlice = result.get(); List<HSuperColumn<UUID, String, String>> superColumns = superSlice.getSuperColumns(); List<ILoggingMessage> logMessages = new ArrayList<ILoggingMessage>(); for (HSuperColumn<UUID, String, String> superColumn : superColumns) { List<HColumn<String, String>> columns = superColumn.getColumns(); if (columns == null || columns.size() < 2) { LOG.warn("Current log message entry has an unexpected number of columns. Skip entry."); continue; } String level = columns.get(0).getValue(); String message = columns.get(1).getValue(); LoggingMessage logMessage = new LoggingMessage(StringUtils.defaultString(message), Loglevel.valueOf(StringUtils.defaultIfEmpty(level, Loglevel.INFO.name()))); logMessages.add(logMessage); } return logMessages; }
From source file:mitm.application.djigzo.ws.impl.X509CertStoreWSImpl.java
@Override @StartTransaction/* w ww. ja va 2s . com*/ public List<X509CertificateDTO> searchBySubject(String subject, Expired expired, MissingKeyAlias missingKeyAlias, Integer firstResult, Integer maxResults) throws WebServiceCheckedException { subject = StringUtils.defaultString(subject); if (expired == null) { throw new WebServiceCheckedException("expired is missing."); } if (missingKeyAlias == null) { throw new WebServiceCheckedException("missingKeyAlias is missing."); } try { return searchBySubjectAction(subject, expired, missingKeyAlias, firstResult, maxResults); } catch (WebServiceCheckedException e) { logger.error("searchBySubject failed.", e); throw new WebServiceCheckedException(WSExceptionUtils.getExceptionMessage(e)); } catch (RuntimeException e) { logger.error("searchBySubject failed.", e); throw new WebServiceCheckedException(WSExceptionUtils.getExceptionMessage(e)); } }
From source file:com.redhat.rhn.frontend.xmlrpc.packages.PackagesHandler.java
/** * List dependencies for a given package. * @param loggedInUser The current user//from www . j a v a 2s . c o m * @param pid The package id for the package in question * @return Returns an array of maps representing a dependency * @throws FaultException A FaultException is thrown if the errata corresponding to * pid cannot be found. * * @xmlrpc.doc List the dependencies for a package. * @xmlrpc.param #session_key() * @xmlrpc.param #param("int", "packageId") * @xmlrpc.returntype * #array() * #struct("dependency") * #prop("string", "dependency") * #prop_desc("string", "dependency_type", "One of the following:") * #options() * #item("requires") * #item("conflicts") * #item("obsoletes") * #item("provides") * #item("recommends") * #item("suggests") * #item("supplements") * #item("enhances") * #options_end() * #prop("string", "dependency_modifier") * #struct_end() * #array_end() */ public Object[] listDependencies(User loggedInUser, Integer pid) throws FaultException { // Get the logged in user Package pkg = lookupPackage(loggedInUser, pid); // The list we'll eventually return List returnList = new ArrayList(); /* * Loop through each of the types of dependencies and create a map representing the * dependency to add to the returnList */ for (int i = 0; i < PackageManager.DEPENDENCY_TYPES.length; i++) { String depType = PackageManager.DEPENDENCY_TYPES[i]; DataResult dr = getDependencies(depType, pkg); // In the off chance we get null back, we should skip the next loop if (dr == null || dr.isEmpty()) { continue; } /* * Loop through each item in the dependencies data result, adding each row * to the returnList */ for (Iterator resultItr = dr.iterator(); resultItr.hasNext();) { Map row = new HashMap(); // The map we'll put into returnList Map map = (Map) resultItr.next(); String name = (String) map.get("name"); String version = (String) map.get("version"); Long sense = (Long) map.get("sense"); row.put("dependency", StringUtils.defaultString(name)); row.put("dependency_type", depType); // If the version for this dep isn't null, we need to calculate the modifier String depmod = " "; if (version != null) { depmod = StringUtils.defaultString(PackageManager.getDependencyModifier(sense, version)); } row.put("dependency_modifier", depmod); returnList.add(row); } } return returnList.toArray(); }