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

io.mosip.admin.bulkdataupload.repositories.LocationRepository Maven / Gradle / Ivy

There is a newer version: 1.2.1.0
Show newest version
package io.mosip.admin.bulkdataupload.repositories;

import java.util.List;
import java.util.Set;

import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import io.mosip.admin.bulkdataupload.entity.Location;
import io.mosip.admin.bulkdataupload.entity.id.CodeAndLanguageCodeID;
import io.mosip.kernel.core.dataaccess.spi.repository.BaseRepository;

/**
 * This interface is JPA repository class which interacts with database and does
 * the CRUD function. It is extended from {@link BaseRepository}
 * 
 * @author Srinivasan
 * @author uday kumar
 * @author Sidhant Agarwal
 *
 */
@Repository
public interface LocationRepository extends BaseRepository {

	@Query("FROM Location WHERE (isDeleted is null OR isDeleted = false) AND isActive = true")
	List findLocationHierarchyByIsDeletedIsNullOrIsDeletedFalse();

	@Query(value = "FROM Location l where l.code=?1 and l.langCode=?2 and (l.isDeleted is null or l.isDeleted=false) and l.isActive = true")
	List findLocationHierarchyByCodeAndLanguageCode(String locCode, String languagecode);

	@Query(value = "FROM Location l where l.code=?1 and l.langCode=?2 and (l.isDeleted is null or l.isDeleted=false)")
	Location findLocationByCodeAndLanguageCode(String locCode, String languagecode);

	@Query(value = "FROM Location l where parentLocCode=?1 and langCode=?2 and (l.isDeleted is null or l.isDeleted=false) and l.isActive=true")
	List findLocationHierarchyByParentLocCodeAndLanguageCode(String parentLocCode, String languageCode);

	@Query(value = "select distinct hierarchy_level, hierarchy_level_name, is_active from master.location where lang_code=?1 and (is_deleted='f' or is_deleted is null) and is_active='t' ", nativeQuery = true)
	List findDistinctLocationHierarchyByIsDeletedFalse(String langCode);

	@Query(value = "FROM Location l where l.code=?1 and (l.isDeleted is null or l.isDeleted=false) and l.isActive = true")
	List findByCode(String locationCode);

	/**
	 *
	 * @param hierarchyName - hierarchy name
	 * @return List
	 */
	@Query(value = "FROM Location l where LOWER(l.hierarchyName)=LOWER(?1) AND (l.isDeleted is null OR l.isDeleted=false) AND l.isActive=true")
	List findAllByHierarchyNameIgnoreCase(String hierarchyName);

	/**
	 *
	 * @param langCode language code
	 * @param level    hierarchy level
	 * @return List of Locations
	 * 
	 */
	@Query(value = "FROM Location l where l.langCode=?1 and l.hierarchyLevel >=?2 and (l.isDeleted is null or l.isDeleted=false) and l.isActive = true")
	List getAllLocationsByLangCodeAndLevel(String langCode, Short level);

	/**
	 * checks whether the location name is valid location or not
	 * 
	 * @param locationName location name
	 * @return {@link Boolean} true or false
	 */
	@Query(value = "SELECT EXISTS(select name FROM master.location where (LOWER(name)=LOWER(?1)) and (is_active=true) and (is_deleted is null or is_deleted =false))", nativeQuery = true)
	boolean isLocationNamePresent(String locationName);

	/**
	 * give list of the immediate Locations for the given parent location code
	 * 
	 * @param locationName location name
	 * @return {@link Boolean} true or false
	 */
	@Query("FROM Location l where l.parentLocCode=?1 and l.langCode=?2 and l.isActive=true and (l.isDeleted is null or l.isDeleted=false)")
	List findDistinctByparentLocCode(String parentLocCode, String langCode);

	/**
	 * give list of the immediate Locations for the given parent location code
	 * 
	 * @param locationName location name
	 * @return {@link Boolean} true or false
	 */
	@Query("SELECT distinct l.code FROM Location l where l.parentLocCode=?1 GROUP BY l.code")
	List findDistinctByparentLocCode(String parentLocCode);

	@Query(value = "select distinct name from master.location where hierarchy_level = ?1 and lang_code = ?2", nativeQuery = true)
	List filterByDistinctHierarchyLevel(int hierarchyLevel, String langCode);

