Changes
This commit is contained in:
parent
f169394f07
commit
f203c807db
|
@ -15,10 +15,6 @@ public interface DMPDao extends Dao<DMP, UUID> {
|
|||
|
||||
List<IDLabelPair> listAllIDsLabels();
|
||||
|
||||
List<DMP> listUserDMPs(String userID);
|
||||
|
||||
|
||||
// public boolean createFromForm();
|
||||
|
||||
|
||||
}
|
|
@ -41,29 +41,6 @@ public class DMPDaoImpl extends JpaDao<DMP, UUID> implements DMPDao {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DMP> listUserDMPs(String userID) {
|
||||
|
||||
// String queryString = "select ui from UserInfo ui join UserAuth ui.authentication ua where ua.username=:username";
|
||||
|
||||
String queryString = "select ui from UserInfo ui join Project ui.pro.authentication ua where ua.username=:username";
|
||||
|
||||
|
||||
// TypedQuery<UserInfo> typedQuery = entityManager.createQuery(queryString, UserInfo.class);
|
||||
// typedQuery.setParameter("username", username);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// @Override
|
||||
// public boolean createFromForm(Map<String,String> keyVals) {
|
||||
// String query = "insert into DMP () values"
|
||||
// return false;
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -14,5 +14,6 @@ public interface DatasetDao extends Dao<Dataset, UUID> {
|
|||
|
||||
List<IDLabelPair> listAllIDsLabels();
|
||||
|
||||
List<Dataset> getDatasetsOfDmp(UUID dmpID);
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package dao.entities;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -38,5 +39,14 @@ public class DatasetDaoImpl extends JpaDao<Dataset, UUID> implements DatasetDao
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dataset> getDatasetsOfDmp(UUID dmpID) {
|
||||
String queryString = "FROM Dataset dataset where dataset.dmp.id=:dmpID";
|
||||
Query query = (Query) entityManager.createQuery(queryString);
|
||||
query.setParameter("dmpID", dmpID);
|
||||
List<Dataset> datasets = (List<Dataset>) query.getResultList();
|
||||
return datasets;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ public class DMP implements Serializable {
|
|||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
public String toString() {
|
||||
try {
|
||||
return new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).writeValueAsString(this);
|
||||
|
@ -200,4 +200,6 @@ public class DMP implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -28,14 +28,14 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
|
||||
@Entity(name = "Dataset")
|
||||
@Entity
|
||||
@Table(name="\"Dataset\"")
|
||||
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
|
||||
public class Dataset implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3575723814399553259L;
|
||||
|
||||
//public Dataset () {}
|
||||
public Dataset () {}
|
||||
|
||||
|
||||
@Id
|
||||
|
@ -67,7 +67,9 @@ public class Dataset implements Serializable {
|
|||
@JoinColumn(name = "\"Profile\"", nullable = true)
|
||||
private DatasetProfile profile;
|
||||
|
||||
|
||||
@Type(type="typedefinition.XMLType")
|
||||
@Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true)
|
||||
private String reference;
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY)
|
||||
@JoinTable(name="\"DatasetDataRepository\"",
|
||||
|
@ -182,5 +184,19 @@ public class Dataset implements Serializable {
|
|||
public void setDataRepositories(Set<DataRepository> dataRepositories) {
|
||||
this.dataRepositories = dataRepositories;
|
||||
}
|
||||
|
||||
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package helpers;
|
||||
|
||||
import entities.DMP;
|
||||
import entities.Dataset;
|
||||
|
||||
public class SafeCleanAttribs {
|
||||
|
||||
|
||||
public static void clean(Dataset dataset) {
|
||||
DMP dmp = dataset.getDmp();
|
||||
if(dmp!=null) {
|
||||
DMP newdmp = new DMP();
|
||||
newdmp.setId(dmp.getId());
|
||||
dataset.setDmp(newdmp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7,9 +7,11 @@ import java.util.stream.Collectors;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -30,11 +32,11 @@ public class SerializerProvider {
|
|||
|
||||
public static void initialize() {
|
||||
Hibernate5Module module = new Hibernate5Module();
|
||||
module.enable(Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS);
|
||||
//module.enable(Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS);
|
||||
objectMapper = new ObjectMapper()
|
||||
// .setSerializationInclusion(Include.NON_NULL)
|
||||
// .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
.registerModule(new Hibernate5Module())
|
||||
//.setSerializationInclusion(Include.NON_NULL)
|
||||
//.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
.registerModule(module)
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -147,6 +147,10 @@ public class DMPs {
|
|||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/update" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseEntity<Object> updateDMP(@RequestBody DMP dmp) {
|
||||
|
||||
DMP previousDmp = dMPDao.read(dmp.getId());
|
||||
addForeignElems(previousDmp, dmp);
|
||||
|
||||
try {
|
||||
DMP updatedDMP = dMPDao.update(dmp);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(updatedDMP));
|
||||
|
@ -250,7 +254,7 @@ public class DMPs {
|
|||
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/getdatasets" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseEntity<Object> getDatasetsOfDMP(@RequestBody DMP dmp) {
|
||||
try {
|
||||
Set<Dataset> datasets = dMPDao.read(dmp.getId()).getDataset();
|
||||
List<Dataset> datasets = datasetDao.getDatasetsOfDmp(dmp.getId());
|
||||
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(datasets));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not get datasets of DMP!\"");
|
||||
|
@ -306,7 +310,7 @@ public class DMPs {
|
|||
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/createofuser" }, produces="text/plain")
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/createofuser" }, produces="text/plain", consumes = "application/json")
|
||||
public @ResponseBody ResponseEntity<Object> createDmpOfUser(@RequestBody DMP dmp){
|
||||
|
||||
|
||||
|
@ -382,5 +386,13 @@ public class DMPs {
|
|||
|
||||
|
||||
|
||||
private static void addForeignElems(DMP existing, DMP newone) {
|
||||
newone.setDataset(existing.getDataset());
|
||||
newone.setOrganisations(existing.getOrganisations());
|
||||
newone.setResearchers(existing.getResearchers());
|
||||
newone.setUsers(existing.getUsers());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
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;
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ import entities.DatasetProfileRuleset;
|
|||
import entities.DatasetProfileViewstyle;
|
||||
import entities.Organisation;
|
||||
import entities.Project;
|
||||
import helpers.SafeCleanAttribs;
|
||||
import helpers.SerializerProvider;
|
||||
import helpers.Transformers;
|
||||
import responses.RestResponse;
|
||||
|
@ -92,6 +93,7 @@ public class Datasets {
|
|||
public @ResponseBody ResponseEntity<Object> getDataset(@PathVariable("id") String id) {
|
||||
try {
|
||||
Dataset ds = datasetDao.read(UUID.fromString(id));
|
||||
ds.setDmp(ds.getDmp());
|
||||
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(ds));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
|
@ -118,7 +120,7 @@ public class Datasets {
|
|||
}
|
||||
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/create" }, consumes = "application/json")
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/create" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseEntity<Object> createDataset(@RequestBody Dataset dataset) {
|
||||
|
||||
dataset.setId(null);
|
||||
|
@ -133,13 +135,21 @@ public class Datasets {
|
|||
}
|
||||
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/update" }, consumes = "application/json")
|
||||
public @ResponseBody ResponseEntity<Object> updateDataset(@RequestBody Dataset dataset) {
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/update" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseEntity<Object> updateDataset(@RequestBody String datasetJson) {
|
||||
|
||||
Dataset dataset;
|
||||
try {
|
||||
dataset = SerializerProvider.fromJson(datasetJson, Dataset.class);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update Dataset! Reason: " + e.getMessage());
|
||||
}
|
||||
|
||||
SafeCleanAttribs.clean(dataset);
|
||||
|
||||
try {
|
||||
dataset = datasetDao.update(dataset);
|
||||
RestResponse rr = new RestResponse("Updated dataset with id: "+dataset.toString(), dataset.getId().toString());
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(rr.toString());
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(dataset));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -149,8 +159,6 @@ public class Datasets {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/delete" }, consumes = "application/json")
|
||||
public @ResponseBody ResponseEntity<Object> deleteDataset(@RequestBody Dataset dataset) {
|
||||
|
||||
|
@ -208,5 +216,8 @@ public class Datasets {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -210,7 +210,7 @@ public class Projects {
|
|||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/project/createofuser" }, produces="text/plain")
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/project/createofuser" }, produces="text/plain", consumes = "application/json")
|
||||
public @ResponseBody ResponseEntity<Object> createProjectOfUser(@RequestBody Project project){
|
||||
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import dao.entities.RegistryDao;
|
|||
import dao.entities.ResearcherDao;
|
||||
import dao.entities.ServiceDao;
|
||||
import dao.entities.UserInfoDao;
|
||||
import entities.DMP;
|
||||
import entities.DatasetProfile;
|
||||
import entities.DatasetProfileRuleset;
|
||||
import entities.DatasetProfileViewstyle;
|
||||
|
@ -160,7 +161,7 @@ public class TestRest {
|
|||
|
||||
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void testUserProject() {
|
||||
|
||||
// System.out.println(projectsService.listProjects().getBody());
|
||||
|
@ -186,15 +187,33 @@ public class TestRest {
|
|||
|
||||
}
|
||||
|
||||
// @Test
|
||||
//@Test
|
||||
public void testDmpUser() {
|
||||
|
||||
System.out.println(dmpsService.getDmpsOfUser().getBody());
|
||||
// System.out.println(dmpsService.getDmpsOfUser());
|
||||
|
||||
DMP dmp = new DMP();
|
||||
dmp.setId(UUID.fromString("52239f0e-4460-4459-a393-bffcb833f39d"));
|
||||
|
||||
System.out.println(dmpsService.getDatasetsOfDMP(dmp).getBody());
|
||||
|
||||
assertEquals("aaa", "aaa");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDataset() {
|
||||
|
||||
System.out.println(datasetsService.getAllDatasets().getBody());
|
||||
|
||||
// System.out.println(dmpsService.getDatasetsOfDMP(dmp).getBody());
|
||||
|
||||
assertEquals("aaa", "aaa");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue