Example usage for org.apache.commons.lang SerializationUtils clone

List of usage examples for org.apache.commons.lang SerializationUtils clone

Introduction

In this page you can find the example usage for org.apache.commons.lang SerializationUtils clone.

Prototype

public static Object clone(Serializable object) 

Source Link

Document

Deep clone an Object using serialization.

This is many times slower than writing clone methods by hand on all objects in your object graph.

Usage

From source file:org.yes.cart.payment.impl.TestExtFormPaymentGatewayImpl.java

/**
 * {@inheritDoc}
 */
public Payment authorizeCapture(final Payment paymentIn) {
    return (Payment) SerializationUtils.clone(paymentIn);
}

From source file:org.yes.cart.payment.impl.TestExtFormPaymentGatewayImpl.java

/**
 * {@inheritDoc}/*from  w ww.j a v a2 s.co  m*/
 */
public Payment refund(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(REFUND);
    payment.setTransactionReferenceId(UUID.randomUUID().toString());
    payment.setTransactionAuthorizationCode(UUID.randomUUID().toString());

    final String responseCode = gatewayConfig.containsKey(REFUND_RESPONSE_CODE_PARAM_KEY)
            ? gatewayConfig.get(REFUND_RESPONSE_CODE_PARAM_KEY).getValue()
            : Payment.PAYMENT_STATUS_MANUAL_PROCESSING_REQUIRED;

    final CallbackResult res = getExternalCallbackResult(new HashMap<String, String>() {
        {
            put(REFUND_RESPONSE_CODE_PARAM_KEY, responseCode);
        }
    });

    payment.setTransactionGatewayLabel(getLabel());
    payment.setTransactionOperationResultCode(responseCode);
    payment.setPaymentProcessorResult(res.getStatus());
    payment.setPaymentProcessorBatchSettlement(false);
    return payment;
}

From source file:org.yes.cart.payment.impl.TestPaymentGatewayImpl.java

/**
 * {@inheritDoc}// ww w . ja v  a 2  s. c  o  m
 */
public Payment authorize(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(AUTH);
    if (isParameterActivated(AUTH_FAIL) || isParameterActivated(AUTH_FAIL_NO + getAuthNum())
            || isParameterActivated(AUTH_FAIL_NO + payment.getPaymentAmount().toPlainString())) {
        payment.setTransactionOperationResultCode("EXTERNAL_ERROR_CODE");
        payment.setTransactionOperationResultMessage("Card rejected exception. Authorize failed for "
                + getAuthNum() + "@" + payment.getPaymentAmount().toPlainString());
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_FAILED);
        payment.setPaymentProcessorBatchSettlement(false);
    } else if (isParameterActivated(PROCESSING) || isParameterActivated(PROCESSING_NO + getAuthNum())
            || isParameterActivated(PROCESSING_NO + payment.getPaymentAmount().toPlainString())) {
        payment.setTransactionReferenceId(UUID.randomUUID().toString());
        payment.setTransactionAuthorizationCode(UUID.randomUUID().toString());
        payment.setTransactionOperationResultCode("EXTERNAL_OK");
        payment.setTransactionOperationResultMessage(
                "Authorize processing for " + getAuthNum() + "@" + payment.getPaymentAmount().toPlainString());
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_PROCESSING);
        payment.setPaymentProcessorBatchSettlement(false);
    } else {
        payment.setTransactionReferenceId(UUID.randomUUID().toString());
        payment.setTransactionAuthorizationCode(UUID.randomUUID().toString());
        payment.setTransactionOperationResultCode("EXTERNAL_OK");
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_OK);
        payment.setPaymentProcessorBatchSettlement(false);
    }
    authNum++;

    return payment;
}

From source file:org.yes.cart.payment.impl.TestPaymentGatewayImpl.java

/**
 * {@inheritDoc}//from  w w w . j a va2 s.com
 */
