com.knowgate.hipergate
Class Category

java.lang.Object
  |
  +--com.knowgate.dataobjs.DBPersist
        |
        +--com.knowgate.hipergate.Category
Direct Known Subclasses:
NewsGroup

public class Category
extends DBPersist

Categories from k_categories database table

Version:
2.1

Field Summary
static int BROWSE_BOTTOMUP
           
static int BROWSE_DOWN
           
static int BROWSE_TOPDOWN
           
static int BROWSE_UP
           
static short ClassId
           
 
Fields inherited from class com.knowgate.dataobjs.DBPersist
AllVals, sAuditCls, sAuditUsr, sTransactId
 
Constructor Summary
  Category()
          Create empty Category
  Category(JDCConnection oConn, java.lang.String sIdCategory)
          Load Category from database
  Category(java.lang.String sIdCategory)
          Create Category and set gu_category.
protected Category(java.lang.String sTableName, java.lang.String sClassName)
           
 
Method Summary
 int addObject(java.sql.Connection oConn, java.lang.String sIdObject, int iIdClass, int iAttribs, int iOdPosition)
          Add object to Category.
 java.util.LinkedList browse(JDCConnection oConn, int iDirection, int iOrder)
          Get a list of all parents or childs of a Category.
static java.lang.String create(JDCConnection oConn, java.lang.Object[] Values)
          Create new Category with translated labels.
 boolean delete(JDCConnection oConn)
          Delete Category and all its childs.
static boolean delete(JDCConnection oConn, java.lang.String sCategoryGUID)
          Delete Category and all its childs.
 void expand(java.sql.Connection oConn)
          Expand all Category childs.
 DBSubset getACLGroups(JDCConnection oConn)
          Get Groups with permissions over this Category.
 DBSubset getACLUsers(JDCConnection oConn)
          Get Users with direct permissions over this Category.
 DBSubset getChilds(JDCConnection oConn)
          Get first level childs as a DBSubset.
static java.lang.String getIdFromName(JDCConnection oConn, java.lang.String sCategoryNm)
          Get Category GUID given its internal name.
 boolean getIsRoot(java.sql.Connection oConn)
           
 java.lang.String getLabel(java.sql.Connection oConn, java.lang.String sLanguage)
          Get translated label for a category.
 DBSubset getNames(JDCConnection oConn)
          Get Category translated labels as a DBSubset.
 DBSubset getObjects(JDCConnection oConn)
          Get objects contained at Category.
 DBSubset getParents(JDCConnection oConn)
          Get inmediate parents as a DBSubset.
 java.lang.String getPath(java.sql.Connection oConn)
          Compose a path to Category by concatenating all parents names.
 int getUserPermissions(java.sql.Connection oConn, java.lang.String sIdUser)
          Get User permissions for Category Calls k_sp_cat_usr_perm stored procedure.
 void inheritPermissions(JDCConnection oConn, java.lang.String sFromCategory, short iRecurse, short iObjects)
          Inherits permissions from another Category.
 boolean isChildOf(java.sql.Connection oConn, java.lang.String sParentCategory)
          Get whether or not this category descends at any level from another one.
 boolean isParentOf(java.sql.Connection oConn, java.lang.String sChildCategory)
          Get whether or not this category is parent at any level of another one.
 int level(JDCConnection oConn)
          Get category depth level.
static java.lang.String makeName(JDCConnection oConn, java.lang.String sCategoryNm)
          Make an internal category name from an arbitrary string.
 void removeGroupPermissions(java.sql.Connection oConn, java.lang.String sIdGroups, short iRecurse, short iObjects)
          Set group permissions.
 int removeObject(java.sql.Connection oConn, java.lang.String sIdObject)
          Remove object from Category Removing an object from a Category does not delete it.
 void removeUserPermissions(java.sql.Connection oConn, java.lang.String sIdUsers, short iRecurse, short iObjects)
          Remove permissions for user at a Category.
 void resetParent(java.sql.Connection oConn, java.lang.String sIdParent)
          Remove Category from parent.
 void setGroupPermissions(java.sql.Connection oConn, java.lang.String sIdGroups, int iACLMask, short iRecurse, short iObjects)
          Set group permissions for Category Calls k_sp_cat_set_grp stored procedure.
 void setIsRoot(java.sql.Connection oConn, boolean bIsRoot)
          Make or unmake a root category.
 void setParent(java.sql.Connection oConn, java.lang.String sIdParent)
          Set New Parent for this category.
 void setUserPermissions(java.sql.Connection oConn, java.lang.String sIdUsers, int iACLMask, short iRecurse, short iObjects)
          Set user permissions for a Category.
 boolean store(JDCConnection oConn)
          Store Category.
static java.lang.String store(JDCConnection oConn, java.lang.String sCategoryId, java.lang.String sParentId, java.lang.String sCategoryName, short iIsActive, int iDocStatus, java.lang.String sOwner, java.lang.String sIcon1, java.lang.String sIcon2)
          Create or Store Category.
 void storeLabels(JDCConnection oConn, java.lang.String sNamesTable, java.lang.String sRowDelim, java.lang.String sColDelim)
           
 void uploadDirectory(JDCConnection oConn, java.lang.String sSourcePath, java.lang.String sProtocol, java.lang.String sServer, java.lang.String sTargetPath, java.lang.String sLanguage)
           
 
Methods inherited from class com.knowgate.dataobjs.DBPersist
clear, exists, get, getDate, getDateFormated, getDecimal, getFloat, getInt, getInteger, getItemMap, getItems, getShort, getString, getStringNull, getTable, getTable, getTableName, getTimestamp, getUIdFromName, isNull, iterator, load, parseXML, put, put, put, put, put, put, put, put, put, put, put, put, putAll, remove, replace, replace, replace, replace, setAuditTransact, setAuditUser, toXML, toXML, toXML
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BROWSE_UP

public static final int BROWSE_UP
See Also:
Constant Field Values

BROWSE_DOWN

public static final int BROWSE_DOWN
See Also:
Constant Field Values

BROWSE_TOPDOWN

public static final int BROWSE_TOPDOWN
See Also:
Constant Field Values

BROWSE_BOTTOMUP

public static final int BROWSE_BOTTOMUP
See Also:
Constant Field Values

ClassId

public static final short ClassId
See Also:
Constant Field Values
Constructor Detail

Category

public Category()
Create empty Category


Category

public Category(java.lang.String sIdCategory)
         throws java.sql.SQLException
Create Category and set gu_category.

Parameters:
sIdCategory - Category GUID
Throws:
java.sql.SQLException

Category

public Category(JDCConnection oConn,
                java.lang.String sIdCategory)
         throws java.sql.SQLException
Load Category from database

Parameters:
oConn - Database Connection
sIdCategory - Category GUID
Throws:
java.sql.SQLException

Category

protected Category(java.lang.String sTableName,
                   java.lang.String sClassName)
Method Detail

browse

public java.util.LinkedList browse(JDCConnection oConn,
                                   int iDirection,
                                   int iOrder)
                            throws java.sql.SQLException

Get a list of all parents or childs of a Category.

All levels up or down are scanned recursively.

Parameters:
oConn - Database Connection
iDirection - BROWSE_UP for browsing parents or BROWSE_DOWN for browsing childs.
iOrder - BROWSE_TOPDOWN first element on the list will be the top most parent, BROWSE_BOTTOMUP first element on the list will be the deepest child.
Returns:
LinkedList of Category objects.
Throws:
java.sql.SQLException

getPath

public java.lang.String getPath(java.sql.Connection oConn)
                         throws java.sql.SQLException

Compose a path to Category by concatenating all parents names.

Calls k_sp_get_cat_path.
Category parents are found and each parent name is extracted.
Then parent names are contenated in order separated by slash '/' characters.
This method is usefull when creating a physical directory path for files belonging to Products contained in a Category. This way the directory paths can mimmic the category tree structure.

