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:org.localmatters.serializer.writer.XMLWriter.java
/** * @see org.localmatters.serializer.writer.Writer#writeValue(org.localmatters.serializer.serialization.Serialization, java.lang.String, java.lang.Object, org.localmatters.serializer.SerializationContext) *//* ww w . j a v a 2s . c o m*/ public void writeValue(Serialization ser, String name, Object value, SerializationContext ctx) throws SerializationException { ctx.nextLevel(StringUtils.defaultIfEmpty(name, VALUE_LEVEL)); String prefix = getPrefix(ctx); String valueStr = String.valueOf(value); if ((value != null) && (StringUtils.isNotEmpty(valueStr))) { String str = EscapeUtils.escapeXml(valueStr); if (StringUtils.isNotBlank(name)) { write(ctx, prefix).write(ctx, LT_BYTES).write(ctx, name).write(ctx, GT_BYTES).write(ctx, str) .write(ctx, LT_SLASH_BYTES).write(ctx, name).write(ctx, GT_BYTES); } else { write(ctx, str); } } else if (ser.isWriteEmpty() && StringUtils.isNotBlank(name)) { write(ctx, prefix).write(ctx, LT_BYTES).write(ctx, name).write(ctx, SLASH_GT_BYTES); } ctx.previousLevel(); }
From source file:org.marketcetera.photon.internal.strategy.ui.RemoteAgentPropertyPage.java
@Override public boolean performOk() { try {//w ww .j av a2s. c o m StrategyManager.getCurrent().updateAgent(mRemoteAgent, new URI(mURI.getText()), StringUtils.defaultIfEmpty(mUsername.getText(), null), StringUtils.defaultIfEmpty(mPassword.getText(), null)); return true; } catch (URISyntaxException e) { // validation really should already have happened SLF4JLoggerProxy.error(this, e); ErrorDialog.openError(getShell(), null, null, ValidationStatus.error(getInvalidURLMessage(), e)); return false; } }
From source file:org.mifos.application.servicefacade.LoanAccountServiceFacadeWebTier.java
@Override public List<CustomerSearchResultDto> retrieveCustomersThatQualifyForLoans(CustomerSearchDto customerSearchDto) { MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); UserContext userContext = toUserContext(user); try {/*from w ww .java2s .c om*/ List<CustomerSearchResultDto> pagedDetails = new ArrayList<CustomerSearchResultDto>(); QueryResult customerForSavings = new CustomerPersistence() .searchGroupClient(customerSearchDto.getSearchTerm(), userContext.getId()); int position = (customerSearchDto.getPage() - 1) * customerSearchDto.getPageSize(); List<AccountSearchResultsDto> pagedResults = customerForSavings.get(position, customerSearchDto.getPageSize()); int i = 1; for (AccountSearchResultsDto customerBO : pagedResults) { CustomerSearchResultDto customer = new CustomerSearchResultDto(); customer.setCustomerId(customerBO.getClientId()); customer.setBranchName(customerBO.getOfficeName()); customer.setGlobalId(customerBO.getGlobelNo()); customer.setSearchIndex(i); customer.setCenterName(StringUtils.defaultIfEmpty(customerBO.getCenterName(), "--")); customer.setGroupName(StringUtils.defaultIfEmpty(customerBO.getGroupName(), "--")); customer.setClientName(customerBO.getClientName()); pagedDetails.add(customer); i++; } return pagedDetails; } catch (PersistenceException e) { throw new MifosRuntimeException(e); } catch (HibernateSearchException e) { throw new MifosRuntimeException(e); } catch (ConfigurationException e) { throw new MifosRuntimeException(e); } }
From source file:org.mifos.application.servicefacade.SavingsServiceFacadeWebTier.java
@Override public List<CustomerSearchResultDto> retrieveCustomerThatQualifyForSavings( CustomerSearchDto customerSearchDto) { MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); UserContext userContext = toUserContext(user); try {// w ww .j a v a 2 s . co m List<CustomerSearchResultDto> pagedDetails = new ArrayList<CustomerSearchResultDto>(); QueryResult customerForSavings = new CustomerPersistence() .searchCustForSavings(customerSearchDto.getSearchTerm(), userContext.getId()); int position = this.resultsetOffset(customerSearchDto.getPage(), customerSearchDto.getPageSize()); List<AccountSearchResultsDto> pagedResults = customerForSavings.get(position, customerSearchDto.getPageSize()); int i = 1; for (AccountSearchResultsDto customerBO : pagedResults) { CustomerSearchResultDto customer = new CustomerSearchResultDto(); customer.setCustomerId(customerBO.getClientId()); customer.setBranchName(customerBO.getOfficeName()); customer.setGlobalId(customerBO.getGlobelNo()); customer.setSearchIndex(i); customer.setCenterName(StringUtils.defaultIfEmpty(customerBO.getCenterName(), "--")); customer.setGroupName(StringUtils.defaultIfEmpty(customerBO.getGroupName(), "--")); customer.setClientName(customerBO.getClientName()); pagedDetails.add(customer); i++; } return pagedDetails; } catch (PersistenceException e) { throw new MifosRuntimeException(e); } catch (HibernateSearchException e) { throw new MifosRuntimeException(e); } }
From source file:org.mifosplatform.accounting.journalentry.domain.JournalEntry.java
public JournalEntry(final Office office, final GLAccount glAccount, final String currencyCode, final String transactionId, final boolean manualEntry, final Date transactionDate, final Integer type, final BigDecimal amount, final String description, final Integer entityType, final Long entityId, final String referenceNumber, final LoanTransaction loanTransaction, final SavingsAccountTransaction savingsTransaction) { this.office = office; this.glAccount = glAccount; this.reversalJournalEntry = null; this.transactionId = transactionId; this.reversed = false; this.manualEntry = manualEntry; this.transactionDate = transactionDate; this.type = type; this.amount = amount; this.description = StringUtils.defaultIfEmpty(description, null); this.entityType = entityType; this.entityId = entityId; this.referenceNumber = referenceNumber; this.currencyCode = currencyCode; this.loanTransaction = loanTransaction; this.savingsTransaction = savingsTransaction; }
From source file:org.mifosplatform.infrastructure.codes.domain.Code.java
public Map<String, Object> update(final JsonCommand command) { if (this.systemDefined) { throw new SystemDefinedCodeCannotBeChangedException(); }/*from w ww . j av a 2 s .c om*/ final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(1); final String firstnameParamName = "name"; if (command.isChangeInStringParameterNamed(firstnameParamName, this.name)) { final String newValue = command.stringValueOfParameterNamed(firstnameParamName); actualChanges.put(firstnameParamName, newValue); this.name = StringUtils.defaultIfEmpty(newValue, null); } return actualChanges; }
From source file:org.mifosplatform.infrastructure.codes.domain.CodeValue.java
private CodeValue(final Code code, final String label, final int position) { this.code = code; this.label = StringUtils.defaultIfEmpty(label, null); this.position = position; }
From source file:org.mifosplatform.infrastructure.codes.domain.CodeValue.java
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(2); final String labelParamName = CODEVALUE_JSON_INPUT_PARAMS.NAME.getValue(); if (command.isChangeInStringParameterNamed(labelParamName, this.label)) { final String newValue = command.stringValueOfParameterNamed(labelParamName); actualChanges.put(labelParamName, newValue); this.label = StringUtils.defaultIfEmpty(newValue, null); }//from www . j a va 2 s. c o m final String positionParamName = CODEVALUE_JSON_INPUT_PARAMS.POSITION.getValue(); if (command.isChangeInIntegerSansLocaleParameterNamed(positionParamName, this.position)) { final Integer newValue = command.integerValueSansLocaleOfParameterNamed(positionParamName); actualChanges.put(positionParamName, newValue); this.position = newValue.intValue(); } return actualChanges; }
From source file:org.mifosplatform.infrastructure.dataqueries.domain.Report.java
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(8); String paramName = "reportName"; if (command.isChangeInStringParameterNamed(paramName, this.reportName)) { final String newValue = command.stringValueOfParameterNamed(paramName); actualChanges.put(paramName, newValue); this.reportName = StringUtils.defaultIfEmpty(newValue, null); }// ww w . java 2s. c o m paramName = "reportType"; if (command.isChangeInStringParameterNamed(paramName, this.reportType)) { final String newValue = command.stringValueOfParameterNamed(paramName); actualChanges.put(paramName, newValue); this.reportType = StringUtils.defaultIfEmpty(newValue, null); } paramName = "reportSubType"; if (command.isChangeInStringParameterNamed(paramName, this.reportSubType)) { final String newValue = command.stringValueOfParameterNamed(paramName); actualChanges.put(paramName, newValue); this.reportSubType = StringUtils.defaultIfEmpty(newValue, null); } paramName = "reportCategory"; if (command.isChangeInStringParameterNamed(paramName, this.reportCategory)) { final String newValue = command.stringValueOfParameterNamed(paramName); actualChanges.put(paramName, newValue); this.reportCategory = StringUtils.defaultIfEmpty(newValue, null); } paramName = "description"; if (command.isChangeInStringParameterNamed(paramName, this.description)) { final String newValue = command.stringValueOfParameterNamed(paramName); actualChanges.put(paramName, newValue); this.description = StringUtils.defaultIfEmpty(newValue, null); } paramName = "useReport"; if (command.isChangeInBooleanParameterNamed(paramName, this.useReport)) { final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(paramName); actualChanges.put(paramName, newValue); this.useReport = newValue; } paramName = "reportSql"; if (command.isChangeInStringParameterNamed(paramName, this.reportSql)) { final String newValue = command.stringValueOfParameterNamed(paramName); actualChanges.put(paramName, newValue); this.reportSql = StringUtils.defaultIfEmpty(newValue, null); } final String reportParametersParamName = "reportParameters"; if (command.hasParameter(reportParametersParamName)) { final JsonArray jsonArray = command.arrayOfParameterNamed(reportParametersParamName); if (jsonArray != null) { actualChanges.put(reportParametersParamName, command.jsonFragment(reportParametersParamName)); } } validate(); if (!actualChanges.isEmpty()) { if (isCoreReport()) { for (final String key : actualChanges.keySet()) { if (!(key.equals("useReport"))) { throw new PlatformDataIntegrityException( "error.msg.only.use.report.can.be.updated.for.core.report", "Only the Use Report field can be updated for Core Reports", key); } } } } return actualChanges; }
From source file:org.mifosplatform.infrastructure.vendordocumentmanagement.domain.VendorDocument.java
private VendorDocument(final String parentEntityType, final String name, final String fileName, final Long size, final String type, final String location) { this.parentEntityType = StringUtils.defaultIfEmpty(parentEntityType, null); this.name = StringUtils.defaultIfEmpty(name, null); this.fileName = StringUtils.defaultIfEmpty(fileName, null); this.size = size; this.type = StringUtils.defaultIfEmpty(type, null); this.location = StringUtils.defaultIfEmpty(location, null); }