Skip to content

Commit

Permalink
Last fixes (#10)
Browse files Browse the repository at this point in the history
* fixed invite logic

* made unzip safer and fixed column name in battle.html

* fixed compile function only compile files named main.c

* removed TODOs and optimized imports

* fixed battleToEval not being used

* cleaned up a few warnings

* fixed css

* modified the zone

* modified the zone

* Fixed some processes

* added possibility to skip some static anlyisis steps

* swapped officail-repo-url with evaluation-params for consistency

* add sec,man,rel

* tryied making token work

* Evaluation params

* Added a check in assign personal score and modified web app

* messo aposto db in dd

* ITD

* Modified some checks

---------

Co-authored-by: tommi <tommi.felle@gmail.com>
Co-authored-by: manuelamarenghi <manuela.marenghi@mail.polimi.it>
  • Loading branch information
3 people authored Feb 4, 2024
1 parent 748f82b commit bae29da
Show file tree
Hide file tree
Showing 50 changed files with 409 additions and 234 deletions.
Binary file added DeliveryFolder/ITD.pdf
Binary file not shown.
33 changes: 21 additions & 12 deletions UML/DD/db-diagram.xml

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions UML/DD/sequence_diagrams/UC9_ApiCall_runtime
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ Solution Evaluation Service->Github: 3: cloneSolution(repository_url)

Github-->Solution Evaluation Service: 4: cloneSolution(repository_url)

Solution Evaluation Service->Solution Evaluation Service: 5: checkSubmission(submission)
Solution Evaluation Service->Battle Manager: 5: evaluationParams(id_team)
activate Battle Manager

Battle Manager-->Solution Evaluation Service: 6: result
deactivate Battle Manager

Solution Evaluation Service->Solution Evaluation Service: 7: checkSubmission(submission)

alt team_registered == true && date < submission_deadline && battle_started == true
Solution Evaluation Service->Battle Manager: 6: assignScore(id_team, score)
Solution Evaluation Service->Battle Manager: 8: assignScore(id_team, score)
activate Battle Manager
// Update Query
Battle Manager->Battle DB: 7: executeQuery(id_team, score)
Battle Manager->Battle DB: 9: executeQuery(id_team, score)
activate Battle DB
Battle DB-->Battle Manager: 8: success
Battle DB-->Battle Manager: 10: success
deactivate Battle DB

Battle Manager-->Solution Evaluation Service: 9: result
Battle Manager-->Solution Evaluation Service: 11: result
deactivate Battle Manager
deactivate Solution Evaluation Service

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.apigateway;

import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.web.cors.reactive.CorsUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@
@SpringBootTest
class ApiGatewayApplicationTests {

@Test
void contextLoads() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,25 @@ public ResponseEntity<Object> createBattle(@RequestBody CreateBattleRequest requ
@PostMapping("/create-battle")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<Object> createBattle(
@RequestParam("zipFile") MultipartFile zipFile, // TODO check if it works with the web app ~ variable name
@RequestParam("zipFile") MultipartFile zipFile,
@RequestParam("tournamentId") Long tournamentId,
@RequestParam("authorId") Long authorId,
@RequestParam("minStudents") Integer minStudents,
@RequestParam("maxStudents") Integer maxStudents,
@RequestParam("regDeadline") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime regDeadline,
@RequestParam("subDeadline") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime subDeadline,
@RequestParam("battleToEval") Boolean battleToEval,
@RequestParam("name") String name) {
@RequestParam("name") String name,
@RequestParam("security") Boolean security,
@RequestParam("reliability") Boolean reliability,
@RequestParam("maintainability") Boolean maintainability) {
try {
// convert the zip file into a List<WorkingPair<String, String>>
if (zipFile == null || zipFile.isEmpty() || zipFile.getOriginalFilename() == null){
log.error("Zip file is null");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Zip file is null");
}
String fileName = zipFile.getOriginalFilename().replace(" ", "-");
String fileName = zipFile.getOriginalFilename().replaceAll("[^a-zA-Z]", "-");
String home = System.getProperty("user.home");
String filePath = home + fileName; // zip file will be put in the home directory

Expand Down Expand Up @@ -106,6 +109,10 @@ public ResponseEntity<Object> createBattle(
.maxStudents(maxStudents)
.regDeadline(regDeadline)
.subDeadline(subDeadline)
.battleToEval(battleToEval)
.security(security)
.reliability(reliability)
.maintainability(maintainability)
.build();
return createBattle(battle);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ckb.BattleManager.controller;

import ckb.BattleManager.dto.input.OfficialRepoRequest;
import ckb.BattleManager.dto.output.EvaluationParamsResponse;
import ckb.BattleManager.service.BattleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -11,25 +12,25 @@

@RestController
@Slf4j
public class GetOfficialRepoUrlController {
public class EvaluationParamsController {
private final BattleService battleService;

@Autowired
public GetOfficialRepoUrlController(BattleService battleService) {
public EvaluationParamsController(BattleService battleService) {
this.battleService = battleService;
}

@PostMapping("/api/battle/official-repo-url")
public ResponseEntity<String> getOfficialRepoUrl(@RequestBody OfficialRepoRequest officialRepoRequest) {
@PostMapping("/api/battle/evaluation-params")
public ResponseEntity<Object> evaluationParams(@RequestBody OfficialRepoRequest officialRepoRequest) {
log.info("[API REQUEST] Official repo request with team id: {}", officialRepoRequest.getTeamId());

try {
String officialRepo = battleService.getOfficialRepo(officialRepoRequest.getTeamId());
log.info("Official repo of the team id {} is {}", officialRepoRequest.getTeamId(), officialRepo);
return ResponseEntity.ok(officialRepo);
EvaluationParamsResponse paramsResponse = battleService.getBattleParams(officialRepoRequest.getTeamId());
log.info("Battle params: {}", paramsResponse.toString());
return ResponseEntity.ok(paramsResponse);
} catch (Exception e) {
log.error("[EXCEPTION] {}", e.getMessage());
return ResponseEntity.badRequest().body(e.getMessage());
return ResponseEntity.badRequest().build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public ResponseEntity<Object> inviteStudentToTeam(@RequestBody InviteStudentTeam
.post()
.uri(mailServiceUri + "/api/mail/direct")
.bodyValue(
// TODO: try the link
new DirectMailRequest(List.of(request.getIdStudent().toString()),
"You have been invited to join the team: " + request.getIdTeam()
+ ". Please join the team by clicking on the link below:\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class SendTeamsPointsController extends Controller {
private final WebClient webClient = WebClient.create();

public void sendIdUsersPointsFinishedBattle(Battle battle, List<WorkingPair<Long, Integer>> pairsIdUserPoints) {
public void sendIdUsersPointsFinishedBattle(Battle battle, List<WorkingPair<Long, Integer>> pairsIdUserPoints) throws Exception {
ResponseEntity<String> response = webClient.post()
.uri(tournamentManagerUri + "/api/tournament/update-score")
.bodyValue(
Expand All @@ -30,12 +30,12 @@ public void sendIdUsersPointsFinishedBattle(Battle battle, List<WorkingPair<Long

if (response == null) {
log.error("Error sending idUsers and points of the finished battle with id: {}. The response is null", battle.getBattleId());
return;
throw new Exception("Error sending idUsers and points of the finished battle with id: " + battle.getBattleId());
}

if (!response.getStatusCode().is2xxSuccessful()) {
log.error("Error sending idUsers and points of the finished battle with id: {}. Error {}", battle.getBattleId(), response.getStatusCode());
return;
throw new Exception("Error sending idUsers and points of the finished battle with id: " + battle.getBattleId());
}

log.info("Successfully sent IdUsers and points of the finished battle with id: {}", battle.getBattleId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ public class CreateBattleRequest {
]
}
*/
private Boolean security;
private Boolean reliability;
private Boolean maintainability;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ckb.BattleManager.model.WorkingPair;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.lang3.tuple.Pair;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ckb.BattleManager.model.WorkingPair;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.lang3.tuple.Pair;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ckb.BattleManager.dto.output;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class EvaluationParamsResponse {
private String repoLink;
private Boolean security;
private Boolean reliability;
private Boolean maintainability;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.tuple.Pair;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ public class Battle {
private Boolean hasEnded;

private Boolean isClosed;

private Boolean security;

private Boolean reliability;

private Boolean maintainability;
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void closeBattles() {
battleRepository.save(battle);
log.info("The battle {} has ended", battle.getName());

if (!battle.getBattleToEval()) {
if (battle.getBattleToEval().equals(false)) {
battle.setIsClosed(true);
log.info("The battle {} has been closed", battle.getName());
battleRepository.save(battle);
Expand All @@ -103,17 +103,22 @@ public void closeBattles() {
);
} catch (Exception e) {
log.error("Error sending emails to the participant of the battle {}. Error {}", battle.getName(), e.getMessage());
return;
}
}

// Get the teams and the points of each battle
// send the class containing tournament_id, List<Pair<idTeam, points>>
// just kidding, we are better, so we use a Working Pair, a pair that actually fucking works
// to the Tournament manager
sendTeamsPointsController.sendIdUsersPointsFinishedBattle(
battle,
teamService.getListPairIdUserPoints(battle)
);
// Get the teams and the points of each battle
// send the class containing tournament_id, List<Pair<idTeam, points>>
// to the Tournament manager
try {
sendTeamsPointsController.sendIdUsersPointsFinishedBattle(
battle,
teamService.getListPairIdUserPoints(battle)
);
} catch (Exception e) {
log.error("Error sending points of the battle {} to the tournament manager. Error {}", battle.getName(), e.getMessage());
return;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ckb.BattleManager.service;

import ckb.BattleManager.controller.CreateGHRepositoryBattleController;
import ckb.BattleManager.controller.SendTeamsPointsController;
import ckb.BattleManager.dto.input.CreateBattleRequest;
import ckb.BattleManager.dto.output.EvaluationParamsResponse;
import ckb.BattleManager.model.Battle;
import ckb.BattleManager.model.Participation;
import ckb.BattleManager.model.Team;
Expand All @@ -21,14 +23,17 @@ public class BattleService {
private final BattleRepository battleRepository;
private final TeamService teamService;
private final CreateGHRepositoryBattleController createGHRepositoryBattleController;
private final SendTeamsPointsController sendTeamsPointsController;

@Autowired

public BattleService(BattleRepository battleRepository, TeamService teamService,
CreateGHRepositoryBattleController createGHRepositoryBattleController) {
CreateGHRepositoryBattleController createGHRepositoryBattleController,
SendTeamsPointsController sendTeamsPointsController) {
this.battleRepository = battleRepository;
this.teamService = teamService;
this.createGHRepositoryBattleController = createGHRepositoryBattleController;
this.sendTeamsPointsController = sendTeamsPointsController;
}

public Battle getBattle(Long id) throws Exception {
Expand All @@ -51,6 +56,9 @@ public Battle createBattle(CreateBattleRequest battleRequest) throws Exception {
.hasStarted(false)
.hasEnded(false)
.isClosed(false)
.security(battleRequest.getSecurity())
.reliability(battleRequest.getReliability())
.maintainability(battleRequest.getMaintainability())
.build();
log.info("Battle built: {}", battle);

Expand Down Expand Up @@ -129,13 +137,16 @@ public List<WorkingPair<Long, Integer>> getAllTeamsOfBattle(Long idBattle) throw
.toList();
}

public String getOfficialRepo(Long teamId) throws Exception {
public EvaluationParamsResponse getBattleParams(Long teamId) throws Exception {
Team team = teamService.getTeam(teamId);
if (!team.getBattle().getHasStarted()) {
log.error("The battle {} has not started yet", team.getBattle().getName());
throw new RuntimeException("The battle " + team.getBattle().getName() + " has not started");
}
return team.getBattle().getRepositoryLink();

Battle battle = team.getBattle();
return EvaluationParamsResponse.builder()
.repoLink(battle.getRepositoryLink())
.security(battle.getSecurity())
.reliability(battle.getReliability())
.maintainability(battle.getMaintainability())
.build();
}

public Team getListParticipation(Long battleId, Long studentId) throws Exception {
Expand Down
Loading

0 comments on commit bae29da

Please sign in to comment.