Parameters:
oConn - Database Connection
Returns:
String with Category parent names concatenated with slash '/' characters. For example "ROOT/DOMAINS/SYSTEM/SYSTEM_APPS/SYSTEM_apps_webbuilder"
Throws:
java.sql.SQLException

delete

public boolean delete(JDCConnection oConn)
               throws java.sql.SQLException

Delete Category and all its childs.

First delete all Products and Companies contained in Category, including physical disk files associted with Products and Company attachments.
Then call k_sp_del_category_r stored procedure and perform recursive deletion of all childs.

Overrides:
delete in class DBPersist
Parameters:
oConn - Database Connection
Returns:
true if register was successfully erased, false if not.
Throws:
java.sql.SQLException

addObject

public int addObject(java.sql.Connection oConn,
                     java.lang.String sIdObject,
                     int iIdClass,
                     int iAttribs,
                     int iOdPosition)
              throws java.sql.SQLException

Add object to Category.

The object GUID and numeric class identifier is inserted at k_x_cat_objs table.

Parameters:
oConn - Database Connection
sIdObject - Object GUID
iIdClass - Object Numeric Class Identifier (variable ClassId)
iAttribs - Object attributes mask (user defined)
iOdPosition - Object Position. An arbitrary position for the object inside the category. Position is not unique for an object. Two or more objects may have the same position.
Throws:
java.sql.SQLException - If object is alredy contanied in Category then a primary key violation exception is raised.

removeObject

public int removeObject(java.sql.Connection oConn,
                        java.lang.String sIdObject)
                 throws java.sql.SQLException

Remove object from Category

Removing an object from a Category does not delete it.

Parameters:
oConn - Database Connection
sIdObject - Object GUID
Returns:
1 if object was present at category, 0 if object was not present at category.
Throws:
java.sql.SQLException

removeGroupPermissions

public void removeGroupPermissions(java.sql.Connection oConn,
                                   java.lang.String sIdGroups,
                                   short iRecurse,
                                   short iObjects)
                            throws java.sql.SQLException

Set group permissions.

Calls k_sp_cat_del_grp stored procedure.

Parameters:
oConn - Database Connection
sIdGroups - String of comma separated GUIDs of ACLGroups with permissions to remove.
iRecurse - Remove permissions also from childs Categories all levels down.
iObjects - Not Used, must be zero.
Throws:
java.sql.SQLException

setGroupPermissions

public void setGroupPermissions(java.sql.Connection oConn,
                                java.lang.String sIdGroups,
                                int iACLMask,
                                short iRecurse,
                                short iObjects)
                         throws java.sql.SQLException

Set group permissions for Category

Calls k_sp_cat_set_grp stored procedure.

Parameters:
oConn - Database Connection
sIdGroups - String of comma separated GUIDs of ACLGroups with permissions to set.
iACLMask - Permissions mask, any combination of { ACL.PERMISSION_LIST, ACL.PERMISSION_READ,ACL.PERMISSION_ADD,ACL.PERMISSION_DELETE,ACL.PERMISSION_MODIFY, ACL.PERMISSION_MODERATE,ACL.PERMISSION_SEND,ACL.PERMISSION_GRANT, ACL.PERMISSION_FULL_CONTROL }
iRecurse - Remove permissions also from childs Categories all levels down.
iObjects - Not Used, must be zero.
Throws:
java.sql.SQLException
See Also:
ACL

getUserPermissions

public int getUserPermissions(java.sql.Connection oConn,
                              java.lang.String sIdUser)
                       throws java.sql.SQLException

Get User permissions for Category

Calls k_sp_cat_usr_perm stored procedure.
User permissions are those granted directy to user plus those grants indirectly by assigning permisssion to a group witch the user belongs to.
Permissions are accumulative; a user gains new permissions by belonging to new groups. All permissions are of grant type, there are no deny permissions.

