Skip to content

Commit

Permalink
feat: Update project and analyzer run data models (#1316)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt committed Dec 8, 2023
1 parent 7a3bff5 commit c4c4562
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 59 deletions.
33 changes: 14 additions & 19 deletions frontend/src/ProjectData.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {gql} from '@apollo/client';
import {BadSmell} from './data/BadSmell';
import {Project} from './data/Project';
import { gql } from '@apollo/client';
import { BadSmell } from './data/BadSmell';
import { Project } from './data/Project';

export const fetchProjectQuery = gql`
query getProjects {
Expand All @@ -21,22 +21,17 @@ export const fetchProjectQuery = gql`
}
}
`;
export const fetchRecentProjectQuery = gql`
query getRecentProjects {
getRecentProjects(size: 30) {
projectName
projectUrl
commitHashes
commits {
analyzerStatuses {
analyzerName
commitHash
localDateTime
numberOfIssues
status
}
export const recentAnalyzerRuns = gql`
query recentAnalyzerRuns {
recentAnalyzerRuns(size: 30) {
analyzerName
commitHash
}
"ISO-8601"
localDateTime
numberOfIssues
projectName
projectUrl
status
}
}
`;
Expand Down Expand Up @@ -95,7 +90,7 @@ export function filterDuplicateBadSmells(params: BadSmell[]) {
});
const ids = params.map((o) => o.snippet);
return params.filter(
({snippet}, index) => !ids.includes(snippet, index + 1)
({ snippet }, index) => !ids.includes(snippet, index + 1)
);
}

Expand Down
9 changes: 5 additions & 4 deletions frontend/src/component/ProjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import { Project } from '../data/Project';
import React, { useMemo } from 'react';
import ProjectTable from './ProjectTable';
import { LinearProgress } from '@mui/material';
import { fetchRecentProjectQuery } from '../ProjectData';
import { recentAnalyzerRuns } from '../ProjectData';
import { AnalyzerRun } from '../data/AnalyzerRun';

export function ProjectList({ filter }: { filter: string }) {
const { data, loading, error } = useQuery(fetchRecentProjectQuery);
const { data, loading, error } = useQuery(recentAnalyzerRuns);

const filteredProjects = useMemo(() => {
if (!data) {
return [];
}
return data.getRecentProjects.filter((project: Project) => {
return project.projectName.toLowerCase().match(filter.toLowerCase());
return data.recentAnalyzerRuns.filter((analyzerRun: AnalyzerRun) => {
return analyzerRun.projectName.toLowerCase().match(filter.toLowerCase());
});
}, [data, filter]);
if (error) {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/component/ProjectTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function ProjectTable(props: ProjectTableProps) {
}
return 0;
}
if (sortConfig.key === 'resultCount') {
if (sortConfig.key === 'numberOfIssues') {
if (aStatus && bStatus) {
return aStatus.numberOfIssues > bStatus.numberOfIssues ? 1 : -1;
}
Expand All @@ -66,7 +66,7 @@ function ProjectTable(props: ProjectTableProps) {
}
return 0;
}
if (sortConfig.key === 'resultCount') {
if (sortConfig.key === 'numberOfIssues') {
if (aStatus && bStatus) {
return aStatus.numberOfIssues < bStatus.numberOfIssues ? 1 : -1;
}
Expand Down Expand Up @@ -105,7 +105,7 @@ function ProjectTable(props: ProjectTableProps) {
label="Number of Results"
sortConfig={sortConfig}
requestSort={requestSort}
sortKey="resultCount"
sortKey="numberOfIssues"
/>
</TableRow>
</TableHead>
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/data/AnalyzerRun.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { LocalDateTime } from '@js-joda/core';

export type AnalyzerRun = {
analyzerName: String;
commitHash: String;
localDateTime: LocalDateTime;
numberOfIssues: number;
projectName: String;
projectUrl: String;
status: String;
};
3 changes: 3 additions & 0 deletions github-bot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ dependencies {

quarkusDependenciesBuild {
dependsOn("jandex")
}
compileJava {
dependsOn("compileQuarkusGeneratedSourcesJava")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package io.github.martinwitt.laughing_train.api.graphql.dto;

import io.github.martinwitt.laughing_train.persistence.dao.AnalyzerRunDao;
import java.time.LocalDateTime;
import org.eclipse.microprofile.graphql.Name;

@Name("AnalyzerRun")
public class AnalyzerRunGraphQlDto {

private String projectName;

Check warning on line 10 in github-bot/src/main/java/io/github/martinwitt/laughing_train/api/graphql/dto/AnalyzerRunGraphQlDto.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `projectName` may be 'final'
private String projectUrl;

Check warning on line 11 in github-bot/src/main/java/io/github/martinwitt/laughing_train/api/graphql/dto/AnalyzerRunGraphQlDto.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `projectUrl` may be 'final'
private String analyzerName;

Check warning on line 12 in github-bot/src/main/java/io/github/martinwitt/laughing_train/api/graphql/dto/AnalyzerRunGraphQlDto.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `analyzerName` may be 'final'
private String status;

Check warning on line 13 in github-bot/src/main/java/io/github/martinwitt/laughing_train/api/graphql/dto/AnalyzerRunGraphQlDto.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `status` may be 'final'
private int numberOfIssues;

Check warning on line 14 in github-bot/src/main/java/io/github/martinwitt/laughing_train/api/graphql/dto/AnalyzerRunGraphQlDto.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `numberOfIssues` may be 'final'
private String commitHash;

Check warning on line 15 in github-bot/src/main/java/io/github/martinwitt/laughing_train/api/graphql/dto/AnalyzerRunGraphQlDto.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `commitHash` may be 'final'
private LocalDateTime localDateTime;

Check warning on line 16 in github-bot/src/main/java/io/github/martinwitt/laughing_train/api/graphql/dto/AnalyzerRunGraphQlDto.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `localDateTime` may be 'final'

public AnalyzerRunGraphQlDto(AnalyzerRunDao dao) {
this.projectName = dao.projectDao.getProjectName();
this.projectUrl = dao.projectDao.getProjectUrl();
this.analyzerName = dao.analyzerName;
this.status = dao.status;
this.numberOfIssues = dao.numberOfIssues;
this.commitHash = dao.commitHash;
this.localDateTime = dao.localDateTime;
}

/**
* @return the analyzerName
*/
public String getAnalyzerName() {
return analyzerName;
}

/**
* @return the commitHash
*/
public String getCommitHash() {
return commitHash;
}

/**
* @return the localDateTime
*/
public LocalDateTime getLocalDateTime() {
return localDateTime;
}

/**
* @return the numberOfIssues
*/
public int getNumberOfIssues() {
return numberOfIssues;
}

/**
* @return the projectName
*/
public String getProjectName() {
return projectName;
}

/**
* @return the projectUrl
*/
public String getProjectUrl() {
return projectUrl;
}

/**
* @return the status
*/
public String getStatus() {
return status;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.github.martinwitt.laughing_train.api.graphql.endpoints;

import com.google.common.flogger.FluentLogger;
import io.github.martinwitt.laughing_train.api.graphql.dto.AnalyzerRunGraphQlDto;
import io.github.martinwitt.laughing_train.api.graphql.dto.ProjectConfigGraphQLDtoInput;
import io.github.martinwitt.laughing_train.api.graphql.dto.ProjectGraphQLDto;
import io.github.martinwitt.laughing_train.domain.entity.GitHubCommit;
import io.github.martinwitt.laughing_train.domain.entity.ProjectConfig;
import io.github.martinwitt.laughing_train.domain.entity.RemoteProject;
import io.github.martinwitt.laughing_train.mining.QodanaPeriodicMiner;
import io.github.martinwitt.laughing_train.persistence.impl.SqlAnalyzerRunRepository;
import io.github.martinwitt.laughing_train.persistence.repository.ProjectRepository;
import io.quarkus.security.Authenticated;
import jakarta.inject.Inject;
Expand All @@ -26,16 +28,20 @@ public class ProjectGraphQL {

@Inject QodanaPeriodicMiner periodicMiner;

@Inject SqlAnalyzerRunRepository sqlAnalyzerRunRepository;

@Query("getProjects")
@Description("Gets all projects from the database")
public List<ProjectGraphQLDto> getAllProjects() {
return projectRepository.getAll().stream().map(this::mapToDto).toList();
}

@Query("getRecentProjects")
@Description("Gets all projects from the database with a limit")
public List<ProjectGraphQLDto> getRecentProjects(int size) {
return projectRepository.getRecent(size).stream().map(this::mapToDto).toList();
@Query("recentAnalyzerRuns")
@Description("Returns a sorted by date list of recent analyzer runs")
public List<AnalyzerRunGraphQlDto> recentAnalyzerRuns(int size) {
return sqlAnalyzerRunRepository.findRecent(size).stream()
.map(AnalyzerRunGraphQlDto::new)
.toList();
}

@Query("getProjectWithName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import java.time.LocalDateTime;

@Entity
Expand All @@ -12,27 +13,9 @@ public class AnalyzerRunDao extends PanacheEntity {
public int numberOfIssues;
public String commitHash;
public LocalDateTime localDateTime;
@ManyToOne public ProjectDao projectDao;

public AnalyzerRunDao() {
// for JPA
}

private AnalyzerRunDao(
String analyzerName,
String status,
int numberOfIssues,
String commitHash,
LocalDateTime localDateTime) {
this.analyzerName = analyzerName;
this.status = status;
this.numberOfIssues = numberOfIssues;
this.commitHash = commitHash;
this.localDateTime = localDateTime;
}

@Override
public String toString() {
return "AnalyzerRunDao{analyzerName='%s', status='%s', numberOfIssues=%d, commitHash='%s', localDateTime=%s}"
.formatted(analyzerName, status, numberOfIssues, commitHash, localDateTime);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.martinwitt.laughing_train.persistence.dao;

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.OneToMany;
import java.time.LocalDateTime;
Expand All @@ -15,7 +16,8 @@ public class ProjectDao extends PanacheEntity {
private String projectUrl;
private LocalDateTime latestRun;

@OneToMany private List<AnalyzerRunDao> commits = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL)
private List<AnalyzerRunDao> commits = new ArrayList<>();

public ProjectDao() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

import io.github.martinwitt.laughing_train.persistence.dao.AnalyzerRunDao;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
import io.quarkus.panache.common.Sort;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.transaction.Transactional;
import java.util.List;

@ApplicationScoped
@Transactional
public class SqlAnalyzerRunRepository implements PanacheRepository<AnalyzerRunDao> {}
public class SqlAnalyzerRunRepository implements PanacheRepository<AnalyzerRunDao> {

public List<AnalyzerRunDao> findRecent(int limit) {
return findAll(Sort.ascending("localDateTime")).page(0, limit).list();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
public class SqlProjectRepository implements ProjectRepository, PanacheRepository<ProjectDao> {

private static final ProjectDaoConverter projectDaoConverter = new ProjectDaoConverter();
private SqlAnalyzerRunRepository sqlAnalyzerRunRepository;

public SqlProjectRepository(SqlAnalyzerRunRepository sqlAnalyzerRunRepository) {
this.sqlAnalyzerRunRepository = sqlAnalyzerRunRepository;
}
public SqlProjectRepository() {}

@Override
public List<RemoteProject> getAll() {
Expand Down Expand Up @@ -76,16 +73,15 @@ public RemoteProject save(RemoteProject project) {
ProjectDao projectDao = projectDaoConverter.convertToDao(project);
if (find("projectUrl", projectDao.getProjectUrl()).stream().findFirst().isEmpty()) {
ProjectDao dao = projectDaoConverter.convertToDao(project);
sqlAnalyzerRunRepository.persist(dao.getCommits());
// sqlAnalyzerRunRepository.persist(dao.getCommits());
persist(dao);
} else {
var dao = projectDaoConverter.convertToDao(project);
ProjectDao databaseEntry = find("projectUrl", dao.getProjectUrl()).stream().findFirst().get();

Check warning on line 80 in github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/impl/SqlProjectRepository.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Optional.get() is called without isPresent() check

`Optional.get()` without 'isPresent()' check
databaseEntry.setProjectName(dao.getProjectName());
databaseEntry.setProjectUrl(dao.getProjectUrl());
databaseEntry.setCommits(dao.getCommits());
databaseEntry.setCommits(dao.getCommits());
sqlAnalyzerRunRepository.persist(databaseEntry.getCommits());
// sqlAnalyzerRunRepository.persist(databaseEntry.getCommits());
persist(databaseEntry);
}
return project;
Expand Down
2 changes: 1 addition & 1 deletion github-bot/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ quarkus.http.cors.origins=*
quarkus.vertx.max-worker-execute-time=30m
%test.quarkus.scheduler.enabled=false
quarkus.datasource.db-kind = mariadb
quarkus.hibernate-orm.database.generation = update
quarkus.hibernate-orm.database.generation = drop-and-create
%dev.quarkus.quinoa=false
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import java.util.List;
import java.util.stream.Collectors;
import org.instancio.Instancio;
import org.junit.jupiter.api.Test;

Expand All @@ -15,6 +16,8 @@ class SqlProjectRepositoryTest {

@Inject SqlProjectRepository sqlProjectRepository;

@Inject SqlAnalyzerRunRepository sqlAnalyzerRunRepository;

@Test
void insertProject() {
RemoteProject remoteProject = Instancio.create(RemoteProject.class);
Expand All @@ -23,6 +26,11 @@ void insertProject() {
List<RemoteProject> byProjectName =
sqlProjectRepository.findByProjectName(remoteProject.getProjectName());
assertThat(byProjectName).isNotEmpty();
Integer expectedSize =
remoteProject.getCommits().stream()
.map(v -> v.getAnalyzerStatuses())
.collect(Collectors.summingInt(v -> v.size()));
assertThat(sqlAnalyzerRunRepository.findRecent(expectedSize)).hasSize(expectedSize);
}

@Test
Expand Down

0 comments on commit c4c4562

Please sign in to comment.