atg.projects.b2bstore.repository
Class B2BRepositoryFormHandler

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.droplet.EmptyFormHandler
              extended by atg.droplet.GenericFormHandler
                  extended by atg.repository.servlet.RepositoryFormHandler
                      extended by atg.projects.b2bstore.repository.B2BRepositoryFormHandler
All Implemented Interfaces:
DropletFormHandler, NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, RepositoryFormConstants, RepositoryFormData, java.util.EventListener

public class B2BRepositoryFormHandler
extends RepositoryFormHandler

This form handler extends RepositoryFormHandler to provide automatic management of relationships between existing repository items and repository items that are created and removed by this form handler.

For example, you can use this form handler to manage the relationship between organizations and billing addresses, automatically adding each a billing address that is created to a parent organization's list of billing addresses, and automatically removing that address from the parent organization's list when it is removed from the repository.

You use this form handler by configuring the repository id and item descriptor type of the parent item whose properties you want to manage, and configuring the name of the property you want to update when a repository item is created or deleted. This configuration is typically performed using hidden input fields in your jhtml pages, since each use of the form handler may affect a different parent item and a different property of that item.

The following properties will typically be set in a properties file

repository
This is the repository that contains items managed by this form handler

The following properties will typically be set in a jhtml file

updateRepositoryId
This is the repository id of the parent repository item whose properties are being updated as repository items are created and deleted.
updateItemDescriptorName
This is the item descriptory type of the parent repository item.
updatePropertyName
This is the property of the parent repository item that will be modified by adding (or removing) items created (or deleted) by this form handler.
updateKey
If a repository item is to be assigned to or removed from a map property of the parent repository item, updateKey identifies which map entry is to be modified.

See Also:
RepositoryFormHandler

Field Summary
static java.lang.String CLASS_VERSION
          Class version string
static java.lang.String MY_RESOURCE_NAME
           
 
Fields inherited from class atg.repository.servlet.RepositoryFormHandler
STATUS_ERROR_REDIRECT, STATUS_ERROR_STAY, STATUS_SUCCESS
 
Fields inherited from class atg.droplet.GenericFormHandler
PARAM_DEFER_FORWARD_OR_REDIRECT, PARAM_USE_FORWARDS
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.repository.servlet.RepositoryFormConstants
NULL_SENTINEL, REPOSITORY_ID_PROPERTY_NAME, RESOURCE_BUNDLE_NAME, UPDATE_APPEND, UPDATE_PREPEND, UPDATE_REMOVE, UPDATE_REPLACE
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
B2BRepositoryFormHandler()
           
 
Method Summary
protected  void addItemToProperty(RepositoryItem pItem, java.lang.Object updatableProperty)
          Based on whether the argument is of type Map or Collection, this method calls addToMap or addToCollection respectively.
protected  void addToCollection(RepositoryItem pItem, java.util.Collection updatableProperty)
          This method adds the newly created repository item to the Collection property of the updateRepositoryItem.
protected  void addToMap(RepositoryItem pItem, java.util.Map updatableProperty)
          This method adds the newly created repository item to the Map property of the updateRepositoryItem.
protected  void checkForRequiredProperties(DynamoHttpServletRequest pRequest)
          Makes sure all the required repository item properties have values submitted in the form.