Parameters:
oConn - Database Connection
sIdUser - User GUID
Returns:
User permissions mask. Any combination of: { ACL.PERMISSION_LIST, ACL.PERMISSION_READ,ACL.PERMISSION_ADD, ACL.PERMISSION_DELETE,ACL.PERMISSION_MODIFY, ACL.PERMISSION_MODERATE, ACL.PERMISSION_SEND,ACL.PERMISSION_GRANT,ACL.PERMISSION_FULL_CONTROL }
Throws:
java.sql.SQLException

removeUserPermissions

public void removeUserPermissions(java.sql.Connection oConn,
                                  java.lang.String sIdUsers,
                                  short iRecurse,
                                  short iObjects)
                           throws java.sql.SQLException

Remove permissions for user at a Category.

Calls k_sp_cat_del_usr.
Only permissions directly granted to user are removed.
Permissions obtained by belonging to a Group remain active.

Parameters:
oConn - Database Connection
sIdUsers - String of user GUIDs separated by commas.
iRecurse - Remove permissions from child categories.
iObjects - Not used, must be zero.
Throws:
java.sql.SQLException

setUserPermissions

public void setUserPermissions(java.sql.Connection oConn,
                               java.lang.String sIdUsers,
                               int iACLMask,
                               short iRecurse,
                               short iObjects)
                        throws java.sql.SQLException

Set user permissions for a Category.

Calls k_sp_cat_set_usr stored procedure.

Parameters:
oConn - Database Connection
sIdUsers - String of user GUIDs separated by commas.
iACLMask - Permissions mask. Any combination of: { ACL.PERMISSION_LIST, ACL.PERMISSION_READ,ACL.PERMISSION_ADD, ACL.PERMISSION_DELETE,ACL.PERMISSION_MODIFY, ACL.PERMISSION_MODERATE, ACL.PERMISSION_SEND,ACL.PERMISSION_GRANT,ACL.PERMISSION_FULL_CONTROL }
iRecurse - Remove permissions from child categories.
iObjects - Not used, must be zero.
Throws:
java.sql.SQLException

inheritPermissions

public void inheritPermissions(JDCConnection oConn,
                               java.lang.String sFromCategory,
                               short iRecurse,
                               short iObjects)
                        throws java.sql.SQLException

Inherits permissions from another Category.

All previous permissions on this Category are removed before copying permission from the other Category.

Parameters:
oConn - Database Connection
sFromCategory - GUID of category with permissions to be inherited.
iRecurse - Propagate permissions to child categories.
iObjects - Not used, must be zero.
Throws:
java.sql.SQLException

isChildOf

public boolean isChildOf(java.sql.Connection oConn,
                         java.lang.String sParentCategory)
                  throws java.sql.SQLException
Get whether or not this category descends at any level from another one.

Parameters:
oConn - Database Connection
sParentCategory - Parent category
Returns:
true if this category descends at any level of depth from sParentCategory.
Throws:
java.sql.SQLException

isParentOf

public boolean isParentOf(java.sql.Connection oConn,
                          java.lang.String sChildCategory)
                   throws java.sql.SQLException
Get whether or not this category is parent at any level of another one.

Parameters:
oConn - Database Connection
sChildCategory - Child Category GUID
Returns:
true if this category is parent at any level.
Throws:
java.sql.SQLException

level

public int level(JDCConnection oConn)
          throws java.sql.SQLException

Get category depth level.

Calls k_sp_cat_level stored procedure.
Root Categories have level 1.

Parameters:
oConn - Database Connection
Returns:
Category depth evel starting at 1.
Throws:
java.sql.SQLException

getIsRoot

public boolean getIsRoot(java.sql.Connection oConn)
                  throws java.sql.SQLException
Parameters:
oConn - Database Connection
Returns:
true if Category is present at k_cat_root table.
Throws:
java.sql.SQLException

setIsRoot

public void setIsRoot(java.sql.Connection oConn,
                      boolean bIsRoot)
               throws java.sql.SQLException
Make or unmake a root category.

