use of org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria in project BroadleafCommerce by BroadleafCommerce.
the class AdminPermissionCustomPersistenceHandler method addDefaultSort.
protected void addDefaultSort(CriteriaTransferObject cto) {
boolean userSort = false;
for (FilterAndSortCriteria fasc : cto.getCriteriaMap().values()) {
if (fasc.getSortDirection() != null) {
userSort = true;
break;
}
}
if (!userSort) {
FilterAndSortCriteria descriptionSort = cto.getCriteriaMap().get("description");
if (descriptionSort == null) {
descriptionSort = new FilterAndSortCriteria("description");
cto.add(descriptionSort);
}
descriptionSort.setSortAscending(true);
}
}
use of org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method getRecord.
@Override
public PersistenceResponse getRecord(PersistencePackageRequest request, String id, ClassMetadata cmd, boolean isCollectionRequest) throws ServiceException {
String idProperty = getIdProperty(cmd);
FilterAndSortCriteria fasc = new FilterAndSortCriteria(idProperty);
fasc.setFilterValue(id);
request.addFilterAndSortCriteria(fasc);
PersistenceResponse response = fetch(request);
Entity[] entities = response.getDynamicResultSet().getRecords();
if (ArrayUtils.isEmpty(entities)) {
throw new EntityNotFoundException();
}
return response;
}
use of org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method getPagedRecordsForCollection.
@Override
public PersistenceResponse getPagedRecordsForCollection(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, FilterAndSortCriteria[] fascs, FetchPageRequest fetchPageRequest, String idValueOverride, List<SectionCrumb> sectionCrumbs) throws ServiceException {
PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(collectionProperty.getMetadata(), sectionCrumbs).withFilterAndSortCriteria(fascs).withStartIndex(fetchPageRequest.getStartIndex()).withMaxIndex(fetchPageRequest.getMaxIndex()).withFirstId(fetchPageRequest.getFirstId()).withLastId(fetchPageRequest.getLastId()).withLowerCount(fetchPageRequest.getLowerCount()).withUpperCount(fetchPageRequest.getUpperCount()).withPageSize(fetchPageRequest.getPageSize()).withPresentationFetch(true);
FilterAndSortCriteria fasc;
FieldMetadata md = collectionProperty.getMetadata();
String collectionCeilingClass = null;
if (md instanceof BasicCollectionMetadata) {
fasc = new FilterAndSortCriteria(ppr.getForeignKey().getManyToField());
collectionCeilingClass = ((CollectionMetadata) md).getCollectionCeilingEntity();
} else if (md instanceof AdornedTargetCollectionMetadata) {
fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName());
collectionCeilingClass = ((CollectionMetadata) md).getCollectionCeilingEntity();
} else if (md instanceof MapMetadata) {
fasc = new FilterAndSortCriteria(ppr.getForeignKey().getManyToField());
} else {
throw new IllegalArgumentException(String.format("The specified field [%s] for class [%s] was not a " + "collection field.", collectionProperty.getName(), containingClassMetadata.getCeilingType()));
}
String id;
if (idValueOverride == null) {
id = getContextSpecificRelationshipId(containingClassMetadata, containingEntity, collectionProperty.getName());
} else {
id = idValueOverride;
}
fasc.setFilterValue(id);
ppr.addFilterAndSortCriteria(fasc);
if (collectionCeilingClass != null) {
ppr.setCeilingEntityClassname(collectionCeilingClass);
}
ppr.setSectionEntityField(collectionProperty.getName());
return fetch(ppr);
}
use of org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria in project BroadleafCommerce by BroadleafCommerce.
the class AdminAbstractController method getSectionPersistencePackageRequest.
/**
* Returns the result of a call to getSectionPersistencePackageRequest(..) with the additional filter
* and sort criteria attached.
*
* @param sectionClassName
* @param requestParams
* @param sectionCrumbs
* @param pathVars
* @return the PersistencePacakageRequest
*/
protected PersistencePackageRequest getSectionPersistencePackageRequest(String sectionClassName, MultiValueMap<String, String> requestParams, List<SectionCrumb> sectionCrumbs, Map<String, String> pathVars) {
FilterAndSortCriteria[] fascs = getCriteria(requestParams);
String[] sectionCriteria = customCriteriaService.mergeSectionCustomCriteria(sectionClassName, getSectionCustomCriteria());
PersistencePackageRequest ppr = PersistencePackageRequest.standard().withCeilingEntityClassname(sectionClassName).withCustomCriteria(sectionCriteria).withFilterAndSortCriteria(fascs).withStartIndex(getStartIndex(requestParams)).withMaxIndex(getMaxIndex(requestParams)).withSectionCrumbs(sectionCrumbs).withLastId(getLastId(requestParams)).withFirstId(getFirstId(requestParams)).withUpperCount(getUpperCount(requestParams)).withLowerCount(getLowerCount(requestParams)).withPageSize(getPageSize(requestParams)).withPresentationFetch(true);
attachSectionSpecificInfo(ppr, pathVars);
return ppr;
}
use of org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria in project BroadleafCommerce by BroadleafCommerce.
the class AdminAbstractController method getCriteria.
/**
* <p>Helper method to return an array of {@link org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria} based on a map of propertyName -> list of criteria
* value. This will also grab the sorts off of the request parameters, if any.</p>
*
* <p>The multi-valued map allows users to specify multiple criteria values per property, as well as multiple sort
* properties and sort directions. For multiple sort properties and sort directions, these would usually come in as
* request parameters like:
* <br />
* <br />
* ....?sortProperty=defaultSku.name&sortProperty=manufacturer&sortDirection=ASCENDING&sortDirection=DESCENDING
* <br />
* <br />
* This would attach criteria such that defaultSku.name was sorted ascending, and manufacturer was sorted descending</p>
*
* @param requestParams usually a {@link MultiValueMap} that has been bound by a controller to receive all of the
* request parameters that are not explicitly named
* @return the final array of {@link org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria} to pass to the fetch
*
* @see {@link #getSortPropertyNames(Map)}
* @see {@link #getSortDirections(Map)}
*/
protected FilterAndSortCriteria[] getCriteria(Map<String, List<String>> requestParams) {
if (requestParams == null || requestParams.isEmpty()) {
return null;
}
Map<String, FilterAndSortCriteria> fasMap = new HashMap<>();
List<FilterAndSortCriteria> result = new ArrayList<>();
for (Entry<String, List<String>> entry : requestParams.entrySet()) {
if (!entry.getKey().equals(FilterAndSortCriteria.SORT_PROPERTY_PARAMETER) && !entry.getKey().equals(FilterAndSortCriteria.SORT_DIRECTION_PARAMETER) && !entry.getKey().equals(FilterAndSortCriteria.MAX_INDEX_PARAMETER) && !entry.getKey().equals(FilterAndSortCriteria.START_INDEX_PARAMETER)) {
List<String> values = entry.getValue();
List<String> collapsedValues = new ArrayList<>();
for (String value : values) {
if (value.contains(FILTER_VALUE_SEPARATOR)) {
String[] vs = value.split(FILTER_VALUE_SEPARATOR_REGEX);
for (String v : vs) {
collapsedValues.add(v);
}
} else {
collapsedValues.add(value);
}
}
FilterAndSortCriteria fasCriteria = new FilterAndSortCriteria(entry.getKey(), collapsedValues, Integer.MIN_VALUE);
fasMap.put(entry.getKey(), fasCriteria);
}
}
List<String> sortProperties = getSortPropertyNames(requestParams);
List<String> sortDirections = getSortDirections(requestParams);
if (CollectionUtils.isNotEmpty(sortProperties)) {
// set up a map to determine if there is already some criteria set for the sort property
for (int i = 0; i < sortProperties.size(); i++) {
boolean sortAscending = SortDirection.ASCENDING.toString().equals(sortDirections.get(i));
FilterAndSortCriteria propertyCriteria = fasMap.get(sortProperties.get(i));
// FilterAndSortCriteria for the sort
if (propertyCriteria != null) {
propertyCriteria.setSortAscending(sortAscending);
} else {
propertyCriteria = new FilterAndSortCriteria(sortProperties.get(i));
propertyCriteria.setOrder(Integer.MIN_VALUE);
propertyCriteria.setSortAscending(sortAscending);
fasMap.put(sortProperties.get(i), propertyCriteria);
}
}
}
result.addAll(fasMap.values());
return result.toArray(new FilterAndSortCriteria[result.size()]);
}
Aggregations