protected  void deleteItem(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Override deleteItem method to check for references to the item being deleted by other repository items.
protected  RepositoryItem getCurrentItem()
          Get the repository item that this form is operating on.
protected  java.util.Locale getLocale(DynamoHttpServletRequest pRequest)
          Get the locale to use for user-visible error messages.
protected  java.lang.String getMsgResource(java.lang.String pMessageKey, DynamoHttpServletRequest pRequest)
          Return a message from a resource file, taking into account the locale used for user-visible messages.
protected  java.lang.String getMsgResource(java.lang.String pMessageKey, DynamoHttpServletRequest pRequest, java.lang.Object pArg)
          Return a message from a resource file, taking into account the locale used for user-visible messages and substituting the value of a specified argument for the {0} placeholder in the message text.
 java.lang.String[] getRequiredFields()
          Return the list of required property names.
static java.lang.String getResourceBundleName()
          Return the name of the resource bundle to use for this class.
protected  MutableRepositoryItem getUpdatableItem()
          Get a mutable version of the repository item whose id updateRepositoryId and whose type is updateItemDescriptorName.
protected  java.lang.Object getUpdatableProperty()
          Get the property of the update repository item that is to be updated when a new repository item is created.
 java.lang.String getUpdateItemDescriptorName()
          Return the item descriptor name for the item specified by updateRepositoryId.
 java.lang.String getUpdateKey()
          Return the key that identifies the map entry to modify, in cases where updatePropertyName specifies a map-valued property.
 java.lang.String getUpdatePropertyName()
          Return the property of the update item to modify when this form handler creates or deletes a repository item.
 java.lang.String getUpdateRepositoryId()
          Return the repository id of a "container" or "parent" item that may be updated automatically whenever a repository item is created or deleted by this form handler.
 java.lang.String getUserLocale()
          Return the preferred Locale for user-vislble error messages.
static boolean isBlank(java.lang.String pStr)
          Return true if pStr is null, the empty string, or consists entirely of whitespace where whitespace is defined by the String.trim method.
protected  void postCreateItem(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method is called just after a new repository item has been created to add the new item to some property of the update item.
protected  void preCreateItem(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method is called just before the item creation process is started to verify that all required properties have been specified in the form.
protected  void preDeleteItem(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method is called just before a repository item is deleted to remove the item from some property of the update item.
protected  void preUpdateItem(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method is called just before the an item is updated to verify that all required properties have been specified in the form.
protected  void removeFromCollection(RepositoryItem pItem, java.util.Collection updatableProperty)
          This method removes a specified repository item from a specified collection.
protected  void removeFromMap(RepositoryItem pItem, java.util.Map updatableProperty)
          This method removes a specified repository item from a specified map.
protected  void removeItemFromProperty(RepositoryItem pItem, java.lang.Object updatableProperty)
          Based on whether the argument is of type Map or Collection, this method calls removeFromMap or removeFromCollection respectively.
 void setRequiredFields(java.lang.String[] pRequiredFields)
          Specify a list of property names that must be set by the form using this form handler.
 void setUpdateItemDescriptorName(java.lang.String pUpdateItemDescriptorName)
          Set the item descriptor name for the item specified by updateRepositoryId.
 void setUpdateKey(java.lang.String pUpdateKey)
          Set the key that identifies the map entry to modify, in cases where updatePropertyName specifies a map-valued property.
 void setUpdatePropertyName(java.lang.String pPropertyName)
          Set the property of the update item to modify when this form handler creates or deletes a repository item.
 void setUpdateRepositoryId(java.lang.String pUpdateRepositoryId)
          Set the repository id of a "container" or "parent" item that may be updated automatically whenever a repository item is created or deleted by this form handler.
 void setUserLocale(java.lang.String pUserLocale)
          Set the preferred Locale for user-vislble error messages.
 
Methods inherited from class atg.repository.servlet.RepositoryFormHandler
checkFormError, checkFormSuccess, checkForRequiredProperties, getCheckForReadOnlyProperties, getCheckForRequiredProperties, getContentItemDescriptor, getContentNameProperty, getContentPathProperty, getCreateErrorURL, getCreateSuccessURL, getDeleteErrorURL, getDeleteSuccessURL, getEditMapsAsLists, getErrorHandler, getExtractDefaultValuesFromItem, getFolderIdProperty, getItemDescriptor, getItemDescriptorName, getItemProperty, getLogger, getMapKeyValueSeparator, getRemoveReferencesToDeletedItems, getRepository, getRepositoryId, getRepositoryItem, getRepositoryItemEditor, getRepositoryPathName, getRequireIdOnCreate, getSpecifiedIdPropertyValue, getTransactionDemarcation, getTransactionManager, getTrimProperties, getUpdateErrorURL, getUpdateSuccessURL, getValue, getValueProperty, handleCreate, handleDelete, handleUpdate, isClearValueOnSet, isCreateTransientItems, isRequireMapKeys, isSortRepositoryItemSets, isTrimProperty, isUpdateItemsInCollection, postDeleteItem, postUpdateItem, postUpdateItemProperties, setCheckForReadOnlyProperties, setCheckForRequiredProperties, setClearValueOnSet, setContentNameProperty, setContentPathProperty, setCreateErrorURL, setCreateSuccessURL, setCreateTransientItems, setDeleteErrorURL, setDeleteSuccessURL, setEditMapsAsLists, setExtractDefaultValuesFromItem, setFolderIdProperty, setItemDescriptorName, setMapKeyValueSeparator, setRemoveReferencesToDeletedItems, setRepository, setRepositoryId, setRepositoryItemEditor, setRepositoryPathName, setRequireIdOnCreate, setRequireMapKeys, setSortRepositoryItemSets, setTrimProperties, setUpdateErrorURL, setUpdateItemsInCollection, setUpdateSuccessURL, setValueProperty, testPropertyAttribute, updateChildItemProperty, updateContentItemValues, updateItem, updateItemProperties, updateListProperty, updateMapProperty
 
Methods inherited from class atg.droplet.GenericFormHandler
addFormException, addUncheckedFormException, afterSet, beforeSet, checkFormRedirect, createFormSubmissionMessage, getCancelURL, getCheckForValidSession, getFormError, getFormExceptions, getFormName, getMessagePort, getMessageSource, getMessageType, getPropertyExceptions, getSendMessages, getUncheckedFormExceptions, handleCancel, handleFormException, handleUncheckedFormException, hasUncheckedFormExceptions, isDeferForwardsAndRedirects, isRestorableForm, isUseForwards, isValidSession, redirectOrForward, resetFormExceptions, setCancelURL, setCheckForValidSession, setDeferForwardsAndRedirects, setFormName, setMessagePort, setMessageSource, setMessageType, setRestorableForm, setSendMessages, setUseForwards
 
Methods inherited from class atg.droplet.EmptyFormHandler
afterGet, beforeGet
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


MY_RESOURCE_NAME

public static final java.lang.String MY_RESOURCE_NAME
See Also:
Constant Field Values
Constructor Detail

B2BRepositoryFormHandler

public B2BRepositoryFormHandler()
Method Detail

getUpdateRepositoryId

public java.lang.String getUpdateRepositoryId()
Return the repository id of a "container" or "parent" item that may be updated automatically whenever a repository item is created or deleted by this form handler. When a new repository item is created, it can be automatically added to a collection- or map-valued property of the update item. When a repository item is deleted, it can be automatically removed from a collection- or map-valued property of the update item.


setUpdateRepositoryId

public void setUpdateRepositoryId(java.lang.String pUpdateRepositoryId)
Set the repository id of a "container" or "parent" item that may be updated automatically whenever a repository item is created or deleted by this form handler.


getUpdateItemDescriptorName

public java.lang.String getUpdateItemDescriptorName()
Return the item descriptor name for the item specified by updateRepositoryId.


setUpdateItemDescriptorName

public void setUpdateItemDescriptorName(java.lang.String pUpdateItemDescriptorName)
Set the item descriptor name for the item specified by updateRepositoryId.


getUpdatePropertyName

public java.lang.String getUpdatePropertyName()
Return the property of the update item to modify when this form handler creates or deletes a repository item. For example, if updateRepositoryId refers to a repository item of type Organization, and the updatePropertyName is billingAddrs, then creating a new repository item will automatically add it to that organization's billingAddrs property, and removing a repository item will automatically remove it from that organization's billingAddrs.


setUpdatePropertyName

public void setUpdatePropertyName(java.lang.String pPropertyName)
Set the property of the update item to modify when this form handler creates or deletes a repository item.


getUpdateKey

public java.lang.String getUpdateKey()
Return the key that identifies the map entry to modify, in cases where updatePropertyName specifies a map-valued property.


setUpdateKey

public void setUpdateKey(java.lang.String pUpdateKey)
Set the key that identifies the map entry to modify, in cases where updatePropertyName specifies a map-valued property.


getRequiredFields

public java.lang.String[] getRequiredFields()
Return the list of required property names. When any item is created or updated using this form handler, the preCreate or preUpdate method checks to make sure all of the required properties have been set. If any required properties are missing, a form exception is added to the form for each missing property.


setRequiredFields

public void setRequiredFields(java.lang.String[] pRequiredFields)
Specify a list of property names that must be set by the form using this form handler. When any item is created or updated using this form handler, the preCreate or preUpdate method checks to make sure all of the required properties have been set. If any required properties are missing, a form exception is added to the form for each missing property.


getUserLocale

public java.lang.String getUserLocale()
Return the preferred Locale for user-vislble error messages.


setUserLocale

public void setUserLocale(java.lang.String pUserLocale)
Set the preferred Locale for user-vislble error messages. If not set, the Locale of the request will be used, if available. Otherwise, the default server Locale will be used.


getResourceBundleName

public static java.lang.String getResourceBundleName()
Return the name of the resource bundle to use for this class.


checkForRequiredProperties

protected void checkForRequiredProperties(DynamoHttpServletRequest pRequest)
Makes sure all the required repository item properties have values submitted in the form. If any errors occur, form exceptions are added.

Throws:
RepositoryException - if there was an error while accessing the repository

preCreateItem

protected void preCreateItem(DynamoHttpServletRequest pRequest,
                             DynamoHttpServletResponse pResponse)
                      throws javax.servlet.ServletException,
                             java.io.IOException
This method is called just before the item creation process is started to verify that all required properties have been specified in the form.

Overrides:
preCreateItem in class RepositoryFormHandler
Parameters:
pRequest - the servlet's request
pResponse - the servlet's response
Throws:
javax.servlet.ServletException - if there was an error while executing the code
java.io.IOException - if there was an error with servlet io

preUpdateItem

protected void preUpdateItem(DynamoHttpServletRequest pRequest,
                             DynamoHttpServletResponse pResponse)
                      throws javax.servlet.ServletException,
                             java.io.IOException
This method is called just before the an item is updated to verify that all required properties have been specified in the form.

Overrides:
preUpdateItem in class RepositoryFormHandler
Parameters:
pRequest - the servlet's request
pResponse - the servlet's response
Throws:
javax.servlet.ServletException - if there was an error while executing the code
java.io.IOException - if there was an error with servlet io

postCreateItem

protected void postCreateItem(DynamoHttpServletRequest pRequest,
                              DynamoHttpServletResponse pResponse)
                       throws javax.servlet.ServletException,
                              java.io.IOException
This method is called just after a new repository item has been created to add the new item to some property of the update item. It finds the repository item identified by updateRepositoryId and the property identified by updatePropertyName, then calls addItemToProperty to add the new item to the named property of the existing item.

Overrides:
postCreateItem in class RepositoryFormHandler
Parameters:
pRequest - the servlet's request
pResponse - the servlet's response
Throws:
javax.servlet.ServletException - if there was an error while executing the code
java.io.IOException - if there was an error with servlet io

preDeleteItem

protected void preDeleteItem(DynamoHttpServletRequest pRequest,
                             DynamoHttpServletResponse pResponse)
                      throws javax.servlet.ServletException,
                             java.io.IOException
This method is called just before a repository item is deleted to remove the item from some property of the update item. It finds the repository item identified by updateRepositoryId and the property identified by updatePropertyName, then calls removeItemFromProperty to remove the item being deleted from that property of the existing item.

Overrides:
preDeleteItem in class RepositoryFormHandler
Parameters:
pRequest - the servlet's request
pResponse - the servlet's response
Throws:
javax.servlet.ServletException - if there was an error while executing the code
java.io.IOException - if there was an error with servlet io

deleteItem

protected void deleteItem(DynamoHttpServletRequest pRequest,
                          DynamoHttpServletResponse pResponse)
                   throws javax.servlet.ServletException,
                          java.io.IOException
Override deleteItem method to check for references to the item being deleted by other repository items. If the item is unreferenced it will be deleted by calling the superclass's deleteItem. If references to the item do exist, the delete operation is silently converted into a no-op.

Overrides:
deleteItem in class RepositoryFormHandler
Parameters:
pRequest - the servlet's request
pResponse - the servlet's response
Throws:
javax.servlet.ServletException - if there was an error while executing the code
java.io.IOException - if there was an error with servlet io

addItemToProperty

protected void addItemToProperty(RepositoryItem pItem,
                                 java.lang.Object updatableProperty)
Based on whether the argument is of type Map or Collection, this method calls addToMap or addToCollection respectively. Override this method to support other property types you may want to manage automatically.


addToMap

protected void addToMap(RepositoryItem pItem,
                        java.util.Map updatableProperty)
This method adds the newly created repository item to the Map property of the updateRepositoryItem.


addToCollection

protected void addToCollection(RepositoryItem pItem,
                               java.util.Collection updatableProperty)
This method adds the newly created repository item to the Collection property of the updateRepositoryItem.


removeItemFromProperty

protected void removeItemFromProperty(RepositoryItem pItem,
                                      java.lang.Object updatableProperty)
Based on whether the argument is of type Map or Collection, this method calls removeFromMap or removeFromCollection respectively. Override this method to support other property types you may want to manage automatically.


removeFromMap

protected void removeFromMap(RepositoryItem pItem,
                             java.util.Map updatableProperty)
This method removes a specified repository item from a specified map.


removeFromCollection

protected void removeFromCollection(RepositoryItem pItem,
                                    java.util.Collection updatableProperty)
This method removes a specified repository item from a specified collection.


getCurrentItem

protected RepositoryItem getCurrentItem()
                                 throws RepositoryException
Get the repository item that this form is operating on. In the case of item creation, this will return the item just created. In the case of item update or removal, this will return the item being modified or deleted.

Throws:
RepositoryException

getUpdatableItem

protected MutableRepositoryItem getUpdatableItem()
                                          throws RepositoryException
Get a mutable version of the repository item whose id updateRepositoryId and whose type is updateItemDescriptorName.

Throws:
RepositoryException

getUpdatableProperty

protected java.lang.Object getUpdatableProperty()
                                         throws RepositoryException
Get the property of the update repository item that is to be updated when a new repository item is created. Return null if no such property can be found.

Throws:
RepositoryException

getMsgResource

protected java.lang.String getMsgResource(java.lang.String pMessageKey,
                                          DynamoHttpServletRequest pRequest)
Return a message from a resource file, taking into account the locale used for user-visible messages.

See Also:
atg.core.util.getMsgResource

getMsgResource

protected java.lang.String getMsgResource(java.lang.String pMessageKey,
                                          DynamoHttpServletRequest pRequest,
                                          java.lang.Object pArg)
Return a message from a resource file, taking into account the locale used for user-visible messages and substituting the value of a specified argument for the {0} placeholder in the message text.

See Also:
atg.core.util.getMsgResource

getLocale

protected java.util.Locale getLocale(DynamoHttpServletRequest pRequest)
Get the locale to use for user-visible error messages. Returns the locale specified by the userLocale property if set, otherwise returns the request locale from pRequest if set, otherwise returns the default server locale.


isBlank

public static boolean isBlank(java.lang.String pStr)
Return true if pStr is null, the empty string, or consists entirely of whitespace where whitespace is defined by the String.trim method.

See Also:
String