org.broadleafcommerce.openadmin.web.service
Class FormBuilderServiceImpl

java.lang.Object
  extended by org.broadleafcommerce.openadmin.web.service.FormBuilderServiceImpl
All Implemented Interfaces:
FormBuilderService

@Service(value="blFormBuilderService")
public class FormBuilderServiceImpl
extends Object
implements FormBuilderService

Author:
Andre Azzolini (apazzolini)

Field Summary
protected  AdminEntityService adminEntityService
           
protected static VisibilityEnum[] FORM_HIDDEN_VISIBILITIES
           
protected static VisibilityEnum[] GRID_HIDDEN_VISIBILITIES
           
protected  AdminNavigationService navigationService
           
 
Constructor Summary
FormBuilderServiceImpl()
           
 
Method Summary
 EntityForm buildAdornedListForm(AdornedTargetCollectionMetadata adornedMd, AdornedTargetList adornedList, String parentId)
          Builds the EntityForm used in modal dialogs when adding items to adorned target collections.
 ListGrid buildCollectionListGrid(String containingEntityId, DynamicResultSet drs, Property field, String sectionKey)
          Builds a list grid that is used to render a collection inline in an entity form.
 ListGrid buildMainListGrid(DynamicResultSet drs, ClassMetadata cmd, String sectionKey)
          Builds a list grid that is typically used at the top entity level to select an entity for modification.
 EntityForm buildMapForm(MapMetadata mapMd, MapStructure mapStructure, ClassMetadata cmd, String parentId)
          Builds the EntityForm used in modal dialogs when adding items to map collections.
protected  DataWrapper convertJsonToDataWrapper(String json)
          When using Thymeleaf, we need to convert the JSON string back to a DataWrapper object because Thymeleaf escapes JSON strings.
protected  Media convertJsonToMedia(String json)
           
 EntityForm createEntityForm(ClassMetadata cmd)
          Creates a new EntityForm with the a default 'Save' action.
 EntityForm createEntityForm(ClassMetadata cmd, Entity entity)
          Creates a new EntityForm that has all of the appropriate fields set up along with the values for those fields from the given Entity.
 EntityForm createEntityForm(ClassMetadata cmd, Entity entity, Map<String,DynamicResultSet> collectionRecords)
          Builds an EntityForm that has all of the appropriate fields set up along with the values for those fields from the given Entity as well as all sub-collections of the given Entity that appear in the collectionRecords map.
protected  Field createHeaderField(Property p, BasicFieldMetadata fmd)
           
protected  ListGrid createListGrid(String className, List<Field> headerFields, ListGrid.Type type, DynamicResultSet drs, String sectionKey, int order, String idProperty)
           
protected  EntityForm createStandardEntityForm()
           
protected  VisibilityEnum[] getFormHiddenVisibilities()
           
protected  VisibilityEnum[] getGridHiddenVisibilities()
           
 void populateAdornedEntityFormFields(EntityForm ef, Entity entity, AdornedTargetList adornedList)
          Sets values for the necessary adorned fields on the EntityForm from the specified entity.
protected  void populateDropdownToOneFields(EntityForm ef, ClassMetadata cmd)
           
 void populateEntityForm(ClassMetadata cmd, Entity entity, EntityForm ef)
          Populates a given ef based on the given cmd to initially create fields with the necessary metadata and then fills those fields out based on the property values from entity.
 void populateEntityForm(ClassMetadata cmd, EntityForm ef)
          Populates the given ef with all of the fields based on the properties from cmd.
 void populateEntityForm(ClassMetadata cmd, Entity entity, Map<String,DynamicResultSet> collectionRecords, EntityForm ef)
          Builds an EntityForm that has all of the appropriate fields set up along with the values for thsoe fields from the given Entity as well as all sub-collections of the given Entity that appear in the collectionRecords map.
 void populateEntityFormFields(EntityForm ef, Entity entity)
          Sets values for all fields found on the EntityForm from the specified entity.
 void populateMapEntityFormFields(EntityForm ef, Entity entity)
          Sets values for the necessary map fields on the EntityForm from the specified entity.
 void removeNonApplicableFields(ClassMetadata cmd, EntityForm entityForm, String entityType)
          Loops through all of the fields that are specified in given class metadata and removes fields that are not applicable for the given polymorphic entity type from the entity form.
protected  void setEntityFormFields(EntityForm ef, List<Property> properties)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

adminEntityService

protected AdminEntityService adminEntityService

navigationService

protected AdminNavigationService navigationService

FORM_HIDDEN_VISIBILITIES

