argos/dmp-backend/src/main/java/eu/eudat/controllers/DmpProfiles.java

127 lines
4.5 KiB
Java
Raw Normal View History

2017-12-15 00:01:26 +01:00
package eu.eudat.controllers;
2017-10-06 19:20:05 +02:00
import java.util.List;
import java.util.UUID;
2017-10-12 14:02:41 +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.DMPProfile;
2018-01-04 10:32:39 +01:00
import eu.eudat.services.ApiContext;
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.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.entities.responses.IDLabelPair;
2017-10-06 19:20:05 +02:00
@RestController
@CrossOrigin
2018-01-04 10:32:39 +01:00
public class DmpProfiles extends BaseController{
@Autowired
public DmpProfiles(ApiContext apiContext) {
super(apiContext);
}
2017-10-06 19:20:05 +02:00
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofiles" })
2017-12-15 00:01:26 +01:00
public @ResponseBody ResponseEntity<List<UUID>> listDmpProfiles(){
2017-10-06 19:20:05 +02:00
try {
2018-01-04 10:32:39 +01:00
List<UUID> allIDs = this.getApiContext().getDatabaseRepository().getDMPProfileDao().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
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofiles/{id}" })
2017-12-15 00:01:26 +01:00
public @ResponseBody ResponseEntity<DMPProfile> getDmpProfile(@PathVariable("id") String id) {
2017-10-06 19:20:05 +02:00
try {
2018-01-04 10:32:39 +01:00
DMPProfile dmpProfile = this.getApiContext().getDatabaseRepository().getDMPProfileDao().read(UUID.fromString(id));
2017-12-15 00:01:26 +01:00
return ResponseEntity.status(HttpStatus.OK).body(dmpProfile);
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
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofile/listAllLabelIDs" })
2017-12-15 00:01:26 +01:00
public @ResponseBody ResponseEntity<List<IDLabelPair>> listLabelIds(){
2017-10-06 19:20:05 +02:00
try {
2018-01-04 10:32:39 +01:00
List<IDLabelPair> allIDs = this.getApiContext().getDatabaseRepository().getDMPProfileDao().listAllIDsLabels();
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-12 14:02:41 +02:00
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofile/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getAllDmpProfiles(){
try {
2018-01-04 10:32:39 +01:00
List<DMPProfile> allDmpProfiles = this.getApiContext().getDatabaseRepository().getDMPProfileDao().getAll();
2017-12-15 00:01:26 +01:00
return ResponseEntity.status(HttpStatus.OK).body(allDmpProfiles);
2017-10-12 14:02:41 +02:00
}
catch(Exception ex) {
2017-12-15 00:01:26 +01:00
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
2017-10-12 14:02:41 +02:00
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/create" }, consumes = "application/json", produces="application/json")
2017-12-15 00:01:26 +01:00
public @ResponseBody ResponseEntity<DMPProfile> setDmpProfile(@RequestBody DMPProfile dmpprofile) {
2017-10-12 14:02:41 +02:00
try {
2018-01-04 10:32:39 +01:00
DMPProfile createdDMPProfile = this.getApiContext().getDatabaseRepository().getDMPProfileDao().update(dmpprofile);
2017-12-15 00:01:26 +01:00
return ResponseEntity.status(HttpStatus.CREATED).body(createdDMPProfile);
} catch (Exception e) {
2017-12-15 00:01:26 +01:00
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
2017-10-12 14:02:41 +02:00
}
}
2017-10-06 19:20:05 +02:00
2017-10-12 14:02:41 +02:00
@RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody DMPProfile dmpprofile) {
DMPProfile dmpp = new DMPProfile();
dmpp.setId(dmpprofile.getId());
2017-10-06 19:20:05 +02:00
try {
2018-01-04 10:32:39 +01:00
this.getApiContext().getDatabaseRepository().getDMPProfileDao().delete(dmpp);
2017-10-17 13:45:11 +02:00
return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted DMP Profile!\"}");
2017-10-12 14:02:41 +02:00
} catch (Exception e) {
2017-10-17 13:45:11 +02:00
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete DMP Profile!\"}");
2017-10-06 19:20:05 +02:00
}
2017-10-12 14:02:41 +02:00
2017-10-06 19:20:05 +02:00
}
2017-10-12 14:02:41 +02:00
2017-10-06 19:20:05 +02:00
}