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:org.apache.fineract.infrastructure.dataqueries.domain.Report.java

public Map<String, Object> update(final JsonCommand command) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>(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);
    }/*w w w .  j  a  v  a2s  . 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.apache.fineract.portfolio.calendar.domain.Calendar.java

public Calendar(final String title, final String description, final String location, final LocalDate startDate,
        final LocalDate endDate, final Integer duration, final Integer typeId, final boolean repeating,
        final String recurrence, final Integer remindById, final Integer firstReminder,
        final Integer secondReminder) {

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(CALENDAR_RESOURCE_NAME);

    final CalendarType calendarType = CalendarType.fromInt(typeId);
    if (calendarType.isCollection() && !repeating) {
        baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue())
                .failWithCodeNoParameterAddedToErrorCode("must.repeat.for.collection.calendar");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/*from  www .ja  v a  2s  .  com*/
    }

    this.title = StringUtils.defaultIfEmpty(title, null);
    this.description = StringUtils.defaultIfEmpty(description, null);
    this.location = StringUtils.defaultIfEmpty(location, null);

    if (null != startDate) {
        this.startDate = startDate.toDateTimeAtStartOfDay().toDate();
    } else {
        this.startDate = null;
    }

    if (null != endDate) {
        this.endDate = endDate.toDateTimeAtStartOfDay().toDate();
    } else {
        this.endDate = null;
    }

    this.duration = duration;
    this.typeId = typeId;
    this.repeating = repeating;
    this.recurrence = StringUtils.defaultIfEmpty(recurrence, null);
    this.remindById = remindById;
    this.firstReminder = firstReminder;
    this.secondReminder = secondReminder;
}

From source file:org.apache.fineract.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.  jav  a 2s .  c o  m

    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;
    }

    return actualChanges;
}

From source file:org.apache.fineract.portfolio.client.data.ClientData.java

private ClientData(final String accountNo, final EnumOptionData status, final CodeValueData subStatus,
        final Long officeId, final String officeName, final Long transferToOfficeId,
        final String transferToOfficeName, final Long id, final String firstname, final String middlename,
        final String lastname, final String fullname, final String displayName, final String externalId,
        final String mobileNo, final LocalDate dateOfBirth, final CodeValueData gender,
        final LocalDate activationDate, final Long imageId, final Long staffId, final String staffName,
        final Collection<OfficeData> allowedOffices, final Collection<GroupGeneralData> groups,
        final Collection<StaffData> staffOptions, final Collection<CodeValueData> narrations,
        final Collection<CodeValueData> genderOptions, final ClientTimelineData timeline,
        final Collection<SavingsProductData> savingProductOptions, final Long savingsProductId,
        final String savingsProductName, final Long savingsAccountId,
        final Collection<SavingsAccountData> savingAccountOptions, final CodeValueData clientType,
        final CodeValueData clientClassification, final Collection<CodeValueData> clientTypeOptions,
        final Collection<CodeValueData> clientClassificationOptions,
        final Collection<CodeValueData> clientNonPersonConstitutionOptions,
        final Collection<CodeValueData> clientNonPersonMainBusinessLineOptions,
        final ClientNonPersonData clientNonPerson, final List<EnumOptionData> clientLegalFormOptions,
        final EnumOptionData legalForm) {
    this.accountNo = accountNo;
    this.status = status;
    if (status != null) {
        this.active = status.getId().equals(300L);
    } else {/*from   ww w.  j av a2s.c om*/
        this.active = null;
    }
    this.subStatus = subStatus;
    this.officeId = officeId;
    this.officeName = officeName;
    this.transferToOfficeId = transferToOfficeId;
    this.transferToOfficeName = transferToOfficeName;
    this.id = id;
    this.firstname = StringUtils.defaultIfEmpty(firstname, null);
    this.middlename = StringUtils.defaultIfEmpty(middlename, null);
    this.lastname = StringUtils.defaultIfEmpty(lastname, null);
    this.fullname = StringUtils.defaultIfEmpty(fullname, null);
    this.displayName = StringUtils.defaultIfEmpty(displayName, null);
    this.externalId = StringUtils.defaultIfEmpty(externalId, null);
    this.mobileNo = StringUtils.defaultIfEmpty(mobileNo, null);
    this.activationDate = activationDate;
    this.dateOfBirth = dateOfBirth;
    this.gender = gender;
    this.clientClassification = clientClassification;
    this.clientType = clientType;
    this.imageId = imageId;
    if (imageId != null) {
        this.imagePresent = Boolean.TRUE;
    } else {
        this.imagePresent = null;
    }
    this.staffId = staffId;
    this.staffName = staffName;

    // associations
    this.groups = groups;

    // template
    this.officeOptions = allowedOffices;
    this.staffOptions = staffOptions;
    this.narrations = narrations;

    this.genderOptions = genderOptions;
    this.clientClassificationOptions = clientClassificationOptions;
    this.clientTypeOptions = clientTypeOptions;

    this.clientNonPersonConstitutionOptions = clientNonPersonConstitutionOptions;
    this.clientNonPersonMainBusinessLineOptions = clientNonPersonMainBusinessLineOptions;
    this.clientLegalFormOptions = clientLegalFormOptions;

    this.timeline = timeline;
    this.savingProductOptions = savingProductOptions;
    this.savingsProductId = savingsProductId;
    this.savingsProductName = savingsProductName;
    this.savingsAccountId = savingsAccountId;
    this.savingAccountOptions = savingAccountOptions;
    this.legalForm = legalForm;
    this.clientNonPersonDetails = clientNonPerson;

}

