org.broadleafcommerce.openadmin.web.controller.entity
Class AdminBasicEntityController

java.lang.Object
  extended by org.broadleafcommerce.common.web.controller.BroadleafAbstractController
      extended by org.broadleafcommerce.openadmin.web.controller.AdminAbstractController
          extended by org.broadleafcommerce.openadmin.web.controller.entity.AdminBasicEntityController

@Controller(value="blAdminBasicEntityController")
@RequestMapping(value="/{sectionKey}")
public class AdminBasicEntityController
extends AdminAbstractController

The default implementation of the #BroadleafAdminAbstractEntityController. This delegates every call to super and does not provide any custom-tailored functionality. It is responsible for rendering the admin for every entity that is not explicitly customized by its own controller.

Author:
Andre Azzolini (apazzolini)

Field Summary
protected  EntityConfiguration entityConfiguration
           
protected  EntityFormValidator entityValidator
           
protected  FormBuilderService formService
           
protected  AdminEntityService service
           
 
Fields inherited from class org.broadleafcommerce.openadmin.web.controller.AdminAbstractController
adminNavigationService
 
Constructor Summary
AdminBasicEntityController()
           
 
Method Summary
 String addCollectionItem(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, String id, String collectionField, EntityForm entityForm)
          Adds the requested collection item
 String addEntity(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, EntityForm entityForm, org.springframework.validation.BindingResult result)
          Processes the request to add a new entity.
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.
 String getCollectionFieldRecords(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, String id, String collectionField, CriteriaForm criteriaForm)
          Returns the records for a given collectionField filtered by a particular criteria
protected  ListGrid getCollectionListGrid(ClassMetadata mainMetadata, Entity entity, Property collectionProperty, FilterAndSortCriteria[] criteria, String sectionKey)
          Convenience method for obtaining a ListGrid DTO object for a collection.
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  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, FilterAndSortCriteria[] filterAndSortCriteria)
          Returns the result of a call to getSectionPersistencePackageRequest(String) with the additional filter and sort criteria attached.
 void initBinder(org.springframework.web.bind.WebDataBinder binder)
          Invoked on every request to provide the ability to register specific binders for Spring's binding process.
 String removeCollectionItem(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, String id, String collectionField, String collectionItemId)
          Removes the requested collection item Note that the request must contain a parameter called "key" when attempting to remove a collection item from a map collection.
 String removeEntity(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, String id, EntityForm entityForm, org.springframework.validation.BindingResult result)
          Attempts to remove the given entity.
 String saveEntity(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, String id, EntityForm entityForm, org.springframework.validation.BindingResult result, org.springframework.web.servlet.mvc.support.RedirectAttributes ra)
          Attempts to save the given entity.
protected  void setModelAttributes(org.springframework.ui.Model model, String sectionKey)
          Attributes to add to the model on every request
 String showAddCollectionItem(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, String id, String collectionField)
          Shows the modal dialog that is used to add an item to a given collection.
 String showSelectCollectionItem(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, String collectionField, CriteriaForm criteriaForm)
          Shows the modal dialog that is used to select a "to-one" collection item.
 String showUpdateCollectionItem(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, String id, String collectionField, String collectionItemId)
          Shows the appropriate modal dialog to edit the selected collection item
 String updateCollectionItem(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, String id, String collectionField, String collectionItemId, EntityForm entityForm)
          Updates the specified collection item
 String viewAddEntityForm(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, String entityType)
          Renders the modal form that is used to add a new parent level entity.
 String viewCollectionItemDetails(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, String collectionField, String id)
          Shows the modal popup for the current selected "to-one" field.
 String viewEntityForm(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, String id)
          Renders the main entity form for the specified entity
 String viewEntityList(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Map<String,String> pathVars, CriteriaForm criteriaForm)
          Renders the main entity listing for the specified class, which is based on the current sectionKey with some optional criteria.
 
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

entityConfiguration

protected EntityConfiguration entityConfiguration

entityValidator

protected EntityFormValidator entityValidator
Constructor Detail

AdminBasicEntityController

public AdminBasicEntityController()
Method Detail

viewEntityList

@RequestMapping(value="",
                method=GET)
public String viewEntityList(javax.servlet.http.HttpServletRequest request,
                                            javax.servlet.http.HttpServletResponse response,
                                            org.springframework.ui.Model model,
                                            @PathVariable
                                            Map<String,String> pathVars,
                                            @ModelAttribute
                                            CriteriaForm criteriaForm)
                      throws Exception
Renders the main entity listing for the specified class, which is based on the current sectionKey with some optional criteria.

Parameters:
request -
response -
model -
pathVars -
criteriaForm - criteria from the frontend; can be null
Returns:
the return view path
Throws:
Exception

viewAddEntityForm

@RequestMapping(value="/add",
                method=GET)
public String viewAddEntityForm(javax.servlet.http.HttpServletRequest request,
                                               javax.servlet.http.HttpServletResponse response,
                                               org.springframework.ui.Model model,
                                               @PathVariable
                                               Map<String,String> pathVars,
                                               @RequestParam(defaultValue="")
                                               String entityType)
                         throws Exception