	@Query(value = "select name from master.location where hierarchy_level = ?1 and lang_code = ?2", nativeQuery = true)
	List filterByHierarchyLevel(int hierarchyLevel, String langCode);

	@Query(value = "FROM Location WHERE langCode=?1 AND (isDeleted is null or isDeleted=false)")
	List findAllByLangCodeNonDeleted(String langCode);

	@Query("FROM Location l where l.hierarchyLevel=?1 and l.name =?2 and l.langCode=?3 and l.isActive=?4 and (l.isDeleted is null or l.isDeleted=false)")
	Location findLocationByHierarchyLevel(short hierachyLevel, String value, String langCode, boolean isActive);

	@Query("FROM Location l where l.langCode=?1 and l.isActive=true and (l.isDeleted is null or l.isDeleted=false)")
	List findAllByLangCode(String langCode);

	@Query("FROM Location l where l.langCode=?1 and l.isActive=?2 and (l.isDeleted is null or l.isDeleted=false)")
	List findAllByLangCode(String langCode, boolean isActive);

	@Query("FROM Location l where  l.hierarchyLevel=?1 and lower(l.name) like ?2 and l.langCode=?3 and l.isActive=?4 and (l.isDeleted is null or l.isDeleted=false)")
	List findLocationByHierarchyLevelContains(short hierarchyLevel, String value, String langCode,
			boolean isActive);

	@Query("FROM Location l where  l.hierarchyLevel=?1 and lower(l.name) like ?2 and l.langCode=?3 and l.isActive=?4 and (l.isDeleted is null or l.isDeleted=false)")
	List findLocationByHierarchyLevelStartsWith(Short hierarchyLevel, String value, String langCode,
			boolean isActive);

	@Query("SELECT l.hierarchyName FROM Location l where l.isActive=true and (l.isDeleted is null or l.isDeleted=false)")
	List findLocationAllHierarchyNames();

	@Query("FROM Location l where l.hierarchyName=?1 and l.langCode=?2 and l.isActive=true and (l.isDeleted is null or l.isDeleted=false)")
	List findAllHierarchyNameAndNameValueForEmptyTextFilter(String hierarchyName, String langCode);

	@Query("FROM Location l where l.hierarchyName=?1 and lower(l.name) like ?2 and l.langCode=?3 and l.isActive=true and (l.isDeleted is null or l.isDeleted=false)")
	List findAllHierarchyNameAndNameValueForTextFilter(String hierarchyName, String text, String langCode);

	@Query("FROM Location l where l.hierarchyName=?1 and l.langCode=?2 and l.isActive=true and (l.isDeleted is null or l.isDeleted=false)")
	List findDistinctHierarchyNameAndNameValueForEmptyTextFilter(String hierarchyName, String langCode);

	@Query("FROM Location l where l.hierarchyName=?1 and lower(l.name) like ?2 and l.langCode=?3 and l.isActive=true and (l.isDeleted is null or l.isDeleted=false)")
	List findDistinctHierarchyNameAndNameValueForTextFilter(String hierarchyName, String text, String langCode);

	@Query(value = "FROM Location l where (l.isDeleted is null or l.isDeleted=false)")
	List findAllNonDeleted();

	@Query("FROM Location l WHERE l.langCode=?1 and (l.isDeleted is null OR l.isDeleted = false) AND l.isActive = true")
	List findByLangCode(String langCode);

	@Query("FROM Location l WHERE l.name=?1 AND l.hierarchyLevel=?2 ")
	List findByNameAndLevel(String name, Short hierarchyLevel);

	@Query("FROM Location l WHERE l.name=?1 AND l.hierarchyLevel=?2 AND l.langCode=?3")
	List findByNameAndLevelLangCode(String name, Short hierarchyLevel, String langCode);
	
	@Query("FROM Location l WHERE l.name=?1 AND l.hierarchyLevel=?2 AND l.langCode=?3 AND NOT code=?4")
	List findByNameAndLevelLangCodeNotCode(String name, Short hierarchyLevel, String langCode, String code);

	/**
	 * give list of the immediate Locations for the given parent location code
	 * 
	 * @param locationCode   location code
	 * @param hierarchyLevel hierarchy level
	 * @return Set
	 */
	@Query("FROM Location l WHERE l.langCode=?1 AND l.hierarchyLevel=?2")
	Set findLocationByLangCodeLevel(String langCode, Short hierarchyLevel);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy