List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty
public static String defaultIfEmpty(String str, String defaultStr)
Returns either the passed in String, or if the String is empty or null
, the value of defaultStr
.
From source file:net.ageto.gyrex.impex.persistence.cassandra.storage.CassandraRepositoryImpl.java
/** * Find all logging messages by the give process run id. * //w ww . 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:com.eviware.soapui.support.components.SimpleForm.java
public JComboBox appendComboBox(String label, Object[] values, String tooltip) { JComboBox comboBox = new JComboBox(values); comboBox.setToolTipText(StringUtils.defaultIfEmpty(tooltip, null)); comboBox.getAccessibleContext().setAccessibleDescription(tooltip); append(label, comboBox);//from ww w.j av a 2 s . c om return comboBox; }
From source file:com.eviware.soapui.support.components.SimpleForm.java
public JComboBox appendComboBox(String label, ComboBoxModel model, String tooltip) { JComboBox comboBox = new JComboBox(model); comboBox.setToolTipText(StringUtils.defaultIfEmpty(tooltip, null)); comboBox.getAccessibleContext().setAccessibleDescription(tooltip); append(label, comboBox);/* w w w . j a v a 2 s .c om*/ return comboBox; }
From source file:com.galeoconsulting.leonardinius.rest.service.ScriptRunner.java
private String scriptName(String filename) { return StringUtils.defaultIfEmpty(filename, "<unnamed script>"); }
From source file:com.gst.portfolio.calendar.domain.Calendar.java
public Map<String, Object> update(final JsonCommand command, final Boolean areActiveEntitiesSynced) { final Map<String, Object> actualChanges = new LinkedHashMap<>(9); if (command.isChangeInStringParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.TITLE.getValue(), this.title)) { final String newValue = command .stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.TITLE.getValue()); actualChanges.put(CALENDAR_SUPPORTED_PARAMETERS.TITLE.getValue(), newValue); this.title = StringUtils.defaultIfEmpty(newValue, null); }/*www. j a v a2 s . com*/ if (command.isChangeInStringParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.DESCRIPTION.getValue(), this.description)) { final String newValue = command .stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.DESCRIPTION.getValue()); actualChanges.put(CALENDAR_SUPPORTED_PARAMETERS.DESCRIPTION.getValue(), newValue); this.description = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.LOCATION.getValue(), this.location)) { final String newValue = command .stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.LOCATION.getValue()); actualChanges.put(CALENDAR_SUPPORTED_PARAMETERS.LOCATION.getValue(), newValue); this.location = StringUtils.defaultIfEmpty(newValue, null); } final String dateFormatAsInput = command.dateFormat(); final String localeAsInput = command.locale(); final String startDateParamName = CALENDAR_SUPPORTED_PARAMETERS.START_DATE.getValue(); if (command.isChangeInLocalDateParameterNamed(startDateParamName, getStartDateLocalDate())) { final String valueAsInput = command.stringValueOfParameterNamed(startDateParamName); final LocalDate newValue = command.localDateValueOfParameterNamed(startDateParamName); final LocalDate currentDate = DateUtils.getLocalDateOfTenant(); if (newValue.isBefore(currentDate)) { final String defaultUserMessage = "New meeting effective from date cannot be in past"; throw new CalendarDateException("new.start.date.cannot.be.in.past", defaultUserMessage, newValue, getStartDateLocalDate()); } else if (isStartDateAfter(newValue) && isStartDateBeforeOrEqual(currentDate)) { // new meeting date should be on or after start date or current // date final String defaultUserMessage = "New meeting effective from date cannot be a date before existing meeting start date"; throw new CalendarDateException("new.start.date.before.existing.date", defaultUserMessage, newValue, getStartDateLocalDate()); } else { actualChanges.put(startDateParamName, valueAsInput); actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); this.startDate = newValue.toDate(); } } final String endDateParamName = CALENDAR_SUPPORTED_PARAMETERS.END_DATE.getValue(); if (command.isChangeInLocalDateParameterNamed(endDateParamName, getEndDateLocalDate())) { final String valueAsInput = command.stringValueOfParameterNamed(endDateParamName); actualChanges.put(endDateParamName, valueAsInput); actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); final LocalDate newValue = command.localDateValueOfParameterNamed(endDateParamName); this.endDate = newValue.toDate(); } final String durationParamName = CALENDAR_SUPPORTED_PARAMETERS.DURATION.getValue(); if (command.isChangeInIntegerSansLocaleParameterNamed(durationParamName, this.duration)) { final Integer newValue = command.integerValueSansLocaleOfParameterNamed(durationParamName); actualChanges.put(durationParamName, newValue); this.duration = newValue; } // Do not allow to change calendar type // TODO: AA Instead of throwing an exception, do not allow meeting // calendar type to update. final String typeParamName = CALENDAR_SUPPORTED_PARAMETERS.TYPE_ID.getValue(); if (command.isChangeInIntegerSansLocaleParameterNamed(typeParamName, this.typeId)) { final Integer newValue = command.integerValueSansLocaleOfParameterNamed(typeParamName); final String defaultUserMessage = "Meeting calendar type update is not supported"; final String oldMeeingType = CalendarType.fromInt(this.typeId).name(); final String newMeetingType = CalendarType.fromInt(newValue).name(); throw new CalendarParameterUpdateNotSupportedException("meeting.type", defaultUserMessage, newMeetingType, oldMeeingType); /* * final Integer newValue = * command.integerValueSansLocaleOfParameterNamed(typeParamName); * actualChanges.put(typeParamName, newValue); this.typeId = * newValue; */ } final String repeatingParamName = CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue(); if (command.isChangeInBooleanParameterNamed(repeatingParamName, this.repeating)) { final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(repeatingParamName); actualChanges.put(repeatingParamName, newValue); this.repeating = newValue; } // if repeating is false then update recurrence to NULL if (!this.repeating) this.recurrence = null; final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(CALENDAR_RESOURCE_NAME); final CalendarType calendarType = CalendarType.fromInt(this.typeId); if (calendarType.isCollection() && !this.repeating) { baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue()) .failWithCodeNoParameterAddedToErrorCode("must.repeat.for.collection.calendar"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } final String newRecurrence = Calendar.constructRecurrence(command, this); if (!StringUtils.isBlank(this.recurrence) && !newRecurrence.equalsIgnoreCase(this.recurrence)) { /* * If active entities like JLG loan or RD accounts are synced to the * calendar then do not allow to change meeting frequency */ if (areActiveEntitiesSynced && !CalendarUtils.isFrequencySame(this.recurrence, newRecurrence)) { final String defaultUserMessage = "Update of meeting frequency is not supported"; throw new CalendarParameterUpdateNotSupportedException("meeting.frequency", defaultUserMessage); } /* * If active entities like JLG loan or RD accounts are synced to the * calendar then do not allow to change meeting interval */ if (areActiveEntitiesSynced && !CalendarUtils.isIntervalSame(this.recurrence, newRecurrence)) { final String defaultUserMessage = "Update of meeting interval is not supported"; throw new CalendarParameterUpdateNotSupportedException("meeting.interval", defaultUserMessage); } actualChanges.put("recurrence", newRecurrence); this.recurrence = StringUtils.defaultIfEmpty(newRecurrence, null); } final String remindByParamName = CALENDAR_SUPPORTED_PARAMETERS.REMIND_BY_ID.getValue(); if (command.isChangeInIntegerSansLocaleParameterNamed(remindByParamName, this.remindById)) { final Integer newValue = command.integerValueSansLocaleOfParameterNamed(remindByParamName); actualChanges.put(remindByParamName, newValue); this.remindById = newValue; } final String firstRemindarParamName = CALENDAR_SUPPORTED_PARAMETERS.FIRST_REMINDER.getValue(); if (command.isChangeInIntegerSansLocaleParameterNamed(firstRemindarParamName, this.firstReminder)) { final Integer newValue = command.integerValueSansLocaleOfParameterNamed(firstRemindarParamName); actualChanges.put(firstRemindarParamName, newValue); this.firstReminder = newValue; } final String secondRemindarParamName = CALENDAR_SUPPORTED_PARAMETERS.SECOND_REMINDER.getValue(); if (command.isChangeInIntegerSansLocaleParameterNamed(secondRemindarParamName, this.secondReminder)) { final Integer newValue = command.integerValueSansLocaleOfParameterNamed(secondRemindarParamName); actualChanges.put(secondRemindarParamName, newValue); this.secondReminder = newValue; } final String timeFormat = command .stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.Time_Format.getValue()); final String time = CALENDAR_SUPPORTED_PARAMETERS.MEETING_TIME.getValue(); if (command.isChangeInTimeParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.MEETING_TIME.getValue(), this.meetingtime, timeFormat)) { final String newValue = command .stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.MEETING_TIME.getValue()); actualChanges.put(CALENDAR_SUPPORTED_PARAMETERS.MEETING_TIME.getValue(), newValue); LocalDateTime timeInLocalDateTimeFormat = command.localTimeValueOfParameterNamed(time); if (timeInLocalDateTimeFormat != null) { this.meetingtime = timeInLocalDateTimeFormat.toDate(); } } return actualChanges; }
From source file:com.opengamma.integration.coppclark.CoppClarkExchangeFileReader.java
private static String optionalStringField(String field) { return StringUtils.defaultIfEmpty(field, null); }
From source file:com.adaptris.core.services.jdbc.JdbcMapInsert.java
protected String columnBookend() { return StringUtils.defaultIfEmpty(CharUtils.toString(getColumnBookendCharacter()), ""); }
From source file:com.opengamma.integration.coppclark.CoppClarkExchangeFileReader.java
private static String requiredStringField(String field) { if (field.isEmpty()) { throw new OpenGammaRuntimeException("required field is empty"); }/*from www . j a v a 2 s . com*/ return StringUtils.defaultIfEmpty(field, null); }
From source file:com.gst.infrastructure.core.api.JsonCommand.java
public String stringValueOfParameterNamed(final String parameterName) { final String value = this.fromApiJsonHelper.extractStringNamed(parameterName, this.parsedCommand); return StringUtils.defaultIfEmpty(value, ""); }
From source file:com.redhat.rhn.domain.user.UserFactory.java
/** * Insert a new user. Invalid to call this when updating a user * TODO: mmccune fill out the other fields in the user object. * @param usr The object we are commiting. * @param addr The address to add to the User * @param orgId Org this new user is a member of * @return User The freshly commited user. *///from ww w . j a va 2s . co m protected User addNewUser(User usr, Address addr, Long orgId) { LOG.debug("Starting addNewUser"); if (addr != null) { usr.setAddress1(addr.getAddress1()); usr.setAddress2(addr.getAddress2()); usr.setCity(addr.getCity()); usr.setCountry(addr.getCountry()); usr.setFax(addr.getFax()); usr.setIsPoBox(addr.getIsPoBox()); usr.setPhone(addr.getPhone()); usr.setState(addr.getState()); usr.setZip(addr.getZip()); } // save the user CallableMode m = ModeFactory.getCallableMode("User_queries", "create_new_user"); Map<String, Object> inParams = new HashMap<String, Object>(); Map<String, Integer> outParams = new HashMap<String, Integer>(); // Can't add the orgId to the object until the User has been // successfully added to the DB. Doing so will mean that if // there are problems, the user won't be rolled back properly. inParams.put("orgId", orgId); inParams.put("login", usr.getLogin()); inParams.put("password", usr.getPassword()); inParams.put("contactId", null); inParams.put("prefix", StringUtils.defaultString(usr.getPrefix(), " ")); inParams.put("fname", StringUtils.defaultString(usr.getFirstNames(), null)); inParams.put("lname", StringUtils.defaultString(usr.getLastName(), null)); inParams.put("genqual", null); inParams.put("parentCompany", StringUtils.defaultIfEmpty(usr.getCompany(), null)); inParams.put("company", StringUtils.defaultIfEmpty(usr.getCompany(), null)); inParams.put("title", StringUtils.defaultIfEmpty(usr.getTitle(), null)); inParams.put("phone", StringUtils.defaultIfEmpty(usr.getPhone(), null)); inParams.put("fax", StringUtils.defaultIfEmpty(usr.getFax(), null)); inParams.put("email", StringUtils.defaultIfEmpty(usr.getEmail(), null)); inParams.put("pin", new Integer(0)); inParams.put("fnameOl", " "); inParams.put("lnameOl", " "); inParams.put("addr1", StringUtils.defaultIfEmpty(usr.getAddress1(), null)); inParams.put("addr2", StringUtils.defaultIfEmpty(usr.getAddress2(), null)); inParams.put("addr3", " "); inParams.put("city", StringUtils.defaultIfEmpty(usr.getCity(), null)); inParams.put("state", StringUtils.defaultIfEmpty(usr.getState(), null)); inParams.put("zip", StringUtils.defaultIfEmpty(usr.getZip(), null)); inParams.put("country", StringUtils.defaultIfEmpty(usr.getCountry(), null)); inParams.put("altFnames", null); inParams.put("altLnames", null); inParams.put("contCall", "N"); inParams.put("contMail", "N"); inParams.put("contFax", "N"); inParams.put("contEmail", "N"); outParams.put("userId", new Integer(Types.NUMERIC)); Map<String, Object> result = m.execute(inParams, outParams); Org org = OrgFactory.lookupById(orgId); if (org != null) { usr.setOrg(org); } long userId = ((Long) result.get("userId")).longValue(); // We need to lookup the User to make sure that the Address in the // User object has an Id and that the User has an org_id. User retval = lookupById(new Long(userId)); saveObject(retval); return retval; }