public Payment authorizeCapture(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(AUTH_CAPTURE);
    if (isParameterActivated(AUTH_CAPTURE_FAIL)
            || isParameterActivated(AUTH_CAPTURE_FAIL_NO + payment.getPaymentAmount().toPlainString())) {

        payment.setTransactionOperationResultCode("EXTERNAL_ERROR_CODE");
        payment.setTransactionOperationResultMessage("Card rejected exception. Authorize-capture failed for "
                + payment.getPaymentAmount().toPlainString());
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_FAILED);
        payment.setPaymentProcessorBatchSettlement(false);

    } else if (isParameterActivated(PROCESSING)
            || isParameterActivated(PROCESSING_NO + payment.getPaymentAmount().toPlainString())) {

        payment.setTransactionReferenceId(UUID.randomUUID().toString());
        payment.setTransactionAuthorizationCode(UUID.randomUUID().toString());
        payment.setTransactionOperationResultCode("EXTERNAL_OK");
        payment.setTransactionOperationResultMessage(
                "Authorize-capture processing for " + payment.getPaymentAmount().toPlainString());
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_PROCESSING);
        payment.setPaymentProcessorBatchSettlement(false);

    } else {
        payment.setTransactionReferenceId(UUID.randomUUID().toString());
        payment.setTransactionAuthorizationCode(UUID.randomUUID().toString());

        payment.setTransactionGatewayLabel(getLabel());
        payment.setTransactionOperationResultCode("OK");

        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_OK);

        payment.setPaymentProcessorBatchSettlement(!isParameterActivated(UNSETTLED)
                && !isParameterActivated(UNSETTLED_NO + payment.getPaymentAmount().toPlainString()));
    }
    return payment;

}

From source file:org.yes.cart.payment.impl.TestPaymentGatewayImpl.java

/**
 * {@inheritDoc}/*from w ww  .ja  v a  2  s  .co m*/
 */
public Payment reverseAuthorization(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(REVERSE_AUTH);
    if (isParameterActivated(REVERSE_AUTH_FAIL)
            || isParameterActivated(REVERSE_AUTH_FAIL_NO + payment.getPaymentAmount().toPlainString())) {

        payment.setTransactionOperationResultCode("EXTERNAL_ERROR_CODE");
        payment.setTransactionOperationResultMessage(
                "Card rejected exception. Reverse authorize for " + payment.getPaymentAmount().toPlainString());
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_FAILED);
        payment.setPaymentProcessorBatchSettlement(false);

    } else {

        payment.setTransactionReferenceId(UUID.randomUUID().toString());
        payment.setTransactionGatewayLabel(getLabel());
        payment.setTransactionOperationResultCode("REVERSE_AUTH_OK");
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_OK);
        payment.setPaymentProcessorBatchSettlement(false);

    }

    return payment;
}

From source file:org.yes.cart.payment.impl.TestPaymentGatewayImpl.java

/**
 * {@inheritDoc}//from  ww w.  j  av a  2s. co  m
 */
public Payment capture(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(CAPTURE);
    if (isParameterActivated(CAPTURE_FAIL)
            || isParameterActivated(CAPTURE_FAIL_NO + payment.getPaymentAmount().toPlainString())) {
        payment.setTransactionOperationResultCode("EXTERNAL_ERROR_CODE");
        payment.setTransactionOperationResultMessage(
                "Card rejected exception. Capture for " + payment.getPaymentAmount().toPlainString());
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_FAILED);
        payment.setPaymentProcessorBatchSettlement(false);
    } else if (isParameterActivated(PROCESSING)
            || isParameterActivated(PROCESSING_NO + payment.getPaymentAmount().toPlainString())) {
        payment.setTransactionReferenceId(UUID.randomUUID().toString());
        payment.setTransactionAuthorizationCode(UUID.randomUUID().toString());
        payment.setTransactionOperationResultCode("EXTERNAL_OK");
        payment.setTransactionOperationResultMessage(
                "Capture processing for " + payment.getPaymentAmount().toPlainString());
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_PROCESSING);
        payment.setPaymentProcessorBatchSettlement(false);
    } else {
        payment.setTransactionReferenceId(UUID.randomUUID().toString());
        payment.setTransactionGatewayLabel(getLabel());
        payment.setTransactionOperationResultCode("OK");
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_OK);
        payment.setPaymentProcessorBatchSettlement(!isParameterActivated(UNSETTLED)
                && !isParameterActivated(UNSETTLED_NO + payment.getPaymentAmount().toPlainString()));
    }
    return payment;

}

From source file:org.yes.cart.payment.impl.TestPaymentGatewayImpl.java

/**
 * {@inheritDoc}/*from w  w  w  . j  a v a2  s. c  om*/
 */
