Skip to content

Commit

Permalink
EPMRPP-90460 projects controller (#1012)
Browse files Browse the repository at this point in the history
* EPMRPP-90460 implement Organization Project DAO
  • Loading branch information
grabsefx authored Jun 7, 2024
1 parent a9cef30 commit d0b04dd
Show file tree
Hide file tree
Showing 13 changed files with 419 additions and 28 deletions.
1 change: 1 addition & 0 deletions project-properties.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ project.ext {
(migrationsUrl + '/migrations/89_add_group_enum_value.up.sql') : 'V089__add_group_enum_value.sql',
(migrationsUrl + '/migrations/200_migrate_org_roles.up.sql') : 'V200__migrate_org_roles.sql',
(migrationsUrl + '/migrations/201_drop_table_onboarding.up.sql') : 'V201__drop_table_onboarding.sql',
(migrationsUrl + '/migrations/202_update_project_table.up.sql') : 'V202__update_project_table.up.sql',

]
excludeTests = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
import com.epam.ta.reportportal.jooq.enums.JLaunchModeEnum;
import com.epam.ta.reportportal.jooq.enums.JStatusEnum;
import com.epam.ta.reportportal.jooq.enums.JTestItemTypeEnum;
import com.epam.ta.reportportal.model.OrganizationInfo;
import com.epam.ta.reportportal.model.ProjectProfile;
import com.google.common.collect.Lists;
import java.sql.Timestamp;
import java.util.ArrayList;
Expand Down Expand Up @@ -1555,17 +1555,75 @@ protected Field<Long> idField() {
return ORGANIZATION.ID.cast(Long.class);
}

/* @Override
},

PROJECT_PROFILE(ProjectProfile.class,
Arrays.asList(
new CriteriaHolderBuilder().newBuilder(CRITERIA_ORG_ID, PROJECT.ORGANIZATION_ID, Long.class)
.get(),
new CriteriaHolderBuilder().newBuilder(PROJECT_USER.USER_ID.getName(), PROJECT_USER.USER_ID, Long.class)
.get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_NAME, PROJECT.NAME, String.class).get(),
new CriteriaHolderBuilder().newBuilder(CRITERIA_NAME, PROJECT.SLUG, String.class).get()
)
) {
@Override
public QuerySupplier getQuery() {
SelectQuery<? extends Record> query = DSL.select(selectFields()).getQuery();
addFrom(query);
query.addGroupBy(PROJECT.ID, PROJECT.CREATION_DATE, PROJECT.KEY, PROJECT.PROJECT_TYPE);
QuerySupplier querySupplier = new QuerySupplier(query);
joinTables(querySupplier);
return querySupplier;
}

@Override
protected Collection<? extends SelectField> selectFields() {
return Lists.newArrayList(DSL.countDistinct(PROJECT_USER.USER_ID).as(USERS_QUANTITY),
DSL.countDistinct(choose().when(LAUNCH.MODE.eq(JLaunchModeEnum.DEFAULT)
.and(LAUNCH.STATUS.ne(JStatusEnum.IN_PROGRESS)),
LAUNCH.ID
)).as(LAUNCHES_QUANTITY),
DSL.max(LAUNCH.START_TIME).as(LAST_RUN),
PROJECT.ID,
PROJECT.CREATION_DATE,
PROJECT.UPDATED_AT,
PROJECT.KEY,
PROJECT.SLUG,
PROJECT.NAME,
PROJECT.PROJECT_TYPE,
PROJECT.ORGANIZATION_ID
);
}

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

@Override
protected void joinTables(QuerySupplier query) {
query.addJoin(PROJECT_USER, JoinType.LEFT_OUTER_JOIN, PROJECT.ID.eq(PROJECT_USER.PROJECT_ID));
query.addJoin(LAUNCH, JoinType.LEFT_OUTER_JOIN, PROJECT.ID.eq(LAUNCH.PROJECT_ID));
}

@Override
public QuerySupplier wrapQuery(SelectQuery<? extends Record> query) {
throw new UnsupportedOperationException("Doesn't supported for Organization Info query");
throw new UnsupportedOperationException("Operation not supported for ProjectProfile query");
}

@Override
public QuerySupplier wrapQuery(SelectQuery<? extends Record> query, String... excluding) {
throw new UnsupportedOperationException("Doesn't supported for Organization Info query");
}*/
throw new UnsupportedOperationException("Operation not supported for ProjectProfile query");
}

@Override
protected Field<Long> idField() {
return PROJECT.ID;
}
};


public static final String FILTERED_QUERY = "filtered";
public static final String ATTRIBUTE_ALIAS = "attribute";
public static final String FILTERED_ID = "id";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,26 @@
package com.epam.ta.reportportal.dao.organization;

