Example usage for org.apache.commons.lang StringUtils defaultIfEmpty

List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfEmpty.

Prototype

public static String defaultIfEmpty(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is empty or null, the value of defaultStr.

Usage

From source file:com.healthcit.cacure.businessdelegates.GeneratedModuleDataManager.java

/**
 * Updates the GeneratedFormDataDetail object with 
 * randomly generated unique key field values.
 *//*from  w ww . j av a2s.  com*/
private Map<String, JSONObject> generateUniqueKey(GeneratedModuleDataDetail form,
        Map<String, JSONObject> lastUniqueKey, String entityId, int moduleId, int entityModuleId) {
    log.debug("Generating unique key..............");
    log.debug("==========================");
    // Get the list of "unique-per-entity" fields
    List<Map<String, Object>> uniquePerEntityQuestions = form.retrieveUniquePerEntityQuestions();

    // Get the list of "unique-per-all-modules" fields
    List<Map<String, Object>> uniquePerAllModulesQuestions = form.retrieveUniquePerAllModulesQuestions();

    // Get the list of "unique-per-entity-modules" fields
    List<Map<String, Object>> uniquePerEntityModulesQuestions = form.retrieveUniquePerEntityModulesQuestions();

    // Generate the answer values: first for "unique-per-entity", then "unique-per-entity-modules", then "unique-per-all-modules"
    Map<String, JSONObject> uniqueKey = new HashMap<String, JSONObject>();

    // Get the map of answer-value to "unique-per-entity" question fields
    Map<Object, List<Object>> uniquePerEntityCombinations = form.getUniquePerEntityQuestionCombinations();

    // Get the map of answer-value to "unique-per-all-modules" question fields
    Map<Object, List<Object>> uniquePerAllModulesCombinations = form
            .getUniquePerAllModuleQuestionCombinations();

    // Get the map of answer-value to "unique-per-entity-modules" question fields
    Map<Object, List<Object>> uniquePerEntityModulesCombinations = form
            .getUniquePerEntityModuleQuestionCombinations();

    // Generate the answer values: first for "unique-per-entity", then "unique-per-entity-modules", then "unique-per-all-modules"
    uniqueKey.clear();

    // First, generate the unique answer values for "unique-per-entity" fields
    buildNewKey(uniqueKey, lastUniqueKey, uniquePerEntityQuestions, uniquePerEntityCombinations, entityId);

    // Then, generate the unique answer values for "unique-per-entity-modules" fields
    buildNewKey(uniqueKey, lastUniqueKey, uniquePerEntityModulesQuestions, uniquePerEntityModulesCombinations,
            entityModuleId);

    // Then, generate the unique answer values for "unique-per-all-modules" fields
    buildNewKey(uniqueKey, lastUniqueKey, uniquePerAllModulesQuestions, uniquePerAllModulesCombinations,
            moduleId);

    // Debugging
    log.debug("Generated unique key fields: " + (uniqueKey.isEmpty() ? "NONE" : ""));
    for (Map.Entry<String, JSONObject> entry : uniqueKey.entrySet()) {
        log.debug("==========Key: " + entry.getKey());
        log.debug("==========Text:"
                + StringUtils.defaultIfEmpty((String) entry.getValue().get(ANSWERVALUE_TEXT), "")
                + "==========Value:" + entry.getValue().get(ANSWERVALUE_VALUE).toString());
    }

    return uniqueKey;
}

From source file:com.manydesigns.portofino.actions.admin.page.PageAdminAction.java

@Button(list = "testUserPermissions", key = "test")
@RequiresPermissions(level = AccessLevel.DEVELOP)
public Resolution testUserPermissions() {
    testUserId = StringUtils.defaultIfEmpty(testUserId, null);
    PortofinoRealm portofinoRealm = ShiroUtils.getPortofinoRealm();
    PrincipalCollection principalCollection;
    if (!StringUtils.isEmpty(testUserId)) {
        Serializable user = portofinoRealm.getUserById(testUserId);
        principalCollection = new SimplePrincipalCollection(user, "realm");
    } else {//  w  w w  .  ja v  a 2  s. c o  m
        principalCollection = null;
    }
    Permissions permissions = SecurityLogic.calculateActualPermissions(getPageInstance());
    testedAccessLevel = AccessLevel.NONE;
    testedPermissions = new HashSet<String>();

    SecurityManager securityManager = SecurityUtils.getSecurityManager();

    for (AccessLevel level : AccessLevel.values()) {
        if (level.isGreaterThanOrEqual(testedAccessLevel) && SecurityLogic.hasPermissions(
                portofinoConfiguration, permissions, securityManager, principalCollection, level)) {
            testedAccessLevel = level;
        }
    }
    String[] supportedPermissions = getSupportedPermissions();
    if (supportedPermissions != null) {
        for (String permission : supportedPermissions) {
            boolean permitted = SecurityLogic.hasPermissions(portofinoConfiguration, permissions,
                    securityManager, principalCollection, testedAccessLevel, permission);
            if (permitted) {
                testedPermissions.add(permission);
            }
        }
    }

    return pagePermissions();
}

From source file:com.evolveum.midpoint.gui.api.util.WebComponentUtil.java

public static <C extends Containerable> String getDisplayName(PrismContainerValue<C> prismContainerValue) {
    if (prismContainerValue == null) {
        return "ContainerPanel.containerProperties";
    }//from w  w w  .  ja va  2  s .  c om

    if (prismContainerValue.canRepresent(AssignmentType.class)) {
        AssignmentType assignmentType = (AssignmentType) prismContainerValue.asContainerable();
        if (assignmentType.getTargetRef() != null) {
            ObjectReferenceType assignemntTargetRef = assignmentType.getTargetRef();
            return getName(assignemntTargetRef) + " - "
                    + normalizeRelation(assignemntTargetRef.getRelation()).getLocalPart();
        } else {
            return "AssignmentTypeDetailsPanel.containerTitle";
        }
    }

    if (prismContainerValue.canRepresent(ExclusionPolicyConstraintType.class)) {
        ExclusionPolicyConstraintType exclusionConstraint = (ExclusionPolicyConstraintType) prismContainerValue
                .asContainerable();
        String displayName = (exclusionConstraint.getName() != null ? exclusionConstraint.getName()
                : exclusionConstraint.asPrismContainerValue().getParent().getPath().last()) + " - "
                + StringUtils.defaultIfEmpty(getName(exclusionConstraint.getTargetRef()), "");
        return StringUtils.isNotEmpty(displayName) ? displayName : "Not defined exclusion name";
    }
    if (prismContainerValue.canRepresent(AbstractPolicyConstraintType.class)) {
        AbstractPolicyConstraintType constraint = (AbstractPolicyConstraintType) prismContainerValue
                .asContainerable();
        String displayName = (StringUtils.isEmpty(constraint.getName())
                ? (constraint.asPrismContainerValue().getParent().getPath().last())
                : constraint.getName())
                + (StringUtils.isEmpty(constraint.getDescription()) ? ""
                        : (" - " + constraint.getDescription()));
        return displayName;
    }
    Class<C> cvalClass = prismContainerValue.getCompileTimeClass();
    if (cvalClass != null) {
        return cvalClass.getSimpleName() + ".details";
    }
    return "ContainerPanel.containerProperties";
}

From source file:com.gst.portfolio.savings.domain.SavingsAccount.java

public void modifyApplication(final JsonCommand command, final Map<String, Object> actualChanges,
        final DataValidatorBuilder baseDataValidator) {

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) {
        baseDataValidator.reset()/* www. j a va 2  s  . c  o  m*/
                .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state");
        return;
    }

    final String localeAsInput = command.locale();
    final String dateFormat = command.dateFormat();

    if (command.isChangeInLocalDateParameterNamed(SavingsApiConstants.submittedOnDateParamName,
            getSubmittedOnLocalDate())) {
        final LocalDate newValue = command
                .localDateValueOfParameterNamed(SavingsApiConstants.submittedOnDateParamName);
        final String newValueAsString = command
                .stringValueOfParameterNamed(SavingsApiConstants.submittedOnDateParamName);
        actualChanges.put(SavingsApiConstants.submittedOnDateParamName, newValueAsString);
        actualChanges.put(SavingsApiConstants.localeParamName, localeAsInput);
        actualChanges.put(SavingsApiConstants.dateFormatParamName, dateFormat);
        this.submittedOnDate = newValue.toDate();
    }

    if (command.isChangeInStringParameterNamed(SavingsApiConstants.accountNoParamName, this.accountNumber)) {
        final String newValue = command.stringValueOfParameterNamed(SavingsApiConstants.accountNoParamName);
        actualChanges.put(SavingsApiConstants.accountNoParamName, newValue);
        this.accountNumber = StringUtils.defaultIfEmpty(newValue, null);
    }

    if (command.isChangeInStringParameterNamed(SavingsApiConstants.externalIdParamName, this.externalId)) {
        final String newValue = command.stringValueOfParameterNamed(SavingsApiConstants.externalIdParamName);
        actualChanges.put(SavingsApiConstants.externalIdParamName, newValue);
        this.externalId = StringUtils.defaultIfEmpty(newValue, null);
    }

    if (command.isChangeInLongParameterNamed(SavingsApiConstants.clientIdParamName, clientId())) {
        final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.clientIdParamName);
        actualChanges.put(SavingsApiConstants.clientIdParamName, newValue);
    }

    if (command.isChangeInLongParameterNamed(SavingsApiConstants.groupIdParamName, groupId())) {
        final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.groupIdParamName);
        actualChanges.put(SavingsApiConstants.groupIdParamName, newValue);
    }

    if (command.isChangeInLongParameterNamed(SavingsApiConstants.productIdParamName, this.product.getId())) {
        final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.productIdParamName);
        actualChanges.put(SavingsApiConstants.productIdParamName, newValue);
    }

    if (command.isChangeInLongParameterNamed(SavingsApiConstants.fieldOfficerIdParamName,
            hasSavingsOfficerId())) {
        final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.fieldOfficerIdParamName);
        actualChanges.put(SavingsApiConstants.fieldOfficerIdParamName, newValue);
    }

    if (command.isChangeInBigDecimalParameterNamed(SavingsApiConstants.nominalAnnualInterestRateParamName,
            this.nominalAnnualInterestRate)) {
        final BigDecimal newValue = command
                .bigDecimalValueOfParameterNamed(SavingsApiConstants.nominalAnnualInterestRateParamName);
        actualChanges.put(SavingsApiConstants.nominalAnnualInterestRateParamName, newValue);
        actualChanges.put("locale", localeAsInput);
        this.nominalAnnualInterestRate = newValue;
    }

    if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestCompoundingPeriodTypeParamName,
            this.interestCompoundingPeriodType)) {
        final Integer newValue = command
                .integerValueOfParameterNamed(SavingsApiConstants.interestCompoundingPeriodTypeParamName);
        this.interestCompoundingPeriodType = newValue != null
                ? SavingsCompoundingInterestPeriodType.fromInt(newValue).getValue()
                : newValue;
        actualChanges.put(SavingsApiConstants.interestCompoundingPeriodTypeParamName,
                this.interestCompoundingPeriodType);
    }

    if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestPostingPeriodTypeParamName,
            this.interestPostingPeriodType)) {
        final Integer newValue = command
                .integerValueOfParameterNamed(SavingsApiConstants.interestPostingPeriodTypeParamName);
        this.interestPostingPeriodType = newValue != null
                ? SavingsPostingInterestPeriodType.fromInt(newValue).getValue()
                : newValue;
        actualChanges.put(SavingsApiConstants.interestPostingPeriodTypeParamName,
                this.interestPostingPeriodType);
    }

    if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestCalculationTypeParamName,
            this.interestCalculationType)) {
        final Integer newValue = command
                .integerValueOfParameterNamed(SavingsApiConstants.interestCalculationTypeParamName);
        this.interestCalculationType = newValue != null
                ? SavingsInterestCalculationType.fromInt(newValue).getValue()
                : newValue;
        actualChanges.put(SavingsApiConstants.interestCalculationTypeParamName, this.interestCalculationType);
    }

    if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestCalculationDaysInYearTypeParamName,
            this.interestCalculationDaysInYearType)) {
        final Integer newValue = command
                .integerValueOfParameterNamed(SavingsApiConstants.interestCalculationDaysInYearTypeParamName);
        this.interestCalculationDaysInYearType = newValue != null
                ? SavingsInterestCalculationDaysInYearType.fromInt(newValue).getValue()
                : newValue;
        actualChanges.put(SavingsApiConstants.interestCalculationDaysInYearTypeParamName,
                this.interestCalculationDaysInYearType);
    }

    if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(
            SavingsApiConstants.minRequiredOpeningBalanceParamName, this.minRequiredOpeningBalance)) {
        final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(
                SavingsApiConstants.minRequiredOpeningBalanceParamName);
        actualChanges.put(SavingsApiConstants.minRequiredOpeningBalanceParamName, newValue);
        actualChanges.put("locale", localeAsInput);
        this.minRequiredOpeningBalance = Money.of(this.currency, newValue).getAmount();
    }

    if (command.isChangeInIntegerParameterNamedDefaultingZeroToNull(
            SavingsApiConstants.lockinPeriodFrequencyParamName, this.lockinPeriodFrequency)) {
        final Integer newValue = command.integerValueOfParameterNamedDefaultToNullIfZero(
                SavingsApiConstants.lockinPeriodFrequencyParamName);
        actualChanges.put(SavingsApiConstants.lockinPeriodFrequencyParamName, newValue);
        actualChanges.put("locale", localeAsInput);
        this.lockinPeriodFrequency = newValue;
    }

    if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.lockinPeriodFrequencyTypeParamName,
            this.lockinPeriodFrequencyType)) {
        final Integer newValue = command
                .integerValueOfParameterNamed(SavingsApiConstants.lockinPeriodFrequencyTypeParamName);
        actualChanges.put(SavingsApiConstants.lockinPeriodFrequencyTypeParamName, newValue);
        this.lockinPeriodFrequencyType = newValue != null
                ? SavingsPeriodFrequencyType.fromInt(newValue).getValue()
                : newValue;
    }

    // set period type to null if frequency is null
    if (this.lockinPeriodFrequency == null) {
        this.lockinPeriodFrequencyType = null;
    }

    if (command.isChangeInBooleanParameterNamed(withdrawalFeeForTransfersParamName,
            this.withdrawalFeeApplicableForTransfer)) {
        final boolean newValue = command
                .booleanPrimitiveValueOfParameterNamed(withdrawalFeeForTransfersParamName);
        actualChanges.put(withdrawalFeeForTransfersParamName, newValue);
        this.withdrawalFeeApplicableForTransfer = newValue;
    }

    // charges
    final String chargesParamName = "charges";
    if (command.hasParameter(chargesParamName)) {
        final JsonArray jsonArray = command.arrayOfParameterNamed(chargesParamName);
        if (jsonArray != null) {
            actualChanges.put(chargesParamName, command.jsonFragment(chargesParamName));
        }
    }

    if (command.isChangeInBooleanParameterNamed(allowOverdraftParamName, this.allowOverdraft)) {
        final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(allowOverdraftParamName);
        actualChanges.put(allowOverdraftParamName, newValue);
        this.allowOverdraft = newValue;
    }

    if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(overdraftLimitParamName,
            this.overdraftLimit)) {
        final BigDecimal newValue = command
                .bigDecimalValueOfParameterNamedDefaultToNullIfZero(overdraftLimitParamName);
        actualChanges.put(overdraftLimitParamName, newValue);
        actualChanges.put(localeParamName, localeAsInput);
        this.overdraftLimit = newValue;
    }

    if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(
            nominalAnnualInterestRateOverdraftParamName, this.nominalAnnualInterestRateOverdraft)) {
        final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(
                nominalAnnualInterestRateOverdraftParamName);
        actualChanges.put(nominalAnnualInterestRateOverdraftParamName, newValue);
        actualChanges.put(localeParamName, localeAsInput);
        this.nominalAnnualInterestRateOverdraft = newValue;
    }

    if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(
            minOverdraftForInterestCalculationParamName, this.minOverdraftForInterestCalculation)) {
        final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(
                minOverdraftForInterestCalculationParamName);
        actualChanges.put(minOverdraftForInterestCalculationParamName, newValue);
        actualChanges.put(localeParamName, localeAsInput);
        this.minOverdraftForInterestCalculation = newValue;
    }

    if (!this.allowOverdraft) {
        this.overdraftLimit = null;
        this.nominalAnnualInterestRateOverdraft = null;
        this.minOverdraftForInterestCalculation = null;
    }

    if (command.isChangeInBooleanParameterNamed(enforceMinRequiredBalanceParamName,
            this.enforceMinRequiredBalance)) {
        final boolean newValue = command
                .booleanPrimitiveValueOfParameterNamed(enforceMinRequiredBalanceParamName);
        actualChanges.put(enforceMinRequiredBalanceParamName, newValue);
        this.enforceMinRequiredBalance = newValue;
    }

    if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(minRequiredBalanceParamName,
            this.minRequiredBalance)) {
        final BigDecimal newValue = command
                .bigDecimalValueOfParameterNamedDefaultToNullIfZero(minRequiredBalanceParamName);
        actualChanges.put(minRequiredBalanceParamName, newValue);
        actualChanges.put(localeParamName, localeAsInput);
        this.minRequiredBalance = newValue;
    }

    if (command.isChangeInBooleanParameterNamed(withHoldTaxParamName, this.withHoldTax)) {
        final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(withHoldTaxParamName);
        actualChanges.put(withHoldTaxParamName, newValue);
        this.withHoldTax = newValue;
        if (this.withHoldTax && this.taxGroup == null) {
            baseDataValidator.reset().parameter(withHoldTaxParamName)
                    .failWithCode("not.supported.for.this.account");
        }
    }

    validateLockinDetails(baseDataValidator);
    esnureOverdraftLimitsSetForOverdraftAccounts();
}

