org.sandev.TaskHeap.TaskHeapUI
Class DemoDataSetup

java.lang.Object
  extended byorg.sandev.TaskHeap.TaskHeapUI.DemoDataSetup

public class DemoDataSetup
extends java.lang.Object

Helper class to populate or remove demo data. The demo data is assumed to be created at startup, and then reset on demand at any point after that. The data consists of a tutorial, which looks something like:

In order to allow for recreating the data in exactly as initially specified, with the same structure, we track the data via the uniqueID and reset it to how it is initially defined here. So this works a lot like initial data verification.


Field Summary
protected  org.sandev.basics.structs.SandPersistMessage[] demoData
          The instances that comprise our data.
protected static java.lang.String newline
          When writing text information we need to store the encoded newline character for it to show up.
protected static java.lang.String para
          A new paragraph is two newlines chained together.
 
Constructor Summary
DemoDataSetup()
           
 
Method Summary
 org.sandev.basics.structs.SandPersistMessage[] getDemoData()
          initializing accessor for demoData
protected  org.sandev.basics.structs.SandPersistMessage hardGetInstance(TaskHeapUINode uinode, java.lang.String classname, long id, org.sandev.basics.util.AuthUser user)
          Retrieve the specified instance from the database, regardless of whatever its recordStatus currently is.
protected  void initDemoData()
          Set up our demoData for query, add or delete operations.
 void setDemoData(org.sandev.basics.structs.SandPersistMessage[] spms)
          mutator for demoData
 void verifyDemoData(TaskHeapUINode uinode, org.sandev.basics.util.AuthUser user)
          Verify the defined demo data exists.
protected  void verifyParentReference(org.sandev.basics.structs.SandPersistMessage msg, TaskHeapUINode uinode, org.sandev.basics.util.AuthUser user)
          Verify that the parent of the given message references this message as a child.
protected  void writeMessage(org.sandev.basics.structs.SandPersistMessage msg, boolean addNew, TaskHeapUINode uinode, org.sandev.basics.util.AuthUser user)
          Write the given message to the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

newline

protected static final java.lang.String newline
When writing text information we need to store the encoded newline character for it to show up. We define this here to make the code easier to read.

When doing the translation for display on a windows box, the newlines don't show up unless you use a crlf. So to have the data look like what it looks like post editing, we do crlf here. This will presumably work on most systems, and makes sense in terms of consistency, since all our initial data was created this way.

See Also:
Constant Field Values

para

protected static final java.lang.String para
A new paragraph is two newlines chained together. We define this here to make the code easier to read.

See Also:
Constant Field Values

demoData

protected org.sandev.basics.structs.SandPersistMessage[] demoData
The instances that comprise our data.

Constructor Detail

DemoDataSetup

public DemoDataSetup()
Method Detail

getDemoData

public org.sandev.basics.structs.SandPersistMessage[] getDemoData()
initializing accessor for demoData


setDemoData

public void setDemoData(org.sandev.basics.structs.SandPersistMessage[] spms)
mutator for demoData


initDemoData

protected void initDemoData()
Set up our demoData for query, add or delete operations. The data is defined in dependency order, so all references are to data that already exists.


verifyDemoData

public void verifyDemoData(TaskHeapUINode uinode,
                           org.sandev.basics.util.AuthUser user)
                    throws org.sandev.basics.structs.SandException
Verify the defined demo data exists. For each defined instance:
  1. retrieve the existing instance.
  2. if not found then add it, but without any child or parent references since the references need to be intact for the recompute processing to work.
After all the data exists, verify the references are intact. For each defined instance:
  1. retrieve the existing instance
  2. if not found, throw. If found, check it is equivalent and reset if necessary, including the child and parent references.

This method assumes that the demo data is declared with the correct parent and child references.

Throws:
org.sandev.basics.structs.SandException

writeMessage

protected void writeMessage(org.sandev.basics.structs.SandPersistMessage msg,
                            boolean addNew,
                            TaskHeapUINode uinode,
                            org.sandev.basics.util.AuthUser user)
                     throws org.sandev.basics.structs.SandException
Write the given message to the database. If addNew is true, then this is an add, otherwise this is an update.

For an add, we change the uniqueID to a temporary value, and then switch it back afterwards. We are relying on the fact that we populate demo data at startup to ensure that the IDs stay in sync.

Throws:
org.sandev.basics.structs.SandException

verifyParentReference

protected void verifyParentReference(org.sandev.basics.structs.SandPersistMessage msg,
                                     TaskHeapUINode uinode,
                                     org.sandev.basics.util.AuthUser user)
                              throws org.sandev.basics.structs.SandException
Verify that the parent of the given message references this message as a child. If not, then update the parent to include us as a reference. Note that this does not guarantee any ordering of child references in the parent, just that a reference exists.

Throws:
org.sandev.basics.structs.SandException

hardGetInstance

protected org.sandev.basics.structs.SandPersistMessage hardGetInstance(TaskHeapUINode uinode,
                                                                       java.lang.String classname,
                                                                       long id,
                                                                       org.sandev.basics.util.AuthUser user)
                                                                throws org.sandev.basics.structs.SandException
Retrieve the specified instance from the database, regardless of whatever its recordStatus currently is.

Throws:
org.sandev.basics.structs.SandException