<commit_before>package eu.bcvsolutions.idm.core.audit.repository;

import java.util.List;
import java.util.UUID;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter;
import eu.bcvsolutions.idm.core.api.repository.AbstractEntityRepository;
import eu.bcvsolutions.idm.core.audit.entity.IdmAudit;

@RepositoryRestResource(//
		collectionResourceRel = "audits", //
		path = "audits", //
		itemResourceRel = "audit", //
		exported = false // 
	)
public interface IdmAuditRepository extends AbstractEntityRepository<IdmAudit> {
	
	@Query(value = "SELECT e "
				+ "FROM "
					+ "#{#entityName} e "
				+ "WHERE "
					+ "("
						+ " ?#{[0].id == null ? 'null' : ''} = 'null' or e.id = ?#{[0].id} "
					+ ")"
					+ " AND "
					+ "("
						+ "?#{[0].text} IS null "
						+ "OR CAST(e.id as string) like ?#{[0].text == null ? '%' : '%'.concat([0].text.toLowerCase()).concat('%')} "
					+ ")"	
					+ " AND "
					+ "("
						+ "?#{[0].modification} IS null "
						+ "OR lower(e.modification) like ?#{[0].modification == null ? '%' : '%'.concat([0].modification.toLowerCase()).concat('%')} "
					+ ")"
					+ " AND "
					+ "("
						+ "?#{[0].changedAttributes} IS null "
						+ "OR lower(e.changedAttributes) like ?#{[0].changedAttributes == null ? '%' : '%'.concat([0].changedAttributes.toLowerCase()).concat('%')} "
					+ ")"
					+ " AND "
					+ "("
						+ "?#{[0].modifier} IS null "
						+ "OR "
						+ "("
							+ "lower(e.modifier) like ?#{[0].modifier == null ? '%' : '%'.concat([0].modifier.toLowerCase()).concat('%')} "
							+ "AND "
							+ "lower(e.originalModifier) like ?#{[0].modifier == null ? '%' : '%'.concat([0].modifier.toLowerCase()).concat('%')} "
						+ ")"
					+ ")"
					+ " AND "
					+ "("
						+ "?#{[0].entityId} IS null "
						+ "OR e.entityId = ?#{[0].entityId} "
					+ ")"
					+ " AND "
					+ "(" 
						+ "?#{[0].from == null ? 'null' : ''} = 'null' or e.timestamp >= ?#{[0].from == null ? null : [0].from.getMillis()} "
					+ ")"
					+ " AND "
					+ "("
						+ "?#{[0].till == null ? 'null' : ''} = 'null' or e.timestamp <= ?#{[0].till == null ? null : [0].till.getMillis()} "
					+ ")"
					+ " AND "
					+ "("
						+ "?#{[0].type} IS null "
						+ "OR lower(e.type) like ?#{[0].type == null ? '%' : '%'.concat([0].type.toLowerCase())} "
					+ ") "
					// owner + subOwner attributes
					+ "AND "
					+ "( "
						+ "?#{[0].ownerCode} IS null "
						+ "OR lower(e.ownerCode) like ?#{[0].ownerCode == null ? '%' : '%'.concat([0].ownerCode.toLowerCase())} "
					+ ") "
					+ "AND "
					+ "( "
						+ "?#{[0].ownerType} IS null "<commit_msg>#1019 fix problem with filtering by GUEST<commit_after>package eu.bcvsolutions.idm.core.audit.repository;

import java.util.List;
import java.util.UUID;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter;
import eu.bcvsolutions.idm.core.api.repository.AbstractEntityRepository;
import eu.bcvsolutions.idm.core.audit.entity.IdmAudit;

@RepositoryRestResource(//
		collectionResourceRel = "audits", //
		path = "audits", //
		itemResourceRel = "audit", //
		exported = false // 
	)
public interface IdmAuditRepository extends AbstractEntityRepository<IdmAudit> {
	
	@Query(value = "SELECT e "
				+ "FROM "
					+ "#{#entityName} e "
				+ "WHERE "
					+ "("
						+ " ?#{[0].id == null ? 'null' : ''} = 'null' or e.id = ?#{[0].id} "
					+ ")"
					+ " AND "
					+ "("
						+ "?#{[0].text} IS null "
						+ "OR CAST(e.id as string) like ?#{[0].text == null ? '%' : '%'.concat([0].text.toLowerCase()).concat('%')} "
					+ ")"	
					+ " AND "
					+ "("
						+ "?#{[0].modification} IS null "
						+ "OR lower(e.modification) like ?#{[0].modification == null ? '%' : '%'.concat([0].modification.toLowerCase()).concat('%')} "
					+ ")"
					+ " AND "
					+ "("
						+ "?#{[0].changedAttributes} IS null "
						+ "OR lower(e.changedAttributes) like ?#{[0].changedAttributes == null ? '%' : '%'.concat([0].changedAttributes.toLowerCase()).concat('%')} "
					+ ")"
					+ " AND "
					+ "("
						+ "?#{[0].modifier} IS null "
						+ "OR "
						+ "("
							+ "lower(e.modifier) like ?#{[0].modifier == null ? '%' : '%'.concat([0].modifier.toLowerCase()).concat('%')} "
							+ "OR "
							+ "lower(e.originalModifier) like ?#{[0].modifier == null ? '%' : '%'.concat([0].modifier.toLowerCase()).concat('%')} "
						+ ")"
					+ ")"
					+ " AND "
					+ "("
						+ "?#{[0].entityId} IS null "
						+ "OR e.entityId = ?#{[0].entityId} "
					+ ")"
					+ " AND "
					+ "(" 
						+ "?#{[0].from == null ? 'null' : ''} = 'null' or e.timestamp >= ?#{[0].from == null ? null : [0].from.getMillis()} "
					+ ")"
					+ " AND "
					+ "("
						+ "?#{[0].till == null ? 'null' : ''} = 'null' or e.timestamp <= ?#{[0].till == null ? null : [0].till.getMillis()} "
					+ ")"
					+ " AND "
					+ "("
						+ "?#{[0].type} IS null "
						+ "OR lower(e.type) like ?#{[0].type == null ? '%' : '%'.concat([0].type.toLowerCase())} "
					+ ") "
					// owner + subOwner attributes
					+ "AND "
					+ "( "
						+ "?#{[0].ownerCode} IS null "
						+ "OR lower(e.ownerCode) like ?#{[0].ownerCode == null ? '%' : '%'.concat([0].ownerCode.toLowerCase())} "
					+ ") "
					+ "AND "
					+ "( "
						+ "?#{[0].ownerType} IS null "
{'fraction_non_alphanumeric': 0.2408834103749358, 'fraction_numerical': 0.011299435028248588, 'mean_word_length': 2.5995070856438693, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7065525', 'n_tokens_mistral': 2636, 'n_tokens_neox': 2145, 'n_words': 314}