Renders the modal form that is used to add a new parent level entity. Note that this form cannot render any subcollections as operations on those collections require the parent level entity to first be saved and have and id. Once the entity is initially saved, we will redirect the user to the normal manage entity screen where they can then perform operations on sub collections.

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

addEntity

@RequestMapping(value="/add",
                method=POST)
public String addEntity(javax.servlet.http.HttpServletRequest request,
                                       javax.servlet.http.HttpServletResponse response,
                                       org.springframework.ui.Model model,
                                       @PathVariable
                                       Map<String,String> pathVars,
                                       @ModelAttribute
                                       EntityForm entityForm,
                                       org.springframework.validation.BindingResult result)
                 throws Exception
Processes the request to add a new entity. If successful, returns a redirect to the newly created entity.

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

viewEntityForm

@RequestMapping(value="/{id}",
                method=GET)
public String viewEntityForm(javax.servlet.http.HttpServletRequest request,
                                            javax.servlet.http.HttpServletResponse response,
                                            org.springframework.ui.Model model,
                                            @PathVariable
                                            Map<String,String> pathVars,
                                            @PathVariable
                                            String id)
                      throws Exception
Renders the main entity form for the specified entity

Parameters:
request -
response -
model -
pathVars -
id -
modal - - whether or not to show the entity in a read-only modal
Returns:
the return view path
Throws:
Exception

saveEntity

@RequestMapping(value="/{id}",
                method=POST)
public String saveEntity(javax.servlet.http.HttpServletRequest request,
                                        javax.servlet.http.HttpServletResponse response,
                                        org.springframework.ui.Model model,
                                        @PathVariable
                                        Map<String,String> pathVars,
                                        @PathVariable
                                        String id,
                                        @ModelAttribute
                                        EntityForm entityForm,
                                        org.springframework.validation.BindingResult result,
                                        org.springframework.web.servlet.mvc.support.RedirectAttributes ra)
                  throws Exception
Attempts to save the given entity. If validation is unsuccessful, it will re-render the entity form with error fields highlighted. On a successful save, it will refresh the entity page.

Parameters:
request -
response -
model -
pathVars -
id -
entityForm -
result -
Returns:
the return view path
Throws:
Exception

removeEntity

@RequestMapping(value="/{id}/delete",
                method=POST)
public String removeEntity(javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response,
                                          org.springframework.ui.Model model,
                                          @PathVariable
                                          Map<String,String> pathVars,
                                          @PathVariable
                                          String id,
                                          @ModelAttribute
                                          EntityForm entityForm,
                                          org.springframework.validation.BindingResult result)
                    throws Exception
Attempts to remove the given entity.

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

showSelectCollectionItem

@RequestMapping(value="/{collectionField}/select",
                method=GET)
public String showSelectCollectionItem(javax.servlet.http.HttpServletRequest request,
                                                      javax.servlet.http.HttpServletResponse response,
                                                      org.springframework.ui.Model model,
                                                      @PathVariable
                                                      Map<String,String> pathVars,
                                                      @PathVariable
                                                      String collectionField,
                                                      @ModelAttribute
                                                      CriteriaForm criteriaForm)
                                throws Exception
Shows the modal dialog that is used to select a "to-one" collection item. For example, this could be used to show a list of categories for the ManyToOne field "defaultCategory" in Product.

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

viewCollectionItemDetails

@RequestMapping(value="/{collectionField}/{id}/view",
                method=GET)
public String viewCollectionItemDetails(javax.servlet.http.HttpServletRequest request,
                                                       javax.servlet.http.HttpServletResponse response,
                                                       org.springframework.ui.Model model,
                                                       @PathVariable
                                                       Map<String,String> pathVars,
                                                       @PathVariable
                                                       String collectionField,
                                                       @PathVariable
                                                       String id)
                                 throws Exception
Shows the modal popup for the current selected "to-one" field. For instance, if you are viewing a list of products then this method is invoked when a user clicks on the name of the default category field.

Parameters:
request -
response -
model -
pathVars -
collectionField -
id -
Returns:
Throws:
Exception

getCollectionFieldRecords

@RequestMapping(value="/{id}/{collectionField}",
                method=GET)
public String getCollectionFieldRecords(javax.servlet.http.HttpServletRequest request,
                                                       javax.servlet.http.HttpServletResponse response,
                                                       org.springframework.ui.Model model,
                                                       @PathVariable
                                                       Map<String,String> pathVars,
                                                       @PathVariable
                                                       String id,
                                                       @PathVariable
                                                       String collectionField,
                                                       @ModelAttribute
                                                       CriteriaForm criteriaForm)
                                 throws Exception
Returns the records for a given collectionField filtered by a particular criteria

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

showAddCollectionItem

@RequestMapping(value="/{id}/{collectionField}/add",
                method=GET)
