i've a question about the search in the order section. I've searched in the forum but i've not found the solution
( i'm a newbie, so sorry if it's a stupid question )
In the Order section, when i type something in the input search, will be searched only in the "orderNumber" field ( example: admin/order?orderNumber=5 ).
So, i'd like to search not only over this order filed, but for example over customer or address fields.
I've created something ( i don't know if it's correct ).
With the code below, i'm able to search about customer fields, ( admin/order?customer.emailAddress=xxx )
but how can i search about addressLine1 for example?? is it possibile?
Code: Select all
@Component("blOrderCustomPersistenceHandler")
public class OrderCustomPersistenceHandler extends CustomPersistenceHandlerAdapter {
private static final Log LOG = LogFactory.getLog(OrderCustomPersistenceHandler.class);
public static final String PREFIX_CUSTOMER_ENTITY = "customer";
public static final String PREFIX_CUSTOMERADDRESSES_ENTITY = "customerAddresses";
public static final String PREFIX_ADDRESS_ENTITY = "address";
@Override
public Boolean canHandleFetch(PersistencePackage persistencePackage) {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
Class testClass = Class.forName(ceilingEntityFullyQualifiedClassname);
return Order.class.isAssignableFrom(testClass);
} catch (ClassNotFoundException e) {
return false;
}
}
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao
dynamicEntityDao, RecordHelper helper) throws ServiceException {
for (String filterProperty : cto.getCriteriaMap().keySet()) {
//if parameters like 'customer.emailAddress' passed
if (filterProperty.startsWith(PREFIX_CUSTOMER_ENTITY)) {
FilterAndSortCriteria criteria = cto.get(filterProperty);
List<String> productOptionValueFilterString = new ArrayList<String>();
productOptionValueFilterString.add(criteria.getFilterValues().get(0));
FilterMapping filterMapping = new FilterMapping()
.withFieldPath(new FieldPath().withTargetProperty(filterProperty))
.withDirectFilterValues(productOptionValueFilterString)
.withRestriction(new Restriction()
.withPredicateProvider(new PredicateProvider<Character, Character>() {
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder,
From root, String ceilingEntity, String fullPropertyName, Path<Character> explicitPath,
List<Character> directValues) {
return builder.like(explicitPath.as(String.class), "%" + directValues.get(0) + "%");
}
})
);
cto.getAdditionalFilterMappings().add(filterMapping);
}
}
cto.getNonCountAdditionalFilterMappings().add(new FilterMapping()
.withDirectFilterValues(new EmptyFilterValues())
.withRestriction(new Restriction()
.withPredicateProvider(new PredicateProvider() {
public Predicate buildPredicate(CriteriaBuilder builder,
FieldPathBuilder fieldPathBuilder, From root,
String ceilingEntity,
String fullPropertyName, Path explicitPath,
List directValues) {
// Join<Order, Customer> jcustomer = root.join(PREFIX_CUSTOMER_ENTITY, JoinType.LEFT);
// ListJoin<Customer, CustomerAddress> jcustaddress = jcustomer.joinList(PREFIX_CUSTOMERADDRESSES_ENTITY, JoinType.LEFT);
// Join<CustomerAddress, Address> jaddress = jcustaddress.join(PREFIX_ADDRESS_ENTITY, JoinType.LEFT);
root.fetch(PREFIX_CUSTOMER_ENTITY, JoinType.LEFT).fetch(PREFIX_CUSTOMERADDRESSES_ENTITY, JoinType.LEFT).fetch(PREFIX_ADDRESS_ENTITY, JoinType.LEFT);
return null;
}
})
));
return helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
}
}
I try passing something like '.../admin/order?customer.customerAddresses.address.addressLine1=xxx' but i think the problem is that customerAddresses is a list, but i'm not sure about it and i've no idea how i can solve it.
thank u all for the help!