protected static final VisibilityEnum[] FORM_HIDDEN_VISIBILITIES

GRID_HIDDEN_VISIBILITIES

protected static final VisibilityEnum[] GRID_HIDDEN_VISIBILITIES
Constructor Detail

FormBuilderServiceImpl

public FormBuilderServiceImpl()
Method Detail

buildMainListGrid

public ListGrid buildMainListGrid(DynamicResultSet drs,
                                  ClassMetadata cmd,
                                  String sectionKey)
                           throws ServiceException
Description copied from interface: FormBuilderService
Builds a list grid that is typically used at the top entity level to select an entity for modification. Note that it can also be used in other places that require the same grid as the main entity search screen provided the type on the returned ListGrid is set appropriately.

Specified by:
buildMainListGrid in interface FormBuilderService
Returns:
the ListGrid
Throws:
ServiceException

createHeaderField

protected Field createHeaderField(Property p,
                                  BasicFieldMetadata fmd)

buildCollectionListGrid

public ListGrid buildCollectionListGrid(String containingEntityId,
                                        DynamicResultSet drs,
                                        Property field,
                                        String sectionKey)
                                 throws ServiceException
Description copied from interface: FormBuilderService
Builds a list grid that is used to render a collection inline in an entity form. Note that it can also be used in other places that require the same grid provided the type on the returned ListGrid is set appropriately.

Specified by:
buildCollectionListGrid in interface FormBuilderService
Returns:
the ListGrid
Throws:
ServiceException

createListGrid

protected ListGrid createListGrid(String className,
                                  List<Field> headerFields,
                                  ListGrid.Type type,
                                  DynamicResultSet drs,
                                  String sectionKey,
                                  int order,
                                  String idProperty)

setEntityFormFields

protected void setEntityFormFields(EntityForm ef,
                                   List<Property> properties)

removeNonApplicableFields

public void removeNonApplicableFields(ClassMetadata cmd,
                                      EntityForm entityForm,
                                      String entityType)
Description copied from interface: FormBuilderService
Loops through all of the fields that are specified in given class metadata and removes fields that are not applicable for the given polymorphic entity type from the entity form.

Specified by:
removeNonApplicableFields in interface FormBuilderService

createEntityForm

public EntityForm createEntityForm(ClassMetadata cmd)
                            throws ServiceException
Description copied from interface: FormBuilderService
Creates a new EntityForm with the a default 'Save' action. This will then delegate to FormBuilderService.populateEntityForm(ClassMetadata, EntityForm) to ensure that the newly created EntityForm has all of the appropriate fields set up without any values based on cmd

Specified by:
createEntityForm in interface FormBuilderService
Returns:
the EntityForm
Throws:
ServiceException
See Also:
#populateEntityForm(ClassMetadata, EntityForm)}

populateEntityForm

public void populateEntityForm(ClassMetadata cmd,
                               EntityForm ef)
                        throws ServiceException
Description copied from interface: FormBuilderService
Populates the given ef with all of the fields based on the properties from cmd. For all the fields that are created, no values are set (as cmd usually does not have any). In order to fill out values in the given ef, consider instead calling FormBuilderService.populateEntityForm(ClassMetadata, Entity, EntityForm)

Specified by:
populateEntityForm in interface FormBuilderService
Throws:
ServiceException

createEntityForm

public EntityForm createEntityForm(ClassMetadata cmd,
                                   Entity entity)
                            throws ServiceException
Description copied from interface: FormBuilderService
Creates a new EntityForm that has all of the appropriate fields set up along with the values for those fields from the given Entity. Delegates to FormBuilderService.createEntityForm(ClassMetadata) for further population

Specified by:
createEntityForm in interface FormBuilderService
Parameters:
cmd - metadata that the created EntityForm should use to initialize its fields
Returns:
the EntityForm
Throws:
ServiceException
See Also:
#createEntityForm(ClassMetadata)}

populateEntityForm

public void populateEntityForm(ClassMetadata cmd,
                               Entity entity,
                               EntityForm ef)
                        throws ServiceException
Description copied from interface: FormBuilderService
Populates a given ef based on the given cmd to initially create fields with the necessary metadata and then fills those fields out based on the property values from entity.

Specified by:
populateEntityForm in interface FormBuilderService
Throws:
ServiceException
See Also:
#populateEntityForm(ClassMetadata, EntityForm)}

convertJsonToMedia

protected Media convertJsonToMedia(String json)

convertJsonToDataWrapper

