package uk.ac.ebi.subs.api.controllers;

import org.springframework.data.rest.webmvc.BasePathAwareController;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import uk.ac.ebi.subs.data.status.StatusDescription;
import uk.ac.ebi.subs.repository.model.Submission;
import uk.ac.ebi.subs.repository.model.SubmissionStatus;
import uk.ac.ebi.subs.repository.repos.SubmissionRepository;
import uk.ac.ebi.subs.repository.repos.status.SubmissionStatusRepository;

import java.util.Map;
import java.util.Set;

/**
 * Created by karoly on 13/07/2017.
 */
@RestController
@BasePathAwareController
@RequestMapping("/submissions/{submissionId}")
public class SubmissionStatusController {

    private Map<String, StatusDescription> submissionStatusDescriptionMap;
    private SubmissionRepository submissionRepository;

    public SubmissionStatusController(Map<String, StatusDescription> submissionStatusDescriptionMap, SubmissionRepository submissionRepository) {
        this.submissionStatusDescriptionMap = submissionStatusDescriptionMap;
        this.submissionRepository = submissionRepository;
    }

    @RequestMapping("/availableSubmissionStatuses")
    public Set<String> availableSubmissionStatuses(@PathVariable String submissionId) {
        Submission currentSubmission = submissionRepository.findOne(submissionId);

        StatusDescription statusDescription = submissionStatusDescriptionMap.get(currentSubmission.getSubmissionStatus().getStatus());

        return statusDescription.getUserTransitions();
    }
}

@@ -316,85 +316,94 @@
 ubs.
-data.status.StatusDescription;%0Aimport uk.ac.ebi.subs.repository.model.Submiss
+api.services.ValidationResultService;%0Aimport uk.ac.ebi.subs.data.status.StatusDescript
 ion;
@@ -452,22 +452,16 @@
 bmission
-Status
 ;%0Aimport
@@ -519,82 +519,38 @@
 ry;%0A
+%0A
 import 
-uk.ac.ebi.subs.repository.repos.status.SubmissionStatusRepository;%0A
+java.util.Collections;
 %0Aimp
@@ -895,16 +895,77 @@
 ository;
+%0A    private ValidationResultService validationResultService;
 %0A%0A    pu
@@ -1100,16 +1100,65 @@
 pository
+, ValidationResultService validationResultService
 ) %7B%0A    
@@ -1285,24 +1285,88 @@
 Repository;%0A
+        this.validationResultService = validationResultService;%0A
     %7D%0A%0A    @
@@ -1568,11 +1568,28 @@
 find
-One
+BySubmissionStatusId
 (sub
@@ -1597,24 +1597,146 @@
 issionId);%0A%0A
+        if (validationResultService.isValidationFinishedAndPassed(currentSubmission.getSubmissionStatus().getId())) %7B%0A    
         Stat
@@ -1867,16 +1867,20 @@
         
+    
 return s
@@ -1918,16 +1918,66 @@
 ions();%0A
+        %7D%0A%0A        return Collections.emptySet();%0A
     %7D%0A%7D%0A

Add available statuses as a set if the validation has finished and all has passed