List of usage examples for org.apache.commons.lang3 StringUtils defaultIfBlank
public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr)
Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null , the value of defaultStr .
StringUtils.defaultIfBlank(null, "NULL") = "NULL" StringUtils.defaultIfBlank("", "NULL") = "NULL" StringUtils.defaultIfBlank(" ", "NULL") = "NULL" StringUtils.defaultIfBlank("bat", "NULL") = "bat" StringUtils.defaultIfBlank("", null) = null
From source file:gobblin.source.extractor.extract.jdbc.OracleExtractor.java
@Override public List<Command> getCountMetadata(String schema, String entity, WorkUnit workUnit, List<Predicate> predicateList) throws RecordCountException { log.debug("Build query to get source record count"); List<Command> commands = new ArrayList<>(); String columnProjection = "count(1)"; String watermarkFilter = StringUtils.defaultIfBlank(this.concatPredicates(predicateList), EMPTY_CONDITION); String query = this.getExtractSql(); query = query.replace(this.getOutputColumnProjection(), columnProjection) .replace(ConfigurationKeys.DEFAULT_SOURCE_QUERYBASED_WATERMARK_PREDICATE_SYMBOL, watermarkFilter); query = addSampleQueryPart(query);//from w ww . j a v a 2s. com query = castCountQuery(query); commands.add(JdbcExtractor.getCommand(query, JdbcCommand.JdbcCommandType.QUERY)); return commands; }
From source file:com.sonicle.webtop.calendar.TplHelper.java
public static String buildEventModificationBody(Locale locale, String dateFormat, String timeFormat, EventFootprint event) throws IOException, TemplateException, AddressException { DateTimeZone etz = DateTimeZone.forID(event.getTimezone()); MapItem i18n = new MapItem(); i18n.put("whenStart", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_WHEN_START)); i18n.put("whenEnd", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_WHEN_END)); i18n.put("where", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_WHERE)); i18n.put("whereMap", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_WHERE_MAP)); DateTimeFormatter fmt = DateTimeUtils.createFormatter(dateFormat + " " + timeFormat, etz); MapItem evt = new MapItem(); evt.put("timezone", event.getTimezone()); evt.put("startDate", fmt.print(event.getStartDate())); evt.put("endDate", fmt.print(event.getEndDate())); evt.put("occurs", null); if (!StringUtils.isEmpty(event.getRecurrenceRule())) { RRuleStringify.Strings strings = WT.getRRuleStringifyStrings(locale); RRuleStringify rrs = new RRuleStringify(strings, etz); evt.put("occurs", rrs.toHumanReadableTextQuietly(event.getRecurrenceRule())); }//from ww w. j a va 2 s . co m evt.put("location", StringUtils.defaultIfBlank(event.getLocation(), null)); evt.put("locationUrl", TplHelper.buildGoogleMapsUrl(event.getLocation())); MapItem vars = new MapItem(); vars.put("i18n", i18n); vars.put("event", evt); return WT.buildTemplate(SERVICE_ID, "tpl/email/eventModification-body.html", vars); }
From source file:controllers.PullRequestApp.java
@AnonymousCheck(requiresLogin = true, displaysFlashMessage = true) @IsCreatable(ResourceType.FORK)/*from www . j a v a 2 s .c o m*/ public static Result newPullRequestForm(String userName, String projectName) throws IOException, GitAPIException { final Project project = Project.findByOwnerAndProjectName(userName, projectName); ValidationResult validation = validateBeforePullRequest(project); if (validation.hasError()) { return validation.getResult(); } final List<Project> projects = project.getAssociationProjects(); final Project fromProject = getSelectedProject(project, request().getQueryString("fromProjectId"), false); final Project toProject = getSelectedProject(project, request().getQueryString("toProjectId"), true); final List<GitBranch> fromBranches = new GitRepository(fromProject).getBranches(); final List<GitBranch> toBranches = new GitRepository(toProject).getBranches(); if (fromBranches.isEmpty()) { return badRequest(ErrorViews.BadRequest.render("error.pullRequest.empty.from.repository", fromProject, MenuType.PULL_REQUEST)); } if (toBranches.isEmpty()) { return badRequest(ErrorViews.BadRequest.render("error.pullRequest.empty.to.repository", toProject)); } final PullRequest pullRequest = PullRequest.createNewPullRequest(fromProject, toProject, StringUtils.defaultIfBlank(request().getQueryString("fromBranch"), fromBranches.get(0).getName()), StringUtils.defaultIfBlank(request().getQueryString("toBranch"), project.defaultBranch())); return ok(create.render("title.newPullRequest", new Form<>(PullRequest.class).fill(pullRequest), project, projects, fromProject, toProject, fromBranches, toBranches, pullRequest)); }
From source file:com.sonicle.webtop.core.io.input.XlsPartsProcessorOLD.java
@Override public void processRecord(Record record) { cellValue = null;//w ww . j a va2s .com switch (record.getSid()) { case BoundSheetRecord.sid: BoundSheetRecord bsr = (BoundSheetRecord) record; if (!sheetFound) { if (StringUtils.equals(bsr.getSheetname(), sheetName)) { sheetFound = true; columnNames = new LinkedHashMap<>(); columnIndexes = new HashMap<>(); } } else { close(); } break; case SSTRecord.sid: sstRecord = (SSTRecord) record; break; case BlankRecord.sid: BlankRecord br = (BlankRecord) record; row = br.getRow(); col = br.getColumn(); cellValue = ""; break; case BoolErrRecord.sid: BoolErrRecord ber = (BoolErrRecord) record; row = ber.getRow(); col = ber.getColumn(); cellValue = ""; break; case FormulaRecord.sid: FormulaRecord fr = (FormulaRecord) record; row = fr.getRow(); col = fr.getColumn(); if (Double.isNaN(fr.getValue())) { // Formula result is a string that is stored in the next record! findNextStringRecord = true; nextRow = fr.getRow(); nextCol = fr.getColumn(); cellValue = null; } else { cellValue = formatTrackingListener.formatNumberDateCell(fr); } break; case StringRecord.sid: if (findNextStringRecord) { // String for formula StringRecord sr = (StringRecord) record; cellValue = sr.getString(); row = nextRow; col = nextCol; // Resets markers... findNextStringRecord = false; nextRow = -1; nextCol = -1; } break; case LabelRecord.sid: LabelRecord lr = (LabelRecord) record; row = lr.getRow(); col = lr.getColumn(); cellValue = lr.getValue(); break; case LabelSSTRecord.sid: LabelSSTRecord lsstr = (LabelSSTRecord) record; row = lsstr.getRow(); col = lsstr.getColumn(); if (sstRecord == null) { cellValue = "#ERROR(undefined string)"; } else { cellValue = sstRecord.getString(lsstr.getSSTIndex()).toString(); } break; case NoteRecord.sid: NoteRecord nr = (NoteRecord) record; row = nr.getRow(); col = nr.getColumn(); // TODO: Find object to match nrec.getShapeId() cellValue = "#ERROR(TODO)"; break; case NumberRecord.sid: NumberRecord rn = (NumberRecord) record; row = rn.getRow(); col = rn.getColumn(); cellValue = formatTrackingListener.formatNumberDateCell(rn); break; case RKRecord.sid: RKRecord rkr = (RKRecord) record; row = rkr.getRow(); col = rkr.getColumn(); cellValue = "#ERROR(TODO)"; break; default: cellValue = null; } if (row == headersRow) { String cellReference = CellReference.convertNumToColString(col); String name = (headersRow == firstDataRow) ? cellReference : StringUtils.defaultIfBlank(cellValue, cellReference); columnNames.put(name.toLowerCase(), name); columnIndexes.put(name, col); } }
From source file:gobblin.source.jdbc.OracleExtractor.java
@Override public List<Command> getDataMetadata(String schema, String entity, WorkUnit workUnit, List<Predicate> predicateList) throws DataRecordException { log.debug("Build query to extract data"); List<Command> commands = new ArrayList<>(); int fetchSize = this.workUnitState.getPropAsInt( ConfigurationKeys.SOURCE_QUERYBASED_JDBC_RESULTSET_FETCH_SIZE, ConfigurationKeys.DEFAULT_SOURCE_QUERYBASED_JDBC_RESULTSET_FETCH_SIZE); log.info("Setting jdbc resultset fetch size as " + fetchSize); String watermarkFilter = StringUtils.defaultIfBlank(this.concatPredicates(predicateList), EMPTY_CONDITION); String query = this.getExtractSql(); query = query.replace(ConfigurationKeys.DEFAULT_SOURCE_QUERYBASED_WATERMARK_PREDICATE_SYMBOL, watermarkFilter);/*from ww w. j ava 2s. com*/ query = addSampleQueryPart(query); commands.add(getCommand(query, JdbcCommand.JdbcCommandType.QUERY)); commands.add(getCommand(fetchSize, JdbcCommand.JdbcCommandType.FETCHSIZE)); return commands; }
From source file:com.smokejumperit.gradle.report.DependencyLicenseReport.java
protected Collection<ResolvedArtifact> resolveArtifacts(Map<String, String> spec) { try {//from w w w. jav a 2s . com return resolvedArtifactCache.getUnchecked(ImmutableMap.copyOf(spec)); } catch (Exception e) { if (getLogger().isInfoEnabled()) { getLogger().info("Failure to retrieve artifacts for " + spec, e); } else { getLogger().warn("Could not retrieve artifacts for " + spec + " -- " + StringUtils.defaultIfBlank(e.getMessage(), e.getClass().getSimpleName())); } return Collections.emptyList(); } }
From source file:gobblin.source.extractor.extract.jdbc.OracleExtractor.java
@Override public List<Command> getDataMetadata(String schema, String entity, WorkUnit workUnit, List<Predicate> predicateList) throws DataRecordException { log.debug("Build query to extract data"); List<Command> commands = new ArrayList<>(); int fetchSize = this.workUnitState.getPropAsInt( ConfigurationKeys.SOURCE_QUERYBASED_JDBC_RESULTSET_FETCH_SIZE, ConfigurationKeys.DEFAULT_SOURCE_QUERYBASED_JDBC_RESULTSET_FETCH_SIZE); log.info("Setting jdbc resultset fetch size as " + fetchSize); String watermarkFilter = StringUtils.defaultIfBlank(this.concatPredicates(predicateList), EMPTY_CONDITION); String query = this.getExtractSql(); query = query.replace(ConfigurationKeys.DEFAULT_SOURCE_QUERYBASED_WATERMARK_PREDICATE_SYMBOL, watermarkFilter);/*from w w w. ja v a2 s . co m*/ query = addSampleQueryPart(query); commands.add(JdbcExtractor.getCommand(query, JdbcCommand.JdbcCommandType.QUERY)); commands.add(JdbcExtractor.getCommand(fetchSize, JdbcCommand.JdbcCommandType.FETCHSIZE)); return commands; }
From source file:com.xwikisas.xcs.tools.dependenciespackager.PackageXARDependenciesMojo.java
private void toExtension(DefaultLocalExtension extension, Model model) throws ComponentLookupException { extension.setName(getPropertyString(model, MPNAME_NAME, model.getName())); extension.setSummary(getPropertyString(model, MPNAME_SUMMARY, model.getDescription())); extension.setWebsite(getPropertyString(model, MPNAME_WEBSITE, model.getUrl())); // authors//from ww w.j a va 2 s . c o m for (Developer developer : model.getDevelopers()) { URL authorURL = null; if (developer.getUrl() != null) { try { authorURL = new URL(developer.getUrl()); } catch (MalformedURLException e) { // TODO: log ? } } extension.addAuthor(new DefaultExtensionAuthor( StringUtils.defaultIfBlank(developer.getName(), developer.getId()), authorURL)); } // licenses if (!model.getLicenses().isEmpty()) { ExtensionLicenseManager licenseManager = componentManager.getInstance(ExtensionLicenseManager.class); for (License license : model.getLicenses()) { extension.addLicense(getExtensionLicense(license, licenseManager)); } } // features String featuresString = getProperty(model, MPNAME_FEATURES); if (StringUtils.isNotBlank(featuresString)) { featuresString = featuresString.replaceAll("[\r\n]", ""); ConverterManager converter = componentManager.getInstance(ConverterManager.class); extension.setFeatures(converter.<Collection<String>>convert(List.class, featuresString)); } // dependencies for (Dependency mavenDependency : model.getDependencies()) { if (!mavenDependency.isOptional() && (mavenDependency.getScope().equals("compile") || mavenDependency.getScope().equals("runtime"))) { extension.addDependency(new DefaultExtensionDependency( mavenDependency.getGroupId() + ':' + mavenDependency.getArtifactId(), new DefaultVersionConstraint(mavenDependency.getVersion()))); } } }
From source file:cop.raml.utils.Utils.java
public static String defOnBlank(String primary, String secondary) { return StringUtils.defaultIfBlank(primary, StringUtils.defaultIfBlank(secondary, null)); }
From source file:com.crosstreelabs.cognitio.service.mongo.MongoCatalogueService.java
protected DBObject toMongoObject(final CatalogueEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry cannot be null"); }//from www . j a va 2 s.co m if (entry.host == null || StringUtils.isBlank(entry.host.id)) { throw new IllegalArgumentException("Cannot persist catalogue entry without host ref"); } BasicDBObject obj = new BasicDBObject(/*"_id", entry.id*/).append("status", entry.status.toString()) .append("status_reason", StringUtils.defaultIfBlank(entry.status_reason, "")) .append("location", entry.location).append("location_hash", DigestUtils.md5(entry.location)) .append("host", new ObjectId(entry.host.id)) .append("path", StringUtils.defaultIfBlank(entry.path, "")) .append("relocated", entry.relocated.toString()) .append("new_location", StringUtils.defaultIfBlank(entry.newLocation, "")) .append("initial_parent", StringUtils.defaultIfBlank(entry.initialParent, "")) .append("initial_depth", entry.initialDepth) .append("initial_parent_title", StringUtils.defaultIfBlank(entry.initialParentTitle, "")); if (entry.firstSeen != null) { obj.append("first_seen", entry.firstSeen.toDate()); } if (entry.lastVisit != null) { obj.append("last_visit", entry.lastVisit.toDate()); } return obj; }