minor changes

This commit is contained in:
satyr 2017-10-18 02:26:27 +03:00
parent 5863ad4e16
commit deb527eef0
3 changed files with 69 additions and 24 deletions

View File

@ -39,7 +39,7 @@ public class DatasetProfileRuleset implements Serializable {
private UUID id;
@OneToOne(fetch = FetchType.EAGER, mappedBy = "ruleset", cascade = CascadeType.ALL)
@OneToOne(fetch = FetchType.EAGER, mappedBy = "ruleset")
private DatasetProfile datasetProfile;

View File

@ -38,7 +38,7 @@ public class DatasetProfileViewstyle implements Serializable {
private UUID id;
@OneToOne(fetch = FetchType.EAGER, mappedBy = "viewstyle", cascade = CascadeType.ALL)
@OneToOne(fetch = FetchType.EAGER, mappedBy = "viewstyle")
private DatasetProfile datasetProfile;
@Column(name = "\"Label\"")

View File

@ -1,8 +1,12 @@
package rest.entities;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;
import java.util.UUID;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@ -18,7 +22,9 @@ 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;
@ -34,9 +40,11 @@ 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.Project;
import helpers.Transformers;
import responses.RestResponse;
@ -59,7 +67,7 @@ public class Datasets {
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
// FETCH BY DATASET(S)
@ -211,37 +219,74 @@ public class Datasets {
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/setDatasetProfile" }, consumes = "application/json")
//@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/set" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setDatasetProfile(@RequestBody DatasetProfile datasetProfile) {
String reason = "";
DatasetProfile storedDatasetProfile = null;
//try first to create
System.out.println("inside setDatasetProfile");
try {
storedDatasetProfile = datasetProfileDao.create(datasetProfile);
return ResponseEntity.status(HttpStatus.CREATED).body(new ObjectMapper().writeValueAsString(storedDatasetProfile));
System.out.println(objectMapper.writeValueAsString(datasetProfile));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
catch(Exception e) {
reason += e.getMessage();
//try updating
try {
storedDatasetProfile = datasetProfileDao.update(datasetProfile);
return ResponseEntity.status(HttpStatus.CREATED).body(new ObjectMapper().writeValueAsString(storedDatasetProfile));
}
catch(Exception ex) {
reason += (System.lineSeparator()+e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("An error occurred! Reason: " + reason);
}
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) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not set dataset profile!\"}");
}
}
/*
@RequestMapping(method = RequestMethod.GET, value = { "/createEmptyDatasetProfile" })
public @ResponseBody ResponseEntity<Object> createEmptyDatasetProfile() {
@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));
datasetProfile.setDataset(ds);
try {
datasetProfile = datasetProfileDao.create(datasetProfile);
return ResponseEntity.status(HttpStatus.CREATED).body(new ObjectMapper().writeValueAsString(datasetProfile));
@ -250,7 +295,7 @@ public class Datasets {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("FAILED: reason: "+e.getMessage());
}
}
*/