org.sandev.TaskHeap.TaskHeapUI
Class DemoDataSetup

java.lang.Object
  extended by org.sandev.TaskHeap.TaskHeapUI.DemoDataSetup

public class DemoDataSetup
extends java.lang.Object

Helper class that creates a new tutorial heap for demonstration purposes. The class makes use of the heap import file processing in order to create tasks and plans that are already old, otherwise it is difficult to demonstrate the activity chromacoding. Because we are using batch load, the main access method is synchronized to avoid conflicts trying to load multiple heaps at the same time. 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:


Field Summary
protected  HeapAssociation ha
           
protected  HeapAttributes heap
           
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.
protected  TaskHeapUINode uinode
           
 
Constructor Summary
DemoDataSetup()
           
 
Method Summary
protected  void createHeapAttributes(Account user)
          Create or reset the tutorial heap for this user.
protected  void createTutorial(long uniqueIDCounter, java.util.ArrayList al, java.util.Date creationTime, Plan immediate)
          Create the instances making up the tutorial.
 HeapAssociation createTutorialHeap(TaskHeapUINode uinode, Account user)
          Create a new tutorial heap for the given user and return their HeapAssociation for access.
protected  void debug(java.lang.String text)
          Utility wrapper for dumping a debug message via our uinode ref.
protected  void debugDumpMessages(org.sandev.basics.structs.SandPersistMessage[] spms)
          Dump the given messages to the log
protected  void deleteHeapContents(HeapAttributes heap)
          Delete the specified heap contents.
protected  void deletionSort(org.sandev.basics.structs.SandInstanceMessage[] instances)
          Have to delete the parent after the children or the deletion process will fail due to orphaning.
protected  HeapAttributes getExistingHeapByName(java.lang.String heapname, Account user)
          Retrieve the existing tutorial heap with this name, or null if not found.
protected  org.sandev.basics.structs.SandPersistMessage[] getTutorialComponents()
          Return an array of all the components for the tutorial.
protected  void importHeap(java.io.File heapfile, Account user)
          Import the demo data from the given file.
protected  void matchDelete(org.sandev.basics.structs.SandQueryMessage sqm, org.sandev.basics.util.AuthUser user)
          Delete all the instances matching the given query.
protected  void resetTopLevelPlanChildRefs(long heapID, long authUserID)
          Clear the children from the top level plans for the given heap
protected  java.io.File serializeMessages(org.sandev.basics.structs.SandPersistMessage[] msgs)
          Serialize the given message array and write it to file, returning the filename.
protected  void uncacheMessages(org.sandev.basics.structs.SandPersistMessage[] msgs)
          Remove the given messages from cache so we don't reference an old version.
protected  void verifyHeapAssociation(org.sandev.basics.sandmessages.AggregateUpdate au, Account user)
          Verify our admin association for our tutorial heap.
 
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.

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

uinode

protected TaskHeapUINode uinode

heap

protected HeapAttributes heap

ha

protected HeapAssociation ha
Constructor Detail

DemoDataSetup

public DemoDataSetup()
Method Detail

createTutorialHeap

public HeapAssociation createTutorialHeap(TaskHeapUINode uinode,
                                          Account user)
                                   throws org.sandev.basics.structs.SandException
Create a new tutorial heap for the given user and return their HeapAssociation for access. To do this we:
  1. Create a new HeapAttributes for the tutorial instance or reset the existing instance and delete everything in it. Create a new admin HeapAssociation for this user which will indicate the uniqueID to use as a base for new data.
  2. Create a SandMessage[] with all the instances we need for the demo heap. Translate the uniqueIDs based on the ID from our new HeapAssociation. Backdate the creation and last modified times by 40 days so they all show up as old.
  3. Serialize the messages out to file
  4. Import the file

Throws:
org.sandev.basics.structs.SandException

createTutorial

protected void createTutorial(long uniqueIDCounter,
                              java.util.ArrayList al,
                              java.util.Date creationTime,
                              Plan immediate)
