Class BranchMergeService

java.lang.Object
ai.chatur.cortex.core.branch.BranchMergeService

public class BranchMergeService extends Object
Resolves a branch pending review by merging its staged assertions into the default graph or discarding them.
  • Constructor Summary

    Constructors
    Constructor
    Description
    BranchMergeService(org.apache.jena.query.Dataset assertions, BranchRepository branchRepository, ProvenanceRecorder provenanceRecorder)
    Creates the service.
  • Method Summary

    Modifier and Type
    Method
    Description
    approve(String branch)
    Merges the assertions staged on the given branch into the default graph — removing the statements it stages for removal and adding those it stages for addition — closing the provenance activity of the ingestion, recording the reification of every merged statement linked to the activity in the provenance graph and clearing the reifications of every retracted one, and deletes the branch.
    void
    reject(String branch)
    Rejects the given branch, discarding both the assertions it stages for addition and those it stages for removal, if it exists.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BranchMergeService

      public BranchMergeService(org.apache.jena.query.Dataset assertions, BranchRepository branchRepository, ProvenanceRecorder provenanceRecorder)
      Creates the service.
      Parameters:
      assertions - the dataset holding the approved assertions and the staged branches
      branchRepository - guards every operation against an unknown branch
      provenanceRecorder - builds the provenance recorded when a branch is approved
  • Method Details

    • approve

      public MergeResult approve(String branch)
      Merges the assertions staged on the given branch into the default graph — removing the statements it stages for removal and adding those it stages for addition — closing the provenance activity of the ingestion, recording the reification of every merged statement linked to the activity in the provenance graph and clearing the reifications of every retracted one, and deletes the branch.

      Retractions are applied before additions, so an edit that replaces the object of a statement leaves the replacement in place rather than removing it again.

      The novelty diff, the merge, and the branch deletion all happen inside one write transaction on the assertions dataset: TDB2 serializes writers, so two branches can never be approved concurrently, and a failure partway through aborts the whole transaction rather than leaving the data merged while the branch is still pending (which used to risk a second, duplicate prov:Activity on a retried approval). Staged triples that were approved through another branch in the meantime are skipped, and staged retractions of statements another branch already retracted are no-ops, so a statement is never merged or reified twice — this is now guaranteed by that same serialization, rather than a best-effort race with the other branch's approval.

      Parameters:
      branch - the branch name
      Returns:
      what the merge did — the newly approved assertions, empty if every staged triple was approved through another branch in the meantime, and whether anything was retracted — or null if the branch does not exist
    • reject

      public void reject(String branch)
      Rejects the given branch, discarding both the assertions it stages for addition and those it stages for removal, if it exists.
      Parameters:
      branch - the branch name