From source file:org.apache.fineract.portfolio.client.domain.ClientIdentifier.java

private ClientIdentifier(final Client client, final CodeValue documentType, final String documentKey,
        final String description) {
    this.client = client;
    this.documentType = documentType;
    this.documentKey = StringUtils.defaultIfEmpty(documentKey, null);
    this.description = StringUtils.defaultIfEmpty(description, null);
}

From source file:org.apache.fineract.portfolio.client.domain.ClientIdentifier.java

public Map<String, Object> update(final JsonCommand command) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>(7);

    final String documentTypeIdParamName = "documentTypeId";
    if (command.isChangeInLongParameterNamed(documentTypeIdParamName, this.documentType.getId())) {
        final Long newValue = command.longValueOfParameterNamed(documentTypeIdParamName);
        actualChanges.put(documentTypeIdParamName, newValue);
    }//from w w w  . ja  va  2 s. c om

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

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

    return actualChanges;
}

From source file:org.apache.fineract.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;/*  www . j a v  a 2  s .  co m*/
    }

    final String dateFormatAsInput = command.dateFormat();
    final String localeAsInput = command.locale();
    final LocalDate recalculationRestFrequencyDate = command
            .localDateValueOfParameterNamed(LoanProductConstants.recalculationRestFrequencyDateParamName);
    final LocalDate recalculationCompoundingFrequencyDate = command.localDateValueOfParameterNamed(
            LoanProductConstants.recalculationCompoundingFrequencyDateParamName);
    updateLoanInterestRecalculationSettings(recalculationRestFrequencyDate,
            recalculationCompoundingFrequencyDate, command, actualChanges);

    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:org.apache.fineract.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()/*w w  w  . ja  va 2s. 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;
    }

    validateLockinDetails(baseDataValidator);
    esnureOverdraftLimitsSetForOverdraftAccounts();
}

From source file:org.apache.fineract.portfolio.tax.domain.TaxGroup.java

public Map<String, Object> update(final JsonCommand command, final List<TaxGroupMappings> taxGroupMappings) {
    final Map<String, Object> changes = new HashMap<>();

    if (command.isChangeInStringParameterNamed(TaxApiConstants.nameParamName, this.name)) {
        final String newValue = command.stringValueOfParameterNamed(TaxApiConstants.nameParamName);
        changes.put(TaxApiConstants.nameParamName, newValue);
        this.name = StringUtils.defaultIfEmpty(newValue, null);
    }//from w w  w  .j a  v  a  2  s . c om

    List<Long> taxComponentList = new ArrayList<>();
    final List<Map<String, Object>> modifications = new ArrayList<>();

    for (TaxGroupMappings groupMappings : taxGroupMappings) {
        TaxGroupMappings mappings = findOneBy(groupMappings);
        if (mappings == null) {
            this.taxGroupMappings.add(groupMappings);
            taxComponentList.add(groupMappings.getTaxComponent().getId());
        } else {
            mappings.update(groupMappings.getEndDate(), modifications);
        }
    }

    if (!taxComponentList.isEmpty()) {
        changes.put("addComponents", taxComponentList);
    }
    if (!modifications.isEmpty()) {
        changes.put("modifiedComponents", modifications);
    }

    return changes;
}

From source file:org.apache.flume.plugins.KafkaSink.java

/**
 * FlumeSinkSource?Channel???, Sink/*from ww w .  j av a  2s. com*/
 * SinkKafka, Source?Kafka?.
 * Kafka??, ?Sink?Producer,
 * Source???, ??, ???
 */
@Override
public Status process() throws EventDeliveryException {
    Status status = null;

    // Start transaction ?
    Channel ch = getChannel(); //producer.sinks.r.channel
    Transaction txn = ch.getTransaction();
    txn.begin();
    try {
        // This try clause includes whatever Channel operations you want to do
        //Source??Channel,Sink. ??Channel?!
        //Channel??,Source???
        Event event = ch.take();

        String partitionKey = (String) parameters.get(KafkaFlumeConstans.PARTITION_KEY_NAME);
        String encoding = StringUtils.defaultIfEmpty(
                (String) this.parameters.get(KafkaFlumeConstans.ENCODING_KEY_NAME),
                KafkaFlumeConstans.DEFAULT_ENCODING);
        // flume-conf.propertiesproducer.sinks.r.custom.topic.name?
        String topic = Preconditions.checkNotNull(
                (String) this.parameters.get(KafkaFlumeConstans.CUSTOM_TOPIC_KEY_NAME),
                "custom.topic.name is required");

        String eventData = new String(event.getBody(), encoding);

        KeyedMessage<String, String> data;

        // if partition key does'nt exist
        //Kafka??KeyedMessage, ??
        if (StringUtils.isEmpty(partitionKey)) {
            data = new KeyedMessage<String, String>(topic, eventData);
        } else {
            data = new KeyedMessage<String, String>(topic, partitionKey, eventData);
        }

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(
                    "Send Message to Kafka : [" + eventData + "] -- [" + EventHelper.dumpEvent(event) + "]");
        }
        // ???, ?topic?
        producer.send(data);

        // ??
        txn.commit();
        status = Status.READY;
    } catch (Throwable t) {
        txn.rollback();
        status = Status.BACKOFF;

        // re-throw all Errors
        if (t instanceof Error) {
            throw (Error) t;
        }
    } finally {
        txn.close();
    }
    return status;
}