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-92350 extended organization filtering #1018

Merged
merged 7 commits into from
Jul 16, 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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
if (releaseMode) {
compile 'com.epam.reportportal:commons'
} else {
api 'com.github.reportportal:commons:a6b1156'
api 'com.github.reportportal:commons:c9999b9'
}

implementation 'io.swagger.core.v3:swagger-annotations:2.2.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ protected Field<Long> idField() {
.get(),
new CriteriaHolderBuilder().newBuilder(PROJECT_USER.USER_ID.getName(), PROJECT_USER.USER_ID, Long.class)
.get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_PROJECT_ID, PROJECT.ID, Long.class).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_NAME, PROJECT.NAME, String.class).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_SLUG, PROJECT.SLUG, String.class).get()
)
Expand Down Expand Up @@ -1576,7 +1577,8 @@ protected Field<Long> idField() {
Arrays.asList(
new CriteriaHolderBuilder().newBuilder(CRITERIA_ORG_ID, ORGANIZATION_USER.ORGANIZATION_ID,
Long.class).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_FULL_NAME, USERS.FULL_NAME, String.class).get()
new CriteriaHolderBuilder().newBuilder(CRITERIA_FULL_NAME, USERS.FULL_NAME, String.class).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_PROJECT_ID, PROJECT.ID, Long.class).get()
)
) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@

import com.epam.ta.reportportal.entity.user.ProjectUser;
import com.epam.ta.reportportal.entity.user.ProjectUserId;
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
* @author Pavel Bortnik
*/
public interface ProjectUserRepository extends ReportPortalRepository<ProjectUser, ProjectUserId>,
ProjectUserRepositoryCustom {

@Query(value = "SELECT pu.project_id FROM project_user pu WHERE pu.user_id = :userId", nativeQuery = true)
List<Long> findProjectIdsByUserId(@Param("userId") Long userId);
}
23 changes: 12 additions & 11 deletions src/main/java/com/epam/ta/reportportal/dao/util/ResultFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
import static com.epam.ta.reportportal.jooq.tables.JUsers.USERS;
import static java.util.Optional.ofNullable;

import com.epam.reportportal.api.model.ProjectRelationshipsRelationships;
import com.epam.reportportal.api.model.ProjectRelationshipsRelationshipsLaunches;
import com.epam.reportportal.api.model.ProjectRelationshipsRelationshipsLaunchesMeta;
import com.epam.reportportal.api.model.ProjectRelationshipsRelationshipsUsers;
import com.epam.reportportal.api.model.ProjectRelationshipsRelationshipsUsersMeta;
import com.epam.reportportal.rules.exception.ErrorType;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.commons.ReportPortalUser;
Expand Down Expand Up @@ -73,11 +78,6 @@
import com.epam.ta.reportportal.entity.widget.Widget;
import com.epam.reportportal.api.model.OrganizationProfile;
import com.epam.reportportal.api.model.ProjectProfile;
import com.epam.reportportal.api.model.ProjectRelation;
import com.epam.reportportal.api.model.ProjectRelationLaunches;
import com.epam.reportportal.api.model.ProjectRelationLaunchesMeta;
import com.epam.reportportal.api.model.ProjectRelationUsers;
import com.epam.reportportal.api.model.ProjectRelationUsersMeta;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -466,24 +466,25 @@ private ResultFetchers() {
projectProfile.setUpdatedAt(row.get(PROJECT.UPDATED_AT, Instant.class));
projectProfile.setKey(row.get(PROJECT.KEY));
projectProfile.setSlug(row.get(PROJECT.SLUG));
projectProfile.setName(row.get(PROJECT.NAME, String.class));

ProjectRelationLaunches prl = new ProjectRelationLaunches();
ProjectRelationshipsRelationshipsLaunches prl = new ProjectRelationshipsRelationshipsLaunches();
// set launches
prl.meta(new ProjectRelationLaunchesMeta()
prl.meta(new ProjectRelationshipsRelationshipsLaunchesMeta()
.count(row.get(OrganizationFilter.LAUNCHES_QUANTITY, Integer.class))
.lastOccurredAt(row.get(OrganizationFilter.LAST_RUN, Instant.class)));

// set users
ProjectRelationUsersMeta usersMeta = new ProjectRelationUsersMeta()
ProjectRelationshipsRelationshipsUsersMeta usersMeta = new ProjectRelationshipsRelationshipsUsersMeta()
.count(row.get(OrganizationFilter.USERS_QUANTITY, Integer.class));
ProjectRelationUsers oru = new ProjectRelationUsers()
ProjectRelationshipsRelationshipsUsers oru = new ProjectRelationshipsRelationshipsUsers()
.meta(usersMeta);

ProjectRelation projectRelation = new ProjectRelation()
ProjectRelationshipsRelationships relationships = new ProjectRelationshipsRelationships()
.launches(prl)
.users(oru);

projectProfile.addRelationshipsItem(projectRelation);
projectProfile.setRelationships(relationships);

projectProfiles.add(projectProfile);

Expand Down
40 changes: 0 additions & 40 deletions src/main/java/com/epam/ta/reportportal/util/OffsetUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.epam.ta.reportportal.dao.organization;

import static com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_PROJECT_ID;
import static com.epam.ta.reportportal.commons.querygen.constant.OrganizationCriteriaConstant.CRITERIA_ORG_ID;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -8,6 +9,7 @@
import com.epam.reportportal.api.model.OrganizationUserProfile;
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.OrganizationUserFilter;
import java.util.List;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -47,6 +49,8 @@ void findOrganizationUsersByFilterPageable(int offset, int limit, String sortFie
false,
"1",
CRITERIA_ORG_ID);
filter.withCondition(
new FilterCondition(Condition.IN, false, "1, 2", CRITERIA_PROJECT_ID));
PageRequest pageRequest = PageRequest.of(offset, limit, Sort.by(Sort.Direction.DESC, sortField));

final Page<OrganizationUserProfile> orgUsers = organizationUsersRepositoryCustom.findByFilter(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.epam.ta.reportportal.dao.project;

import static com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_PROJECT_ID;
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -45,6 +46,7 @@ void findAllOrganizationProjects(Long orgId, String role) {
void findOrganizationProjectsAssignedToUser(Long userId, Long orgId, String role) {
Filter filter = new Filter(ProjectProfile.class, Lists.newArrayList())
.withCondition(new FilterCondition(Condition.EQUALS, false, orgId.toString(), "organization_id"))
.withCondition(new FilterCondition(Condition.IN, false, "1, 2", CRITERIA_PROJECT_ID))
.withCondition(new FilterCondition(Condition.EQUALS, false, userId.toString(), "user_id"));
Pageable pageable = PageRequest.of(0, 10, Sort.by("name"));

Expand Down
Loading