Parameters:
oConn - Database Connection
bIsRoot - true if category is to be made root.
Throws:
java.sql.SQLException - If This Category is present as a child of another category at k_cat_tree table.

getLabel

public java.lang.String getLabel(java.sql.Connection oConn,
                                 java.lang.String sLanguage)
                          throws java.sql.SQLException
Get translated label for a category.

Parameters:
oConn - Database Connection
sLanguage - Language code from k_lu_languages table.
Returns:
Translated label or null if no translated label for such language was found at k_cat_labels table.
Throws:
java.sql.SQLException

getNames

public DBSubset getNames(JDCConnection oConn)
                  throws java.sql.SQLException

Get Category translated labels as a DBSubset.

Parameters:
oConn - Database Connection
Returns:
DBSubset with columns:
id_languagetr_categoryurl_category
2 chras. Lang. Id.Translated Category NameURL for Category
Throws:
java.sql.SQLException

getChilds

public DBSubset getChilds(JDCConnection oConn)
                   throws java.sql.SQLException

Get first level childs as a DBSubset.

Parameters:
oConn - Database Connection
Returns:
Single column DBSubset with child GUIDs
Throws:
java.sql.SQLException

getParents

public DBSubset getParents(JDCConnection oConn)
                    throws java.sql.SQLException

Get inmediate parents as a DBSubset.

Parameters:
oConn - Database Connection
Returns:
Single column DBSubset with parent GUIDs
Throws:
java.sql.SQLException

getObjects

public DBSubset getObjects(JDCConnection oConn)
                    throws java.sql.SQLException
Get objects contained at Category.

Parameters:
oConn - Database Connection
Returns:
DBSubset with columns:
gu_objectid_classbi_attribs
Throws:
java.sql.SQLException

getACLGroups

public DBSubset getACLGroups(JDCConnection oConn)
                      throws java.sql.SQLException
Get Groups with permissions over this Category.

Parameters:
oConn - Database Connection
Returns:
A DBSubset with 2 columns: gu_acl_group, acl_mask
Throws:
java.sql.SQLException

getACLUsers

public DBSubset getACLUsers(JDCConnection oConn)
                     throws java.sql.SQLException
Get Users with direct permissions over this Category.

Parameters:
oConn - Database Connection
Returns:
A DBSubset with 2 columns: gu_user, acl_mask
Throws:
java.sql.SQLException

setParent

public void setParent(java.sql.Connection oConn,
                      java.lang.String sIdParent)
               throws java.sql.SQLException

Set New Parent for this category.

The old parent (if any) is not changed nor removed.
If Category is already a child of selected parent method proceeds silently and no error is raised.

Parameters:
oConn - Database Connection
sIdParent - GUID of parent Category
Throws:
java.sql.SQLException

resetParent

public void resetParent(java.sql.Connection oConn,
                        java.lang.String sIdParent)
                 throws java.sql.SQLException

Remove Category from parent.

Removing a Category from a parent does not delete it.

Parameters:
oConn - Database Connection
sIdParent - Parent Category GUID
Throws:
java.sql.SQLException

store

public boolean store(JDCConnection oConn)
              throws java.sql.SQLException

Store Category.

If gu_category is null a new GUID is automatically assigned.
dt_modified field is set to current date.

Overrides:
store in class DBPersist
Parameters:
oConn - Database Connection
Returns:
true is register was successfully stored, false if not.
Throws:
java.sql.SQLException

expand

public void expand(java.sql.Connection oConn)
            throws java.sql.SQLException

Expand all Category childs.

Calls k_sp_cat_expand stored procedure.
Expansion tree is stored at k_cat_expand table.

Parameters:
oConn - Database Connection
Throws:
java.sql.SQLException

storeLabels

public void storeLabels(JDCConnection oConn,
                        java.lang.String sNamesTable,
                        java.lang.String sRowDelim,
                        java.lang.String sColDelim)
                 throws java.sql.SQLException,
                        java.util.NoSuchElementException
