Skip to content

Commit 7ea69c9

Browse files
author
jefffischer
committed
BroadleafCommerce/QA#1711 - Add special handling for product list grid fetches - make eager fetching of category and sku optional - introduce hints to enterprise for special state handling - add control for how sorting in the resulting fetch query is handled
1 parent e980e15 commit 7ea69c9

File tree

2 files changed

+60
-17
lines changed

2 files changed

+60
-17
lines changed

admin/broadleaf-admin-module/src/main/java/org/broadleafcommerce/admin/server/service/extension/ProductCustomPersistenceHandlerExtensionHandler.java

+16
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,20 @@ public interface ProductCustomPersistenceHandlerExtensionHandler extends Extensi
5555
* @return
5656
*/
5757
ExtensionResultStatusType manageRemove(PersistencePackage persistencePackage, Product product) throws ServiceException;
58+
59+
/**
60+
* Setup any special state to influence the fetch results
61+
*
62+
* @return
63+
* @throws ServiceException
64+
*/
65+
ExtensionResultStatusType initiateFetchState() throws ServiceException;
66+
67+
/**
68+
* Cleanup any special state started by {@link #initiateFetchState()}
69+
*
70+
* @return
71+
* @throws ServiceException
72+
*/
73+
ExtensionResultStatusType endFetchState() throws ServiceException;
5874
}

admin/broadleaf-admin-module/src/main/java/org/broadleafcommerce/admin/server/service/handler/ProductCustomPersistenceHandler.java

+44-17
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public class ProductCustomPersistenceHandler extends CustomPersistenceHandlerAda
101101
@Value("${product.query.limit:500}")
102102
protected long queryLimit;
103103

104+
@Value("${product.eager.fetch.associations.admin:true}")
105+
protected boolean eagerFetchAssociations = true;
106+
104107
private static final Log LOG = LogFactory.getLog(ProductCustomPersistenceHandler.class);
105108

106109
@Override
@@ -212,23 +215,47 @@ public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldP
212215
}
213216
}
214217

215-
cto.getNonCountAdditionalFilterMappings().add(new FilterMapping()
216-
.withDirectFilterValues(new EmptyFilterValues())
217-
.withRestriction(new Restriction()
218-
.withPredicateProvider(new PredicateProvider() {
219-
@Override
220-
public Predicate buildPredicate(CriteriaBuilder builder,
221-
FieldPathBuilder fieldPathBuilder, From root,
222-
String ceilingEntity,
223-
String fullPropertyName, Path explicitPath,
224-
List directValues) {
225-
root.fetch("defaultSku", JoinType.LEFT);
226-
root.fetch("defaultCategory", JoinType.LEFT);
227-
return null;
228-
}
229-
})
230-
));
231-
return helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
218+
if (eagerFetchAssociations) {
219+
cto.getNonCountAdditionalFilterMappings().add(new FilterMapping()
220+
.withDirectFilterValues(new EmptyFilterValues())
221+
.withRestriction(new Restriction()
222+
.withPredicateProvider(new PredicateProvider() {
223+
@Override
224+
public Predicate buildPredicate(CriteriaBuilder builder,
225+
FieldPathBuilder fieldPathBuilder, From root,
226+
String ceilingEntity,
227+
String fullPropertyName, Path explicitPath,
228+
List directValues) {
229+
root.fetch("defaultSku", JoinType.LEFT);
230+
root.fetch("defaultCategory", JoinType.LEFT);
231+
return null;
232+
}
233+
})
234+
));
235+
}
236+
if (ArrayUtils.isEmpty(persistencePackage.getSectionCrumbs()) &&
237+
(!cto.getCriteriaMap().containsKey("id") || CollectionUtils.isEmpty(cto.getCriteriaMap().get("id").getFilterValues()))) {
238+
boolean hasExplicitSort = false;
239+
for (FilterAndSortCriteria filter : cto.getCriteriaMap().values()) {
240+
hasExplicitSort = filter.getSortDirection() != null;
241+
if (hasExplicitSort) {
242+
break;
243+
}
244+
}
245+
if (!hasExplicitSort) {
246+
FilterAndSortCriteria filter = cto.get("id");
247+
filter.setNullsLast(false);
248+
filter.setSortAscending(true);
249+
}
250+
try {
251+
extensionManager.getProxy().initiateFetchState();
252+
return helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
253+
} finally {
254+
extensionManager.getProxy().endFetchState();
255+
}
256+
} else {
257+
return helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
258+
}
232259
}
233260

234261
@Override

0 commit comments

Comments
 (0)