179 lines
6.5 KiB
Java
179 lines
6.5 KiB
Java
package rest.entities;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
import java.util.stream.Collectors;
|
|
|
|
import org.apache.commons.lang3.SerializationUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.util.MultiValueMap;
|
|
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 com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import dao.entities.DMPDao;
|
|
import dao.entities.DMPProfileDao;
|
|
import dao.entities.DataRepositoryDao;
|
|
import dao.entities.DatasetDao;
|
|
import dao.entities.DatasetProfileDao;
|
|
import dao.entities.DatasetProfileRulesetDao;
|
|
import dao.entities.DatasetProfileViewstyleDao;
|
|
import dao.entities.OrganisationDao;
|
|
import dao.entities.ProjectDao;
|
|
import dao.entities.RegistryDao;
|
|
import dao.entities.ResearcherDao;
|
|
import dao.entities.ServiceDao;
|
|
import entities.DMP;
|
|
import entities.DMPProfile;
|
|
import entities.DataRepository;
|
|
import entities.Dataset;
|
|
import entities.DatasetProfile;
|
|
import entities.DatasetProfileRuleset;
|
|
import entities.Organisation;
|
|
import entities.Project;
|
|
import entities.Registry;
|
|
import entities.Researcher;
|
|
import entities.Service;
|
|
import entities.responses.IDLabelPair;
|
|
import helpers.SerializerProvider;
|
|
import helpers.Transformers;
|
|
import proxy.config.exceptions.HugeResultSet;
|
|
import proxy.config.exceptions.NoURLFound;
|
|
import proxy.fetching.RemoteFetcher;
|
|
import responses.RestResponse;
|
|
|
|
|
|
@RestController
|
|
@CrossOrigin
|
|
public class Registries {
|
|
|
|
@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/registries" }, produces="application/json;charset=UTF-8")
|
|
public @ResponseBody ResponseEntity<Object> listExternalRegistries(@RequestParam(value="query", required=false) String query ){
|
|
try {
|
|
List<Map<String,String>> remoteRepos = remoteFetcher.getRegistries(query);
|
|
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(remoteRepos));
|
|
}
|
|
catch(NoURLFound ex) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"reason\":\""+ex.getMessage()+"\"}");
|
|
}
|
|
catch(HugeResultSet ex) {
|
|
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("{\"reason\":\""+ex.getMessage()+"\"}"); //the ex.getMessage has the appropriate text description
|
|
}
|
|
}
|
|
|
|
|
|
// MANAGE REGISTRY(IES)
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/registries" })
|
|
public @ResponseBody ResponseEntity<Object> listRegistries(){
|
|
try {
|
|
List<UUID> allIDs = registryDao.listAllIDs();
|
|
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/registries/{id}" })
|
|
public @ResponseBody ResponseEntity<Object> getRegistries(@PathVariable("id") String id) {
|
|
try {
|
|
Registry registry = registryDao.read(UUID.fromString(id));
|
|
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(registry));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/registries/listAllLabelIDs" })
|
|
public @ResponseBody ResponseEntity<Object> listLabelIds(){
|
|
try {
|
|
List<IDLabelPair> allIDs = registryDao.listAllIDsLabels();
|
|
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/registry/getAll" }, produces="application/json;charset=UTF-8")
|
|
public @ResponseBody ResponseEntity<Object> getAllRegistries(){
|
|
try {
|
|
List<Registry> allRegistries = registryDao.getAll();
|
|
|
|
return new ResponseEntity<Object>(SerializerProvider.toJson(allRegistries), HttpStatus.OK);
|
|
|
|
}
|
|
catch(Exception ex) {
|
|
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/registry/create" }, consumes = "application/json", produces="application/json;charset=UTF-8")
|
|
public @ResponseBody ResponseEntity<Object> setRegistry(@RequestBody Registry registry) {
|
|
Registry createdRegistry = registryDao.update(registry);
|
|
try {
|
|
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdRegistry));
|
|
} catch (Exception e) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create registry!\"}");
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/registry/delete" }, consumes = "application/json", produces="text/plain")
|
|
public @ResponseBody ResponseEntity<Object> delete(@RequestBody Registry registry) {
|
|
|
|
Registry r = new Registry();
|
|
r.setId(registry.getId());
|
|
try {
|
|
registryDao.delete(r);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted registry!\"}");
|
|
} catch (Exception e) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete registry!\"}");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|