Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Update Tracking

This document describes how the backend services should use to view to detect changes in records.

Motivation

Given that we want to work on Views of data, we want to be able to monitor when an object View has changed. We say that an object View has changed if any of the objects in the View have changed.

States in Fedora get special treatment for a view. A View is considered Active if all objects are Active. A View is considered Deleted if the entry object is Deleted. In all other combinations the View is considered Inactive.

We want to be able to return all Views in a given Collection for a given State that have been modified after a given Time. To do this, we maintain a database of Views that is updated on all changes of an object.

Maintaining state

Whenever one of the components of a View is changed, the whole View counts as updated. As such, any services that subscribe to the View in any way need to be notified. If there is a search index for the Views, and one is updated, its state in the index must be recomputed.

The problem arrives when trying to do this. The View system is designed to ease the computing of a View when knowing the Entry object. The reverse is finding the Views, ie. the Entry objects, that have this data object in their View. Rather than encoding this information in the model, we chose to keep an external record of all the views.

The external record will be SQL based, or something similar. It will have two tables.

The first table, ENTRIES, will have these columns

  • entryPid: This is the pid of the entry object
  • viewAngle: This is the viewangle
  • state: This is the fedora object state
  • dateForChange: This is the timestamp when this row was created
  • collectionPid: This is the collection this entry object is part of
  • contentModelPid: This is the content model that marked this object as an entry object in this view angle

EntryPid, viewAngle and State will form an unique key.

To explain the reasoning: Each Entry Object can be an entry object for multiple viewAngles. If the object state is changed, the old entry should remain. As such, each entry object can result in many rows.

The second table, OBJECTS, will have these columns

  • objectPid: The pid of this object
  • entryPid: The pid of the entry object that includes this object
  • viewAngle: The name of the view angle by which the entry object includes this object

Finding Changed objects

To find changed objects we will ask for a set of objects with the following criteria

  • collectionPid
  • state
  • viewAngle
  • offset
  • limit

This can easily be found by a simple query in the ENTRIES table.

 

Changing an object and marking the view as updated

Basically, we need three kinds of operations to handle updates:

  • We need to update the time for when a bundle was last updated. We'll call this "updateTimestamps"
  • We need to update which bundles in which states exist. We'll call this "modifyState"
  • We need to update which objects are part of the view. We'll call this "recalculateView"

There are a fixed number of operations that can be done on objects in doms. 

For each of these, this is what should be done on the index as a result

  1. Object Created: The Object was created in DOMS
    Fedora operations: 
    - ingest
    Action:

      modifystate()
      recalculateview()

     

  2. Object Deleted: The Object was purged from DOMS
    Fedora operations:
    - purgeObject
    Action:

      modifystate('D')

     

  3. Object State Changed: The Object changed state in DOMS
    Fedora operations:
    - modifyObject
    Action:

      modifystate()

     

  4. Datastream Changed: The Object datastreams changed. Handled differently depending on whether this is the relations datastream
    Fedora operations:
    addDatastream
    - modifyDatastreamByReference
    - modifyDatastreamByValue
    purgeDatastream
    - setDatastreamState
    - setDatastreamVersionable
    updatetimestamp
    Action:

      if RELS-EXT
        recalculateview()
      else
        updatetimestamp()

     

  5. Object Relations Changed: The Object changed in a fashion that DOES require the view to be recomputed.
    Fedora operations:
    - addRelationship
    - purgeRelationship
    Action:

      recalculateview()


Each of these operations will be elaborated below

Modifystate

When the object state changes, we will have to update the state in the object, and possibly in any view containing the state.

So for each ENTRIES object containing this object, we update it with a new timestamp and state

  • Active, if the new state is Active and all other objects in the view are current Active
  • Deleted, if this is the entry object, and
  • Inactive, otherwise
modifystate(pid, date, state) {
    //If this object was previously unknown and is an entry object, add it as a new entry object
    if (!OBJECTS.contains(pid)) {
        List<viewangle,cmpid,collection> viewEntries = doms.getViewEntries();
        foreach (viewEntry : viewEntries) {
            ENTRIES.add(pid,date,state,viewangle,cmpid,collection)
            OBJECTS.add(pid,pid,viewangle)
        }
    }
 
	//Find the DomsObject rows that regard this object.
	//There will be one per entry/viewAngle combination
	results = OBJECTS.list(objectPid=pid);

	//Find all Entries that include this object
	foreach (result : results) {
        oldstate = result.entryPid.state;
        newstate = calculatestate(result.entryPid, pid, timestamp, state) //TODO! Missing        
        // If this deletes the entry, handle that
        if (newstate = 'D') {
            if (oldstate != 'D') {
              ENTRIES.removeAll(result.entryPid)
              OBJECTS.removeAll(entryPid=result.entryPid)
              ENTRIES.add(entryPid,'D',timestamp)
            }
            return
        }
        // If it is set active, remove any deleted entries
        if (newstate = 'A') {
            ENTRIES.remove(result.entryPid, 'D');
     }
     updatetimestamp()

Updatetimestamp

// Update the Entries table regarding a change
void updatetimestamps(String pid, Date date) {
	objects = OBJECTS.list(objectPid=pid);

	//Find all Entries that include this object
	foreach (object : objects) {

        state = calculatestate(object.entryPid) //TODO! Missing
 
        //If entry is currently deleted, skip
        if (state = 'D') {
            return;
        }
        //Find the Entry objects that fulfill these restrictions
        List<Entry> results = ENTRIES.list(entrypid = object.entrypid)

        for (Entry result : results) {
            //Only update active entry if bundle is active
            if (result.state = 'A' and state != 'A') {
                continue
            }
	        //Is this entry older than the current change?
            if (result.getDateForChange < date) {
                ENTRIES.update(result, date);
            }
        }
    }
} 


Recalculateview

An object's relations changed. This could change which objects are in which entry's views. 

We find all the Entries that contain this object by listing OBJECTS.

For each of these, we recalculate the view bundle and update the relevant rows in OBJECTS and ENTRIES.

Each row in OBJECTS specify that an object is contained in a named view for a specific entry object.

Then we update the ENTRIES table to mark that the view is changed. 

This may also update content model or collection relations, which is handled separately

objectRelationsChanged(pid, date) {
  //This code is pseudo'er than the rest
  if relation changes collection
    if it is an entry object
      update collection field for inactive
      if entry object is active
        update collection field for active


  //This code is pseudo'er than the rest
  if relation changes content model
    if it is previously an entry object
      remove
    if it is now an entry object
      ingest
      return


    //This can change the structure of the views and we must therefore recaculate the views

    //if a current entry object use this object, we will need to recalculate the view of that object

    //This method will only be called on objects that already exist.
    //ObjectModified() creates an Entry row, if the object is an entry object. As such, there will always be
    // the correct Entry entries when this method is called, and these should just be recalculated

    List<DomsObject> results = OBJECTS.list(objectPid=pid);

    //we now have a list of all the entries that include this object.

    for (DomsObject result : results) {

        //get the ViewBundle from fedora
        ViewBundle bundle = fedora.calcViewBundle(result.getEntryPid(), result.getViewAngle(), date);


        //First, remove all the objects in this bundle from the table
        OBJECTS.delete(result.getEntryPid(), result.getViewAngle())
 
        //Add all the objects from the bundle to the objects Table.
        OBJECTS.addAll(result.getEntryPid(), result.getViewAngle(), bundle.getObjects())


        updateTimestamp(bundle.getEntry(), date);

    }
}

  • No labels