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 DynamicDaoHelperprotected jakarta.persistence.EntityManagerprotected EntityConfigurationprotected CriteriaTransferObjectExtensionManagerprotected static final org.apache.commons.logging.Logprotected PersistencePackageFactoryprotected DynamicEntityService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(PersistencePackageRequest request) Thin layer on top ofDynamicEntityService.add(org.broadleafcommerce.openadmin.dto.PersistencePackage)that swallows allValidationExceptions that could be thrown and still just returns aPersistenceResponsewith theEntitythat 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 collectionvoidprotected voidensureEntityMarkedAsValidationFailure(ValidationException e, PersistencePackageRequest originalRequest) Should be invoked when aValidationExceptionis thrown to verify that theEntitycontained 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 CriteriaTransferObjectprotected intprotected DynamicEntityDaogetDynamicEntityDao(String owningClass) getForeignEntityName(String owningClass, String id) For the given class (which could be an interface) and id, finds theAdminMainEntityvalue for the foreign entityReturns the name of the property in this ClassMetadata that has field type set toSupportedFieldType.IDgetPagedRecordsForCollection(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)voidpopulateParentRecordStructure(PersistencePackage persistencePackage, Entity entity, ClassMetadata parentMetadata) Store parent record value, parent metadata to thePersistencePackageremove(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 ObjecttoIdFieldType(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 voidupdateTabInfo(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:AdminEntityServiceReturns class metadata for the given request object- Specified by:
getClassMetadatain interfaceAdminEntityService- Returns:
- ClassMetadata for the given request
- Throws:
ServiceException
-
getRecords
Description copied from interface:AdminEntityServiceReturns the DynamicResultSet containing the total records for the query and the currently fetched Entity[]- Specified by:
getRecordsin interfaceAdminEntityService- Returns:
- DynamicResultSet
- Throws:
ServiceException
-
getRecord
public PersistenceResponse getRecord(PersistencePackageRequest request, String id, ClassMetadata cmd, boolean isCollectionRequest) throws ServiceException Description copied from interface:AdminEntityServiceReturns a specific record for the given request and primary key id/property- Specified by:
getRecordin interfaceAdminEntityServiceisCollectionRequest- 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:AdminEntityServicePersists the given entity- Specified by:
addEntityin interfaceAdminEntityService- Returns:
- the persisted Entity
- Throws:
ServiceException
-
updateEntity
public PersistenceResponse updateEntity(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) throws ServiceException Description copied from interface:AdminEntityServiceUpdates the given entity- Specified by:
updateEntityin interfaceAdminEntityService- Returns:
- the persisted Entity
- Throws:
ServiceException
-
removeEntity
public PersistenceResponse removeEntity(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) throws ServiceException Description copied from interface:AdminEntityServiceRemoves the given entity- Specified by:
removeEntityin interfaceAdminEntityService- Throws:
ServiceException
-
getPropertiesFromEntityForm
-
getRequestForEntityForm
public PersistencePackageRequest getRequestForEntityForm(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumbs) Description copied from interface:AdminEntityServiceGets the PersistencePackageRequest for the passed in EntityForm- Specified by:
getRequestForEntityFormin interfaceAdminEntityService
-
getAdvancedCollectionRecord
public PersistenceResponse getAdvancedCollectionRecord(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, String collectionItemId, List<SectionCrumb> sectionCrumbs, String alternateId) throws ServiceException Description copied from interface:AdminEntityServiceGets an Entity representing a specific collection item- Specified by:
getAdvancedCollectionRecordin 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:AdminEntityServiceGets an Entity representing a specific collection item- Specified by:
getAdvancedCollectionRecordin 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:AdminEntityServiceReturns the DynamicResultSet representing the records that belong to the specified collectionProperty for the given containingClass and the primary key for the containingClass- Specified by:
getRecordsForCollectionin 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:AdminEntityServiceThe 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 aFetchPageRequestto encapsulate result set paging configuration, which is needed forFetchType.LARGERESULTSETcases, if applicable.- Specified by:
getPagedRecordsForCollectionin 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:AdminEntityServiceThe 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:
getRecordsForCollectionin 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:AdminEntityServiceoverloading containing paging parameters- Specified by:
getRecordsForAllSubCollectionsin interfaceAdminEntityService- Returns:
- Throws:
ServiceException
-
getAllRecordsForAllSubCollections
public Map<String,DynamicResultSet> getAllRecordsForAllSubCollections(ClassMetadata cmd, Entity containingEntity, List<SectionCrumb> sectionCrumb) throws ServiceException Description copied from interface:AdminEntityServiceoverloading containing paging parameters- Specified by:
getAllRecordsForAllSubCollectionsin interfaceAdminEntityService- Returns:
- Throws:
ServiceException
-
getRecordsForAllSubCollections
public Map<String,DynamicResultSet> getRecordsForAllSubCollections(PersistencePackageRequest ppr, Entity containingEntity, List<SectionCrumb> sectionCrumb) throws ServiceException Description copied from interface:AdminEntityServiceReturns all records for all subcollections of the specified request and its primary key- Specified by:
getRecordsForAllSubCollectionsin 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:AdminEntityServiceReturns all records for selected tab of the specified request and its primary key- Specified by:
getRecordsForSelectedTabin 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:AdminEntityServiceAdds an item into the specified collection- Specified by:
addSubCollectionEntityin interfaceAdminEntityService- Returns:
- the persisted Entity
- Throws:
ServiceExceptionClassNotFoundException
-
updateSubCollectionEntity
public PersistenceResponse updateSubCollectionEntity(EntityForm entityForm, ClassMetadata mainMetadata, Property field, Entity parentEntity, String collectionItemId, List<SectionCrumb> sectionCrumb) throws ServiceException, ClassNotFoundException Description copied from interface:AdminEntityServiceUpdates the specified collection item- Specified by:
updateSubCollectionEntityin interfaceAdminEntityService- Returns:
- the persisted Entity
- Throws:
ServiceExceptionClassNotFoundException
-
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:AdminEntityServiceUpdates the specified collection item- Specified by:
updateSubCollectionEntityin interfaceAdminEntityService- Returns:
- the persisted Entity
- Throws:
ServiceExceptionClassNotFoundException
-
removeSubCollectionEntity
public PersistenceResponse removeSubCollectionEntity(ClassMetadata mainMetadata, Property field, Entity parentEntity, String itemId, String priorKey, List<SectionCrumb> sectionCrumbs) throws ServiceException Description copied from interface:AdminEntityServiceRemoves the given item from the specified collection.- Specified by:
removeSubCollectionEntityin interfaceAdminEntityServicepriorKey- - 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:AdminEntityServiceRemoves the given item from the specified collection.- Specified by:
removeSubCollectionEntityin interfaceAdminEntityServicepriorKey- - only needed for Map type collections- Throws:
ServiceException
-
getContextSpecificRelationshipId
public String getContextSpecificRelationshipId(ClassMetadata cmd, Entity entity, String propertyName) Description copied from interface:AdminEntityServiceReturns 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:
getContextSpecificRelationshipIdin interfaceAdminEntityService- Returns:
- the id to be used for this relationship
-
getIdProperty
Description copied from interface:AdminEntityServiceReturns the name of the property in this ClassMetadata that has field type set toSupportedFieldType.ID- Specified by:
getIdPropertyin interfaceAdminEntityService- Returns:
- the id property name
- Throws:
ServiceException
-
add
Description copied from interface:AdminEntityServiceThin layer on top ofDynamicEntityService.add(org.broadleafcommerce.openadmin.dto.PersistencePackage)that swallows allValidationExceptions that could be thrown and still just returns aPersistenceResponsewith theEntitythat failed validation.- Specified by:
addin interfaceAdminEntityService- Returns:
- Throws:
ServiceException- if there were exceptions other than aValidationExceptionthat was thrown as a result of the attempted add
-
add
public PersistenceResponse add(PersistencePackageRequest request, boolean transactional) throws ServiceException Description copied from interface:AdminEntityServiceWorks 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:
addin interfaceAdminEntityService- Returns:
- Throws:
ServiceException
-
update
Description copied from interface:AdminEntityServiceThin layer on top ofDynamicEntityService.update(org.broadleafcommerce.openadmin.dto.PersistencePackage)- Specified by:
updatein interfaceAdminEntityService- Returns:
- Throws:
ServiceException- if there were exceptions other than aValidationExceptionthat was thrown as a result of the attempted update
-
update
public PersistenceResponse update(PersistencePackageRequest request, boolean transactional) throws ServiceException Description copied from interface:AdminEntityServiceWorks 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:
updatein interfaceAdminEntityService- Returns:
- Throws:
ServiceException
-
inspect
Description copied from interface:AdminEntityServiceThin layer on top ofDynamicEntityService.inspect(org.broadleafcommerce.openadmin.dto.PersistencePackage)- Specified by:
inspectin interfaceAdminEntityService- Returns:
- Throws:
ServiceException
-
remove
Description copied from interface:AdminEntityServiceThin layer on top ofDynamicEntityService.remove(org.broadleafcommerce.openadmin.dto.PersistencePackage)- Specified by:
removein interfaceAdminEntityService- Returns:
- Throws:
ServiceException
-
remove
public PersistenceResponse remove(PersistencePackageRequest request, boolean transactional) throws ServiceException Description copied from interface:AdminEntityServiceWorks 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:
removein interfaceAdminEntityService- Returns:
- Throws:
ServiceException
-
ensureEntityMarkedAsValidationFailure
protected void ensureEntityMarkedAsValidationFailure(ValidationException e, PersistencePackageRequest originalRequest) Should be invoked when a
ValidationExceptionis thrown to verify that theEntitycontained within the given originalRequest has a validationFailure = trueThis will also check for a cause of
ConstraintViolationExceptionand add a gloal error to that. -
fetch
Description copied from interface:AdminEntityServiceThin layer on top ofDynamicEntityService.fetch(org.broadleafcommerce.openadmin.dto.PersistencePackage, org.broadleafcommerce.openadmin.dto.CriteriaTransferObject). This will glean and create aCriteriaTransferObjectfromPersistencePackageRequest.getFilterAndSortCriteria()to pass toDynamicEntityService.- Specified by:
fetchin interfaceAdminEntityService- Returns:
- Throws:
ServiceException
-
getDefaultCto
-
getForeignEntityName
Description copied from interface:AdminEntityServiceFor the given class (which could be an interface) and id, finds theAdminMainEntityvalue for the foreign entity- Specified by:
getForeignEntityNamein interfaceAdminEntityService- Returns:
- the friendly name for the given foreign entity
-
getDynamicEntityDao
-
getDefaultMaxResults
protected int getDefaultMaxResults() -
toIdFieldType
-
clearEntityManager
public void clearEntityManager()- Specified by:
clearEntityManagerin interfaceAdminEntityService
-
populateParentRecordStructure
public void populateParentRecordStructure(PersistencePackage persistencePackage, Entity entity, ClassMetadata parentMetadata) Description copied from interface:AdminEntityServiceStore parent record value, parent metadata to thePersistencePackage- Specified by:
populateParentRecordStructurein interfaceAdminEntityService
-