Hi all,
I am implementing changelog functionality for our project and we use A12 relationship. So when user update a linkDocument of a relationship, I want to know its origin value and new value.
I met a problem that I could not retrieve the origin link document when modifying a linkDocument of a relationship.
When MODIFY_LINK is triggered, it trigger the RelationshipLinkAfterUpdateEvent which only contains the relationship and newLinkDocument.
I was trying to find the workaround for this by looking at the events triggered by MODIFY_LINK in order:
DocumentBeforeCreateEvent newLinkDocument
DocumentAfterCreateEvent newLinkDocument
RelationshipLinkAfterUpdateEvent relationship
DocumentBeforeDeleteEvent originLinkDocument
DocumentAfterDeleteEvent originalLinkDocument
But I don’t know how to link the originLinkDocument events with the relationship event together.
Any thought?
Thank you!
Hi @quynh-wintry-root,
If you are using the RelationshipLinkAfterCreateEvent event, please try this:
RelationshipLink link = relationshipLinkAfterCreateEvent .getLink();
DocumentReference sourceRelationshipDocRef = ((RelationshipRole) link.getRoles().values().toArray()[0]).getDocRef();
DocumentReference targetRelationshipDocRef = ((RelationshipRole) link.getRoles().values().toArray()[1]).getDocRef();
Please correct me if I’m wrong.
As far as I understand in the implementation, when MODIFY_LINK, Dataservies creates a new relationship link, and at the same time removes the old one.
I believe we can not do something like comparing between the created relationship link & deleted relationship link. In addition, it doesn’t seem to make perfect sense because the source role or target role can be totally different. Because you are not comparing changes in the same document, then even if you can get the deleted & created link, the comparison may not much meaningful.
However, by listening to DocumentAfterDeleteEvent and RelationshipLinkAfterUpdateEvent, something like the list events of relationship changes can be feasible, e.g.
timestamp A: link removed
timestamp after A: link created
Hi @quynh-wintry-root,
currently, you can not bind these events together, as there is no any identifier for this.
And also, the delete document which is aware of the original document is called after the link update event. So it’s too late.
Thank you all for the replies!
@ben-keen-aspen
I actually want to retrieve the change of the linkDocument link.getLinkDocumentDocRef() not the roles link.getRoles(). But the event only provides the newLinkDocument and not the oldLinkDocument.
@loi-risen-dale
“In addition, it doesn’t seem to make perfect sense because the source role or target role can be totally different” Yes you’re right. But I still believe it makes sense in the current A12 context. From what I observe, when you change the source/target roles, the client will call to DELETE_LINK/ADD_LINK operation instead. And MODIFY_LINK operation only triggers when you change the linkDocument.
And for now, seem like timestamp base is the only possible solution.