protected DataWrapper convertJsonToDataWrapper(String json)
When using Thymeleaf, we need to convert the JSON string back to a DataWrapper object because Thymeleaf escapes JSON strings. Thymeleaf uses it's own object de-serializer see: https://github.com/thymeleaf/thymeleaf/issues/84 see: http://forum.thymeleaf.org/Spring-Javascript-and-escaped-JSON-td4024739.html

Parameters:
json -
Returns:
DataWrapper
Throws:
IOException

populateDropdownToOneFields

protected void populateDropdownToOneFields(EntityForm ef,
                                           ClassMetadata cmd)
                                    throws ServiceException
Throws:
ServiceException

createEntityForm

public EntityForm createEntityForm(ClassMetadata cmd,
                                   Entity entity,
                                   Map<String,DynamicResultSet> collectionRecords)
                            throws ServiceException
Description copied from interface: FormBuilderService
Builds an EntityForm that has all of the appropriate fields set up along with the values for those fields from the given Entity as well as all sub-collections of the given Entity that appear in the collectionRecords map. This method simply delegates to create a standard EntityForm (that has a save action) and then populates that EntityForm using FormBuilderService.populateEntityForm(ClassMetadata, Entity, Map, EntityForm). NOTE: if you are submitting a validation result, you must not call this method and instead invoke the one that has an EntityForm as a parameter. You cannot re-assign the entityForm to the model after it has already been bound to a BindingResult, else the binding result will be removed.

Specified by:
createEntityForm in interface FormBuilderService
Returns:
the EntityForm
Throws:
ServiceException
See Also:
#populateEntityForm(ClassMetadata, Entity, Map, EntityForm)}

populateEntityForm

public void populateEntityForm(ClassMetadata cmd,
                               Entity entity,
                               Map<String,DynamicResultSet> collectionRecords,
                               EntityForm ef)
                        throws ServiceException
Description copied from interface: FormBuilderService
Builds an EntityForm that has all of the appropriate fields set up along with the values for thsoe fields from the given Entity as well as all sub-collections of the given Entity that appear in the collectionRecords map. NOTE: This method is mainly used when coming back from validation. In the case of validation, you cannot re-add a new EntityForm to the model or else you lose the whole BindingResult and errors will not properly be displayed. In that scenario, you must use this method rather than the one that does not take in an entityForm as it will attempt to instantiate a new object.

Specified by:
populateEntityForm in interface FormBuilderService
ef - rather than instantiate a new EntityForm, this will use this parameter to fill out
Throws:
ServiceException

populateEntityFormFields

public void populateEntityFormFields(EntityForm ef,
                                     Entity entity)
Description copied from interface: FormBuilderService
Sets values for all fields found on the EntityForm from the specified entity.

Specified by:
populateEntityFormFields in interface FormBuilderService

populateAdornedEntityFormFields

public void populateAdornedEntityFormFields(EntityForm ef,
                                            Entity entity,
                                            AdornedTargetList adornedList)
Description copied from interface: FormBuilderService
Sets values for the necessary adorned fields on the EntityForm from the specified entity.

Specified by:
populateAdornedEntityFormFields in interface FormBuilderService

populateMapEntityFormFields

public void populateMapEntityFormFields(EntityForm ef,
                                        Entity entity)
Description copied from interface: FormBuilderService
Sets values for the necessary map fields on the EntityForm from the specified entity.

Specified by:
populateMapEntityFormFields in interface FormBuilderService

buildAdornedListForm

public EntityForm buildAdornedListForm(AdornedTargetCollectionMetadata adornedMd,
                                       AdornedTargetList adornedList,
                                       String parentId)
                                throws ServiceException
Description copied from interface: FormBuilderService
Builds the EntityForm used in modal dialogs when adding items to adorned target collections.

Specified by:
buildAdornedListForm in interface FormBuilderService
Returns:
the EntityForm
Throws:
ServiceException

buildMapForm

public EntityForm buildMapForm(MapMetadata mapMd,
                               MapStructure mapStructure,
                               ClassMetadata cmd,
                               String parentId)
                        throws ServiceException
Description copied from interface: FormBuilderService
Builds the EntityForm used in modal dialogs when adding items to map collections.

Specified by:
buildMapForm in interface FormBuilderService
Returns:
the EntityForm
Throws:
ServiceException

createStandardEntityForm

protected EntityForm createStandardEntityForm()

getGridHiddenVisibilities

protected VisibilityEnum[] getGridHiddenVisibilities()

getFormHiddenVisibilities

protected VisibilityEnum[] getFormHiddenVisibilities()


Copyright © 2013. All Rights Reserved.