Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPMRPP-91743 fix search query #1013

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
import com.epam.ta.reportportal.entity.item.TestItem;
import com.epam.ta.reportportal.entity.launch.Launch;
import com.epam.ta.reportportal.entity.log.Log;
import com.epam.ta.reportportal.entity.organization.Organization;
import com.epam.ta.reportportal.entity.organization.OrganizationFilter;
import com.epam.ta.reportportal.entity.project.Project;
import com.epam.ta.reportportal.entity.project.ProjectInfo;
Expand Down Expand Up @@ -1419,54 +1418,7 @@ protected Field<Long> idField() {
}
},

ORGANIZATION_TARGET(Organization.class, Arrays.asList(
new CriteriaHolderBuilder().newBuilder(CRITERIA_ID, ORGANIZATION.ID, Long.class).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_NAME, ORGANIZATION.NAME, String.class).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_SLUG, ORGANIZATION.SLUG, String.class).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_ORG_CREATED_DATE, ORGANIZATION.CREATED_AT,
Timestamp.class).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_ORG_TYPE, ORGANIZATION.ORGANIZATION_TYPE,
String.class).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_USER, USERS.LOGIN, String.class)
.withAggregateCriteria(DSL.max(USERS.LOGIN).toString())
.get()
)) {
@Override
protected Collection<? extends SelectField> selectFields() {
return Lists.newArrayList(ORGANIZATION.ID,
ORGANIZATION.ID,
ORGANIZATION.NAME,
ORGANIZATION.SLUG,
ORGANIZATION.CREATED_AT,
ORGANIZATION.UPDATED_AT,
ORGANIZATION.EXTERNAL_ID,
ORGANIZATION.ORGANIZATION_TYPE
);
}

@Override
protected void addFrom(SelectQuery<? extends Record> query) {
query.addFrom(ORGANIZATION);
}

@Override
protected void joinTables(QuerySupplier query) {
query.addJoin(ORGANIZATION_USER,
JoinType.LEFT_OUTER_JOIN,
ORGANIZATION_USER.ORGANIZATION_ID.eq(ORGANIZATION.ID));

query.addJoin(USERS,
JoinType.LEFT_OUTER_JOIN,
ORGANIZATION_USER.USER_ID.eq(USERS.ID));
}

@Override
protected Field<Long> idField() {
return ORGANIZATION.ID.cast(Long.class);
}
},

ORGANIZATION_INFO_TARGET(OrganizationFilter.class, Arrays.asList(
ORGANIZATION_TARGET(OrganizationFilter.class, Arrays.asList(
new CriteriaHolderBuilder().newBuilder(CRITERIA_ID, ORGANIZATION.ID, Long.class).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_NAME, ORGANIZATION.NAME, String.class).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_SLUG, ORGANIZATION.SLUG, String.class).get(),
Expand All @@ -1493,7 +1445,6 @@ protected Field<Long> idField() {
.and(LAUNCH.STATUS.ne(JStatusEnum.IN_PROGRESS)), LAUNCH.ID)).toString())
.get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_USER, USERS.LOGIN, String.class)
.withAggregateCriteria(DSL.max(USERS.LOGIN).toString())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed aggregate function

.get()

)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@

import com.epam.ta.reportportal.commons.querygen.QueryBuilder;
import com.epam.ta.reportportal.commons.querygen.Queryable;
import com.epam.ta.reportportal.dao.custom.ElasticSearchClient;
import com.epam.ta.reportportal.entity.organization.Organization;
import com.epam.ta.reportportal.model.OrganizationProfile;
import java.util.List;
import java.util.Optional;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.SelectQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -41,23 +46,35 @@
@Repository
public class OrganizationRepositoryCustomImpl implements OrganizationRepositoryCustom {

protected final Logger LOGGER = LoggerFactory.getLogger(OrganizationRepositoryCustomImpl.class);

@Autowired
private DSLContext dsl;

@Override
public List<OrganizationProfile> findByFilter(Queryable filter) {
return ORGANIZATION_FETCHER.apply(
dsl.fetch(QueryBuilder.newBuilder(filter, collectJoinFields(filter))
.build()));

SelectQuery<? extends Record> query = QueryBuilder
.newBuilder(filter, collectJoinFields(filter))
.build();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Find organizations query: {}", query);
}
return ORGANIZATION_FETCHER
.apply(dsl.fetch(query));
}

