Class AdminAbstractController

java.lang.Object
org.broadleafcommerce.common.web.controller.BroadleafAbstractController
org.broadleafcommerce.openadmin.web.controller.AdminAbstractController
Direct Known Subclasses:
AdminAssetUploadController, AdminBasicEntityController, AdminBasicOperationsController, AdminCatalogActionsController, 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
  • Field Details

  • Constructor Details

    • AdminAbstractController

      public AdminAbstractController()
  • Method Details

    • getEntityForm

      protected EntityForm getEntityForm(String sectionKey, String sectionClassName, String id) throws ServiceException
      Convenience method for obtaining a fully built EntityForm for the given sectionKey, sectionClassName, and id.
      Parameters:
      sectionKey -
      sectionClassName -
      id -
      Returns:
      a fully composed EntityForm
      Throws:
      ServiceException
    • getDynamicForm

      protected String getDynamicForm(jakarta.servlet.http.HttpServletRequest request, jakarta.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, PersistenceResponse persistenceResponse, List<SectionCrumb> sectionCrumbs) 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
      entity -
      collectionProperty - property that this collection should be based on from the root entity
      requestParams -
      sectionKey - the current main section key
      persistenceResponse -
      sectionCrumbs -
      Returns:
      the list grid
      Throws:
      ServiceException
    • getCollectionListGrid

      protected ListGrid getCollectionListGrid(ClassMetadata mainMetadata, Entity entity, Property collectionProperty, org.springframework.util.MultiValueMap<String,String> requestParams, String sectionKey, List<SectionCrumb> sectionCrumbs) 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
      entity -
      collectionProperty - property that this collection should be based on from the root entity
      requestParams -
      sectionKey - the current main section key
      sectionCrumbs -
      Returns:
      the list grid
      Throws:
      ServiceException
    • getEntityForm

      protected EntityForm getEntityForm(DynamicEntityFormInfo info) throws ServiceException
      Throws:
      ServiceException
    • getEntityForm

      protected EntityForm getEntityForm(DynamicEntityFormInfo info, EntityForm dynamicFormOverride) throws ServiceException
      Throws:
      ServiceException
    • getDynamicFieldTemplateForm

      protected EntityForm getDynamicFieldTemplateForm(DynamicEntityFormInfo info, String entityId, EntityForm dynamicFormOverride) 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.

      Optionally, you can pass in a pre-existing dynamic form to this method that already has updated values. Example usage would be for after validation has failed and you do not want to lookup old values from the database again.

      Parameters:
      info -
      entityId -
      dynamicFormOverride - optional dynamic form that already has values to fill out
      Returns:
      the entity form
      Throws:
      ServiceException
    • setSpecializedNameForFields

      protected void setSpecializedNameForFields(DynamicEntityFormInfo info, EntityForm dynamicForm)
    • extractDynamicFormFields

      protected void extractDynamicFormFields(ClassMetadata cmd, EntityForm entityForm)
      This method will scan the entityForm for all dynamic form fields and pull them out as appropriate.
      Parameters:
      cmd -
      entityForm -
    • 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
    • modifyCriteria

      protected void modifyCriteria(Map<String,FilterAndSortCriteria> fasMap)
    • 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 -
      Returns:
      a List representing all potentially avaialble entity types to create
    • 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

      @Deprecated protected void attachSectionSpecificInfo(PersistencePackageRequest ppr)
    • modifyEntityForm

      protected void modifyEntityForm(EntityForm entityForm, Map<String,String> pathVars) throws Exception
      This method is invoked whenever an assembled EntityForm is rendered. This typically occurs when viewing an entity in the admin or viewing an error state on a POST for that entity.
      Parameters:
      entityForm -
      Throws:
      Exception
    • modifyAddEntityForm

      protected void modifyAddEntityForm(EntityForm entityForm, Map<String,String> pathVars)
      This method is invoked whenever an assembled EntityForm is rendered for the add entity screen.
      Parameters:
      entityForm -
    • attachSectionSpecificInfo

      protected void attachSectionSpecificInfo(PersistencePackageRequest ppr, Map<String,String> pathVars)
      A hook method that is invoked every time the getSectionPersistencePackageRequest(..) 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:
    • getMaxResults

      protected Integer getMaxResults(Map<String,List<String>> requestParams)
      Obtains the requested max index parameter
      Parameters:
      requestParams -
      Returns:
    • getLastId

      protected Long getLastId(Map<String,List<String>> requestParams)
    • getFirstId

      protected Long getFirstId(Map<String,List<String>> requestParams)
    • getUpperCount

      protected Integer getUpperCount(Map<String,List<String>> requestParams)
    • getLowerCount

      protected Integer getLowerCount(Map<String,List<String>> requestParams)
    • getPageSize

      protected Integer getPageSize(Map<String,List<String>> requestParams)
    • setModelAttributes

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

      @Deprecated protected PersistencePackageRequest getSectionPersistencePackageRequest(String sectionClassName, List<SectionCrumb> sectionCrumbs)
    • getSectionPersistencePackageRequest

      protected PersistencePackageRequest getSectionPersistencePackageRequest(String sectionClassName, List<SectionCrumb> sectionCrumbs, Map<String,String> pathVars)
      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 -
      sectionCrumbs -
      pathVars -
      Returns:
    • getSectionPersistencePackageRequest

      @Deprecated protected PersistencePackageRequest getSectionPersistencePackageRequest(String sectionClassName, org.springframework.util.MultiValueMap<String,String> requestParams, List<SectionCrumb> sectionCrumbs)
    • getPersistencePackageRequest

      protected PersistencePackageRequest getPersistencePackageRequest(org.springframework.util.MultiValueMap<String,String> requestParams, Class<?> ceilingEntityClass)
      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:
      requestParams -
      ceilingEntityClass -
      Returns:
    • getSectionPersistencePackageRequest

      protected PersistencePackageRequest getSectionPersistencePackageRequest(String sectionClassName, org.springframework.util.MultiValueMap<String,String> requestParams, List<SectionCrumb> sectionCrumbs, Map<String,String> pathVars)
      Returns the result of a call to getSectionPersistencePackageRequest(..) with the additional filter and sort criteria attached.
      Parameters:
      sectionClassName -
      requestParams -
      sectionCrumbs -
      pathVars -
      Returns:
      the PersistencePacakageRequest
    • getSectionCrumbs

      protected List<SectionCrumb> getSectionCrumbs(jakarta.servlet.http.HttpServletRequest request, String currentSection, String currentSectionId)
    • createSectionCrumb

      protected SectionCrumb createSectionCrumb(String currentSection, String currentSectionId)
    • populateJsonValidationErrors

      protected JsonResponse populateJsonValidationErrors(EntityForm form, org.springframework.validation.BindingResult result, JsonResponse json)
      Populates the given json response object based on the given form and result
      Returns:
      the same result that was passed in
    • translateErrorMessage

      protected String translateErrorMessage(org.springframework.validation.ObjectError error)
    • declareForceUseAdditionStatusFilter

      protected void declareForceUseAdditionStatusFilter()