Skip to content

Commit

Permalink
EPMRPP-93780 fix organization users filtering (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Aug 20, 2024
1 parent e9d5f1e commit 2e08e11
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import static com.epam.ta.reportportal.commons.querygen.constant.OrganizationCriteriaConstant.CRITERIA_ORG_TYPE;
import static com.epam.ta.reportportal.commons.querygen.constant.OrganizationCriteriaConstant.CRITERIA_ORG_UPDATED_AT;
import static com.epam.ta.reportportal.commons.querygen.constant.OrganizationCriteriaConstant.CRITERIA_ORG_USERS;
import static com.epam.ta.reportportal.commons.querygen.constant.OrganizationCriteriaConstant.CRITERIA_ORG_USER_ID;
import static com.epam.ta.reportportal.commons.querygen.constant.ProjectCriteriaConstant.CRITERIA_ALLOCATED_STORAGE;
import static com.epam.ta.reportportal.commons.querygen.constant.ProjectCriteriaConstant.CRITERIA_PROJECT_ATTRIBUTE_NAME;
import static com.epam.ta.reportportal.commons.querygen.constant.ProjectCriteriaConstant.CRITERIA_PROJECT_CREATION_DATE;
Expand Down Expand Up @@ -1431,6 +1432,9 @@ protected Field<Long> idField() {
new CriteriaHolderBuilder().newBuilder(CRITERIA_ORG_USERS, USERS_QUANTITY, Long.class)
.withAggregateCriteria(DSL.countDistinct(ORGANIZATION_USER.USER_ID).toString())
.get(),
new CriteriaHolderBuilder()
.newBuilder(CRITERIA_ORG_USER_ID, ORGANIZATION_USER.USER_ID, Long.class)
.get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_ORG_PROJECTS, PROJECTS_QUANTITY, Long.class)
.withAggregateCriteria(DSL.countDistinct(PROJECT.ID).toString()).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_ORG_LAST_LAUNCH_RUN, LAST_RUN, Timestamp.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public final class OrganizationCriteriaConstant {
public static final String CRITERIA_ORG_CREATED_AT = "created_at";
public static final String CRITERIA_ORG_UPDATED_AT = "updated_at";
public static final String CRITERIA_ORG_USERS = "users";
public static final String CRITERIA_ORG_USER_ID = "org_user_id";
public static final String CRITERIA_ORG_PROJECTS = "projects";
public static final String CRITERIA_ORG_LAUNCHES = "launches";
public static final String CRITERIA_ORG_LAST_LAUNCH_RUN = "last_launch_occurred";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import com.epam.ta.reportportal.dao.ReportPortalRepository;
import com.epam.ta.reportportal.entity.user.OrganizationUser;
import com.epam.ta.reportportal.entity.user.OrganizationUserId;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
* This interface represents a repository for the OrganizationUser entity.
Expand All @@ -39,4 +42,15 @@ public interface OrganizationUserRepository extends
* @return A list of OrganizationUser entities that match the given user ID and organization ID.
*/
Optional<OrganizationUser> findByUserIdAndOrganization_Id(Long userId, Long orgId);


/**
* This method is used to find a list of organization IDs associated with a specific user ID.
* It executes a native SQL query to retrieve the organization IDs.
*
* @param userId The ID of the user.
* @return A list of organization IDs associated with the specified user ID.
*/
@Query(value = "SELECT ou.organization_id FROM organization_user ou WHERE ou.user_id = :userId", nativeQuery = true)
List<Long> findOrganizationIdsByUserId(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void findOrganizationByFilterWithUser(String field, String condition, String val
value,
field);

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

final List<OrganizationProfile> orgs = organizationRepositoryCustom.findByFilter(filter);
assertEquals(rows, orgs.size());
Expand All @@ -105,6 +105,8 @@ void findOrganizationByFilterWithUser(String field, String condition, String val
"slug|eq|notexists|0",
"users|eq|2|1",
"users|eq|845|0",
"org_user_id|eq|1|1",
"org_user_id|eq|3|0",
"launches|gt|-1|1",
"launches|gt|999|0",
"projects|eq|2|1",
Expand Down

0 comments on commit 2e08e11

Please sign in to comment.