org.broadleafcommerce.openadmin.web.controller
Class AdminAbstractController

java.lang.Object
  extended by org.broadleafcommerce.common.web.controller.BroadleafAbstractController
      extended by org.broadleafcommerce.openadmin.web.controller.AdminAbstractController
Direct Known Subclasses:
AdminBasicEntityController, AdminBasicOperationsController, AdminExportController, AdminTranslationController

public abstract class AdminAbstractController
extends BroadleafAbstractController

An abstract controller that provides convenience methods and resource declarations for the Admin Operations that are shared between all admin controllers belong here.

Author:
elbertbautista, apazzolini
See Also:
AdminNavigationHandlerMapping

Field Summary
protected  AdminNavigationService adminNavigationService
           
protected  SecurityVerifier adminRemoteSecurityService
           
protected  EntityConfiguration entityConfiguration
           
protected  EntityFormValidator entityValidator
           
protected  FormBuilderService formService
           
protected  AdminEntityService service
           
 
Constructor Summary
AdminAbstractController()
           
 
Method Summary
protected  void attachSectionSpecificInfo(PersistencePackageRequest ppr)
          A hook method that is invoked every time the getSectionPersistencePackageRequest(String) method is invoked.
protected  List<ClassTree> getAddEntityTypes(ClassTree classTree)
          If there are certain types of entities that should not be allowed to be created, an override of this method would be able to specify that.
protected  EntityForm getBlankDynamicFieldTemplateForm(DynamicEntityFormInfo info)
          Convenience method for obtaining a blank dynamic field template form.
protected  String getClassNameForSection(String sectionKey)
          Gets the fully qualified ceiling entity classname for this section.
protected  ListGrid getCollectionListGrid(ClassMetadata mainMetadata, Entity entity, Property collectionProperty, org.springframework.util.MultiValueMap<String,String> requestParams, String sectionKey)
          Convenience method for obtaining a ListGrid DTO object for a collection.
protected  FilterAndSortCriteria[] getCriteria(Map<String,List<String>> requestParams)
          Helper method to return an array of FilterAndSortCriteria based on a map of propertyName -> list of criteria value.
protected  String getDefaultEntityType()
          This method is called when attempting to add new entities that have a polymorphic tree.
protected  EntityForm getDynamicFieldTemplateForm(DynamicEntityFormInfo info, String entityId)
          Convenience method for obtaining a dynamic field template form for a particular entity.
protected  String getDynamicForm(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, DynamicEntityFormInfo info)
          Returns a partial representing a dynamic form.
protected  Integer getMaxIndex(Map<String,List<String>> requestParams)
          Obtains the requested max index parameter
protected  String[] getSectionCustomCriteria()
          This method is invoked for every request for this controller.
protected  String getSectionKey(Map<String,String> pathVars)
          This method is used to determine the current section key.
protected  PersistencePackageRequest getSectionPersistencePackageRequest(String sectionClassName)
          Returns a PersistencePackageRequest for the given sectionClassName.
protected  PersistencePackageRequest getSectionPersistencePackageRequest(String sectionClassName, org.springframework.util.MultiValueMap<String,String> requestParams)
          Returns the result of a call to getSectionPersistencePackageRequest(String) with the additional filter and sort criteria attached.
protected  List<String> getSortDirections(Map<String,List<String>> requestParams)
          Obtains the list of sort directions from the bound request parameters.
protected  List<String> getSortPropertyNames(Map<String,List<String>> requestParams)
          Obtains the list of property names to sort on from the bound request parameters.
protected  Integer getStartIndex(Map<String,List<String>> requestParams)
          Obtains the requested start index parameter
protected  void setModelAttributes(org.springframework.ui.Model model, String sectionKey)
          Attributes to add to the model on every request
 
Methods inherited from class org.broadleafcommerce.common.web.controller.BroadleafAbstractController
getContextPath, isAjaxRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

service

protected AdminEntityService service

formService

protected FormBuilderService formService

adminNavigationService

protected AdminNavigationService adminNavigationService

entityConfiguration

protected EntityConfiguration entityConfiguration

entityValidator

protected EntityFormValidator entityValidator

adminRemoteSecurityService

protected SecurityVerifier adminRemoteSecurityService
Constructor Detail

AdminAbstractController

public AdminAbstractController()
Method Detail

getDynamicForm

protected String getDynamicForm(javax.servlet.http.HttpServletRequest request,
                                javax.servlet.http.HttpServletResponse response,
                                org.springframework.ui.Model model,
                                Map<String,String> pathVars,
                                DynamicEntityFormInfo info)
                         throws Exception
Returns a partial representing a dynamic form. An example of this is the dynamic fields that render on structured content, which are determined by the currently selected structured content type. This method is typically only invoked through Javascript and used to replace the current dynamic form with the one for the newly selected type.

Parameters:
request -
response -
model -
pathVars -
info -
Returns:
the return view path
Throws:
Exception

getCollectionListGrid

protected ListGrid getCollectionListGrid(ClassMetadata mainMetadata,
                                         Entity entity,
                                         Property collectionProperty,
                                         org.springframework.util.MultiValueMap<String,String> requestParams,
                                         String sectionKey)
                                  throws ServiceException
Convenience method for obtaining a ListGrid DTO object for a collection. Note that if no criteria is available, then this should be null (or empty)

Parameters:
mainMetadata - class metadata for the root entity that this collectionProperty relates to
id - foreign key from the root entity for collectionProperty
collectionProperty - property that this collection should be based on from the root entity
form - the criteria form model attribute
sectionKey - the current main section key
Returns:
the list grid
Throws:
ServiceException

getBlankDynamicFieldTemplateForm

protected EntityForm getBlankDynamicFieldTemplateForm(DynamicEntityFormInfo info)
                                               throws ServiceException
Convenience method for obtaining a blank dynamic field template form. For example, if the main entity form should render different fields depending on the value of a specific field in that main form itself, the "dynamic" fields are generated by this method. Because this is invoked when a new value is chosen, the form generated by this method will never have values set.

Parameters:
info -
Returns:
the entity form
Throws:
ServiceException

getDynamicFieldTemplateForm

protected EntityForm getDynamicFieldTemplateForm(DynamicEntityFormInfo info,
                                                 String entityId)
                                          throws ServiceException
Convenience method for obtaining a dynamic field template form for a particular entity. This method differs from getBlankDynamicFieldTemplateForm(DynamicEntityFormInfo) in that it will fill out the current values for the fields in this dynamic form from the database. This method is invoked when the initial view of a page containing a dynamic form is triggered.

Parameters:
info -
entityId -
Returns:
the entity form
Throws:
ServiceException

getSectionKey

protected String getSectionKey(Map<String,String> pathVars)
This method is used to determine the current section key. For this default implementation, the sectionKey is pulled from the pathVariable, {sectionKey}, as defined by the request mapping on this controller. To support controller inheritance and allow more specialized controllers to delegate some methods to this basic controller, overridden implementations of this method could return a hardcoded value instead of reading the map

Parameters:
pathVars - - the map of all currently bound path variables for this request
Returns:
the sectionKey for this request

getCriteria

protected FilterAndSortCriteria[] getCriteria(Map<String,List<String>> requestParams)

Helper method to return an array of FilterAndSortCriteria based on a map of propertyName -> list of criteria value. This will also grab the sorts off of the request parameters, if any.

The multi-valued map allows users to specify multiple criteria values per property, as well as multiple sort properties and sort directions. For multiple sort properties and sort directions, these would usually come in as request parameters like:

....?sortProperty=defaultSku.name&sortProperty=manufacturer&sortDirection=ASCENDING&sortDirection=DESCENDING

This would attach criteria such that defaultSku.name was sorted ascending, and manufacturer was sorted descending

