Просмотр исходного кода

Use shorter names in ReportViewer DTOs

Nesta Bentum 4 лет назад
Родитель
Сommit
eaa1d27a87

+ 4 - 2
jplag/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java

@@ -31,6 +31,8 @@ public class ReportObjectFactory {
     private static final MetricMapper metricMapper = new MetricMapper();
     private static final ComparisonReportMapper comparisonReportMapper = new ComparisonReportMapper();
     private static final FileWriter fileWriter = new FileWriter();
+    public static final String OVERVIEW_FILE_NAME = "overview.json";
+    public static final String SUBMISSIONS_FOLDER = "submissions";
 
     /**
      * @param result The JPlagResult to be converted into a report.
@@ -82,14 +84,14 @@ public class ReportObjectFactory {
         overviewReport.setMetrics(getMetrics(result));
         overviewReport.setClusters(clusteringResultMapper.map(result));
 
-        fileWriter.saveAsJSON(overviewReport, path, "overview.json");
+        fileWriter.saveAsJSON(overviewReport, path, OVERVIEW_FILE_NAME);
 
     }
 
     private static void copySubmissionFilesToReport(String path, JPlagResult result) {
         List<JPlagComparison> comparisons = result.getComparisons(result.getOptions().getMaximumNumberOfComparisons());
         var submissions = getSubmissions(comparisons);
-        var submissionsPath = createDirectory(path, "Submissions");
+        var submissionsPath = createDirectory(path, SUBMISSIONS_FOLDER);
         for (var submission : submissions) {
             File directory = createDirectory(submissionsPath.getPath(), submission.getName());
             for (var file : submission.getFiles()) {

+ 2 - 2
jplag/src/main/java/de/jplag/reporting/reportobject/model/ComparisonReport.java

@@ -11,8 +11,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
  * @param matchPercentage similarity in percent. between 0f and 100f.
  * @param matches the list of matches found in the comparison of the two submissions
  */
-public record ComparisonReport(@JsonProperty("first_submission_id") String firstSubmissionId,
-        @JsonProperty("second_submission_id") String secondSubmissionId, @JsonProperty("match_percentage") float matchPercentage,
+public record ComparisonReport(@JsonProperty("id1") String firstSubmissionId,
+        @JsonProperty("id2") String secondSubmissionId, @JsonProperty("similarity") float matchPercentage,
         @JsonProperty("matches") List<Match> matches) {
 
 }

+ 3 - 3
jplag/src/main/java/de/jplag/reporting/reportobject/model/Match.java

@@ -2,7 +2,7 @@ package de.jplag.reporting.reportobject.model;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
 
-public record Match(@JsonProperty("first_file_name") String firstFileName, @JsonProperty("second_file_name") String secondFileName,
-        @JsonProperty("start_in_first") int startInFirst, @JsonProperty("end_in_first") int endInFirst,
-        @JsonProperty("start_in_second") int startInSecond, @JsonProperty("end_in_second") int endInSecond, @JsonProperty("tokens") int tokens) {
+public record Match(@JsonProperty("file1") String firstFileName, @JsonProperty("file2") String secondFileName,
+        @JsonProperty("start1") int startInFirst, @JsonProperty("end1") int endInFirst,
+        @JsonProperty("start2") int startInSecond, @JsonProperty("end2") int endInSecond, @JsonProperty("tokens") int tokens) {
 }

+ 11 - 11
report-viewer/src/model/factories/ComparisonFactory.ts

@@ -7,10 +7,10 @@ import store from "@/store/store";
 export class ComparisonFactory {
   static getComparison(json: Record<string, unknown>): Comparison {
     const filesOfFirstSubmission = store.getters.filesOfSubmission(
-      json.first_submission_id
+      json.id1
     );
     const filesOfSecondSubmission = store.getters.filesOfSubmission(
-      json.second_submission_id
+      json.id2
     );
 
     const filesOfFirstConverted = this.convertToFilesByName(
@@ -30,9 +30,9 @@ export class ComparisonFactory {
     const matchesInSecond = this.groupMatchesByFileName(coloredMatches, 2);
 
     const comparison = new Comparison(
-      json.first_submission_id as string,
-      json.second_submission_id as string,
-      json.match_percentage as number
+      json.id1 as string,
+      json.id2 as string,
+      json.similarity as number
     );
     comparison.filesOfFirstSubmission = filesOfFirstConverted;
     comparison.filesOfSecondSubmission = filesOfSecondConverted;
@@ -116,12 +116,12 @@ export class ComparisonFactory {
     color: string
   ): Match {
     return {
-      firstFile: match.first_file_name as string,
-      secondFile: match.second_file_name as string,
-      startInFirst: match.start_in_first as number,
-      endInFirst: match.end_in_first as number,
-      startInSecond: match.start_in_second as number,
-      endInSecond: match.end_in_second as number,
+      firstFile: match.file1 as string,
+      secondFile: match.file2 as string,
+      startInFirst: match.start1 as number,
+      endInFirst: match.end1 as number,
+      startInSecond: match.start2 as number,
+      endInSecond: match.end2 as number,
       tokens: match.tokens as number,
       color: color,
     };

+ 4 - 4
report-viewer/src/views/FileUploadView.vue

@@ -60,7 +60,7 @@ export default defineComponent({
     const handleZipFile = (file: File) => {
       jszip.loadAsync(file).then(async (zip) => {
         for (const fileName of Object.keys(zip.files)) {
-          if (fileName.match(/Submissions\/(.+)\/(.+)/)) {
+          if (fileName.match(/submissions\/(.+)\/(.+)/)) {
             const filePath = path.parse(fileName);
             const submissionName = filePath.dir.split("/")[2];
             await zip.files[fileName].async("string").then((data) => {
@@ -98,7 +98,7 @@ export default defineComponent({
           fileString: str,
         });
         navigateToOverview();
-      } else if (json["first_submission_id"] && json["second_submission_id"]) {
+      } else if (json["id1"] && json["id2"]) {
         store.commit("setLoadingType", {
           local: false,
           zip: false,
@@ -106,8 +106,8 @@ export default defineComponent({
           fileString: str,
         });
         navigateToComparisonView(
-          json["first_submission_id"],
-          json["second_submission_id"]
+          json["id1"],
+          json["id2"]
         );
       }
     };