From source file:com.gst.portfolio.loanaccount.domain.Loan.java

public Map<String, Object> loanApplicationModification(final JsonCommand command,
        final Set<LoanCharge> possiblyModifedLoanCharges,
        final Set<LoanCollateral> possiblyModifedLoanCollateralItems, final AprCalculator aprCalculator,
        boolean isChargesModified) {

    final Map<String, Object> actualChanges = this.loanRepaymentScheduleDetail
            .updateLoanApplicationAttributes(command, aprCalculator);
    if (!actualChanges.isEmpty()) {
        final boolean recalculateLoanSchedule = !(actualChanges.size() == 1
                && actualChanges.containsKey("inArrearsTolerance"));
        actualChanges.put("recalculateLoanSchedule", recalculateLoanSchedule);
        isChargesModified = true;/*from  w w  w .  java 2  s .c  o  m*/
    }

    final String dateFormatAsInput = command.dateFormat();
    final String localeAsInput = command.locale();

    final String accountNoParamName = "accountNo";
    if (command.isChangeInStringParameterNamed(accountNoParamName, this.accountNumber)) {
        final String newValue = command.stringValueOfParameterNamed(accountNoParamName);
        actualChanges.put(accountNoParamName, newValue);
        this.accountNumber = StringUtils.defaultIfEmpty(newValue, null);
    }

    final String createSiAtDisbursementParameterName = "createStandingInstructionAtDisbursement";
    if (command.isChangeInBooleanParameterNamed(createSiAtDisbursementParameterName,
            shouldCreateStandingInstructionAtDisbursement())) {
        final Boolean valueAsInput = command
                .booleanObjectValueOfParameterNamed(createSiAtDisbursementParameterName);
        actualChanges.put(createSiAtDisbursementParameterName, valueAsInput);
        this.createStandingInstructionAtDisbursement = valueAsInput;
    }

    final String externalIdParamName = "externalId";
    if (command.isChangeInStringParameterNamed(externalIdParamName, this.externalId)) {
        final String newValue = command.stringValueOfParameterNamed(externalIdParamName);
        actualChanges.put(externalIdParamName, newValue);
        this.externalId = StringUtils.defaultIfEmpty(newValue, null);
    }

    // add clientId, groupId and loanType changes to actual changes

    final String clientIdParamName = "clientId";
    final Long clientId = this.client == null ? null : this.client.getId();
    if (command.isChangeInLongParameterNamed(clientIdParamName, clientId)) {
        final Long newValue = command.longValueOfParameterNamed(clientIdParamName);
        actualChanges.put(clientIdParamName, newValue);
    }

    // FIXME: AA - We may require separate api command to move loan from one
    // group to another
    final String groupIdParamName = "groupId";
    final Long groupId = this.group == null ? null : this.group.getId();
    if (command.isChangeInLongParameterNamed(groupIdParamName, groupId)) {
        final Long newValue = command.longValueOfParameterNamed(groupIdParamName);
        actualChanges.put(groupIdParamName, newValue);
    }

    final String productIdParamName = "productId";
    if (command.isChangeInLongParameterNamed(productIdParamName, this.loanProduct.getId())) {
        final Long newValue = command.longValueOfParameterNamed(productIdParamName);
        actualChanges.put(productIdParamName, newValue);
        actualChanges.put("recalculateLoanSchedule", true);
    }

    final String isFloatingInterestRateParamName = "isFloatingInterestRate";
    if (command.isChangeInBooleanParameterNamed(isFloatingInterestRateParamName, this.isFloatingInterestRate)) {
        final Boolean newValue = command.booleanObjectValueOfParameterNamed(isFloatingInterestRateParamName);
        actualChanges.put(isFloatingInterestRateParamName, newValue);
        this.isFloatingInterestRate = newValue;
    }

    final String interestRateDifferentialParamName = "interestRateDifferential";
    if (command.isChangeInBigDecimalParameterNamed(interestRateDifferentialParamName,
            this.interestRateDifferential)) {
        final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(interestRateDifferentialParamName);
        actualChanges.put(interestRateDifferentialParamName, newValue);
        this.interestRateDifferential = newValue;
    }

    Long existingFundId = null;
    if (this.fund != null) {
        existingFundId = this.fund.getId();
    }
    final String fundIdParamName = "fundId";
    if (command.isChangeInLongParameterNamed(fundIdParamName, existingFundId)) {
        final Long newValue = command.longValueOfParameterNamed(fundIdParamName);
        actualChanges.put(fundIdParamName, newValue);
    }

    Long existingLoanOfficerId = null;
    if (this.loanOfficer != null) {
        existingLoanOfficerId = this.loanOfficer.getId();
    }
    final String loanOfficerIdParamName = "loanOfficerId";
    if (command.isChangeInLongParameterNamed(loanOfficerIdParamName, existingLoanOfficerId)) {
        final Long newValue = command.longValueOfParameterNamed(loanOfficerIdParamName);
        actualChanges.put(loanOfficerIdParamName, newValue);
    }

    Long existingLoanPurposeId = null;
    if (this.loanPurpose != null) {
        existingLoanPurposeId = this.loanPurpose.getId();
    }
    final String loanPurposeIdParamName = "loanPurposeId";
    if (command.isChangeInLongParameterNamed(loanPurposeIdParamName, existingLoanPurposeId)) {
        final Long newValue = command.longValueOfParameterNamed(loanPurposeIdParamName);
        actualChanges.put(loanPurposeIdParamName, newValue);
    }

    final String strategyIdParamName = "transactionProcessingStrategyId";
    if (command.isChangeInLongParameterNamed(strategyIdParamName, this.transactionProcessingStrategy.getId())) {
        final Long newValue = command.longValueOfParameterNamed(strategyIdParamName);
        actualChanges.put(strategyIdParamName, newValue);
    }

    final String submittedOnDateParamName = "submittedOnDate";
    if (command.isChangeInLocalDateParameterNamed(submittedOnDateParamName, getSubmittedOnDate())) {
        final String valueAsInput = command.stringValueOfParameterNamed(submittedOnDateParamName);
        actualChanges.put(submittedOnDateParamName, valueAsInput);
        actualChanges.put("dateFormat", dateFormatAsInput);
        actualChanges.put("locale", localeAsInput);

        final LocalDate newValue = command.localDateValueOfParameterNamed(submittedOnDateParamName);
        this.submittedOnDate = newValue.toDate();
    }

    final String expectedDisbursementDateParamName = "expectedDisbursementDate";
    if (command.isChangeInLocalDateParameterNamed(expectedDisbursementDateParamName,
            getExpectedDisbursedOnLocalDate())) {
        final String valueAsInput = command.stringValueOfParameterNamed(expectedDisbursementDateParamName);
        actualChanges.put(expectedDisbursementDateParamName, valueAsInput);
        actualChanges.put("dateFormat", dateFormatAsInput);
        actualChanges.put("locale", localeAsInput);
        actualChanges.put("recalculateLoanSchedule", true);

        final LocalDate newValue = command.localDateValueOfParameterNamed(expectedDisbursementDateParamName);
        this.expectedDisbursementDate = newValue.toDate();
        removeFirstDisbursementTransaction();
    }

    final String repaymentsStartingFromDateParamName = "repaymentsStartingFromDate";
    if (command.isChangeInLocalDateParameterNamed(repaymentsStartingFromDateParamName,
            getExpectedFirstRepaymentOnDate())) {
        final String valueAsInput = command.stringValueOfParameterNamed(repaymentsStartingFromDateParamName);
        actualChanges.put(repaymentsStartingFromDateParamName, valueAsInput);
        actualChanges.put("dateFormat", dateFormatAsInput);
        actualChanges.put("locale", localeAsInput);
        actualChanges.put("recalculateLoanSchedule", true);

        final LocalDate newValue = command.localDateValueOfParameterNamed(repaymentsStartingFromDateParamName);
        if (newValue != null) {
            this.expectedFirstRepaymentOnDate = newValue.toDate();
        } else {
            this.expectedFirstRepaymentOnDate = null;
        }
    }

    final String syncDisbursementParameterName = "syncDisbursementWithMeeting";
    if (command.isChangeInBooleanParameterNamed(syncDisbursementParameterName,
            isSyncDisbursementWithMeeting())) {
        final Boolean valueAsInput = command.booleanObjectValueOfParameterNamed(syncDisbursementParameterName);
        actualChanges.put(syncDisbursementParameterName, valueAsInput);
        this.syncDisbursementWithMeeting = valueAsInput;
    }

    final String interestChargedFromDateParamName = "interestChargedFromDate";
    if (command.isChangeInLocalDateParameterNamed(interestChargedFromDateParamName,
            getInterestChargedFromDate())) {
        final String valueAsInput = command.stringValueOfParameterNamed(interestChargedFromDateParamName);
        actualChanges.put(interestChargedFromDateParamName, valueAsInput);
        actualChanges.put("dateFormat", dateFormatAsInput);
        actualChanges.put("locale", localeAsInput);
        actualChanges.put("recalculateLoanSchedule", true);

        final LocalDate newValue = command.localDateValueOfParameterNamed(interestChargedFromDateParamName);
        if (newValue != null) {
            this.interestChargedFromDate = newValue.toDate();
        } else {
            this.interestChargedFromDate = null;
        }
    }

    // the comparison should be done with the tenant date
    // (DateUtils.getLocalDateOfTenant()) and not the server date (new
    // LocalDate())
    if (getSubmittedOnDate().isAfter(DateUtils.getLocalDateOfTenant())) {
        final String errorMessage = "The date on which a loan is submitted cannot be in the future.";
        throw new InvalidLoanStateTransitionException("submittal", "cannot.be.a.future.date", errorMessage,
                getSubmittedOnDate());
    }

    if (!(this.client == null)) {
        if (getSubmittedOnDate().isBefore(this.client.getActivationLocalDate())) {
            final String errorMessage = "The date on which a loan is submitted cannot be earlier than client's activation date.";
            throw new InvalidLoanStateTransitionException("submittal",
                    "cannot.be.before.client.activation.date", errorMessage, getSubmittedOnDate());
        }
    } else if (!(this.group == null)) {
        if (getSubmittedOnDate().isBefore(this.group.getActivationLocalDate())) {
            final String errorMessage = "The date on which a loan is submitted cannot be earlier than groups's activation date.";
            throw new InvalidLoanStateTransitionException("submittal", "cannot.be.before.group.activation.date",
                    errorMessage, getSubmittedOnDate());
        }
    }

    if (getSubmittedOnDate().isAfter(getExpectedDisbursedOnLocalDate())) {
        final String errorMessage = "The date on which a loan is submitted cannot be after its expected disbursement date: "
                + getExpectedDisbursedOnLocalDate().toString();
        throw new InvalidLoanStateTransitionException("submittal", "cannot.be.after.expected.disbursement.date",
                errorMessage, getSubmittedOnDate(), getExpectedDisbursedOnLocalDate());
    }

    final String chargesParamName = "charges";

    if (isChargesModified) {
        actualChanges.put(chargesParamName, getLoanCharges(possiblyModifedLoanCharges));
        actualChanges.put("recalculateLoanSchedule", true);
    }

    final String collateralParamName = "collateral";
    if (command.parameterExists(collateralParamName)) {

        if (!possiblyModifedLoanCollateralItems.equals(this.collateral)) {
            actualChanges.put(collateralParamName,
                    listOfLoanCollateralData(possiblyModifedLoanCollateralItems));
        }
    }

    final String loanTermFrequencyParamName = "loanTermFrequency";
    if (command.isChangeInIntegerParameterNamed(loanTermFrequencyParamName, this.termFrequency)) {
        final Integer newValue = command.integerValueOfParameterNamed(loanTermFrequencyParamName);
        actualChanges.put(externalIdParamName, newValue);
        this.termFrequency = newValue;
    }

    final String loanTermFrequencyTypeParamName = "loanTermFrequencyType";
    if (command.isChangeInIntegerParameterNamed(loanTermFrequencyTypeParamName, this.termPeriodFrequencyType)) {
        final Integer newValue = command.integerValueOfParameterNamed(loanTermFrequencyTypeParamName);
        final PeriodFrequencyType newTermPeriodFrequencyType = PeriodFrequencyType.fromInt(newValue);
        actualChanges.put(loanTermFrequencyTypeParamName, newTermPeriodFrequencyType.getValue());
        this.termPeriodFrequencyType = newValue;
    }

    final String principalParamName = "principal";
    if (command.isChangeInBigDecimalParameterNamed(principalParamName, this.approvedPrincipal)) {
        final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(principalParamName);
        this.approvedPrincipal = newValue;
    }

    if (command.isChangeInBigDecimalParameterNamed(principalParamName, this.proposedPrincipal)) {
        final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(principalParamName);
        this.proposedPrincipal = newValue;
    }

    if (loanProduct.isMultiDisburseLoan()) {
        updateDisbursementDetails(command, actualChanges);
        if (command.isChangeInBigDecimalParameterNamed(LoanApiConstants.maxOutstandingBalanceParameterName,
                this.maxOutstandingLoanBalance)) {
            this.maxOutstandingLoanBalance = command
                    .bigDecimalValueOfParameterNamed(LoanApiConstants.maxOutstandingBalanceParameterName);
        }
        final JsonArray disbursementDataArray = command
                .arrayOfParameterNamed(LoanApiConstants.disbursementDataParameterName);

        if (disbursementDataArray == null || disbursementDataArray.size() == 0) {
            final String errorMessage = "For this loan product, disbursement details must be provided";
            throw new MultiDisbursementDataRequiredException(LoanApiConstants.disbursementDataParameterName,
                    errorMessage);
        }
        if (disbursementDataArray.size() > loanProduct.maxTrancheCount()) {
            final String errorMessage = "Number of tranche shouldn't be greter than "
                    + loanProduct.maxTrancheCount();
            throw new ExceedingTrancheCountException(LoanApiConstants.disbursementDataParameterName,
                    errorMessage, loanProduct.maxTrancheCount(), disbursementDetails.size());
        }
    } else {
        this.disbursementDetails.clear();
    }

    if (loanProduct.isMultiDisburseLoan() || loanProduct.canDefineInstallmentAmount()) {
        if (command.isChangeInBigDecimalParameterNamed(LoanApiConstants.emiAmountParameterName,
                this.fixedEmiAmount)) {
            this.fixedEmiAmount = command
                    .bigDecimalValueOfParameterNamed(LoanApiConstants.emiAmountParameterName);
            actualChanges.put(LoanApiConstants.emiAmountParameterName, this.fixedEmiAmount);
            actualChanges.put("recalculateLoanSchedule", true);
        }
    } else {
        this.fixedEmiAmount = null;
    }

    return actualChanges;
}