public String showAddCollectionItem(javax.servlet.http.HttpServletRequest request,
                                                   javax.servlet.http.HttpServletResponse response,
                                                   org.springframework.ui.Model model,
                                                   @PathVariable
                                                   Map<String,String> pathVars,
                                                   @PathVariable
                                                   String id,
                                                   @PathVariable
                                                   String collectionField)
                             throws Exception
Shows the modal dialog that is used to add an item to a given collection. There are several possible outcomes of this call depending on the type of the specified collection field.

showUpdateCollectionItem

@RequestMapping(value="/{id}/{collectionField}/{collectionItemId}",
                method=GET)
public String showUpdateCollectionItem(javax.servlet.http.HttpServletRequest request,
                                                      javax.servlet.http.HttpServletResponse response,
                                                      org.springframework.ui.Model model,
                                                      @PathVariable
                                                      Map<String,String> pathVars,
                                                      @PathVariable
                                                      String id,
                                                      @PathVariable
                                                      String collectionField,
                                                      @PathVariable
                                                      String collectionItemId)
                                throws Exception
Shows the appropriate modal dialog to edit the selected collection item

Parameters:
request -
response -
model -
pathVars -
id -
collectionField -
collectionItemId -
Returns:
the return view path
Throws:
Exception

addCollectionItem

@RequestMapping(value="/{id}/{collectionField}/add",
                method=POST)
public String addCollectionItem(javax.servlet.http.HttpServletRequest request,
                                               javax.servlet.http.HttpServletResponse response,
                                               org.springframework.ui.Model model,
                                               @PathVariable
                                               Map<String,String> pathVars,
                                               @PathVariable
                                               String id,
                                               @PathVariable
                                               String collectionField,
                                               @ModelAttribute
                                               EntityForm entityForm)
                         throws Exception
Adds the requested collection item

Parameters:
request -
response -
model -
pathVars -
id -
collectionField -
entityForm -
Returns:
the return view path
Throws:
Exception

updateCollectionItem

@RequestMapping(value="/{id}/{collectionField}/{collectionItemId}",
                method=POST)
public String updateCollectionItem(javax.servlet.http.HttpServletRequest request,
                                                  javax.servlet.http.HttpServletResponse response,
                                                  org.springframework.ui.Model model,
                                                  @PathVariable
                                                  Map<String,String> pathVars,
                                                  @PathVariable
                                                  String id,
                                                  @PathVariable
                                                  String collectionField,
                                                  @PathVariable
                                                  String collectionItemId,
                                                  @ModelAttribute
                                                  EntityForm entityForm)
                            throws Exception
Updates the specified collection item

Parameters:
request -
response -
model -
pathVars -
id -
collectionField -
entityForm -
Returns:
the return view path
Throws:
Exception

removeCollectionItem

@RequestMapping(value="/{id}/{collectionField}/{collectionItemId}/delete",
                method=POST)
public String removeCollectionItem(javax.servlet.http.HttpServletRequest request,
                                                  javax.servlet.http.HttpServletResponse response,
                                                  org.springframework.ui.Model model,
                                                  @PathVariable
                                                  Map<String,String> pathVars,
                                                  @PathVariable
                                                  String id,
                                                  @PathVariable
                                                  String collectionField,
                                                  @PathVariable
                                                  String collectionItemId)
                            throws Exception
Removes the requested collection item Note that the request must contain a parameter called "key" when attempting to remove a collection item from a map collection.

Parameters:
request -
response -
model -
pathVars -
id -
collectionField -
collectionItemId -
Returns:
the return view path
Throws:
Exception

initBinder

@InitBinder
public void initBinder(org.springframework.web.bind.WebDataBinder binder)
Invoked on every request to provide the ability to register specific binders for Spring's binding process. By default, we register a binder that treats empty Strings as null and a Boolean editor that supports either true or false. If the value is passed in as null, it will treat it as false.

Parameters:
binder -

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,
                                         FilterAndSortCriteria[] criteria,
                                         String sectionKey)
                                  throws ServiceException,
                                         com.gwtincubator.security.exception.ApplicationSecurityException
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
criteria - criteria to filter the subcollection list by, can be null
sectionKey - the current main section key
Returns:
the list grid
Throws:
ServiceException
com.gwtincubator.security.exception.ApplicationSecurityException

getBlankDynamicFieldTemplateForm

protected EntityForm getBlankDynamicFieldTemplateForm(DynamicEntityFormInfo info)
                                               throws ServiceException,
                                                      com.gwtincubator.security.exception.ApplicationSecurityException
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
com.gwtincubator.security.exception.ApplicationSecurityException

getDynamicFieldTemplateForm

protected EntityForm getDynamicFieldTemplateForm(DynamicEntityFormInfo info,
                                                 String entityId)
                                          throws ServiceException,
                                                 com.gwtincubator.security.exception.ApplicationSecurityException
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
com.gwtincubator.security.exception.ApplicationSecurityException

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

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 -

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,
                                                                        FilterAndSortCriteria[] filterAndSortCriteria)
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.