Skip to content

Commit

Permalink
fix: processBattleEntry returns void, store BattleEntryProcessResult …
Browse files Browse the repository at this point in the history
…in BattleEntry as JSONB
  • Loading branch information
giovanni-orciuolo committed Feb 4, 2024
1 parent b8eba38 commit 783ac5b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import com.fasterxml.jackson.annotation.JsonBackReference;
import io.hypersistence.utils.hibernate.type.json.JsonType;
import it.polimi.codekatabattle.models.BattleTestResult;
import it.polimi.codekatabattle.models.BattleEntryProcessResult;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Type;

import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "battle_entries")
@Getter
Expand All @@ -32,7 +29,7 @@ public class BattleEntry extends BaseEntity {

@Column(columnDefinition = "jsonb")
@Type(JsonType.class)
private List<BattleTestResult> testResults = new ArrayList<>();
private BattleEntryProcessResult processResult;

@Column
private Integer score = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package it.polimi.codekatabattle.services;

import it.polimi.codekatabattle.entities.BattleEntry;
import it.polimi.codekatabattle.models.BattleEntryProcessResult;
import it.polimi.codekatabattle.models.BattleTestResult;
import it.polimi.codekatabattle.models.SATResult;

import java.net.URL;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

public interface ScoreService {

CompletableFuture<BattleEntryProcessResult> processBattleEntry(BattleEntry battleEntry, URL artifactUrl);
void processBattleEntry(BattleEntry battleEntry, URL artifactUrl);

List<BattleTestResult> executeBattleTests(BattleEntry battleEntry, URL artifactUrl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.net.URL;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand All @@ -37,18 +36,18 @@ public ScoreServiceImpl(BattleEntryRepository battleEntryRepository) {

@Override
@Async
public CompletableFuture<BattleEntryProcessResult> processBattleEntry(BattleEntry battleEntry, URL artifactUrl) {
public void processBattleEntry(BattleEntry battleEntry, URL artifactUrl) {
List<BattleTestResult> testResults = this.executeBattleTests(battleEntry, artifactUrl);
Optional<SATResult> satResult = this.executeSAT(battleEntry, artifactUrl);

BattleEntryProcessResult results = new BattleEntryProcessResult();
results.setTestResults(testResults);
results.setSatResult(satResult.orElse(null));
BattleEntryProcessResult processResult = new BattleEntryProcessResult();
processResult.setTestResults(testResults);
processResult.setSatResult(satResult.orElse(null));

battleEntry.setProcessResult(processResult);
battleEntry.setStatus(BattleEntryStatus.COMPLETED);
this.battleEntryRepository.save(battleEntry);

return CompletableFuture.completedFuture(results);
this.battleEntryRepository.save(battleEntry);
}

@Override
Expand Down

0 comments on commit 783ac5b

Please sign in to comment.