use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class AdornedTargetListPersistenceModule method fetch.
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto) throws ServiceException {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
AdornedTargetList adornedTargetList = (AdornedTargetList) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST);
Entity[] payload;
int totalRecords;
try {
Class<?>[] entities = persistenceManager.getPolymorphicEntities(ceilingEntityFullyQualifiedClassname);
Map<String, FieldMetadata> mergedPropertiesTarget = persistenceManager.getDynamicEntityDao().getMergedProperties(ceilingEntityFullyQualifiedClassname, entities, null, persistencePerspective.getAdditionalNonPersistentProperties(), persistencePerspective.getAdditionalForeignKeys(), MergedPropertyType.PRIMARY, persistencePerspective.getPopulateToOneFields(), persistencePerspective.getIncludeFields(), persistencePerspective.getExcludeFields(), persistencePerspective.getConfigurationKey(), "");
AdornedTargetRetrieval adornedTargetRetrieval = new AdornedTargetRetrieval(persistencePackage, adornedTargetList, cto).invokeForFetch();
List<Serializable> records = adornedTargetRetrieval.getRecords();
Map<String, FieldMetadata> mergedProperties = adornedTargetRetrieval.getMergedProperties();
payload = getRecords(mergedPropertiesTarget, records, mergedProperties, adornedTargetList.getTargetObjectPath(), persistencePackage.getCustomCriteria());
totalRecords = getTotalRecords(adornedTargetList.getAdornedTargetEntityClassname(), adornedTargetRetrieval.getFilterMappings());
} catch (Exception e) {
throw new ServiceException("Unable to fetch results for " + adornedTargetList.getAdornedTargetEntityClassname(), e);
}
DynamicResultSet results = new DynamicResultSet(null, payload, totalRecords);
return results;
}
use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class BasicPersistenceModule method fetch.
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto) throws ServiceException {
Entity[] payload;
int totalRecords;
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
ForeignKey foreignKey = (ForeignKey) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.FOREIGNKEY);
try {
if (foreignKey != null && foreignKey.getSortField() != null) {
FilterAndSortCriteria sortCriteria = cto.get(foreignKey.getSortField());
sortCriteria.setSortAscending(foreignKey.getSortAscending());
}
Map<String, FieldMetadata> mergedProperties = getMergedProperties(persistencePackage, cto);
List<FilterMapping> filterMappings = getFilterMappings(persistencePerspective, cto, persistencePackage.getFetchTypeFullyQualifiedClassname(), mergedProperties);
List<FilterMapping> standardFilterMappings = new ArrayList<FilterMapping>(filterMappings);
if (CollectionUtils.isNotEmpty(cto.getAdditionalFilterMappings())) {
standardFilterMappings.addAll(cto.getAdditionalFilterMappings());
}
if (CollectionUtils.isNotEmpty(cto.getNonCountAdditionalFilterMappings())) {
standardFilterMappings.addAll(cto.getNonCountAdditionalFilterMappings());
}
FetchRequest fetchRequest = new FetchRequest(persistencePackage, cto, persistencePackage.getFetchTypeFullyQualifiedClassname(), standardFilterMappings);
List<Serializable> records = getPersistentRecords(fetchRequest);
List<FilterMapping> countFilterMappings = new ArrayList<FilterMapping>(filterMappings);
if (CollectionUtils.isNotEmpty(cto.getAdditionalFilterMappings())) {
countFilterMappings.addAll(cto.getAdditionalFilterMappings());
}
FetchRequest countFetchRequest = new FetchRequest(persistencePackage, cto, persistencePackage.getFetchTypeFullyQualifiedClassname(), countFilterMappings);
totalRecords = getTotalRecords(countFetchRequest);
FetchExtractionRequest fetchExtractionRequest = new FetchExtractionRequest(persistencePackage, cto, persistencePackage.getFetchTypeFullyQualifiedClassname(), mergedProperties, records);
payload = getRecords(fetchExtractionRequest);
} catch (Exception e) {
throw new ServiceException("Unable to fetch results for " + ceilingEntityFullyQualifiedClassname, e);
}
return new DynamicResultSet(null, payload, totalRecords);
}
use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class PersistenceManagerImpl method fetch.
@Override
public PersistenceResponse fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto) throws ServiceException {
for (PersistenceManagerEventHandler handler : persistenceManagerEventHandlers) {
PersistenceManagerEventHandlerResponse response = handler.preFetch(this, persistencePackage, cto);
if (PersistenceManagerEventHandlerResponse.PersistenceManagerEventHandlerResponseStatus.HANDLED_BREAK == response.getStatus()) {
break;
}
}
// check to see if there is a custom handler registered
for (CustomPersistenceHandler handler : getCustomPersistenceHandlers()) {
if (handler.canHandleFetch(persistencePackage)) {
if (!handler.willHandleSecurity(persistencePackage)) {
adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.FETCH);
}
DynamicResultSet results = handler.fetch(persistencePackage, cto, dynamicEntityDao, (RecordHelper) getCompatibleModule(OperationType.BASIC));
return executePostFetchHandlers(persistencePackage, cto, new PersistenceResponse().withDynamicResultSet(results));
}
}
adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.FETCH);
PersistenceModule myModule = getCompatibleModule(persistencePackage.getPersistencePerspective().getOperationTypes().getFetchType());
try {
DynamicResultSet results = myModule.fetch(persistencePackage, cto);
return executePostFetchHandlers(persistencePackage, cto, new PersistenceResponse().withDynamicResultSet(results));
} catch (ServiceException e) {
if (e.getCause() instanceof NoPossibleResultsException) {
DynamicResultSet drs = new DynamicResultSet(null, new Entity[] {}, 0);
return executePostFetchHandlers(persistencePackage, cto, new PersistenceResponse().withDynamicResultSet(drs));
}
throw e;
}
}
use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class PersistenceManagerImpl method inspect.
@Override
public PersistenceResponse inspect(PersistencePackage persistencePackage) throws ServiceException, ClassNotFoundException {
for (PersistenceManagerEventHandler handler : persistenceManagerEventHandlers) {
PersistenceManagerEventHandlerResponse response = handler.preInspect(this, persistencePackage);
if (PersistenceManagerEventHandlerResponse.PersistenceManagerEventHandlerResponseStatus.HANDLED_BREAK == response.getStatus()) {
break;
}
}
// check to see if there is a custom handler registered
for (CustomPersistenceHandler handler : getCustomPersistenceHandlers()) {
if (handler.canHandleInspect(persistencePackage)) {
if (!handler.willHandleSecurity(persistencePackage)) {
adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.INSPECT);
}
DynamicResultSet results = handler.inspect(persistencePackage, dynamicEntityDao, this);
return executePostInspectHandlers(persistencePackage, new PersistenceResponse().withDynamicResultSet(results));
}
}
adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.INSPECT);
Class<?>[] entities = getPolymorphicEntities(persistencePackage.getCeilingEntityFullyQualifiedClassname());
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<>();
for (PersistenceModule module : modules) {
module.updateMergedProperties(persistencePackage, allMergedProperties);
}
ClassMetadata classMetadata = buildClassMetadata(entities, persistencePackage, allMergedProperties);
DynamicResultSet results = new DynamicResultSet(classMetadata);
return executePostInspectHandlers(persistencePackage, new PersistenceResponse().withDynamicResultSet(results));
}
use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class CustomPersistenceHandlerAdapter method getResultSet.
/**
* This is a helper method that can be invoked as the last step in a custom inspect phase. It will assemble the
* appropriate DynamicResultSet from the given parameters.
*/
protected DynamicResultSet getResultSet(PersistencePackage persistencePackage, InspectHelper helper, Map<String, FieldMetadata> metadata) throws ServiceException {
String entityName = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
if (helper instanceof PersistenceManager) {
Class<?>[] entities = ((PersistenceManager) helper).getPolymorphicEntities(entityName);
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
allMergedProperties.put(MergedPropertyType.PRIMARY, metadata);
ClassMetadata mergedMetadata = helper.buildClassMetadata(entities, persistencePackage, allMergedProperties);
DynamicResultSet results = new DynamicResultSet(mergedMetadata);
return results;
}
} catch (ClassNotFoundException e) {
throw new ServiceException(e);
}
return new DynamicResultSet();
}
Aggregations