Wondering if anyone can tell me where/how Hybris is generating versionIDs for orders on amendment etc
Thanks
The Order VersionID is generated in the DefaultOrderHistoryService.createHistorySnapshot(OrderModel) using the KeyGenerator
The versionID is assigned to the order in case of order cancellation, return or replacement.
The full reference to the Service ; de.hybris.platform.orderhistory.impl.DefaultOrderHistoryService
The purpose of maintaining Order History and Order Versioning is to keep track of changes applied to the order which help customer service agents to look what actually happened to a particular order.
OrderHistoryEntry is used to store historical information of order processing. This will not create a new version of original order but can have a reference to an order state snapshot.
OrderHistoryEntryModel entry = modelService.create(OrderHistoryEntryModel.class);
entry.setTimestamp(new Date());
entry.setOrder(processedOrder);
entry.setDescription("fraud check manually passed");
entry.setEmployee( (EmployeeModel)userService.getCurrentUser() );
To keep the previous order state as historical information requires the creation a snapshot of the order before altering the order. This will create a new version of original order. Each snapshot will contain particular versionID.
OrderHistoryService historyService = ..
// create snapshot - not persisted yet !
OrderModel snapshot = historyService.createHistorySnapshot(processedOrder);
The service will produces a deep copy of the original order.
Now we can save this snapshot in OrderHistoryEntryModel as well.
entry.setPreviousOrderVersion(snapshot);
We need to manually persist snapshot
// persist snapshot manually - this is necessary due to historical reasons
historyService.saveHistorySnapshot(snapshot);
Since snapshot is also like order and resides in same table, to fetch all original order, you need to apply {versionID} IS NULL condition as well while fetching orders.
Related
The PrePersistHook offers this method
Optional<ItemModel> execute(ItemModel item);
When implementing the PrePersistHook the changed model is passed to the method. The executing path already open a transaction and it seems that the item is already persisted, but the transaction is not committed, yet.
If I try to get the same Item again from the database with flexible search, it returns the already updated object.
The documentation => https://help.sap.com/viewer/bad9b0b66bac476f8a4a5c4a08e4ab6b/v2005/en-US/028a2af06880407cb4b1c0624693dadd.html
defines that one should not open transactions or create new threads.
But if it is not allowed, how is it possible to get the old version of the Model in a PrePersistHook to perform a validation or perform other check before the changes are persisted?
In our case, we want to create a new version of the OrderModel, but the persisted old version ever already have the old values. We see no opportunity to get the old version in a clean way.
Many standard prepersist hooks always fetch the item again from the database and return Option.empty() in the hook
Best Regards,
Michael.
I found a solution that works for me. I override the DefaultModelEntityService and read the data before it's updated.
I have an array that is saved on the policyPeriod level right now called listOfAdditionalInsured. This list is display on one of the pages in the UI in PC.
The issue that I am having is that each time there is a policy change it will erase the data on that list because it's on the policyPeriod level. I see other arrays in PolicyPeriod that are not deleted during policy change and will appear fine. They look like they are effdated entities.
I am new to this so I am trying to figure out how to keep an array on the policyPeriod level but let it be editable during a change. I have tried putting it on the Policy level but it will change the array for all the transactions if I do it that way. I want each transaction to be able to edit the list in its own way.
Make sure your array entity is an Effective Dated entity and that the effDatedBrachType is PolicyPeriod. Take a look at how PolicyContactRole is implemented and try to do the same.
I want to store information in some activities that are modified versions of activities imported from an existing database (ecoinvent).
I know we can add fields to activities created from scratch (example). (I guess this is because the structure of the database has not yet been defined...) but is there a way of adding it to activities of an already defined database without breaking it?
The way around I found is to add entries to the author dict, which I can easily access later on. e.g.
act['author']['scenario']='myscenario'
but I admit it is not a very elegant solution.
You can just add whatever data you want. Brightway is a (semi-)schemaless database for exactly this reason.
act['foo'] = 'bar'
act.save()
I would like to create work order using escalation once the asset is moved to some other location (like REPAIR) using move/modify. I do understand that we can trigger CREATEWO however I am not sure on how to set the values on some fields in work order like worktype, workact , etc. Also I am unable to pick the correct record which has performed move modify ( unable to fetch the exact record using ASSETTRANS table).
Let me know if anyone has done this before, thanks in advance!
It sounds like you have an Escalation calling an Action that calls the AppAction CREATEWO. Assuming that's correct..
First, create a Relationship in DB Config between the ASSET object and WORKORDER that will find the most recent work order against this asset. You can look at the NEWWORKORDER relationships on WORKORDER and TICKET as an example. For reference, I will assume you name this relationship MYNEWWORKORDER.
Next, create some Actions against the ASSET object that use MYNEWWORKORDER.<ATTRIBUTENAME> in the Parameter/Attribute field, where <ATTRIBUTENAME> is the name of the attribute (e.g. WORKTYPE) you want to supply a value for in the Value field.
Once that is done, create an Action of type Action Group where CREATEWO is the first member and the Actions you just made are the succeeding members.
Finally, update the Escalation to call your new Action Group instead of the numbered one that the Escalation application created for you.
How can I get last created document in couchdb? Maybe some how I can use _changes feature of couchdb? But documentation says, that I only can get list of document, ordered by first created document, ant there is no way to change order.
So how can I get last created document?
You can get the changes feed in descending order as it's also a view.
GET /dbname/_changes?descending=true
You can use limit= as well, so;
GET /dbname/_changes?descending=true&limit=1
will give the latest update.
Your only surefire way to get the last created document is to include a timestamp (created_at or something) with your document. From there, you just need a simple view to output all the docs by their creation date.
I was going to suggest using the last_seq information from the database, but the sequence number changes with every single write, and replication also complicates the matter further.