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

com.infusers.core.search.AbsractSpecification Maven / Gradle / Ivy

There is a newer version: 2024.12.0008
Show newest version
package com.infusers.core.search;

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.jpa.domain.Specification;

import com.infusers.core.search.util.SpecificationUtility;

import jakarta.persistence.criteria.Predicate;

public abstract class AbsractSpecification {
	private String userName;
	private String searchString;
	private String userNameKey;
	
	public AbsractSpecification(String userName, String searchString, String userNameKey) {
		this.userName = userName;
		this.searchString = searchString;
		this.userNameKey = userNameKey;
	}
	
	protected String getUserNameFieldName() {
		return userNameKey;
	}
	
	protected String getUserName() {
		return this.userName;
	}
	
	public String getSearchString() {
		return this.searchString;
	}
	
	protected abstract List getConfigElements();	
	
    public Specification getSpec() {
        return (root, query, criteriaBuilder) -> 
        {        	
        	final String likeSearchString = SpecificationUtility.getSearchLikeString(searchString);
                                    
            ArrayList predicateListOr = new ArrayList();
             
            //User Name permissions
            Predicate predicateUserNameUserAccess = null;
            if (userName != null && !userName.isEmpty()) {
                predicateUserNameUserAccess = criteriaBuilder.equal(root.get(userNameKey), userName);
            }
            
        	List configElements = getConfigElements();
        	int count = configElements.size();
        	
        	for(int i=0;i predicates = new ArrayList<>();
        	if(predicateFinal!=null) {
        		predicates.add(predicateFinal);
        	}
        	
            return criteriaBuilder.and(predicates.toArray(new Predicate[0]));        
        };
    }

 }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy