2020-01-23 17:35:11 +01:00
|
|
|
package eu.eudat.controllers;
|
|
|
|
|
2020-01-27 17:38:24 +01:00
|
|
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
|
|
|
import eu.eudat.models.data.security.Principal;
|
|
|
|
import eu.eudat.types.ApiMessageCode;
|
2020-01-23 17:35:11 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
2020-01-27 17:38:24 +01:00
|
|
|
import java.io.*;
|
|
|
|
import java.util.UUID;
|
2020-01-23 17:35:11 +01:00
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
|
|
|
@RequestMapping(value = {"/api/language/"})
|
|
|
|
public class LanguageController {
|
|
|
|
|
2020-02-17 11:58:17 +01:00
|
|
|
private Environment environment;
|
2020-01-23 17:35:11 +01:00
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public LanguageController(Environment environment) {
|
|
|
|
this.environment = environment;
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "{lang}", method = RequestMethod.GET)
|
|
|
|
public ResponseEntity getLanguage(@PathVariable String lang) throws IOException {
|
|
|
|
|
|
|
|
String fileName = this.environment.getProperty("language.path") + lang + ".json";
|
2020-01-24 17:03:05 +01:00
|
|
|
InputStream is = new FileInputStream(fileName);
|
2020-01-23 17:35:11 +01:00
|
|
|
|
|
|
|
HttpHeaders responseHeaders = new HttpHeaders();
|
|
|
|
responseHeaders.setContentLength(is.available());
|
2020-01-24 17:03:05 +01:00
|
|
|
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
|
2020-01-23 17:35:11 +01:00
|
|
|
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName);
|
|
|
|
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
|
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
|
|
|
|
|
|
|
|
byte[] content = new byte[is.available()];
|
|
|
|
is.read(content);
|
|
|
|
is.close();
|
|
|
|
|
|
|
|
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
|
|
|
|
}
|
2020-01-27 17:38:24 +01:00
|
|
|
|
|
|
|
@RequestMapping(value = "update/{lang}", method = RequestMethod.POST)
|
|
|
|
public @ResponseBody
|
|
|
|
ResponseEntity<ResponseItem<String>> updateLang(@PathVariable String lang, @RequestBody String json) throws Exception {
|
|
|
|
String fileName = this.environment.getProperty("language.path") + lang + ".json";
|
|
|
|
OutputStream os = new FileOutputStream(fileName);
|
|
|
|
os.write(json.getBytes());
|
|
|
|
os.close();
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Updated").payload("Updated"));
|
|
|
|
}
|
2020-01-23 17:35:11 +01:00
|
|
|
}
|