260 lines
9.4 KiB
Java
260 lines
9.4 KiB
Java
package rest.entities;
|
|
|
|
import java.io.IOException;
|
|
import java.io.PrintStream;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.UUID;
|
|
import java.util.stream.Collectors;
|
|
|
|
import javax.transaction.Transactional;
|
|
|
|
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.JsonParseException;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
|
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.Dataset;
|
|
import entities.DatasetProfile;
|
|
import entities.DatasetProfileRuleset;
|
|
import entities.DatasetProfileViewstyle;
|
|
import entities.Organisation;
|
|
import entities.Project;
|
|
import helpers.SerializerProvider;
|
|
import helpers.Transformers;
|
|
import responses.RestResponse;
|
|
|
|
|
|
@RestController
|
|
@CrossOrigin
|
|
public class DatasetProfiles {
|
|
|
|
@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;
|
|
|
|
private ObjectMapper objectMapper =
|
|
new ObjectMapper();
|
|
//SerializerProvider.getJsonSerializer();
|
|
|
|
|
|
//FETCH BY DATASET PROFILE
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/datasetprofiles" }, produces="text/plain")
|
|
public @ResponseBody ResponseEntity<Object> listDMPs(){
|
|
try {
|
|
List<UUID> allIDs = datasetProfileDao.listAllIDs();
|
|
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/datasetprofiles/{id}" })
|
|
public @ResponseBody ResponseEntity<Object> getDatasetProfile(@PathVariable("id") String id) {
|
|
try {
|
|
DatasetProfile profile = datasetProfileDao.read(UUID.fromString(id));
|
|
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(profile));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/create" }, consumes = "application/json", produces="application/json")
|
|
public @ResponseBody ResponseEntity<Object> createDatasetProfile(@RequestBody DatasetProfile datasetProfile) {
|
|
|
|
DatasetProfileRuleset datasetprofileruleset = datasetProfile.getRuleset();
|
|
DatasetProfileViewstyle datasetprofileviewstyle = datasetProfile.getViewstyle();
|
|
|
|
if(datasetprofileruleset != null) {
|
|
if(datasetprofileruleset.getId()==null)
|
|
datasetprofileruleset = datasetProfileRulesetDao.create(datasetprofileruleset);
|
|
else
|
|
datasetProfileRulesetDao.update(datasetprofileruleset);
|
|
datasetProfile.setRuleset(datasetprofileruleset);
|
|
}
|
|
if(datasetprofileviewstyle != null) {
|
|
if(datasetprofileviewstyle.getId()==null)
|
|
datasetprofileviewstyle = datasetProfileViewstyleDao.create(datasetprofileviewstyle);
|
|
else
|
|
datasetProfileViewstyleDao.update(datasetprofileviewstyle);
|
|
datasetProfile.setViewstyle(datasetprofileviewstyle);
|
|
}
|
|
|
|
|
|
try {
|
|
if(datasetProfile.getId()==null)
|
|
datasetProfile = datasetProfileDao.create(datasetProfile);
|
|
else
|
|
datasetProfileDao.update(datasetProfile);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(datasetProfile));
|
|
} catch (JsonProcessingException e) {
|
|
e.printStackTrace();
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create dataset profile!\"}");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/update" }, consumes = "application/json", produces="application/json")
|
|
public @ResponseBody ResponseEntity<Object> updateDatasetProfile(@RequestBody DatasetProfile datasetProfile) {
|
|
|
|
DatasetProfileRuleset datasetprofileruleset = datasetProfile.getRuleset();
|
|
DatasetProfileViewstyle datasetprofileviewstyle = datasetProfile.getViewstyle();
|
|
|
|
if(datasetprofileruleset != null) {
|
|
if(datasetprofileruleset.getId()==null)
|
|
datasetProfileRulesetDao.create(datasetprofileruleset);
|
|
else
|
|
datasetProfileRulesetDao.update(datasetprofileruleset);
|
|
}
|
|
if(datasetprofileviewstyle != null) {
|
|
if(datasetprofileviewstyle.getId()==null)
|
|
datasetProfileViewstyleDao.create(datasetprofileviewstyle);
|
|
else
|
|
datasetProfileViewstyleDao.update(datasetprofileviewstyle);
|
|
}
|
|
|
|
|
|
try {
|
|
if(datasetProfile.getId()==null)
|
|
datasetProfile = datasetProfileDao.create(datasetProfile);
|
|
else
|
|
datasetProfile = datasetProfileDao.update(datasetProfile);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(datasetProfile));
|
|
} catch (JsonProcessingException e) {
|
|
e.printStackTrace();
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create dataset profile!\"}");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
// //@Transactional
|
|
// @RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/set" }, consumes = "application/json", produces="application/json")
|
|
// public @ResponseBody ResponseEntity<Object> setDatasetProfile(@RequestBody DatasetProfile datasetProfile) {
|
|
//
|
|
// System.out.println("inside setDatasetProfile");
|
|
// try {
|
|
// System.out.println(objectMapper.writeValueAsString(datasetProfile));
|
|
// } catch (JsonProcessingException e) {
|
|
// e.printStackTrace();
|
|
// }
|
|
//
|
|
// if(datasetProfile.getRuleset()!=null && datasetProfile.getRuleset().getId()!=null){
|
|
// DatasetProfileRuleset dpr = datasetProfile.getRuleset();
|
|
// datasetProfileRulesetDao.update(dpr);
|
|
// DatasetProfileRuleset n = new DatasetProfileRuleset();
|
|
// n.setId(dpr.getId());
|
|
// datasetProfile.setRuleset(n);
|
|
// }
|
|
//
|
|
// if(datasetProfile.getViewstyle()!=null && datasetProfile.getViewstyle().getId()!=null){
|
|
// DatasetProfileViewstyle dpv = datasetProfile.getViewstyle();
|
|
// datasetProfileViewstyleDao.update(dpv);
|
|
// DatasetProfileViewstyle n = new DatasetProfileViewstyle();
|
|
// n.setId(dpv.getId());
|
|
// datasetProfile.setViewstyle(n);
|
|
// }
|
|
//
|
|
// datasetProfile.setDataset(null);
|
|
//
|
|
// DatasetProfile createdDatasetProfile = datasetProfileDao.update(datasetProfile);
|
|
// try {
|
|
// return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDatasetProfile));
|
|
// } catch (JsonProcessingException e) {
|
|
// e.printStackTrace();
|
|
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not set dataset profile!\"}");
|
|
// }
|
|
//
|
|
// }
|
|
|
|
|
|
|
|
// @RequestMapping(method = RequestMethod.POST, value = { "/createEmptyDatasetProfile" })
|
|
// public @ResponseBody ResponseEntity<Object> createEmptyDatasetProfile(@RequestParam("datasetID") String datasetID) {
|
|
//
|
|
// DatasetProfileRuleset dpr = new DatasetProfileRuleset();
|
|
// dpr.setLabel("");
|
|
// dpr.setDefinition("");
|
|
// dpr.setId(datasetProfileRulesetDao.create(dpr).getId());
|
|
//
|
|
// DatasetProfileViewstyle dpv = new DatasetProfileViewstyle();
|
|
// dpv.setLabel("");
|
|
// dpv.setDefinition("");
|
|
// dpv.setId(datasetProfileViewstyleDao.create(dpv).getId());
|
|
//
|
|
// DatasetProfile datasetProfile = new DatasetProfile();
|
|
// datasetProfile.setLabel("");
|
|
// datasetProfile.setDefinition("");
|
|
// datasetProfile.setRuleset(dpr);
|
|
// datasetProfile.setViewstyle(dpv);
|
|
//
|
|
// Dataset ds = new Dataset();
|
|
// ds.setId(UUID.fromString(datasetID));
|
|
// Set<Dataset> datasets = new HashSet<Dataset>();
|
|
// datasets.add(ds);
|
|
// datasetProfile.setDataset(datasets);
|
|
//
|
|
// try {
|
|
// datasetProfile = datasetProfileDao.create(datasetProfile);
|
|
// return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(datasetProfile));
|
|
// }
|
|
// catch(Exception e) {
|
|
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("FAILED: reason: "+e.getMessage());
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|