- CpsDataUpdatedEvent createCpsDataUpdatedEvent(final String dataspaceName, final String anchorName) {
- final var dataNode = cpsDataService
- .getDataNode(dataspaceName, anchorName, "/", FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
- final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
- return toCpsDataUpdatedEvent(anchor, dataNode);
+ /**
+ * Generates CPS Data Updated event. If observedTimestamp is not provided, then current timestamp is used.
+ *
+ * @param anchor anchor
+ * @param observedTimestamp observedTimestamp
+ * @param operation operation
+ * @return CpsDataUpdatedEvent
+ */
+ public CpsDataUpdatedEvent createCpsDataUpdatedEvent(final Anchor anchor,
+ final OffsetDateTime observedTimestamp, final Operation operation) {
+ final var dataNode = (operation == Operation.DELETE) ? null :
+ cpsDataService.getDataNode(anchor.getDataspaceName(), anchor.getName(),
+ "/", FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
+ return toCpsDataUpdatedEvent(anchor, dataNode, observedTimestamp, operation);