Create the instances making up the tutorial.


getTutorialComponents

protected org.sandev.basics.structs.SandPersistMessage[] getTutorialComponents()
                                                                        throws org.sandev.basics.structs.SandException
Return an array of all the components for the tutorial. The components are created using temporary IDs that are internally consistent. Then they are converted using an offset that consist of the maximum ID currently in use plus some buffer space. We also verify the heap reference is set for all.

Throws:
org.sandev.basics.structs.SandException

createHeapAttributes

protected void createHeapAttributes(Account user)
                             throws org.sandev.basics.structs.SandException
Create or reset the tutorial heap for this user. The demo heap uniqueID is preserved if it already exists to allow the user to define what order they want to see the heaps they are working with. If the demo heap ID were to change, it would shift within the display which is not good. Create a new admin association for this user. The HeapAssociation is created new each time so the uniqueID can be used as a base for creating the demo heap data. This is done automatically by the update processing as part of writing the HeapAttributes. The update succeeds without a HeapAssociation being present because the heap has this account as the owner.

Throws:
org.sandev.basics.structs.SandException

getExistingHeapByName

protected HeapAttributes getExistingHeapByName(java.lang.String heapname,
                                               Account user)
                                        throws org.sandev.basics.structs.SandException
Retrieve the existing tutorial heap with this name, or null if not found.

Throws:
org.sandev.basics.structs.SandException

verifyHeapAssociation

protected void verifyHeapAssociation(org.sandev.basics.sandmessages.AggregateUpdate au,
                                     Account user)
                              throws org.sandev.basics.structs.SandException
Verify our admin association for our tutorial heap. The association is created automatically by the update processing, so all we do is set up to use it.

Throws:
org.sandev.basics.structs.SandException

deleteHeapContents

protected void deleteHeapContents(HeapAttributes heap)
                           throws org.sandev.basics.structs.SandException
Delete the specified heap contents. This includes all existing HeapAssociations, especially the owner admin association which needs to get recreated with a fresh uniqueID.

Throws:
org.sandev.basics.structs.SandException

matchDelete

protected void matchDelete(org.sandev.basics.structs.SandQueryMessage sqm,
                           org.sandev.basics.util.AuthUser user)
                    throws org.sandev.basics.structs.SandException
Delete all the instances matching the given query. Throws if anything goes wrong.

Throws:
org.sandev.basics.structs.SandException

resetTopLevelPlanChildRefs

protected void resetTopLevelPlanChildRefs(long heapID,
                                          long authUserID)
                                   throws org.sandev.basics.structs.SandException
Clear the children from the top level plans for the given heap

Throws:
org.sandev.basics.structs.SandException

deletionSort

protected void deletionSort(org.sandev.basics.structs.SandInstanceMessage[] instances)
Have to delete the parent after the children or the deletion process will fail due to orphaning. Good old bubble sort. Not the most efficient perhaps, but not dealing with a lot of stuff and a comparator is more of pain.


serializeMessages

protected java.io.File serializeMessages(org.sandev.basics.structs.SandPersistMessage[] msgs)
                                  throws org.sandev.basics.structs.SandException
Serialize the given message array and write it to file, returning the filename.

Throws:
org.sandev.basics.structs.SandException

importHeap

protected void importHeap(java.io.File heapfile,
                          Account user)
                   throws org.sandev.basics.structs.SandException
Import the demo data from the given file.

Throws:
org.sandev.basics.structs.SandException

uncacheMessages

protected void uncacheMessages(org.sandev.basics.structs.SandPersistMessage[] msgs)
Remove the given messages from cache so we don't reference an old version. Data import processing does not send cache notices.


debugDumpMessages

protected void debugDumpMessages(org.sandev.basics.structs.SandPersistMessage[] spms)
Dump the given messages to the log


debug

protected void debug(java.lang.String text)
Utility wrapper for dumping a debug message via our uinode ref.