Changed {lazy/eager} annotations of hibernate fetching...

This commit is contained in:
Nikolaos Laskaris 2017-10-20 18:11:40 +03:00
parent 2364d10c0e
commit 38676904c8
38 changed files with 415 additions and 106 deletions

View File

@ -142,6 +142,13 @@
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate5</artifactId>
<version>2.8.4</version>
</dependency>
<!-- Json <-> XML transformations -->

View File

@ -14,6 +14,9 @@ public interface DMPDao extends Dao<DMP, UUID> {
List<IDLabelPair> listAllIDsLabels();
List<DMP> listUserDMPs(String username);
// public boolean createFromForm();

View File

@ -11,6 +11,7 @@ import org.hibernate.query.Query;
import dao.JpaDao;
import entities.DMP;
import entities.UserInfo;
import entities.responses.IDLabelPair;
public class DMPDaoImpl extends JpaDao<DMP, UUID> implements DMPDao {
@ -39,6 +40,23 @@ public class DMPDaoImpl extends JpaDao<DMP, UUID> implements DMPDao {
.collect(Collectors.toList());
}
@Override
public List<DMP> listUserDMPs(String username) {
// String queryString = "select ui from UserInfo ui join UserAuth ui.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"

View File

@ -20,10 +20,14 @@ import javax.persistence.Table;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@ -31,14 +35,15 @@ import com.fasterxml.jackson.databind.SerializationFeature;
@Entity
@Table(name="\"DMP\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class DMP implements Serializable {
private static final long serialVersionUID = -8263056535208547615L;
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@ -55,10 +60,11 @@ public class DMP implements Serializable {
@Column(name = "\"Version\"")
private Integer version;
@OneToOne(mappedBy = "dmp", fetch = FetchType.EAGER)
private Dataset dataset;
@OneToMany(mappedBy = "dmp", fetch = FetchType.LAZY)
private Set<Dataset> dataset;
@OneToOne(fetch = FetchType.EAGER)
@ManyToOne()
@JoinColumn(name = "\"Project\"")
private Project project;
@ -67,12 +73,12 @@ public class DMP implements Serializable {
@Column(name = "\"ProfileData\"", columnDefinition = "xml", nullable = true)
private String profileData;
@OneToOne(fetch = FetchType.EAGER)
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Profile\"")
private DMPProfile profile;
@OneToMany(fetch = FetchType.EAGER)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"DMPOrganisation\"",
joinColumns={@JoinColumn(name="\"DMP\"", referencedColumnName="\"ID\"")},
inverseJoinColumns={@JoinColumn(name="\"Organisation\"", referencedColumnName="\"ID\"")}
@ -80,7 +86,7 @@ public class DMP implements Serializable {
private Set<Organisation> organisations;
@OneToMany(fetch = FetchType.EAGER)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"DMPResearcher\"",
joinColumns={@JoinColumn(name="\"DMP\"", referencedColumnName="\"ID\"")},
inverseJoinColumns={@JoinColumn(name="\"Researcher\"", referencedColumnName="\"ID\"")}
@ -88,7 +94,7 @@ public class DMP implements Serializable {
private Set<Researcher> researchers;
@OneToMany(fetch = FetchType.EAGER)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"UserDMP\"",
joinColumns={@JoinColumn(name="dmp", referencedColumnName="\"ID\"")},
inverseJoinColumns={@JoinColumn(name="usr", referencedColumnName="id")}
@ -161,11 +167,11 @@ public class DMP implements Serializable {
this.profile = profile;
}
public Dataset getDataset() {
public Set<Dataset> getDataset() {
return dataset;
}
public void setDataset(Dataset dataset) {
public void setDataset(Set<Dataset> dataset) {
this.dataset = dataset;
}

View File

@ -11,15 +11,20 @@ import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"DMPOrganisation\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class DMPOrganisation implements Serializable {

View File

@ -14,15 +14,20 @@ import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"DMPProfile\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class DMPProfile implements Serializable {
private static final long serialVersionUID = 3213099144442689808L;
@ -37,7 +42,7 @@ public class DMPProfile implements Serializable {
private UUID id;
@OneToOne(fetch = FetchType.EAGER, mappedBy = "profile")
@OneToOne(fetch = FetchType.LAZY, mappedBy = "profile")
private DMP dmp;

View File

@ -11,15 +11,20 @@ import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"DMPResearcher\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class DMPResearcher implements Serializable {
private static final long serialVersionUID = 135449857355252959L;

View File

@ -18,14 +18,19 @@ import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"DataRepository\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class DataRepository implements Serializable {

View File

@ -13,20 +13,26 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity(name = "Dataset")
@Table(name="\"Dataset\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class Dataset implements Serializable {
private static final long serialVersionUID = 3575723814399553259L;
@ -44,7 +50,7 @@ public class Dataset implements Serializable {
private String label;
@OneToOne(fetch = FetchType.EAGER)
@ManyToOne(fetch = FetchType.EAGER)
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "\"DMP\"", nullable = true)
private DMP dmp;
@ -58,12 +64,13 @@ public class Dataset implements Serializable {
private String properties;
@OneToOne(fetch = FetchType.EAGER)
@ManyToOne(fetch = FetchType.EAGER)
//@Cascade(value=org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "\"Profile\"", nullable = true)
private DatasetProfile profile;
@OneToMany(fetch = FetchType.EAGER)
@JoinTable(name="\"DatasetDataRepository\"",
joinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")},

View File

@ -11,15 +11,20 @@ import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"DatasetDataRepository\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class DatasetDataRepository implements Serializable {

View File

@ -2,6 +2,7 @@ package entities;
import java.io.Serializable;
import java.util.Set;
import java.util.UUID;
import javax.persistence.CascadeType;
@ -11,6 +12,7 @@ import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@ -20,13 +22,16 @@ import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"DatasetProfile\"")
//@Proxy(lazy = false)
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class DatasetProfile implements Serializable {
@ -44,8 +49,13 @@ public class DatasetProfile implements Serializable {
@Column(name = "\"Label\"")
private String label;
@OneToOne(fetch = FetchType.EAGER, mappedBy = "profile")
private Dataset dataset;
// @OneToOne(fetch = FetchType.EAGER, mappedBy = "profile")
// private Dataset dataset;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "profile")
private Set<Dataset> dataset;
@OneToOne(fetch = FetchType.EAGER)
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
@ -105,11 +115,13 @@ public class DatasetProfile implements Serializable {
this.definition = definition;
}
public Dataset getDataset() {
public Set<Dataset> getDataset() {
return dataset;
}
public void setDataset(Dataset dataset) {
public void setDataset(Set<Dataset> dataset) {
this.dataset = dataset;
}

View File

@ -14,17 +14,22 @@ import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import org.json.JSONObject;
import org.json.XML;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"DatasetProfileRuleset\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class DatasetProfileRuleset implements Serializable {
private static final long serialVersionUID = 4249565129050898613L;

View File

@ -14,16 +14,21 @@ import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import org.json.XML;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"DatasetProfileViewstyle\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class DatasetProfileViewstyle implements Serializable {
private static final long serialVersionUID = -3251295258160291468L;

View File

@ -11,15 +11,20 @@ import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"DatasetRegistry\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class DatasetRegistry implements Serializable {
private static final long serialVersionUID = -5594183793725819187L;

View File

@ -11,15 +11,20 @@ import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"DatasetService\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class DatasetService implements Serializable {
private static final long serialVersionUID = 1469161193939096037L;

View File

@ -17,15 +17,20 @@ import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"Organisation\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class Organisation implements Serializable {
@ -58,7 +63,7 @@ public class Organisation implements Serializable {
private String definition;
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"DMPOrganisation\"",
joinColumns={@JoinColumn(name="\"Organisation\"", referencedColumnName="\"ID\"")},
inverseJoinColumns={@JoinColumn(name="\"DMP\"", referencedColumnName="\"ID\"")}

View File

@ -16,10 +16,13 @@ import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@ -27,6 +30,8 @@ import com.fasterxml.jackson.databind.SerializationFeature;
@Entity
@Table(name="\"Project\"")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class Project implements Serializable {
@ -42,8 +47,8 @@ public class Project implements Serializable {
private UUID id;
@OneToOne(fetch = FetchType.EAGER, mappedBy = "project")
private DMP dmp;
@OneToMany(mappedBy = "project")
private Set<DMP> dmps;
@Column(name = "\"Label\"")
@ -112,14 +117,16 @@ public class Project implements Serializable {
}
public DMP getDMP() {
return dmp;
public Set<DMP> getDmps() {
return dmps;
}
public void setDMP(DMP dmp) {
this.dmp = dmp;
public void setDmps(Set<DMP> dmps) {
this.dmps = dmps;
}
public String toString() {
try {
return new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).writeValueAsString(this).replace("\"", "&quot;");
@ -129,4 +136,5 @@ public class Project implements Serializable {
}
}

View File

@ -17,15 +17,20 @@ import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"Registry\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class Registry implements Serializable {
private static final long serialVersionUID = -277572262583178090L;
@ -57,7 +62,7 @@ public class Registry implements Serializable {
private String definition;
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
@OneToMany(fetch = FetchType.EAGER)
@JoinTable(name="\"DatasetRegistry\"",
joinColumns={@JoinColumn(name="\"Registry\"", referencedColumnName="\"ID\"")},
inverseJoinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")}

View File

@ -17,15 +17,20 @@ import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"Researcher\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class Researcher implements Serializable {
@ -58,7 +63,7 @@ public class Researcher implements Serializable {
private String reference;
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"DMPResearcher\"",
joinColumns={@JoinColumn(name="\"Researcher\"", referencedColumnName="\"ID\"")},
inverseJoinColumns={@JoinColumn(name="\"DMP\"", referencedColumnName="\"ID\"")}

View File

@ -19,15 +19,20 @@ import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"Service\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class Service implements Serializable {
private static final long serialVersionUID = 7243446610500174060L;

View File

@ -10,19 +10,23 @@ import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"UserDMP\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class UserDMP implements Serializable{
private static final long serialVersionUID = -4467370784003784660L;
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")

View File

@ -19,17 +19,22 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import entities.security.UserAuth;
@Entity
@Table(name="\"UserInfo\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class UserInfo implements Serializable{
private static final long serialVersionUID = 1225151430484658395L;
@ -73,7 +78,7 @@ public class UserInfo implements Serializable{
@Column(name = "additionalinfo", columnDefinition = "xml", nullable = true)
private String additionalinfo;
@OneToMany(fetch = FetchType.EAGER)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"UserDMP\"",
joinColumns={@JoinColumn(name="usr", referencedColumnName="id")},
inverseJoinColumns={@JoinColumn(name="dmp", referencedColumnName="\"ID\"")}

View File

@ -9,9 +9,18 @@ import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"UserAuth\"")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class UserAuth {
@Id

View File

@ -0,0 +1,22 @@
package helpers;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;
public class SerializerProvider {
private static ObjectMapper objectMapper = new ObjectMapper()
// .setSerializationInclusion(Include.NON_NULL)
// .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(new Hibernate5Module())
;
public static ObjectMapper getJsonSerializer() {
return objectMapper;
}
}

View File

@ -2,6 +2,7 @@ package helpers;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.springframework.util.MultiValueMap;
@ -80,6 +81,9 @@ public class Transformers {
ds.setRegistries(new HashSet<Registry>(Arrays.asList(reg)));
ds.setServices(new HashSet<Service>(Arrays.asList(ser)));
Set<Dataset> datasets = new HashSet<Dataset>();
datasets.add(ds);
DMP dmp = new DMP();
dmp.setLabel(formData.getFirst("DMP.label"));
@ -90,7 +94,7 @@ public class Transformers {
dmp.setProfileData(formData.getFirst("DMP.profileData"));
dmp.setProject(project);
dmp.setVersion(Integer.parseInt(formData.getFirst("DMP.version")));
dmp.setDataset(ds);
dmp.setDataset(datasets);
System.out.println(dmp);

View File

@ -1,18 +1,15 @@
package rest.entities;
import java.io.Console;
import java.util.List;
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.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
@ -22,7 +19,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.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mchange.v2.sql.filter.SynchronizedFilterDataSource;
@ -38,13 +37,16 @@ import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import dao.entities.UserInfoDao;
import entities.DMP;
import entities.DMPProfile;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.Project;
import entities.UserInfo;
import entities.responses.IDLabelPair;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@ -65,9 +67,11 @@ public class DMPs {
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private UserInfoDao userInfoDao;
private ObjectMapper objectMapper = new ObjectMapper();
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// FETCH BY DMP(S)
@ -75,20 +79,26 @@ public class DMPs {
public @ResponseBody ResponseEntity<Object> listDMPs(){
try {
List<UUID> allIDs = dMPDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@Transactional
@RequestMapping(method = RequestMethod.GET, value = { "/dmps/{id}" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getDMP(@PathVariable("id") String id){
try {
System.out.println("Trying for id: "+ id);
DMP dmp = dMPDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(dmp));
System.out.println("tried, got : "+ dmp.getId());
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(dmp));
// return ResponseEntity.status(HttpStatus.OK).body(dmp);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@ -97,13 +107,36 @@ public class DMPs {
public @ResponseBody ResponseEntity<Object> listDmpLabelID(){
try {
List<IDLabelPair> allIDLabels = dMPDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDLabels));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDLabels));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/ofuser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> getDmpsOfUser(){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
try {
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(userInfo.getDmps()));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@ -112,6 +145,7 @@ public class DMPs {
*/
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getAllDMPs(){
try {
List<DMP> allDMPs = dMPDao.getAll();
@ -136,7 +170,6 @@ public class DMPs {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setDMP(@RequestBody DMP dmp) {
ObjectMapper objectMapper = new ObjectMapper();
DMP createdDmp = dMPDao.update(dmp);
try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDmp));
@ -146,7 +179,7 @@ public class DMPs {
}
/*
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/set/full" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setFullDMP(@RequestBody DMP dmp) {
@ -231,6 +264,8 @@ public class DMPs {
}
*/
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody DMP dmp) {
@ -249,7 +284,7 @@ public class DMPs {
/*
// OLD ONES, USED BY THE EMBEDDED (simple) UI OF THIS SERVICE
@RequestMapping(method = RequestMethod.POST, value = { "/setDMPByForm" }, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces="text/plain")
public @ResponseBody ResponseEntity<Object> setDMPByForm(@RequestBody MultiValueMap<String,String> formData) {
@ -267,6 +302,7 @@ public class DMPs {
dmp.getDataset().getProfile().getViewstyle().setDefinition(formData.getFirst("DatasetProfileViewStyle.definition"));
return setDMP(dmp);
}
*/

View File

@ -47,6 +47,7 @@ import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@ -69,7 +70,7 @@ public class DataRepositories {
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE DATAREPOSITORy(IES)
@ -77,7 +78,7 @@ public class DataRepositories {
public @ResponseBody ResponseEntity<Object> listDataRepositories(){
try {
List<UUID> allIDs = dataRepositoryDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -89,7 +90,7 @@ public class DataRepositories {
public @ResponseBody ResponseEntity<Object> getDataRepository(@PathVariable("id") String id) {
try {
DataRepository dataRepository = dataRepositoryDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(dataRepository));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(dataRepository));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());

View File

@ -2,7 +2,9 @@ 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;
@ -48,6 +50,7 @@ import entities.DatasetProfileRuleset;
import entities.DatasetProfileViewstyle;
import entities.Organisation;
import entities.Project;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@ -69,7 +72,7 @@ public class Datasets {
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// FETCH BY DATASET(S)
@ -78,7 +81,7 @@ public class Datasets {
public @ResponseBody ResponseEntity<Object> listDatasets(){
try {
List<UUID> allIDs = datasetDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -90,7 +93,7 @@ public class Datasets {
public @ResponseBody ResponseEntity<Object> getDataset(@PathVariable("id") String id) {
try {
Dataset ds = datasetDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(ds));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(ds));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -226,7 +229,7 @@ public class Datasets {
public @ResponseBody ResponseEntity<Object> getDatasetProfile(@PathVariable("id") String id) {
try {
DatasetProfile profile = datasetProfileDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(profile));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(profile));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -300,11 +303,13 @@ public class Datasets {
Dataset ds = new Dataset();
ds.setId(UUID.fromString(datasetID));
datasetProfile.setDataset(ds);
Set<Dataset> datasets = new HashSet<Dataset>();
datasets.add(ds);
datasetProfile.setDataset(datasets);
try {
datasetProfile = datasetProfileDao.create(datasetProfile);
return ResponseEntity.status(HttpStatus.CREATED).body(new ObjectMapper().writeValueAsString(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());

View File

@ -48,6 +48,7 @@ import entities.Registry;
import entities.Researcher;
import entities.Service;
import entities.responses.IDLabelPair;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@ -69,7 +70,7 @@ public class DmpProfiles {
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE DMPPROFILE(S)
@ -77,7 +78,7 @@ public class DmpProfiles {
public @ResponseBody ResponseEntity<Object> listDmpProfiles(){
try {
List<UUID> allIDs = dMPProfileDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -91,7 +92,7 @@ public class DmpProfiles {
public @ResponseBody ResponseEntity<Object> getDmpProfile(@PathVariable("id") String id) {
try {
DMPProfile dmpProfile = dMPProfileDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(dmpProfile));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(dmpProfile));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -104,7 +105,7 @@ public class DmpProfiles {
public @ResponseBody ResponseEntity<Object> listLabelIds(){
try {
List<IDLabelPair> allIDs = dMPProfileDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());

View File

@ -47,6 +47,7 @@ import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@ -69,7 +70,7 @@ public class Organisations {
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE ORGANISATIONS(S)
@ -77,7 +78,7 @@ public class Organisations {
public @ResponseBody ResponseEntity<Object> listOrganisations(){
try {
List<UUID> allIDs = organisationDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -89,7 +90,7 @@ public class Organisations {
public @ResponseBody ResponseEntity<Object> getOrganisations(@PathVariable("id") String id) {
try {
Organisation organisation = organisationDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(organisation));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(organisation));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());

View File

@ -21,8 +21,11 @@ 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.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;
import dao.entities.DMPDao;
import dao.entities.DMPProfileDao;
@ -48,6 +51,7 @@ import entities.Registry;
import entities.Researcher;
import entities.Service;
import entities.responses.IDLabelPair;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@ -70,7 +74,7 @@ public class Projects {
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE PROJECT(S)
@ -78,7 +82,7 @@ public class Projects {
public @ResponseBody ResponseEntity<Object> listProjects(){
try {
List<UUID> allIDs = projectDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -89,7 +93,10 @@ public class Projects {
public @ResponseBody ResponseEntity<Object> getProject(@PathVariable("id") String id) {
try {
Project project = projectDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(project));
System.out.println(project.getId().toString());
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(project));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -101,7 +108,7 @@ public class Projects {
public @ResponseBody ResponseEntity<Object> listLabelIds(){
try {
List<IDLabelPair> allIDs = projectDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());

View File

@ -47,6 +47,7 @@ import entities.Registry;
import entities.Researcher;
import entities.Service;
import entities.responses.IDLabelPair;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@ -69,7 +70,7 @@ public class Registries {
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE REGISTRY(IES)
@ -77,7 +78,7 @@ public class Registries {
public @ResponseBody ResponseEntity<Object> listRegistries(){
try {
List<UUID> allIDs = registryDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -89,7 +90,7 @@ public class Registries {
public @ResponseBody ResponseEntity<Object> getRegistries(@PathVariable("id") String id) {
try {
Registry registry = registryDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(registry));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(registry));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());

View File

@ -47,6 +47,7 @@ import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@ -69,7 +70,7 @@ public class Researchers {
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE RESEARCHER(S)
@ -77,7 +78,7 @@ public class Researchers {
public @ResponseBody ResponseEntity<Object> listResearchers(){
try {
List<UUID> allIDs = researcherDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -89,7 +90,7 @@ public class Researchers {
public @ResponseBody ResponseEntity<Object> getResearchers(@PathVariable("id") String id) {
try {
Researcher researcher = researcherDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(researcher));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(researcher));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -100,7 +101,7 @@ public class Researchers {
public @ResponseBody ResponseEntity<Object> getResearcherByEmail(@RequestParam("email") String email){
try {
Researcher researcher = researcherDao.getResearcherByEmail(email);
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(researcher));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(researcher));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());

View File

@ -47,6 +47,7 @@ import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@ -69,7 +70,7 @@ public class Services {
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE SERVICE(S)

View File

@ -0,0 +1,83 @@
package rest.entities;
import java.util.List;
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.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 helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@RestController
@CrossOrigin
public class Users {
@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 = SerializerProvider.getJsonSerializer();
}

View File

@ -52,9 +52,9 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
throw new AuthenticationServiceException("Token validation failed - Not a valid token");
}
// if reached this point, authentication is ok, so return just an instance with whatever.
return new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), new ArrayList<>());
// if reached this point, authentication is ok, so return just an instance where the principal is the UserInfo ID
//(to have it at the webservices calls - it's ESSENTIAL) while the password can be whatever...
return new UsernamePasswordAuthenticationToken(userInfo.getId(), authentication.getCredentials(), new ArrayList<>());
}
else

View File

@ -55,6 +55,8 @@
<prop key="hibernate.hbm2ddl.auto">${persistence.hibernate.hbm2dll}</prop>
<prop key="hibernate.dialect">${persistence.hibernate.dialect}</prop>
<prop key="hibernate.enable_lazy_load_no_trans">true</prop> <!-- USE WITH CAUTION -->
<prop key="hibernate.jdbc.batch_size">${persistence.hibernate.jdbc.batch_size}</prop>
<prop key="hibernate.order_inserts">${persistence.hibernate.order_inserts}</prop>
<prop key="hibernate.order_updates">${persistence.hibernate.order_updates}</prop>

View File

@ -67,22 +67,22 @@
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/spring-security.xml</param-value>
<!-- <param-value>/WEB-INF/applicationContext.xml</param-value> -->
<!-- <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/spring-security.xml</param-value> -->
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<!-- THIS FILTER IS FOR SPRING SECURITY -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/rest/*</url-pattern>
</filter-mapping>
<!-- <filter> -->
<!-- <filter-name>springSecurityFilterChain</filter-name> -->
<!-- <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> -->
<!-- </filter> -->
<!-- <filter-mapping> -->
<!-- <filter-name>springSecurityFilterChain</filter-name> -->
<!-- <url-pattern>/rest/*</url-pattern> -->
<!-- </filter-mapping> -->