2017-12-15 00:01:26 +01:00
|
|
|
package eu.eudat.controllers;
|
2017-10-06 19:20:05 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
2017-11-21 17:29:16 +01:00
|
|
|
import java.util.Map;
|
2017-10-06 19:20:05 +02:00
|
|
|
import java.util.UUID;
|
2017-10-17 13:45:11 +02:00
|
|
|
|
|
|
|
import javax.transaction.Transactional;
|
2017-10-06 19:20:05 +02:00
|
|
|
|
2017-12-15 00:01:26 +01:00
|
|
|
import eu.eudat.entities.DataRepository;
|
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;
|
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
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.bind.annotation.ResponseBody;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
2017-12-15 00:01:26 +01:00
|
|
|
import eu.eudat.dao.entities.DMPDao;
|
|
|
|
import eu.eudat.dao.entities.DMPProfileDao;
|
|
|
|
import eu.eudat.dao.entities.DataRepositoryDao;
|
|
|
|
import eu.eudat.dao.entities.DatasetDao;
|
|
|
|
import eu.eudat.dao.entities.DatasetProfileDao;
|
|
|
|
import eu.eudat.dao.entities.DatasetProfileRulesetDao;
|
|
|
|
import eu.eudat.dao.entities.DatasetProfileViewstyleDao;
|
|
|
|
import eu.eudat.dao.entities.OrganisationDao;
|
|
|
|
import eu.eudat.dao.entities.ProjectDao;
|
|
|
|
import eu.eudat.dao.entities.RegistryDao;
|
|
|
|
import eu.eudat.dao.entities.ResearcherDao;
|
|
|
|
import eu.eudat.dao.entities.ServiceDao;
|
|
|
|
import eu.eudat.proxy.config.exceptions.HugeResultSet;
|
|
|
|
import eu.eudat.proxy.config.exceptions.NoURLFound;
|
|
|
|
import eu.eudat.proxy.fetching.RemoteFetcher;
|
2017-10-06 19:20:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
|
|
|
public class DataRepositories {
|
|
|
|
|
|
|
|
@Autowired private DataRepositoryDao dataRepositoryDao;
|
|
|
|
@Autowired private DatasetDao datasetDao;
|
|
|
|
@Autowired private DatasetProfileDao datasetProfileDao;
|
|
|
|
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
|
|
|
|
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
|
|
|
|
@Autowired private DMPDao dMPDao;
|
|
|
|
@Autowired private DMPProfileDao dMPProfileDao;
|
|
|
|
@Autowired private OrganisationDao organisationDao;
|
|
|
|
@Autowired private ProjectDao projectDao;
|
|
|
|
@Autowired private RegistryDao registryDao;
|
|
|
|
@Autowired private ResearcherDao researcherDao;
|
|
|
|
@Autowired private ServiceDao serviceDao;
|
|
|
|
|
2017-11-21 17:29:16 +01:00
|
|
|
@Autowired private RemoteFetcher remoteFetcher;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-22 11:14:10 +01:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/external/datarepos" }, produces="application/json")
|
2017-12-15 00:01:26 +01:00
|
|
|
public @ResponseBody ResponseEntity<List<Map<String,String>>> listExternalDataRepositories(@RequestParam(value="query", required=false) String query ){
|
2017-11-21 17:29:16 +01:00
|
|
|
try {
|
|
|
|
List<Map<String,String>> remoteRepos = remoteFetcher.getRepositories(query);
|
2017-12-15 00:01:26 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(remoteRepos);
|
2017-11-21 17:29:16 +01:00
|
|
|
}
|
2017-11-22 10:50:47 +01:00
|
|
|
catch(NoURLFound ex) {
|
2017-12-15 00:01:26 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
|
2017-11-22 10:50:47 +01:00
|
|
|
}
|
|
|
|
catch(HugeResultSet ex) {
|
2017-12-15 00:01:26 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(null); //the ex.getMessage has the appropriate text description
|
2017-11-21 17:29:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-06 19:20:05 +02:00
|
|
|
// MANAGE DATAREPOSITORy(IES)
|
|
|
|
|
2017-10-17 13:45:11 +02:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/datarepos" })
|
2017-12-15 00:01:26 +01:00
|
|
|
public @ResponseBody ResponseEntity<List<UUID>> listDataRepositories(){
|
2017-10-06 19:20:05 +02:00
|
|
|
try {
|
|
|
|
List<UUID> allIDs = dataRepositoryDao.listAllIDs();
|
2017-12-15 00:01:26 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(allIDs);
|
2017-10-06 19:20:05 +02:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
2017-12-15 00:01:26 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
|
2017-10-06 19:20:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-17 13:45:11 +02:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/datarepos/{id}" })
|
2017-12-15 00:01:26 +01:00
|
|
|
public @ResponseBody ResponseEntity<DataRepository> getDataRepository(@PathVariable("id") String id) {
|
2017-10-06 19:20:05 +02:00
|
|
|
try {
|
|
|
|
DataRepository dataRepository = dataRepositoryDao.read(UUID.fromString(id));
|
2017-12-15 00:01:26 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(dataRepository);
|
2017-10-06 19:20:05 +02:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
2017-12-15 00:01:26 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
|
2017-10-06 19:20:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 13:45:11 +02:00
|
|
|
|
2017-10-06 19:20:05 +02:00
|
|
|
|
2017-10-17 13:45:11 +02:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/datarepo/getAll" }, produces="application/json")
|
2017-12-15 00:01:26 +01:00
|
|
|
public @ResponseBody ResponseEntity<List<DataRepository>> getAllDataRepositories(){
|
2017-10-17 13:45:11 +02:00
|
|
|
|
2017-10-06 19:20:05 +02:00
|
|
|
try {
|
2017-10-17 13:45:11 +02:00
|
|
|
List<DataRepository> allDataRepositories = dataRepositoryDao.getAll();
|
|
|
|
|
2017-12-15 00:01:26 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(allDataRepositories);
|
2017-10-17 13:45:11 +02:00
|
|
|
|
2017-10-06 19:20:05 +02:00
|
|
|
}
|
2017-10-17 13:45:11 +02:00
|
|
|
catch(Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2017-12-15 00:01:26 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
|
2017-10-17 13:45:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/datarepo/create" }, consumes = "application/json", produces="application/json")
|
2017-12-15 00:01:26 +01:00
|
|
|
public @ResponseBody ResponseEntity<DataRepository> setOrganisation(@RequestBody DataRepository dataRepository) {
|
2017-10-17 13:45:11 +02:00
|
|
|
try {
|
2017-12-15 00:01:26 +01:00
|
|
|
DataRepository createdDataRepository = dataRepositoryDao.update(dataRepository);
|
|
|
|
return ResponseEntity.status(HttpStatus.CREATED).body(createdDataRepository);
|
2017-10-27 12:52:12 +02:00
|
|
|
} catch (Exception e) {
|
2017-12-15 00:01:26 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
|
2017-10-17 13:45:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/datarepo/delete" }, consumes = "application/json", produces="text/plain")
|
|
|
|
public @ResponseBody ResponseEntity<Object> delete(@RequestBody DataRepository dataRepository) {
|
|
|
|
|
|
|
|
DataRepository dr = new DataRepository();
|
|
|
|
dr.setId(dataRepository.getId());
|
|
|
|
try {
|
|
|
|
dataRepositoryDao.delete(dr);
|
|
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted data repository!\"}");
|
|
|
|
} catch (Exception e) {
|
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete data repository!\"}");
|
2017-10-06 19:20:05 +02:00
|
|
|
}
|
2017-10-17 13:45:11 +02:00
|
|
|
|
2017-10-06 19:20:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|