2017-10-12 14:04:38 +02:00
|
|
|
package rest.entities;
|
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 java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import javax.transaction.Transactional;
|
2017-10-06 19:20:05 +02:00
|
|
|
|
|
|
|
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.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;
|
2017-10-20 17:11:40 +02:00
|
|
|
import helpers.SerializerProvider;
|
2017-10-06 19:20:05 +02:00
|
|
|
import helpers.Transformers;
|
|
|
|
import responses.RestResponse;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
|
|
|
public class DmpProfiles {
|
|
|
|
|
|
|
|
@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;
|
|
|
|
|
|
|
|
|
|
|
|
// MANAGE DMPPROFILE(S)
|
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofiles" })
|
|
|
|
public @ResponseBody ResponseEntity<Object> listDmpProfiles(){
|
|
|
|
try {
|
|
|
|
List<UUID> allIDs = dMPProfileDao.listAllIDs();
|
2017-10-27 12:52:12 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
|
2017-10-06 19:20:05 +02:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofiles/{id}" })
|
|
|
|
public @ResponseBody ResponseEntity<Object> getDmpProfile(@PathVariable("id") String id) {
|
|
|
|
try {
|
|
|
|
DMPProfile dmpProfile = dMPProfileDao.read(UUID.fromString(id));
|
2017-10-27 12:52:12 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(dmpProfile));
|
2017-10-06 19:20:05 +02:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofile/listAllLabelIDs" })
|
|
|
|
public @ResponseBody ResponseEntity<Object> listLabelIds(){
|
|
|
|
try {
|
|
|
|
List<IDLabelPair> allIDs = dMPProfileDao.listAllIDsLabels();
|
2017-10-27 12:52:12 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
|
2017-10-06 19:20:05 +02:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-12 14:02:41 +02:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofile/getAll" }, produces="application/json")
|
|
|
|
public @ResponseBody ResponseEntity<Object> getAllDmpProfiles(){
|
|
|
|
try {
|
|
|
|
List<DMPProfile> allDmpProfiles = dMPProfileDao.getAll();
|
2017-10-27 12:52:12 +02:00
|
|
|
return new ResponseEntity<Object>(SerializerProvider.toJson(allDmpProfiles), HttpStatus.OK);
|
2017-10-12 14:02:41 +02:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
|
|
|
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/create" }, consumes = "application/json", produces="application/json")
|
|
|
|
public @ResponseBody ResponseEntity<Object> setDmpProfile(@RequestBody DMPProfile dmpprofile) {
|
|
|
|
try {
|
2017-10-27 12:52:12 +02:00
|
|
|
DMPProfile createdDMPProfile = dMPProfileDao.update(dmpprofile);
|
|
|
|
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdDMPProfile));
|
|
|
|
} catch (Exception e) {
|
2017-10-17 13:45:11 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create DMP Profile!\"}");
|
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 {
|
2017-10-12 14:02:41 +02:00
|
|
|
dMPProfileDao.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
|
|
|
}
|
|
|
|
|