Page 1 of 1

override JPA annotations attribute values

Posted: Mon Sep 08, 2014 1:00 am
by sharma
Hi phillip,

@Column(name = "DATE_CREATED", updatable = false)
@Temporal(TemporalType.TIMESTAMP)
@AdminPresentation(friendlyName = "Auditable_Date_Created", order = 1000,
tab = Presentation.Tab.Name.Audit, tabOrder = Presentation.Tab.Order.Audit,
group = "Auditable_Audit", groupOrder = 1000,
readOnly = true)
protected Date dateCreated;

i want to override dateCreated value when i place an order. i am not able to override datecreated value b'coz of updateable =false.
My problem is :--
i added one product to cart on the date of sep 1st then i placed an order on the date of sep 5th.In UI level i have to show order creation date when he/she placed an order.


@phillip, Please help on this.. :)

Re: override JPA annotations attribute values

Posted: Mon Sep 08, 2014 7:25 am
by phillipuniverse
That is not the property for when the order was submitted. That's when the order was originally created, meaning when the user added the first item to the order.

You are looking for the submitDate property on Order. This is already being set on the order once the order has completed the checkout workflow.

Re: override JPA annotations attribute values

Posted: Mon Sep 08, 2014 1:41 pm
by sharma
@phillip, I agree with you.

but , if order is cancel or return then which date i have to consider either create date or submit date or update date .
we want to show when order is cancel/return and also we have to show when order is created.

help me on this issue.

Re: override JPA annotations attribute values

Posted: Mon Sep 08, 2014 2:05 pm
by phillipuniverse
The Broadleaf Order domain in the open source framework is not designed to deal with OMS concerns like when the order was cancelled or returned. Of the dates that are on Order, this is how they are used:

create date - when the order is first created, meaning when a user first added an item to their cart (thus triggering an order creation)
update date - when the last time anything about the order changed (repriced, added a new item, etc)
submit date - when the item was checked out

None of those properties are designed for cancellation or returns. We have an OMS module in our enterprise offering that extends this and adds the concept of a FulfillmentOrder that is designed to do returns and cancellations off of. If you want to build it yourself, you will need to add properties likes cancellation or return date.

Re: override JPA annotations attribute values

Posted: Wed Sep 10, 2014 1:13 am
by sharma
@phillip,

i extend orderimpl entity.In that entity i specified below like this.

@EntityListeners(value = { CustomAuditableListener.class, OrderPersistedEntityListener.class })
@ExcludeSuperclassListeners

i create one JPA listener for controlling of update time stamp. i specified logic below like this.

Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");

if(!(entity instanceof NullOrderImpl)){
CustomOrderEntity custOrder=(CustomOrderEntity)entity;
if(custOrder.getStatus() == CustomOrderStatus.SUBMITTED || custOrder.getStatus() == CustomOrderStatus.PAYMENT_COMPLETED || custOrder.getStatus() == CustomOrderStatus.IN_PAYMENT){
setAuditValueTemporal(temporalField, auditable);
}
}

is it correct way or not?

help me on this issue.

Re: override JPA annotations attribute values

Posted: Wed Sep 10, 2014 12:50 pm
by phillipuniverse
The dateUpdated field should get updated already. Why would you need to customize the auditable listeners? If you re-persist an order, that dateUpdated field will always be updated.

Unless you were trying to update your custom 'dateReturned' field or something then an auditable listener like that makes sense. But it seems like the code that you wrote below essentially duplicates the functionality that is already there.

I think that you should add a new field onto CustomOrderEntity (which I assume extends from OrderImpl) and then perhaps update that field within this auditable listener indicating when it was returned or whatever.

Re: override JPA annotations attribute values

Posted: Thu Sep 11, 2014 1:09 am
by sharma
@phillip,

i agree with you. what i am going do is i will create one JPA listener, in that jpa listener i will stop to update 'updateedtimestamp' . i will update 'updatedtimestamp' manually.

other wise i will create one more time stamp.

which one is better way?

Re: override JPA annotations attribute values

Posted: Sat Sep 13, 2014 12:30 pm
by sharma
@phillip,

May i have your skype id.

Re: override JPA annotations attribute values

Posted: Sat Sep 13, 2014 2:26 pm
by phillipuniverse
May i have your skype id.


No. If you require more immediate support than we can give on the forums, we are more than happy to start a formal support discussion. Email us at support AT broadleafcommerce.com if you would like more information on what we can offer.