package uk.ac.ebi.pride.archive.redirections.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author Florian Reisinger
 * @since 1.0
 */
@Controller
public class PrideLegacyRedirectionsController {

    private static Logger accessLog = LoggerFactory.getLogger("uk.ac.ebi.pride.archive.redirections.AccessLogger");

    public final static String PRIDE_LEGACY_URL = "/legacy";


    @RequestMapping(value = "/directLink.do", method = RequestMethod.GET)
    public org.springframework.web.servlet.ModelAndView prideDirectExperimentLinkToPrideLegacy(@RequestParam("experimentAccessionNumber") String accession) {
        String target = "/directLink.do?experimentAccessionNumber=" + accession;
        accessLog.info("FROM " + target + " TO: " + PRIDE_LEGACY_URL + target);
        return new ModelAndView("redirect:" + PRIDE_LEGACY_URL + target);
    }

    @RequestMapping(value = "/experimentLink.do", method = RequestMethod.GET)
    public org.springframework.web.servlet.ModelAndView prideExperimentLinkToPrideLegacy(@RequestParam("experimentAccessionNumber") String accession) {
        String target = "/experimentLink.do?experimentAccessionNumber=" + accession;
        accessLog.info("FROM " + target + " TO: " + PRIDE_LEGACY_URL + target);
        return new ModelAndView("redirect:" + PRIDE_LEGACY_URL + target);
    }

    @RequestMapping(value = "/experiment.do", method = RequestMethod.GET)
    public org.springframework.web.servlet.ModelAndView prideExperimentToPrideLegacy(@RequestParam("experimentAccessionNumber") String accession) {
        String target = "/experiment.do?experimentAccessionNumber=" + accession;
        accessLog.info("FROM " + target + " TO: " + PRIDE_LEGACY_URL + target);
        return new ModelAndView("redirect:" + PRIDE_LEGACY_URL + target);
    }

    @RequestMapping(value = "/prideMart.do", method = RequestMethod.GET)
    public org.springframework.web.servlet.ModelAndView prideBioMartLinkToPrideLegacy() {
        String target = "/prideMart.do";
        accessLog.info("FROM " + target + " TO: " + PRIDE_LEGACY_URL + target);
        return new ModelAndView("redirect:" + PRIDE_LEGACY_URL + target);
    }

    @RequestMapping( value = "/searchSummary.do", method = RequestMethod.GET)
    public org.springframework.web.servlet.ModelAndView prideSearchToPrideLegacy(@RequestParam("queryTypeSelected") String type, @RequestParam("identificationAccessionNumber") String accession) {
        String target = "/searchSummary.do?queryTypeSelected=" + type + "&identificationAccessionNumber=" + accession;
        accessLog.info("FROM " + target + " TO: " + PRIDE_LEGACY_URL + target);
        return new ModelAndView("redirect:" + PRIDE_LEGACY_URL + target);
    }

}

@@ -939,32 +939,34 @@
 g accession) %7B%0D%0A
+//
         String t
@@ -1023,32 +1023,89 @@
 %22 + accession;%0D%0A
+        String target = %22/archive/assays/%22 + accession;%0D%0A
         accessLo
@@ -1139,35 +1139,16 @@
  TO: %22 +
- PRIDE_LEGACY_URL +
  target)
@@ -1195,35 +1195,16 @@
 rect:%22 +
- PRIDE_LEGACY_URL +
  target)
@@ -1439,32 +1439,34 @@
 g accession) %7B%0D%0A
+//
         String t
@@ -1527,32 +1527,89 @@
 %22 + accession;%0D%0A
+        String target = %22/archive/assays/%22 + accession;%0D%0A
         accessLo
@@ -1643,35 +1643,16 @@
  TO: %22 +
- PRIDE_LEGACY_URL +
  target)
@@ -1699,35 +1699,16 @@
 rect:%22 +
- PRIDE_LEGACY_URL +
  target)
@@ -1935,32 +1935,34 @@
 g accession) %7B%0D%0A
+//
         String t
@@ -2019,32 +2019,89 @@
 %22 + accession;%0D%0A
+        String target = %22/archive/assays/%22 + accession;%0D%0A
         accessLo
@@ -2135,35 +2135,16 @@
  TO: %22 +
- PRIDE_LEGACY_URL +
  target)
@@ -2191,35 +2191,16 @@
 rect:%22 +
- PRIDE_LEGACY_URL +
  target)
@@ -2855,24 +2855,26 @@
 cession) %7B%0D%0A
+//
         Stri
@@ -2973,32 +2973,97 @@
 %22 + accession;%0D%0A
+        String target = %22/archive/simpleSearch?q=%22 + accession;%0D%0A
         accessLo
@@ -3097,35 +3097,16 @@
  TO: %22 +
- PRIDE_LEGACY_URL +
  target)
@@ -3153,35 +3153,16 @@
 rect:%22 +
- PRIDE_LEGACY_URL +
  target)

change to redirect to PRIDE Archive instead of legacy PRIDE