Skip to content

Commit

Permalink
Epmrpp-92350 extended organization filtering (#1018)
Browse files Browse the repository at this point in the history
* EPMRPP-92350 extend organization users filtering
  • Loading branch information
grabsefx authored Jul 16, 2024
1 parent eed07e1 commit c47066c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 53 deletions.
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

0 comments on commit c47066c

Please sign in to comment.