public Payment voidCapture(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(VOID_CAPTURE);
    if (isParameterActivated(VOID_CAPTURE_FAIL)
            || isParameterActivated(VOID_CAPTURE_FAIL_NO + payment.getPaymentAmount().toPlainString())) {
        payment.setTransactionOperationResultCode("EXTERNAL_ERROR_CODE");
        payment.setTransactionOperationResultMessage(
                "Card rejected exception. Void Capture for " + payment.getPaymentAmount().toPlainString());
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_FAILED);
        payment.setPaymentProcessorBatchSettlement(false);
    } else {
        payment.setTransactionReferenceId(UUID.randomUUID().toString());
        payment.setTransactionGatewayLabel(getLabel());
        payment.setTransactionOperationResultCode("OK");
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_OK);
        payment.setPaymentProcessorBatchSettlement(false);
    }
    return payment;
}

From source file:org.yes.cart.payment.impl.TestPaymentGatewayImpl.java

/**
 * {@inheritDoc}// www. java  2s .  c o  m
 */
public Payment refund(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(REFUND);
    if (isParameterActivated(REFUND_FAIL)
            || isParameterActivated(REFUND_FAIL_NO + payment.getPaymentAmount().toPlainString())) {
        payment.setTransactionOperationResultCode("EXTERNAL_ERROR_CODE");
        payment.setTransactionOperationResultMessage(
                "Card rejected exception. Refund for " + payment.getPaymentAmount().toPlainString());
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_FAILED);
        payment.setPaymentProcessorBatchSettlement(false);
    } else {
        payment.setTransactionReferenceId(UUID.randomUUID().toString());
        payment.setTransactionGatewayLabel(getLabel());
        payment.setTransactionOperationResultCode("OK");
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_OK);
        payment.setPaymentProcessorBatchSettlement(false);
    }
    return payment;
}

From source file:org.yes.cart.service.payment.impl.PaymentProcessorImpl.java

/**
 * Create list of payment to authorize.//from w w w .  ja v a 2 s  .  c  om
 *
 * @param order                order
 * @param params               parameters
 * @param transactionOperation operation in term of payment processor
 * @param forceSinglePaymentIn flag is true for authCapture operation, when payment gateway not supports several payments per
 *                             order
 * @return list of  payments with details
 */
public List<Payment> createPaymentsToAuthorize(final CustomerOrder order, final boolean forceSinglePaymentIn,
        final Map params, final String transactionOperation) {

    Assert.notNull(order, "Customer order expected");

    final boolean forceSinglePayment = forceSinglePaymentIn || params.containsKey("forceSinglePayment");

    final Payment templatePayment = fillPaymentPrototype(order,
            getPaymentGateway().createPaymentPrototype(transactionOperation, params), transactionOperation,
            getPaymentGateway().getLabel());

    final List<Payment> rez = new ArrayList<Payment>();
    if (forceSinglePayment
            || !getPaymentGateway().getPaymentGatewayFeatures().isSupportAuthorizePerShipment()) {

        final List<CustomerOrderPayment> existing = customerOrderPaymentService.findBy(order.getOrdernum(),
                null, Payment.PAYMENT_STATUS_OK, transactionOperation);
        if (existing.isEmpty()) {

            Payment payment = (Payment) SerializationUtils.clone(templatePayment);
            for (CustomerOrderDelivery delivery : order.getDelivery()) {
                fillPayment(order, delivery, payment, true);
            }
            rez.add(payment);

        }

    } else {
        for (CustomerOrderDelivery delivery : order.getDelivery()) {
            final List<CustomerOrderPayment> existing = customerOrderPaymentService.findBy(order.getOrdernum(),
                    delivery.getDeliveryNum(), Payment.PAYMENT_STATUS_OK, transactionOperation);
            if (existing.isEmpty()) {
                Payment payment = (Payment) SerializationUtils.clone(templatePayment);
                fillPayment(order, delivery, payment, false);
                rez.add(payment);
            }
        }
    }
    return rez;
}

From source file:org.yes.cart.web.support.service.impl.ShippingServiceFacadeImpl.java

private List<Carrier> deepCopyCarriers(final List<Carrier> cached) {

    final List<Carrier> carriers = new ArrayList<Carrier>(cached.size());
    for (final Carrier cache : cached) {

        carriers.add((Carrier) SerializationUtils.clone(cache));

    }//from   w  w w  .j  av a2 s.co m

    return carriers;
}