package eu.eudat.controllers; import java.util.List; import java.util.Map; import java.util.UUID; import javax.transaction.Transactional; import eu.eudat.entities.DataRepository; 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; 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; @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; @Autowired private RemoteFetcher remoteFetcher; @RequestMapping(method = RequestMethod.GET, value = { "/external/datarepos" }, produces="application/json") public @ResponseBody ResponseEntity>> listExternalDataRepositories(@RequestParam(value="query", required=false) String query ){ try { List> remoteRepos = remoteFetcher.getRepositories(query); return ResponseEntity.status(HttpStatus.OK).body(remoteRepos); } catch(NoURLFound ex) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); } catch(HugeResultSet ex) { return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(null); //the ex.getMessage has the appropriate text description } } // MANAGE DATAREPOSITORy(IES) // @RequestMapping(method = RequestMethod.GET, value = { "/datarepos" }) // public @ResponseBody ResponseEntity> listDataRepositories(){ // try { // List allIDs = dataRepositoryDao.listAllIDs(); // return ResponseEntity.status(HttpStatus.OK).body(allIDs); // } // catch(Exception ex) { // return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); // } // } // // // @RequestMapping(method = RequestMethod.GET, value = { "/datarepos/{id}" }) // public @ResponseBody ResponseEntity getDataRepository(@PathVariable("id") String id) { // try { // DataRepository dataRepository = dataRepositoryDao.read(UUID.fromString(id)); // return ResponseEntity.status(HttpStatus.OK).body(dataRepository); // } // catch(Exception ex) { // return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); // } // } // // // // @RequestMapping(method = RequestMethod.GET, value = { "/datarepo/getAll" }, produces="application/json") // public @ResponseBody ResponseEntity> getAllDataRepositories(){ // // try { // List allDataRepositories = dataRepositoryDao.getAll(); // // return ResponseEntity.status(HttpStatus.OK).body(allDataRepositories); // // } // catch(Exception ex) { // ex.printStackTrace(); // return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); // } // // } // // // @Transactional // @RequestMapping(method = RequestMethod.POST, value = { "/datarepo/create" }, consumes = "application/json", produces="application/json") // public @ResponseBody ResponseEntity setOrganisation(@RequestBody DataRepository dataRepository) { // try { // DataRepository createdDataRepository = dataRepositoryDao.update(dataRepository); // return ResponseEntity.status(HttpStatus.CREATED).body(createdDataRepository); // } catch (Exception e) { // return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); // } // } // // // @RequestMapping(method = RequestMethod.POST, value = { "/datarepo/delete" }, consumes = "application/json", produces="text/plain") // public @ResponseBody ResponseEntity 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!\"}"); // } // // } }