2017-12-15 00:01:26 +01:00
|
|
|
package eu.eudat.controllers;
|
2017-10-06 19:20:05 +02:00
|
|
|
|
2018-09-04 11:36:18 +02:00
|
|
|
import eu.eudat.data.entities.DataRepository;
|
|
|
|
import eu.eudat.logic.managers.DataRepositoryManager;
|
2018-06-27 12:29:21 +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-09-04 11:36:18 +02:00
|
|
|
import eu.eudat.models.data.datarepository.DataRepositoryModel;
|
2018-06-29 10:29:43 +02:00
|
|
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
2018-09-04 11:36:18 +02:00
|
|
|
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-09-04 11:36:18 +02:00
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2018-02-16 11:34:02 +01:00
|
|
|
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;
|
2017-10-06 19:20:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
2019-02-01 17:56:55 +01:00
|
|
|
@RequestMapping(value = {"/api/external/datarepos"})
|
2018-02-16 11:34:02 +01:00
|
|
|
public class DataRepositories extends BaseController {
|
|
|
|
|
2019-02-01 17:56:55 +01:00
|
|
|
private DataRepositoryManager dataRepositoryManager;
|
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
@Autowired
|
2019-02-01 17:56:55 +01:00
|
|
|
public DataRepositories(ApiContext apiContext, DataRepositoryManager dataRepositoryManager) {
|
2018-02-16 11:34:02 +01:00
|
|
|
super(apiContext);
|
2019-02-01 17:56:55 +01:00
|
|
|
this.dataRepositoryManager = dataRepositoryManager;
|
2018-02-16 11:34:02 +01:00
|
|
|
}
|
|
|
|
|
2019-02-01 17:56:55 +01:00
|
|
|
@RequestMapping(method = RequestMethod.GET, produces = "application/json")
|
2018-02-16 11:34:02 +01:00
|
|
|
public @ResponseBody
|
2019-09-25 17:31:41 +02:00
|
|
|
ResponseEntity<ResponseItem<List<DataRepositoryModel>>> listExternalDataRepositories(
|
|
|
|
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type, Principal principal
|
2018-08-31 16:12:31 +02:00
|
|
|
) throws HugeResultSet, NoURLFound {
|
2019-09-25 17:31:41 +02:00
|
|
|
List<DataRepositoryModel> dataRepositoryModels = this.dataRepositoryManager.getDataRepositories(query, type, principal);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DataRepositoryModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataRepositoryModels));
|
2018-02-16 11:34:02 +01:00
|
|
|
}
|
|
|
|
|
2018-09-04 11:36:18 +02:00
|
|
|
@Transactional
|
2019-02-01 17:56:55 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
2018-09-04 11:36:18 +02:00
|
|
|
public @ResponseBody
|
2019-12-13 16:10:21 +01:00
|
|
|
ResponseEntity<ResponseItem<DataRepositoryModel>> create(@RequestBody eu.eudat.models.data.datarepository.DataRepositoryModel dataRepositoryModel, Principal principal) throws Exception {
|
2019-09-25 12:43:17 +02:00
|
|
|
DataRepository dataRepository = this.dataRepositoryManager.create(dataRepositoryModel, principal);
|
2019-12-13 16:10:21 +01:00
|
|
|
DataRepositoryModel dataRepositoryModel1 = new DataRepositoryModel().fromDataModel(dataRepository);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataRepositoryModel>().payload(dataRepositoryModel1).status(ApiMessageCode.SUCCESS_MESSAGE));
|
2018-09-04 11:36:18 +02:00
|
|
|
}
|
2017-10-06 19:20:05 +02:00
|
|
|
}
|
|
|
|
|