edu.northwestern.at.wordhoard.swing.calculator.modelutils
Class WorkSetUtils

java.lang.Object
  extended by edu.northwestern.at.wordhoard.swing.calculator.modelutils.WorkSetUtils

public class WorkSetUtils
extends java.lang.Object

Work set utilities.


Constructor Summary
protected WorkSetUtils()
          Don't allow instantiation but do allow overrides.
 
Method Summary
static WorkSet addWorkSet(java.lang.String title, java.lang.String description, java.lang.String webPageURL, boolean isPublic, java.lang.String query, java.util.Collection workParts)
          Add a new work set with specified work parts.
static WorkSet addWorkSet(java.lang.String title, java.lang.String description, java.lang.String webPageURL, boolean isPublic, java.lang.String query, WorkPart[] workParts)
          Add a new work set with specified work parts.
static boolean containsOnlyWorks(WorkSet workSet)
          Determine if work set contains only works.
static boolean deleteWorkSet(java.lang.String title)
          Delete a work set by title.
static boolean deleteWorkSet(WorkSet workSet)
          Delete a work set.
static boolean deleteWorkSets(WorkSet[] workSets)
          Delete multiple work sets.
static WorkPart[] getWorkParts(WorkSet workSet)
          Get work parts in a work set as an array.
static Work[] getWorks(WorkSet workSet)
          Get works in a work set as an array.
static WorkSet getWorkSet(java.lang.String title)
          Get a work set by title.
static WorkSet getWorkSet(java.lang.String title, java.lang.String owner)
          Get a work set by title.
static WorkSet[] getWorkSets()
          Get all available public work sets as an array.
static WorkSet[] getWorkSets(java.lang.String owner)
          Get all available work sets for a specified owner as an array.
static int getWorkSetsCount()
          Get count of all available work sets.
static int getWorkSetsCount(java.lang.String owner)
          Get count of work sets for specified user.
static WorkSet[] getWorkSetsForLoggedInUser()
          Get work sets for logged in user as an array.
static Work[] getWorksOnly(WorkSet workSet)
          Get work parts in work set that are works as an array.
static WorkSet importFromDOMDocument(org.w3c.dom.Node workSetNode)
          Import a specified work set from a DOM document.
static WorkSet[] importWorkSets(org.w3c.dom.Document importDocument)
          Import one or more work sets from XML file.
static WorkSet saveWorkSet(javax.swing.JFrame parentWindow, WorkPartGetter workPartGetter)
          Display dialog for creating/updating a work set.
protected static WorkSet[] udosToWorkSets(UserDataObject[] udos)
          Copy UserDataObject array to WorkSet array.
static boolean updateWorkSet(WorkSet workSet, java.lang.String title, java.lang.String description, java.lang.String webPageURL, boolean isPublic, java.util.Collection workParts)
          Update a work set.
static boolean updateWorkSet(WorkSet workSet, java.lang.String title, java.lang.String description, java.lang.String webPageURL, boolean isPublic, WorkPart[] workParts)
          Update a work set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkSetUtils

protected WorkSetUtils()
Don't allow instantiation but do allow overrides.

Method Detail

udosToWorkSets

protected static WorkSet[] udosToWorkSets(UserDataObject[] udos)
Copy UserDataObject array to WorkSet array.

Parameters:
udos - Array of user data objects, all actually WorkSet objects.
Returns:
Array of WorkSet objects.

addWorkSet

public static WorkSet addWorkSet(java.lang.String title,
                                 java.lang.String description,
                                 java.lang.String webPageURL,
                                 boolean isPublic,
                                 java.lang.String query,
                                 WorkPart[] workParts)
                          throws DuplicateWorkSetException,
                                 BadOwnerException
Add a new work set with specified work parts.

Parameters:
title - Title for the new work set.
description - Description for the new work set.
webPageURL - Web page URL for the new work set.
isPublic - True if work set to be public.
query - CQL query which generates work set.
workParts - Array of WorkPart entries to add to work set.
Returns:
WorkSet object if work set added, else null.
Throws:
DuplicateWorkSetException - if (title,owner) combination already exists.
BadOwnerException - if the owner is null or empty.

addWorkSet

public static WorkSet addWorkSet(java.lang.String title,
                                 java.lang.String description,
                                 java.lang.String webPageURL,
                                 boolean isPublic,
                                 java.lang.String query,
                                 java.util.Collection workParts)
                          throws DuplicateWorkSetException,
                                 BadOwnerException
Add a new work set with specified work parts.

Parameters:
title - Title for the new work set.
description - Description for the new work set.
webPageURL - Web page URL for the new work set.
isPublic - True if work set to be public.
query - CQL query which generates work set.
workParts - Collection of WorkPart entries to add to work set.
Returns:
WorkSet object if work set added, else null.
Throws:
DuplicateWorkSetException - if (title,owner) combination already exists.
BadOwnerException - if the owner is null or empty.

deleteWorkSet

public static boolean deleteWorkSet(WorkSet workSet)
Delete a work set.

Parameters:
workSet - The work set to delete.
Returns:
true if work set deleted, false otherwise.

The currently logged in user must be the owner to delete a work set.


deleteWorkSet

public static boolean deleteWorkSet(java.lang.String title)
Delete a work set by title.