java.sql.SQLException
java.util.NoSuchElementException

uploadDirectory

public void uploadDirectory(JDCConnection oConn,
                            java.lang.String sSourcePath,
                            java.lang.String sProtocol,
                            java.lang.String sServer,
                            java.lang.String sTargetPath,
                            java.lang.String sLanguage)
                     throws java.lang.Exception,
                            java.io.IOException,
                            java.sql.SQLException
java.lang.Exception
java.io.IOException
java.sql.SQLException

store

public static java.lang.String store(JDCConnection oConn,
                                     java.lang.String sCategoryId,
                                     java.lang.String sParentId,
                                     java.lang.String sCategoryName,
                                     short iIsActive,
                                     int iDocStatus,
                                     java.lang.String sOwner,
                                     java.lang.String sIcon1,
                                     java.lang.String sIcon2)
                              throws java.sql.SQLException

Create or Store Category.

Parameters:
oConn - Database Connection
sCategoryId - GUID of Category to store or null if it is a new Category.
sParentId - GUID of Parent Category or null if it is a root category.
sCategoryName - Internal Category Name. It is recommended that makeName() method is applied always on sCategoryName. Because category names are often used for composing physical disk paths, assigning characters such as '*', '/', '?' etc. to category names may lead to errors when creating directories for contained Products. As a general rule use ONLY upper case letters and numbers for category names.
iIsActive - 1 if category is to be marked active, 0 if it is to be marked as unactive.
iDocStatus - Initial Document Status, { 0=Pending, 1=Active, 2=Locked } See k_lu_status table.
sOwner - GUID of User owner of this Category.
sIcon1 - Icon for closed folder.
sIcon2 - Icon for opened folder.
Returns:
GUID of new Category or sCategoryId if Category already existed.
Throws:
java.sql.SQLException

delete

public static boolean delete(JDCConnection oConn,
                             java.lang.String sCategoryGUID)
                      throws java.sql.SQLException,
                             java.io.IOException

Delete Category and all its childs.

First delete all Products and Companies contained in Category, including physical disk files associted with Products and Company attachments.
Then call k_sp_del_category_r stored procedure and perform recursive deletion of all childs.

Parameters:
oConn - Database Connection
sCategoryGUID - GUID of Category to delete.
Throws:
java.sql.SQLException
java.io.IOException

create

public static java.lang.String create(JDCConnection oConn,
                                      java.lang.Object[] Values)
                               throws java.sql.SQLException
Create new Category with translated labels.

Parameters:
oConn - Database Connection
Values - An array with the following elements:
{ (String) gu_parent, (String) gu_owner, (String) nm_category, (Short) bo_active, (Short) id_doc_status, (String) nm_icon, (String) nm_icon2 }
Returns:
GUID of new Category
Throws:
java.sql.SQLException

getIdFromName

public static java.lang.String getIdFromName(JDCConnection oConn,
                                             java.lang.String sCategoryNm)
                                      throws java.sql.SQLException

Get Category GUID given its internal name.

Calls k_sp_get_cat_id stored procedure.

Parameters:
oConn - Databse Connection
sCategoryNm - Category Internal Name
Returns:
Category GUID
Throws:
java.sql.SQLException

makeName

public static java.lang.String makeName(JDCConnection oConn,
                                        java.lang.String sCategoryNm)
                                 throws java.sql.SQLException

Make an internal category name from an arbitrary string.

Because nm_category is a primary key for table k_categories and because category names are used for composing physical disk paths, some special rules must be followed when assigning category names.

Parameters:
oConn - Database Connection
sCategoryNm - String to be used as a guide for making category name.
Returns:
The input string truncated to 18 characters and transformed to upper case. Method Gadgets.ASCIIEncode() is applies and spaces, commas, asterisks, slashes, backslashes and other characters are removed or substituted. Finally an 8 decimals integer tag is appended to name for making it unique. For example "Barnes & Noble" is transormed to "BARNES_A_NOBLE~00000001"
Throws:
java.sql.SQLException