From source file:jp.primecloud.auto.service.impl.InstanceServiceImpl.java

/**
 * // w  w w  .j  av  a  2s.  c  o m
 *
 * ??????????
 *
 * ?configKey??????????
 * ??????
 * ?configKey?????(?????????)?
 * ??"default"?????"default"?
 * ???????????????
 * ??
 *
 * @param securityGroups ????
 * @param configKey config.properties???
 * @return
 */
protected String setSecurityGroup(List<SecurityGroupDto> securityGroups, String configKey) {

    String groupName = null;
    String defaultSecurityGroup = StringUtils.defaultIfEmpty(Config.getProperty(configKey), "default");

    // ?
    if (!defaultSecurityGroup.equals("default")) {
        for (SecurityGroupDto securityGroup : securityGroups) {
            if (defaultSecurityGroup.equals(securityGroup.getGroupName())) {
                groupName = securityGroup.getGroupName();
                break;
            }
        }
    }

    // ?("groupName == null"????)
    if (groupName == null) {
        for (SecurityGroupDto securityGroup : securityGroups) {
            if ("default".equals(securityGroup.getGroupName())) {
                groupName = securityGroup.getGroupName();
                break;
            }
        }
    }

    // ?
    if (groupName == null && securityGroups.size() > 0) {
        groupName = securityGroups.get(0).getGroupName();
    }
    return groupName;
}

