All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.mosip.kernel.masterdata.utils.DefaultSort Maven / Gradle / Ivy

There is a newer version: 1.2.1.0
Show newest version
package io.mosip.kernel.masterdata.utils;

import java.util.Arrays;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import io.mosip.kernel.masterdata.dto.request.Pagination;
import io.mosip.kernel.masterdata.dto.request.SearchDto;
import io.mosip.kernel.masterdata.dto.request.SearchSort;

/**
 * 
 * @author Uday Kumar
 * @since 1.0.0
 *
 */

@Aspect
public class DefaultSort {

	@Before("searchWithinPointCut() && searchArgsPointCut()")
	public void defalultSortField(JoinPoint joinPoint) {
		Object[] args = joinPoint.getArgs();
		for (Object arg : args) {
			if (arg instanceof SearchDto) {
				SearchDto dto = (SearchDto) arg;
				if (dto.getSort().isEmpty()) {
					SearchSort sort1 = new SearchSort("createdDateTime", "desc");
					SearchSort sort2 = new SearchSort("updatedDateTime", "desc");
					dto.setSort(Arrays.asList(sort1, sort2));
				}
				if (dto.getPagination() == null) {
					Pagination page = new Pagination(0, 10);
					dto.setPagination(page);

				}
			}
		}

	}

	@Pointcut("args(io.mosip.kernel.masterdata.dto.request.SearchDto)")
	public void searchArgsPointCut() {
	}

	@Pointcut("within(io.mosip.kernel.masterdata.service.impl.*)")
	public void searchWithinPointCut() {
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy