Java Code Examples for org.springframework.data.domain.Page#getSort()
The following examples show how to use
org.springframework.data.domain.Page#getSort() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaginationSortBaseAttrProcessor.java From thymeleaf-spring-data-dialect with Apache License 2.0 | 6 votes |
@Override protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler) { String attrValue = String.valueOf(Expressions.evaluate(context, attributeValue)).trim(); Page<?> page = PageUtils.findPage(context); String url = PageUtils.createSortUrl(context, attrValue, getForcedDirection()); // Append class to the element if sorted by this field Sort sort = page.getSort(); boolean isSorted = sort != null && sort.getOrderFor(attrValue) != null; String clas = isSorted ? SORTED_PREFIX.concat(sort.getOrderFor(attrValue).getDirection().toString().toLowerCase()) : EMPTY; structureHandler.setAttribute(HREF, url); String currentClass = tag.getAttributeValue(CLASS); structureHandler.setAttribute(CLASS, Strings.concat(currentClass, BLANK, clas)); }
Example 2
Source File: PageUtils.java From thymeleaf-spring-data-dialect with Apache License 2.0 | 6 votes |
/** * Creates an url to sort data by fieldName * * @param context execution context * @param fieldName field name to sort * @param forcedDir optional, if specified then only this sort direction will be allowed * @return sort URL */ public static String createSortUrl(final ITemplateContext context, final String fieldName, final Direction forcedDir) { // Params can be prefixed to manage multiple pagination on the same page final String prefix = getParamPrefix(context); final Collection<String> excludedParams = Arrays .asList(new String[] { prefix.concat(SORT), prefix.concat(PAGE) }); final String baseUrl = buildBaseUrl(context, excludedParams); final StringBuilder sortParam = new StringBuilder(); final Page<?> page = findPage(context); final Sort sort = page.getSort(); final boolean hasPreviousOrder = sort != null && sort.getOrderFor(fieldName) != null; if (forcedDir != null) { sortParam.append(fieldName).append(COMMA).append(forcedDir.toString().toLowerCase()); } else if (hasPreviousOrder) { // Sort parameters exists for this field, modify direction Order previousOrder = sort.getOrderFor(fieldName); Direction dir = previousOrder.isAscending() ? Direction.DESC : Direction.ASC; sortParam.append(fieldName).append(COMMA).append(dir.toString().toLowerCase()); } else { sortParam.append(fieldName); } return buildUrl(baseUrl, context).append(SORT).append(EQ).append(sortParam).toString(); }
Example 3
Source File: TPage.java From issue-management with MIT License | 5 votes |
public void setStat(Page page, List<T> list) { this.number = page.getNumber(); this.size = page.getSize(); this.sort = page.getSort(); this.totalPages = page.getTotalPages(); this.totalElements = page.getTotalElements(); this.content = list; }
Example 4
Source File: AbstractConverter.java From abixen-platform with GNU Lesser General Public License v2.1 | 5 votes |
public final Page<Target> convertToPage(Page<Source> sourcePage, Map<String, Object> parameters) { final List<Target> targets = new ArrayList<>(sourcePage.getContent().size()); for (Source source : sourcePage) { targets.add(convert(source, parameters)); } final Pageable pageable = new PageRequest(sourcePage.getNumber(), sourcePage.getSize(), sourcePage.getSort()); return new PageImpl<>(targets, pageable, sourcePage.getTotalElements()); }
Example 5
Source File: PlatformPageImpl.java From abixen-platform with GNU Lesser General Public License v2.1 | 5 votes |
public PlatformPageImpl(Page page) { super(page.getContent(), new PageRequest(page.getNumber(), page.getSize(), page.getSort()), page.getTotalElements()); this.number = page.getNumber(); this.size = page.getSize(); this.totalPages = page.getTotalPages(); this.numberOfElements = page.getNumberOfElements(); this.totalElements = page.getTotalElements(); this.first = page.isFirst(); this.last = page.isLast(); this.content = page.getContent(); this.sort = page.getSort(); }
Example 6
Source File: DTOUtils.java From angularjs-springmvc-sample-boot with Apache License 2.0 | 5 votes |
public static <S, T> Page<T> mapPage(Page<S> source, Class<T> targetClass) { List<S> sourceList = source.getContent(); List<T> list = new ArrayList<>(); for (int i = 0; i < sourceList.size(); i++) { T target = INSTANCE.map(sourceList.get(i), targetClass); list.add(target); } return new PageImpl<>(list, new PageRequest(source.getNumber(), source.getSize(), source.getSort()), source.getTotalElements()); }
Example 7
Source File: LifecycleController.java From fullstop with Apache License 2.0 | 5 votes |
private Page<LifecylceDTO> mapToDto(final Page<LifecycleEntity> lifecycleEntities) { final List<LifecylceDTO> lifecylceDTOList = newArrayList(); for (final LifecycleEntity lifecycleEntity : lifecycleEntities) { final LifecylceDTO lifecylceDTO = new LifecylceDTO(); lifecylceDTO.setApplication(lifecycleEntity.getApplicationEntity().getName()); lifecylceDTO.setCreated(lifecycleEntity.getCreated()); lifecylceDTO.setEventDate(lifecycleEntity.getEventDate()); lifecylceDTO.setEventType(lifecycleEntity.getEventType()); lifecylceDTO.setImageID(lifecycleEntity.getImageId()); lifecylceDTO.setImageName(lifecycleEntity.getImageName()); lifecylceDTO.setInstanceBootTime(lifecycleEntity.getInstanceBootTime()); lifecylceDTO.setInstanceId(lifecycleEntity.getInstanceId()); lifecylceDTO.setRegion(lifecycleEntity.getRegion()); lifecylceDTO.setVersion(lifecycleEntity.getVersionEntity().getName()); lifecylceDTOList.add(lifecylceDTO); } final PageRequest currentPageRequest = new PageRequest( lifecycleEntities.getNumber(), lifecycleEntities.getSize(), lifecycleEntities.getSort()); return new PageImpl<>(lifecylceDTOList, currentPageRequest, lifecycleEntities.getTotalElements()); }
Example 8
Source File: ViolationsController.java From fullstop with Apache License 2.0 | 5 votes |
private Page<Violation> mapBackendToFrontendViolations(final Page<ViolationEntity> backendViolations) { final PageRequest currentPageRequest = new PageRequest( backendViolations.getNumber(), backendViolations.getSize(), backendViolations.getSort()); return new PageImpl<>( backendViolations.getContent().stream().map(entityToDto::convert).collect(toList()), currentPageRequest, backendViolations.getTotalElements()); }