From source file:net.sourceforge.subsonic.controller.HomeController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();

    Player player = playerService.getPlayer(request, response);

    User user = securityService.getCurrentUser(request);
    UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
    if (user.isAdminRole() && settingsService.isGettingStartedEnabled()) {
        return new ModelAndView(new RedirectView("gettingStarted.view"));
    }/*from   w w  w  .j  a  v  a  2  s.com*/

    if (!libraryBrowserService.hasArtists()) {
        return new ModelAndView(new RedirectView("settings.view"));
    }

    String listType = request.getParameter("listType");
    String listGroup = request.getParameter("listGroup");
    String listUsers = StringUtils.defaultIfEmpty(request.getParameter("listUsers"),
            userSettings.isViewStatsForAllUsers() ? "all" : "current");
    String query = StringUtils.trimToNull(request.getParameter("query"));
    int page = "random".equals(listType) ? 0 : toInt(request.getParameter("page"), 0);
    String lastFmUsername = "current".equals(listUsers) || "topartists".equals(listType)
            || "recommended".equals(listType) ? userSettings.getLastFmUsername() : null;

    if (listType == null) {
        String defaultHomeView = userSettings.getDefaultHomeView();
        if (defaultHomeView != null) {
            int index;
            if ((index = defaultHomeView.indexOf('+')) != -1) {
                listType = defaultHomeView.substring(0, index);
                listGroup = defaultHomeView.substring(index + 1);
            } else {
                listType = defaultHomeView;
            }
        } else {
            listType = "newest";
        }
    }
    if (listGroup == null) {
        listGroup = "topartists".equals(listType) ? "3month" : "Albums";
    }

    if ("topartists".equals(listType) || "recommended".equals(listType) || "Artists".equals(listGroup)) {
        setArtists(listType, listGroup, query, page, userSettings, lastFmUsername, map);
    } else if ("newest".equals(listType) || "Albums".equals(listGroup)) {
        setAlbums(player, listType, query, page, userSettings, lastFmUsername, map);
    } else if ("Songs".equals(listGroup)) {
        setSongs(listType, query, page, userSettings, lastFmUsername, map);
    }

    map.put("player", player);
    map.put("welcomeTitle", settingsService.getWelcomeTitle());
    map.put("welcomeSubtitle", settingsService.getWelcomeSubtitle());
    map.put("welcomeMessage", settingsService.getWelcomeMessage());
    map.put("isIndexCreated", libraryUpdateService.isIndexCreated());
    map.put("listType", listType);
    map.put("listGroup", listGroup);
    map.put("listUsers", listUsers);
    map.put("user", user);
    map.put("lastFmUser", userSettings.getLastFmUsername());

    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);

    return result;
}