@Override
public Page<OrganizationProfile> findByFilter(Queryable filter, Pageable pageable) {
return PageableExecutionUtils.getPage(
ORGANIZATION_FETCHER.apply(
dsl.fetch(QueryBuilder.newBuilder(filter, collectJoinFields(filter, pageable.getSort()))
.with(pageable)
.build())),
SelectQuery<? extends Record> query = QueryBuilder.newBuilder(filter,
collectJoinFields(filter, pageable.getSort()))
.with(pageable)
.build();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Find organizations with pagination query: {}", query);
}
return PageableExecutionUtils.getPage(ORGANIZATION_FETCHER
.apply(dsl.fetch(query)),
pageable,
() -> dsl.fetchCount(QueryBuilder.newBuilder(filter).build())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import com.epam.ta.reportportal.BaseTest;
import com.epam.ta.reportportal.commons.querygen.Condition;
import com.epam.ta.reportportal.commons.querygen.Filter;
import com.epam.ta.reportportal.commons.querygen.FilterCondition;
import com.epam.ta.reportportal.entity.organization.Organization;
import com.epam.ta.reportportal.entity.organization.OrganizationFilter;
import com.epam.ta.reportportal.model.OrganizationInfo;
import com.epam.ta.reportportal.model.OrganizationProfile;
import java.util.List;
import java.util.Optional;
Expand All @@ -41,7 +41,7 @@ class OrganizationRepositoryCustomTest extends BaseTest {
@Autowired
private OrganizationRepositoryCustom organizationRepositoryCustom;

/* @Test
@Test
void findByNameTest() {
String name = "My organization";
Optional<Organization> organization = organizationRepositoryCustom.findOrganizationByName(name);
Expand All @@ -59,7 +59,7 @@ void findBySlugTest() {
void findByIdTest() {
Optional<Organization> organization = organizationRepositoryCustom.findById(1L);
assertTrue("Organization not found", organization.isPresent());
}*/
}

@Test
void organizationByFilterNotFound() {
Expand All @@ -77,18 +77,23 @@ void organizationByFilterNotFound() {
@CsvSource(value = {
"slug|eq|my-organization|1",
"slug|eq|notexists|0",
"user|eq|superadmin|1",
"user|eq|notexists|0",
"organization_type|eq|INTERNAL|1",
"usersQuantity|eq|1|1",
"usersQuantity|eq|845|0",
"launchesQuantity|gt|-1|1",
"launchesQuantity|gt|999|0",
"projectsQuantity|eq|2|1",
"projectsQuantity|eq|999|0"
}, delimiter = '|')
void findOrganizationByFilter(String field, String condition, String value, int rows) {
final List<OrganizationProfile> orgs = organizationRepositoryCustom.findByFilter(
new Filter(OrganizationFilter.class,
Condition.findByMarker(condition).get(),
false,
value,
field
));
void findOrganizationByFilterWithUser(String field, String condition, String value, int rows) {
Filter filter = new Filter(OrganizationFilter.class,
Condition.findByMarker(condition).get(),
false,
value,
field);

filter.withCondition(new FilterCondition(Condition.EQUALS, false, "default", "user"));

final List<OrganizationProfile> orgs = organizationRepositoryCustom.findByFilter(filter);
assertEquals(rows, orgs.size());
}

Expand All @@ -106,14 +111,14 @@ void findOrganizationByFilter(String field, String condition, String value, int
"user|eq|superadmin|1",
"user|eq|notexists|0"
}, delimiter = '|')
void findOrganizationInfoByFilter(String field, String condition, String value, int rows) {
final List<OrganizationProfile> orgsInfo = organizationRepositoryCustom.findByFilter(
void findOrganizationByFilter(String field, String condition, String value, int rows) {
final List<OrganizationProfile> orgs = organizationRepositoryCustom.findByFilter(
new Filter(OrganizationFilter.class,
Condition.findByMarker(condition).get(),
false,
value,
field
));
assertEquals(rows, orgsInfo.size());
assertEquals(rows, orgs.size());
}
}
Loading