Class AdminEntityServiceImpl
java.lang.Object
org.broadleafcommerce.openadmin.server.service.AdminEntityServiceImpl
- All Implemented Interfaces:
AdminEntityService
@Service("blAdminEntityService")
public class AdminEntityServiceImpl
extends Object
implements AdminEntityService
- Author:
- Andre Azzolini (apazzolini)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DynamicDaoHelper
protected jakarta.persistence.EntityManager
protected EntityConfiguration
protected CriteriaTransferObjectExtensionManager
protected static final org.apache.commons.logging.Log
protected PersistencePackageFactory
protected DynamicEntityService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd
(PersistencePackageRequest request) Thin layer on top ofDynamicEntityService.add(org.broadleafcommerce.openadmin.dto.PersistencePackage)
that swallows allValidationException
s that could be thrown and still just returns aPersistenceResponse
with theEntity
that failed validation.add
(PersistencePackageRequest request, boolean transactional) Works the same asAdminEntityService.add(PersistencePackageRequest)
but you can optionally invoke the transactional version ofDynamicEntityRemoteService.add(org.broadleafcommerce.openadmin.dto.PersistencePackage)
in situations where you want to manage the transactions in a parent componentaddEntity
(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) Persists the given entityaddSubCollectionEntity
(EntityForm entityForm, ClassMetadata mainMetadata, Property field, Entity parentEntity, List<SectionCrumb> sectionCrumbs) Adds an item into the specified collectionvoid
protected void
ensureEntityMarkedAsValidationFailure
(ValidationException e, PersistencePackageRequest originalRequest) Should be invoked when aValidationException
is thrown to verify that theEntity
contained within the given originalRequest has a validationFailure = truefetch
(PersistencePackageRequest request) getAdvancedCollectionRecord
(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, String collectionItemId, List<SectionCrumb> sectionCrumbs, String alternateId) Gets an Entity representing a specific collection itemgetAdvancedCollectionRecord
(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, String collectionItemId, List<SectionCrumb> sectionCrumbs, String alternateId, String[] customCriteria) Gets an Entity representing a specific collection itemgetAllRecordsForAllSubCollections
(ClassMetadata cmd, Entity containingEntity, List<SectionCrumb> sectionCrumb) overloading containing paging parametersReturns class metadata for the given request objectgetContextSpecificRelationshipId
(ClassMetadata cmd, Entity entity, String propertyName) Returns the appropriate id to use for the given entity/metadata and prefix when dealing with collections.protected CriteriaTransferObject
protected int
protected DynamicEntityDao
getDynamicEntityDao
(String owningClass) getForeignEntityName
(String owningClass, String id) For the given class (which could be an interface) and id, finds theAdminMainEntity
value for the foreign entityReturns the name of the property in this ClassMetadata that has field type set toSupportedFieldType.ID
getPagedRecordsForCollection
(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, FilterAndSortCriteria[] fascs, FetchPageRequest fetchPageRequest, String idValueOverride, List<SectionCrumb> sectionCrumbs) The same as the other getRecordsForCollection method, except that this one expects allow the caller to explicitly set the id value that will be used in the fetch instead of delegating to#getContextSpecificRelationshipId()
.getPropertiesFromEntityForm
(EntityForm entityForm) getRecord
(PersistencePackageRequest request, String id, ClassMetadata cmd, boolean isCollectionRequest) Returns a specific record for the given request and primary key id/propertygetRecords
(PersistencePackageRequest request) Returns the DynamicResultSet containing the total records for the query and the currently fetched Entity[]getRecordsForAllSubCollections
(PersistencePackageRequest ppr, Entity containingEntity, Integer startIndex, Integer maxIndex, List<SectionCrumb> sectionCrumb) overloading containing paging parametersgetRecordsForAllSubCollections
(PersistencePackageRequest ppr, Entity containingEntity, List<SectionCrumb> sectionCrumb) Returns all records for all subcollections of the specified request and its primary keygetRecordsForCollection
(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, FilterAndSortCriteria[] fascs, Integer startIndex, Integer maxIndex, String idValueOverride, List<SectionCrumb> sectionCrumbs) The same as the other getRecordsForCollection method, except that this one expects allow the caller to explicitly set the id value that will be used in the fetch instead of delegating to#getContextSpecificRelationshipId()
getRecordsForCollection
(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, FilterAndSortCriteria[] fascs, Integer startIndex, Integer maxIndex, List<SectionCrumb> sectionCrumb) Returns the DynamicResultSet representing the records that belong to the specified collectionProperty for the given containingClass and the primary key for the containingClassgetRecordsForSelectedTab
(ClassMetadata cmd, Entity containingEntity, List<SectionCrumb> sectionCrumb, String currentTabName) Returns all records for selected tab of the specified request and its primary keygetRequestForEntityForm
(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumbs) Gets the PersistencePackageRequest for the passed in EntityForminspect
(PersistencePackageRequest request) Thin layer on top ofDynamicEntityService.inspect(org.broadleafcommerce.openadmin.dto.PersistencePackage)
void
populateParentRecordStructure
(PersistencePackage persistencePackage, Entity entity, ClassMetadata parentMetadata) Store parent record value, parent metadata to thePersistencePackage
remove
(PersistencePackageRequest request) Thin layer on top ofDynamicEntityService.remove(org.broadleafcommerce.openadmin.dto.PersistencePackage)
remove
(PersistencePackageRequest request, boolean transactional) Works the same asAdminEntityService.remove(PersistencePackageRequest)
but you can optionally invoke the transactional version ofDynamicEntityRemoteService.remove(org.broadleafcommerce.openadmin.dto.PersistencePackage)
in situations where you want to manage the transactions in a parent componentremoveEntity
(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) Removes the given entityremoveSubCollectionEntity
(ClassMetadata mainMetadata, Property field, Entity parentEntity, String itemId, String alternateId, String priorKey, List<SectionCrumb> sectionCrumbs) Removes the given item from the specified collection.removeSubCollectionEntity
(ClassMetadata mainMetadata, Property field, Entity parentEntity, String itemId, String priorKey, List<SectionCrumb> sectionCrumbs) Removes the given item from the specified collection.protected Object
toIdFieldType
(String id, Class<?> entityClass) update
(PersistencePackageRequest request) Thin layer on top ofDynamicEntityService.update(org.broadleafcommerce.openadmin.dto.PersistencePackage)
update
(PersistencePackageRequest request, boolean transactional) Works the same asAdminEntityService.update(PersistencePackageRequest)
but you can optionally invoke the transactional version ofDynamicEntityRemoteService.update(org.broadleafcommerce.openadmin.dto.PersistencePackage)
in situations where you want to manage the transactions in a parent componentupdateEntity
(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) Updates the given entityupdateSubCollectionEntity
(EntityForm entityForm, ClassMetadata mainMetadata, Property field, Entity parentEntity, String collectionItemId, String alternateId, List<SectionCrumb> sectionCrumbs) Updates the specified collection itemupdateSubCollectionEntity
(EntityForm entityForm, ClassMetadata mainMetadata, Property field, Entity parentEntity, String collectionItemId, List<SectionCrumb> sectionCrumb) Updates the specified collection itemprotected void
updateTabInfo
(CollectionMetadata fmd, ClassMetadata cmd, String tabName, int tabOrder)
-
Field Details
-
LOG
protected static final org.apache.commons.logging.Log LOG -
service
-
persistencePackageFactory
-
em
protected jakarta.persistence.EntityManager em -
entityConfiguration
-
extensionManager
-
dynamicDaoHelper
-
-
Constructor Details
-
AdminEntityServiceImpl
public AdminEntityServiceImpl()
-
-
Method Details
-
getClassMetadata
public PersistenceResponse getClassMetadata(PersistencePackageRequest request) throws ServiceException Description copied from interface:AdminEntityService
Returns class metadata for the given request object- Specified by:
getClassMetadata
in interfaceAdminEntityService
- Returns:
- ClassMetadata for the given request
- Throws:
ServiceException
-
getRecords
Description copied from interface:AdminEntityService
Returns the DynamicResultSet containing the total records for the query and the currently fetched Entity[]- Specified by:
getRecords
in interfaceAdminEntityService
- Returns:
- DynamicResultSet
- Throws:
ServiceException
-
getRecord
public PersistenceResponse getRecord(PersistencePackageRequest request, String id, ClassMetadata cmd, boolean isCollectionRequest) throws ServiceException Description copied from interface:AdminEntityService
Returns a specific record for the given request and primary key id/property- Specified by:
getRecord
in interfaceAdminEntityService
isCollectionRequest
- whether or not this record request was initiated from a collection on a parent entity- Returns:
- the Entity
- Throws:
ServiceException
-
addEntity
public PersistenceResponse addEntity(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) throws ServiceException Description copied from interface:AdminEntityService
Persists the given entity- Specified by:
addEntity
in interfaceAdminEntityService
- Returns:
- the persisted Entity
- Throws:
ServiceException
-
updateEntity
public PersistenceResponse updateEntity(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) throws ServiceException Description copied from interface:AdminEntityService
Updates the given entity- Specified by:
updateEntity
in interfaceAdminEntityService
- Returns:
- the persisted Entity
- Throws:
ServiceException
-
removeEntity
public PersistenceResponse removeEntity(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) throws ServiceException Description copied from interface:AdminEntityService
Removes the given entity- Specified by:
removeEntity
in interfaceAdminEntityService
- Throws:
ServiceException
-
getPropertiesFromEntityForm
-
getRequestForEntityForm
public PersistencePackageRequest getRequestForEntityForm(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumbs) Description copied from interface:AdminEntityService
Gets the PersistencePackageRequest for the passed in EntityForm- Specified by:
getRequestForEntityForm
in interfaceAdminEntityService
-
getAdvancedCollectionRecord
public PersistenceResponse getAdvancedCollectionRecord(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, String collectionItemId, List<SectionCrumb> sectionCrumbs, String alternateId) throws ServiceException Description copied from interface:AdminEntityService
Gets an Entity representing a specific collection item- Specified by:
getAdvancedCollectionRecord
in interfaceAdminEntityService
- Returns:
- the Entity
- Throws:
ServiceException
-
getAdvancedCollectionRecord
public PersistenceResponse getAdvancedCollectionRecord(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, String collectionItemId, List<SectionCrumb> sectionCrumbs, String alternateId, String[] customCriteria) throws ServiceException Description copied from interface:AdminEntityService
Gets an Entity representing a specific collection item- Specified by:
getAdvancedCollectionRecord
in interfaceAdminEntityService
- Returns:
- the Entity
- Throws:
ServiceException
-
getRecordsForCollection
public PersistenceResponse getRecordsForCollection(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, FilterAndSortCriteria[] fascs, Integer startIndex, Integer maxIndex, List<SectionCrumb> sectionCrumb) throws ServiceException Description copied from interface:AdminEntityService
Returns the DynamicResultSet representing the records that belong to the specified collectionProperty for the given containingClass and the primary key for the containingClass- Specified by:
getRecordsForCollection
in interfaceAdminEntityService
- Returns:
- the DynamicResultSet
- Throws:
ServiceException
-
getPagedRecordsForCollection
public PersistenceResponse getPagedRecordsForCollection(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, FilterAndSortCriteria[] fascs, FetchPageRequest fetchPageRequest, String idValueOverride, List<SectionCrumb> sectionCrumbs) throws ServiceException Description copied from interface:AdminEntityService
The same as the other getRecordsForCollection method, except that this one expects allow the caller to explicitly set the id value that will be used in the fetch instead of delegating to#getContextSpecificRelationshipId()
. Also utilizes aFetchPageRequest
to encapsulate result set paging configuration, which is needed forFetchType.LARGERESULTSET
cases, if applicable.- Specified by:
getPagedRecordsForCollection
in interfaceAdminEntityService
- Returns:
- Throws:
ServiceException
-
getRecordsForCollection
public PersistenceResponse getRecordsForCollection(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, FilterAndSortCriteria[] fascs, Integer startIndex, Integer maxIndex, String idValueOverride, List<SectionCrumb> sectionCrumbs) throws ServiceException Description copied from interface:AdminEntityService
The same as the other getRecordsForCollection method, except that this one expects allow the caller to explicitly set the id value that will be used in the fetch instead of delegating to#getContextSpecificRelationshipId()
- Specified by:
getRecordsForCollection
in interfaceAdminEntityService
- Returns:
- the PersistenceResponse
- Throws:
ServiceException
-
getRecordsForAllSubCollections
public Map<String,DynamicResultSet> getRecordsForAllSubCollections(PersistencePackageRequest ppr, Entity containingEntity, Integer startIndex, Integer maxIndex, List<SectionCrumb> sectionCrumb) throws ServiceException Description copied from interface:AdminEntityService
overloading containing paging parameters- Specified by:
getRecordsForAllSubCollections
in interfaceAdminEntityService
- Returns:
- Throws:
ServiceException
-
getAllRecordsForAllSubCollections
public Map<String,DynamicResultSet> getAllRecordsForAllSubCollections(ClassMetadata cmd, Entity containingEntity, List<SectionCrumb> sectionCrumb) throws ServiceException Description copied from interface:AdminEntityService
overloading containing paging parameters- Specified by:
getAllRecordsForAllSubCollections
in interfaceAdminEntityService
- Returns:
- Throws:
ServiceException
-
getRecordsForAllSubCollections
public Map<String,DynamicResultSet> getRecordsForAllSubCollections(PersistencePackageRequest ppr, Entity containingEntity, List<SectionCrumb> sectionCrumb) throws ServiceException Description copied from interface:AdminEntityService
Returns all records for all subcollections of the specified request and its primary key- Specified by:
getRecordsForAllSubCollections
in interfaceAdminEntityService
- Returns:
- all Entity[] for all collections for the specified containingClass
- Throws:
ServiceException
- See Also:
-
#getRecordsForCollection(ClassMetadata, String, Property)
-
getRecordsForSelectedTab
public Map<String,DynamicResultSet> getRecordsForSelectedTab(ClassMetadata cmd, Entity containingEntity, List<SectionCrumb> sectionCrumb, String currentTabName) throws ServiceException Description copied from interface:AdminEntityService
Returns all records for selected tab of the specified request and its primary key- Specified by:
getRecordsForSelectedTab
in interfaceAdminEntityService
- Returns:
- all Entity[] for selected tab for the specified containingClass
- Throws:
ServiceException
- See Also:
-
#getRecordsForCollection(ClassMetadata, String, Property)
-
updateTabInfo
protected void updateTabInfo(CollectionMetadata fmd, ClassMetadata cmd, String tabName, int tabOrder) -
addSubCollectionEntity
public PersistenceResponse addSubCollectionEntity(EntityForm entityForm, ClassMetadata mainMetadata, Property field, Entity parentEntity, List<SectionCrumb> sectionCrumbs) throws ServiceException, ClassNotFoundException Description copied from interface:AdminEntityService
Adds an item into the specified collection- Specified by:
addSubCollectionEntity
in interfaceAdminEntityService
- Returns:
- the persisted Entity
- Throws:
ServiceException
ClassNotFoundException
-
updateSubCollectionEntity
public PersistenceResponse updateSubCollectionEntity(EntityForm entityForm, ClassMetadata mainMetadata, Property field, Entity parentEntity, String collectionItemId, List<SectionCrumb> sectionCrumb) throws ServiceException, ClassNotFoundException Description copied from interface:AdminEntityService
Updates the specified collection item- Specified by:
updateSubCollectionEntity
in interfaceAdminEntityService
- Returns:
- the persisted Entity
- Throws:
ServiceException
ClassNotFoundException
-
updateSubCollectionEntity
public PersistenceResponse updateSubCollectionEntity(EntityForm entityForm, ClassMetadata mainMetadata, Property field, Entity parentEntity, String collectionItemId, String alternateId, List<SectionCrumb> sectionCrumbs) throws ServiceException, ClassNotFoundException Description copied from interface:AdminEntityService
Updates the specified collection item- Specified by:
updateSubCollectionEntity
in interfaceAdminEntityService
- Returns:
- the persisted Entity
- Throws:
ServiceException
ClassNotFoundException
-
removeSubCollectionEntity
public PersistenceResponse removeSubCollectionEntity(ClassMetadata mainMetadata, Property field, Entity parentEntity, String itemId, String priorKey, List<SectionCrumb> sectionCrumbs) throws ServiceException Description copied from interface:AdminEntityService
Removes the given item from the specified collection.- Specified by:
removeSubCollectionEntity
in interfaceAdminEntityService
priorKey
- - only needed for Map type collections- Throws:
ServiceException
-
removeSubCollectionEntity
public PersistenceResponse removeSubCollectionEntity(ClassMetadata mainMetadata, Property field, Entity parentEntity, String itemId, String alternateId, String priorKey, List<SectionCrumb> sectionCrumbs) throws ServiceException Description copied from interface:AdminEntityService
Removes the given item from the specified collection.- Specified by:
removeSubCollectionEntity
in interfaceAdminEntityService
priorKey
- - only needed for Map type collections- Throws:
ServiceException
-
getContextSpecificRelationshipId
public String getContextSpecificRelationshipId(ClassMetadata cmd, Entity entity, String propertyName) Description copied from interface:AdminEntityService
Returns the appropriate id to use for the given entity/metadata and prefix when dealing with collections. For example, on the Product screen, we display associated media. However, this media is actually owned by the Sku entity, which means its property name is "defaultSku.skuMedia". In this case, when wanting to look up media for this product, we cannot use the id of the product. Instead, we need to use the id of the sku.- Specified by:
getContextSpecificRelationshipId
in interfaceAdminEntityService
- Returns:
- the id to be used for this relationship
-
getIdProperty
Description copied from interface:AdminEntityService
Returns the name of the property in this ClassMetadata that has field type set toSupportedFieldType.ID
- Specified by:
getIdProperty
in interfaceAdminEntityService
- Returns:
- the id property name
- Throws:
ServiceException
-
add
Description copied from interface:AdminEntityService
Thin layer on top ofDynamicEntityService.add(org.broadleafcommerce.openadmin.dto.PersistencePackage)
that swallows allValidationException
s that could be thrown and still just returns aPersistenceResponse
with theEntity
that failed validation.- Specified by:
add
in interfaceAdminEntityService
- Returns:
- Throws:
ServiceException
- if there were exceptions other than aValidationException
that was thrown as a result of the attempted add
-
add
public PersistenceResponse add(PersistencePackageRequest request, boolean transactional) throws ServiceException Description copied from interface:AdminEntityService
Works the same asAdminEntityService.add(PersistencePackageRequest)
but you can optionally invoke the transactional version ofDynamicEntityRemoteService.add(org.broadleafcommerce.openadmin.dto.PersistencePackage)
in situations where you want to manage the transactions in a parent component- Specified by:
add
in interfaceAdminEntityService
- Returns:
- Throws:
ServiceException
-
update
Description copied from interface:AdminEntityService
Thin layer on top ofDynamicEntityService.update(org.broadleafcommerce.openadmin.dto.PersistencePackage)
- Specified by:
update
in interfaceAdminEntityService
- Returns:
- Throws:
ServiceException
- if there were exceptions other than aValidationException
that was thrown as a result of the attempted update
-
update
public PersistenceResponse update(PersistencePackageRequest request, boolean transactional) throws ServiceException Description copied from interface:AdminEntityService
Works the same asAdminEntityService.update(PersistencePackageRequest)
but you can optionally invoke the transactional version ofDynamicEntityRemoteService.update(org.broadleafcommerce.openadmin.dto.PersistencePackage)
in situations where you want to manage the transactions in a parent component- Specified by:
update
in interfaceAdminEntityService
- Returns:
- Throws:
ServiceException
-
inspect
Description copied from interface:AdminEntityService
Thin layer on top ofDynamicEntityService.inspect(org.broadleafcommerce.openadmin.dto.PersistencePackage)
- Specified by:
inspect
in interfaceAdminEntityService
- Returns:
- Throws:
ServiceException
-
remove
Description copied from interface:AdminEntityService
Thin layer on top ofDynamicEntityService.remove(org.broadleafcommerce.openadmin.dto.PersistencePackage)
- Specified by:
remove
in interfaceAdminEntityService
- Returns:
- Throws:
ServiceException
-
remove
public PersistenceResponse remove(PersistencePackageRequest request, boolean transactional) throws ServiceException Description copied from interface:AdminEntityService
Works the same asAdminEntityService.remove(PersistencePackageRequest)
but you can optionally invoke the transactional version ofDynamicEntityRemoteService.remove(org.broadleafcommerce.openadmin.dto.PersistencePackage)
in situations where you want to manage the transactions in a parent component- Specified by:
remove
in interfaceAdminEntityService
- Returns:
- Throws:
ServiceException
-
ensureEntityMarkedAsValidationFailure
protected void ensureEntityMarkedAsValidationFailure(ValidationException e, PersistencePackageRequest originalRequest) Should be invoked when a
ValidationException
is thrown to verify that theEntity
contained within the given originalRequest has a validationFailure = trueThis will also check for a cause of
ConstraintViolationException
and add a gloal error to that. -
fetch
Description copied from interface:AdminEntityService
Thin layer on top ofDynamicEntityService.fetch(org.broadleafcommerce.openadmin.dto.PersistencePackage, org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)
. This will glean and create aCriteriaTransferObject
fromPersistencePackageRequest.getFilterAndSortCriteria()
to pass toDynamicEntityService
.- Specified by:
fetch
in interfaceAdminEntityService
- Returns:
- Throws:
ServiceException
-
getDefaultCto
-
getForeignEntityName
Description copied from interface:AdminEntityService
For the given class (which could be an interface) and id, finds theAdminMainEntity
value for the foreign entity- Specified by:
getForeignEntityName
in interfaceAdminEntityService
- Returns:
- the friendly name for the given foreign entity
-
getDynamicEntityDao
-
getDefaultMaxResults
protected int getDefaultMaxResults() -
toIdFieldType
-
clearEntityManager
public void clearEntityManager()- Specified by:
clearEntityManager
in interfaceAdminEntityService
-
populateParentRecordStructure
public void populateParentRecordStructure(PersistencePackage persistencePackage, Entity entity, ClassMetadata parentMetadata) Description copied from interface:AdminEntityService
Store parent record value, parent metadata to thePersistencePackage
- Specified by:
populateParentRecordStructure
in interfaceAdminEntityService
-