Parameters:
title - The title of the work set to delete.
Returns:
true if work set deleted, false otherwise. If the work set didn't exist, true is returned.

deleteWorkSets

public static boolean deleteWorkSets(WorkSet[] workSets)
Delete multiple work sets.

Parameters:
workSets - The work sets to delete.
Returns:
true if work sets deleted, false otherwise.

getWorkSet

public static WorkSet getWorkSet(java.lang.String title,
                                 java.lang.String owner)
Get a work set by title.

Parameters:
owner - The owner for the work set to fetch.
title - The title of the work set to fetch.
Returns:
The work set with the requested title, or null if not found.

If the owner is not the same as the currently logged in user, the work set will only be returned if it is public.


getWorkSet

public static WorkSet getWorkSet(java.lang.String title)
Get a work set by title.

Parameters:
title - The title of the work set to fetch.
Returns:
The work set with the requested title, or null if not found.

Only public work sets are returned.


getWorkSets

public static WorkSet[] getWorkSets()
Get all available public work sets as an array.

Returns:
All available public work sets as an array of WorkSet.

If the user is logged in, any private work sets belonging to the logged in are also returned.


getWorkSets

public static WorkSet[] getWorkSets(java.lang.String owner)
Get all available work sets for a specified owner as an array.

Parameters:
owner - The owner.
Returns:
All available work sets as an array of WorkSet.

getWorkSetsForLoggedInUser

public static WorkSet[] getWorkSetsForLoggedInUser()
Get work sets for logged in user as an array.

Returns:
All work sets for logged in user as an array of WorkSet.

getWorkSetsCount

public static int getWorkSetsCount(java.lang.String owner)
Get count of work sets for specified user.

Returns:
Count of work sets owned by "owner".

getWorkSetsCount

public static int getWorkSetsCount()
Get count of all available work sets.

Returns:
Count of all available work sets.

getWorkParts

public static WorkPart[] getWorkParts(WorkSet workSet)
Get work parts in a work set as an array.

Parameters:
workSet - The work set.
Returns:
All available work parts in the work set as an array of WorkPart.

Returns null if work set is null.


getWorks

public static Work[] getWorks(WorkSet workSet)
Get works in a work set as an array.

Parameters:
workSet - The work set.
Returns:
The works with at least one work part in the work set.

Returns null if work set is null.


getWorksOnly

public static Work[] getWorksOnly(WorkSet workSet)
Get work parts in work set that are works as an array.

Parameters:
workSet - The work set.
Returns:
All available work parts that are actually works in the work set as an array of WorkPart.

Returns null if work set is null.


containsOnlyWorks

public static boolean containsOnlyWorks(WorkSet workSet)
Determine if work set contains only works.

Parameters:
workSet - The work set.
Returns:
true if all the work parts in the work set are actually works.

Returns false if work set is null.


updateWorkSet

public static boolean updateWorkSet(WorkSet workSet,
                                    java.lang.String title,
                                    java.lang.String description,
                                    java.lang.String webPageURL,
                                    boolean isPublic,
                                    WorkPart[] workParts)
                             throws BadOwnerException,
                                    DuplicateWorkSetException
Update a work set.

Parameters:
workSet - The work set to update.
title - Title for the work set.
description - Description for the work set.
isPublic - True if work set is public.
workParts - Array of WorkPart entries for work set.
Returns:
true if update succeed, false otherwise.
Throws:
BadOwnerException - if user is not logged in or is not the work set owner .
DuplicateWorkSetException - if new (title,owner) combination already exists.

updateWorkSet

public static boolean updateWorkSet(WorkSet workSet,
                                    java.lang.String title,
                                    java.lang.String description,
                                    java.lang.String webPageURL,
                                    boolean isPublic,
                                    java.util.Collection workParts)
                             throws BadOwnerException,
                                    DuplicateWorkSetException
Update a work set.

Parameters:
workSet - The work set to update.
title - Title for the work set.
description - Description for the work set.
isPublic - True if work set is public.
workParts - Collection of WorkPart entries for work set.
Returns:
true if update succeed, false otherwise.
Throws:
BadOwnerException - if user is not logged in or is not the work set owner .
DuplicateWorkSetException - if new (title,owner) combination already exists.

importFromDOMDocument

public static WorkSet importFromDOMDocument(org.w3c.dom.Node workSetNode)
                                     throws BadOwnerException
Import a specified work set from a DOM document.

Parameters:
workSetNode - The DOM node which is the root of the work set to import.
Returns:
The imported work set, or null if the import fails.
Throws:
BadOwnerException - if the user is not logged in.

importWorkSets

public static WorkSet[] importWorkSets(org.w3c.dom.Document importDocument)
Import one or more work sets from XML file.

Parameters:
importDocument - The DOM document containing the work sets to import.
Returns:
The imported work sets. May be empty.
Throws:
BadOwnerException - if the user is not logged in.

Note: The work sets are not persisted here. That is the responsibility of the caller.


saveWorkSet

public static WorkSet saveWorkSet(javax.swing.JFrame parentWindow,
                                  WorkPartGetter workPartGetter)
                           throws java.lang.Exception
Display dialog for creating/updating a work set.

Parameters:
parentWindow - Parent window for dialog.
workPartGetter - WorkPartGetter to retrieve list of work parts to add to work set.
Returns:
The work set.
Throws:
java.lang.Exception - if something went wrong.