From source file:net.vnpttech.collection.openacs.poller.TR069ONTPoller.java

public WanServiceObject addPPPoEWanService_ethernet(String serviceName, String username, String password,
        int vlanMux802_1Priority, int vlanMuxID, boolean ipV4Enabled, boolean ipV6Enabled, boolean natEnabled,
        boolean firewallEnabled, String modelName, String connectionId, int wanIndex) throws Exception {
    Layer2InterfaceObject layer2 = addLayer2LanObjByVersion(modelName);
    //add wan interface
    serviceName = StringUtils.defaultIfEmpty(serviceName, "pppoe_veip0");
    WanServiceObject returnVl = addPPPoEWanService(layer2, serviceName, username, password,
            vlanMux802_1Priority, vlanMuxID, ipV4Enabled, ipV6Enabled, natEnabled, firewallEnabled,
            connectionId, wanIndex);/*from w  w  w. ja v  a 2s  . c om*/
    return returnVl;
}

From source file:net.ymate.framework.commons.QRCodeHelper.java

/**
 * @param content      ?/*from www. j  a  va2 s . c om*/
 * @param characterSet ?UTF-8
 * @param width        ?
 * @param height       ?
 * @param margin       ??3
 * @param level        ?
 * @return ?
 * @throws WriterException ?
 */
public static QRCodeHelper create(String content, String characterSet, int width, int height, int margin,
        ErrorCorrectionLevel level) throws WriterException {
    Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
    //?
    hints.put(EncodeHintType.CHARACTER_SET, StringUtils.defaultIfEmpty(characterSet, "UTF-8"));
    //        // ...
    //        hints.put(EncodeHintType.MAX_SIZE, 298);
    //        hints.put(EncodeHintType.MIN_SIZE, 235);
    hints.put(EncodeHintType.MARGIN, margin <= 0 ? 3 : margin);
    //QR?H
    if (level != null) {
        hints.put(EncodeHintType.ERROR_CORRECTION, level);
    }
    //??
    return new QRCodeHelper(
            new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints));
}

From source file:net.ymate.framework.commons.QRCodeHelper.java

/**
 * @param format ?//from  w w w .  j ava2s.  c o  m
 * @return ??PNG
 */
public QRCodeHelper setFormat(String format) {
    this.__format = StringUtils.defaultIfEmpty(format, "png");
    return this;
}