Parameters:
requestParams - usually a MultiValueMap that has been bound by a controller to receive all of the request parameters that are not explicitly named
Returns:
the final array of FilterAndSortCriteria to pass to the fetch
See Also:
#getSortPropertyNames(Map)}, #getSortDirections(Map)}

getSortDirections

protected List<String> getSortDirections(Map<String,List<String>> requestParams)
Obtains the list of sort directions from the bound request parameters. Note that these should appear in the same relative order as getSortPropertyNames(Map)

Parameters:
requestParams -
Returns:

getSortPropertyNames

protected List<String> getSortPropertyNames(Map<String,List<String>> requestParams)
Obtains the list of property names to sort on from the bound request parameters. Note that these should appear in the same relative order as getSortDirections(Map).

Parameters:
requestParams -
Returns:

getClassNameForSection

protected String getClassNameForSection(String sectionKey)
Gets the fully qualified ceiling entity classname for this section. If this section is not explicitly defined in the database, will return the value passed into this function. For example, if there is a mapping from "/myentity" to "com.mycompany.myentity", both "http://localhost/myentity" and "http://localhost/com.mycompany.myentity" are valid request paths.

Parameters:
sectionKey -
Returns:
the className for this sectionKey if found in the database or the sectionKey if not

getAddEntityTypes

protected List<ClassTree> getAddEntityTypes(ClassTree classTree)
If there are certain types of entities that should not be allowed to be created, an override of this method would be able to specify that. It could also add additional types if desired.

Parameters:
classTree -

getDefaultEntityType

protected String getDefaultEntityType()
This method is called when attempting to add new entities that have a polymorphic tree. If this method returns null, there is no default type set for this particular entity type, and the user will be presented with a selection of possible types to utilize. If it returns a non-null value, the returned fullyQualifiedClassname will be used and will bypass the selection step.

Returns:
null if there is no default type, otherwise the default type

getSectionCustomCriteria

protected String[] getSectionCustomCriteria()
This method is invoked for every request for this controller. By default, we do not want to specify a custom criteria, but specialized controllers may want to.

Returns:
the custom criteria for this section for all requests, if any

attachSectionSpecificInfo

protected void attachSectionSpecificInfo(PersistencePackageRequest ppr)
A hook method that is invoked every time the getSectionPersistencePackageRequest(String) method is invoked. This allows specialized controllers to hook into every request and manipulate the persistence package request as desired.

Parameters:
ppr -

getStartIndex

protected Integer getStartIndex(Map<String,List<String>> requestParams)
Obtains the requested start index parameter

Parameters:
requestParams -
Returns:

getMaxIndex

protected Integer getMaxIndex(Map<String,List<String>> requestParams)
Obtains the requested max index parameter

Parameters:
requestParams -
Returns:

setModelAttributes

protected void setModelAttributes(org.springframework.ui.Model model,
                                  String sectionKey)
Attributes to add to the model on every request

Parameters:
model -
sectionKey -

getSectionPersistencePackageRequest

protected PersistencePackageRequest getSectionPersistencePackageRequest(String sectionClassName)
Returns a PersistencePackageRequest for the given sectionClassName. Will also invoke the getSectionCustomCriteria() and attachSectionSpecificInfo(PersistencePackageRequest) to allow specialized controllers to manipulate the request for every action in this controller.

Parameters:
sectionClassName -
Returns:
the PersistencePacakageRequest

getSectionPersistencePackageRequest

protected PersistencePackageRequest getSectionPersistencePackageRequest(String sectionClassName,
                                                                        org.springframework.util.MultiValueMap<String,String> requestParams)
Returns the result of a call to getSectionPersistencePackageRequest(String) with the additional filter and sort criteria attached.

Parameters:
sectionClassName -
filterAndSortCriteria -
Returns:
the PersistencePacakageRequest


Copyright © 2013. All Rights Reserved.