import com.epam.ta.reportportal.dao.ReportPortalRepository;
import com.epam.ta.reportportal.entity.user.OrganizationUserId;
import com.epam.ta.reportportal.entity.user.OrganizationUser;
import com.epam.ta.reportportal.entity.user.OrganizationUserId;
import java.util.Optional;

/**
* This interface represents a repository for the OrganizationUser entity.
*
* @author Siarhei Hrabko
*/
public interface OrganizationUserRepository extends
ReportPortalRepository<OrganizationUser, OrganizationUserId> {

/**
* This method is used to find a list of OrganizationUser entities by user ID and organization ID.
* It returns a list of OrganizationUser entities that match the given user ID and organization
* ID.
*
* @param userId The ID of the user.
* @param orgId The ID of the organization.
* @return A list of OrganizationUser entities that match the given user ID and organization ID.
*/
Optional<OrganizationUser> findByUserIdAndOrganization_Id(Long userId, Long orgId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.epam.ta.reportportal.dao.project;

import com.epam.ta.reportportal.commons.querygen.Queryable;
import com.epam.ta.reportportal.model.ProjectProfile;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface OrganizationProjectRepository {

Page<ProjectProfile> getProjectProfileListByFilter(Queryable filter, Pageable pageable);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.epam.ta.reportportal.dao.project;

import static com.epam.ta.reportportal.dao.util.ResultFetchers.ORGANIZATION_PROJECT_LIST_FETCHER;

import com.epam.ta.reportportal.commons.querygen.FilterTarget;
import com.epam.ta.reportportal.commons.querygen.QueryBuilder;
import com.epam.ta.reportportal.commons.querygen.Queryable;
import com.epam.ta.reportportal.model.ProjectProfile;
import org.jooq.DSLContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.support.PageableExecutionUtils;
import org.springframework.stereotype.Repository;

@Repository
public class OrganizationProjectRepositoryImpl implements OrganizationProjectRepository {

private DSLContext dsl;

@Autowired
public void setDsl(DSLContext dsl) {
this.dsl = dsl;
}

@Override
public Page<ProjectProfile> getProjectProfileListByFilter(Queryable filter, Pageable pageable) {
return PageableExecutionUtils.getPage(ORGANIZATION_PROJECT_LIST_FETCHER.apply(
dsl.fetch(QueryBuilder.newBuilder(filter).with(pageable).build())),
pageable,
() -> dsl.fetchCount(QueryBuilder.newBuilder(FilterTarget.PROJECT_PROFILE).build()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
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.pattern.PatternTemplateTestItem;
import com.epam.ta.reportportal.entity.project.Project;
import com.epam.ta.reportportal.entity.project.ProjectAttribute;
Expand All @@ -69,9 +70,16 @@
import com.epam.ta.reportportal.entity.user.UserRole;
import com.epam.ta.reportportal.entity.widget.Widget;
import com.epam.ta.reportportal.model.OrganizationProfile;
import com.epam.ta.reportportal.model.ProjectProfile;
import com.epam.ta.reportportal.model.ProjectRelation;
import com.epam.ta.reportportal.model.ProjectRelationLaunches;
import com.epam.ta.reportportal.model.ProjectRelationLaunchesMeta;
import com.epam.ta.reportportal.model.ProjectRelationUsers;
import com.epam.ta.reportportal.model.ProjectRelationUsersMeta;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -427,4 +435,44 @@ private ResultFetchers() {
return null;
};

public static final Function<Result<? extends Record>, List<ProjectProfile>> ORGANIZATION_PROJECT_LIST_FETCHER = rows -> {
List<ProjectProfile> projectProfiles = new ArrayList<>(rows.size());

rows.forEach(row -> {
ProjectProfile projectProfile = new ProjectProfile();

projectProfile.setId(row.get(PROJECT.ID));
projectProfile.setName(row.get(PROJECT.NAME));
projectProfile.setOrganizationId(row.get(PROJECT.ORGANIZATION_ID));
projectProfile.setCreatedAt(row.get(PROJECT.CREATION_DATE, Instant.class));
projectProfile.setUpdatedAt(row.get(PROJECT.UPDATED_AT, Instant.class));
projectProfile.setName(row.get(PROJECT.NAME));
projectProfile.setKey(row.get(PROJECT.KEY));
projectProfile.setSlug(row.get(PROJECT.SLUG));

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

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

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

projectProfile.setRelationships(projectRelation);

projectProfiles.add(projectProfile);

});

return projectProfiles;
};

}
15 changes: 10 additions & 5 deletions src/main/java/com/epam/ta/reportportal/jooq/tables/JProject.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d0b04dd

Please sign in to comment.