argos/dmp-backend/web/src/main/java/eu/eudat/controllers/CommonController.java

58 lines
2.6 KiB
Java
Raw Normal View History

2018-03-28 15:24:47 +02:00
package eu.eudat.controllers;
import eu.eudat.dynamicproject.DynamicProjectConfiguration;
import eu.eudat.dynamicproject.entities.Language;
2018-05-28 11:50:42 +02:00
import eu.eudat.managers.CommonsManager;
import eu.eudat.models.externalurl.ExternalSourcesConfiguration;
2018-03-28 15:24:47 +02:00
import eu.eudat.models.helpers.responses.ResponseItem;
2018-05-28 11:50:42 +02:00
import eu.eudat.proxy.config.configloaders.ConfigLoader;
2018-03-28 15:24:47 +02:00
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* Created by ikalyvas on 3/28/2018.
*/
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/common"})
public class CommonController {
private DynamicProjectConfiguration dynamicProjectConfiguration;
2018-05-28 11:50:42 +02:00
private ConfigLoader configLoader;
2018-03-28 15:24:47 +02:00
@Autowired
2018-05-28 11:50:42 +02:00
public CommonController(DynamicProjectConfiguration dynamicProjectConfiguration, ConfigLoader configLoader) {
2018-03-28 15:24:47 +02:00
this.dynamicProjectConfiguration = dynamicProjectConfiguration;
2018-05-28 11:50:42 +02:00
this.configLoader = configLoader;
2018-03-28 15:24:47 +02:00
}
@RequestMapping(method = RequestMethod.GET, value = {"/language"}, produces = "application/json")
public @ResponseBody
2018-05-14 08:44:35 +02:00
ResponseEntity<ResponseItem<List<Language>>> getPaged() {
2018-03-28 15:24:47 +02:00
try {
List<Language> language = this.dynamicProjectConfiguration.getConfiguration().getMainExternalField().getLanguage();
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Language>>().status(ApiMessageCode.NO_MESSAGE).payload(language));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<Language>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
2018-05-28 11:50:42 +02:00
@RequestMapping(method = RequestMethod.GET, value = {"/externalSourcesConfiguration"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<ExternalSourcesConfiguration>> getExternalSourcesConfiguration() {
try {
ExternalSourcesConfiguration configuration = CommonsManager.getExternalSourcesConfiguration(configLoader);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalSourcesConfiguration>().status(ApiMessageCode.NO_MESSAGE).payload(configuration));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ExternalSourcesConfiguration>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
2018-03-28 15:24:47 +02:00
}