2017-12-15 00:01:26 +01:00
|
|
|
package eu.eudat.controllers;
|
2017-10-06 19:20:05 +02:00
|
|
|
|
2018-08-31 16:12:31 +02:00
|
|
|
import eu.eudat.data.query.items.item.researcher.ResearcherCriteriaRequest;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.logic.managers.ResearcherManager;
|
2018-08-31 16:12:31 +02:00
|
|
|
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
|
|
|
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
|
|
|
import eu.eudat.logic.services.ApiContext;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.dmp.Researcher;
|
|
|
|
import eu.eudat.models.data.external.ResearchersExternalSourcesModel;
|
|
|
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
|
|
|
import eu.eudat.models.data.security.Principal;
|
2018-01-23 16:21:38 +01:00
|
|
|
import eu.eudat.types.ApiMessageCode;
|
2017-10-06 19:20:05 +02:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
2018-02-07 10:56:30 +01:00
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
2017-10-06 19:20:05 +02:00
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2017-10-06 19:20:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
2019-02-11 14:44:03 +01:00
|
|
|
@RequestMapping(value = {"/api/researchers"})
|
2018-02-09 16:54:41 +01:00
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
public class Researchers extends BaseController {
|
2018-01-04 10:32:39 +01:00
|
|
|
|
2019-02-01 17:56:55 +01:00
|
|
|
private ResearcherManager researcherManager;
|
2018-02-16 11:34:02 +01:00
|
|
|
@Autowired
|
2019-02-01 17:56:55 +01:00
|
|
|
public Researchers(ApiContext apiContext, ResearcherManager researcherManager) {
|
2018-02-16 11:34:02 +01:00
|
|
|
super(apiContext);
|
2019-02-01 17:56:55 +01:00
|
|
|
this.researcherManager = researcherManager;
|
2018-02-16 11:34:02 +01:00
|
|
|
}
|
2018-01-04 10:32:39 +01:00
|
|
|
|
2019-02-01 17:56:55 +01:00
|
|
|
/*@RequestMapping(method = RequestMethod.GET, value = {"/external/researchers"}, produces = "application/json")
|
2018-02-16 11:34:02 +01:00
|
|
|
public @ResponseBody
|
2018-05-28 11:50:42 +02:00
|
|
|
ResponseEntity<ResponseItem<ResearchersExternalSourcesModel>> listExternalResearchers(
|
2018-08-31 16:12:31 +02:00
|
|
|
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound {
|
|
|
|
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getResearchers(query, type);
|
|
|
|
ResearchersExternalSourcesModel researchersExternalSourcesModel = new ResearchersExternalSourcesModel().fromExternalItem(remoteRepos);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ResearchersExternalSourcesModel>().payload(researchersExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
|
2019-02-01 17:56:55 +01:00
|
|
|
}*/
|
2017-10-06 19:20:05 +02:00
|
|
|
|
2019-02-11 14:44:03 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/getWithExternal"}, consumes = "application/json", produces = "application/json")
|
2018-03-08 11:54:56 +01:00
|
|
|
public @ResponseBody
|
2018-08-31 16:12:31 +02:00
|
|
|
ResponseEntity<ResponseItem<List<eu.eudat.models.data.dmp.Researcher>>> getWithExternal(@RequestBody ResearcherCriteriaRequest researcherCriteriaRequest, Principal principal) throws HugeResultSet, NoURLFound {
|
2019-02-01 17:56:55 +01:00
|
|
|
List<eu.eudat.models.data.dmp.Researcher> dataTable = this.researcherManager.getCriteriaWithExternal(this.getApiContext(), this.getApiContext().getOperationsContext().getRemoteFetcher(), researcherCriteriaRequest);
|
2018-08-31 16:12:31 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.data.dmp.Researcher>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
2018-03-08 11:54:56 +01:00
|
|
|
}
|
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
@Transactional
|
2019-02-01 17:56:55 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
2018-02-16 11:34:02 +01:00
|
|
|
public @ResponseBody
|
2018-08-31 16:12:31 +02:00
|
|
|
ResponseEntity<ResponseItem<Researcher>> create(@RequestBody eu.eudat.models.data.researcher.Researcher researcher, Principal principal) throws Exception {
|
2019-02-01 17:56:55 +01:00
|
|
|
this.researcherManager.create(this.getApiContext(), researcher);
|
2018-08-31 16:12:31 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Researcher>().status(ApiMessageCode.SUCCESS_MESSAGE));
|
2018-02-16 11:34:02 +01:00
|
|
|
}
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2017-10-06 19:20:05 +02:00
|
|
|
}
|
|
|
|
|