Removed relational data from JSON serialization.

This commit is contained in:
neviyn 2018-09-24 21:59:59 +01:00
parent 4aa20221f0
commit 40ad371748
6 changed files with 18 additions and 11 deletions

View File

@ -1,8 +1,7 @@
package uk.co.neviyn.Observations.core;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.*;
import org.joda.time.DateTime;
@ -17,7 +16,6 @@ import java.util.Set;
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Observation implements Serializable {
@NonNull
@ -28,10 +26,12 @@ public class Observation implements Serializable {
@ManyToOne
@JoinColumn(name="site_id", nullable=false)
@JsonIgnore
@EqualsAndHashCode.Exclude
private Site site;
@ManyToMany(mappedBy = "observations")
@JsonIgnore
@EqualsAndHashCode.Exclude
private Set<Tutor> tutors;

View File

@ -1,8 +1,7 @@
package uk.co.neviyn.Observations.core;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.*;
import javax.persistence.*;
@ -15,7 +14,6 @@ import java.util.Set;
@NoArgsConstructor
@Builder
@AllArgsConstructor
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Site implements Serializable {
@NonNull
@ -29,10 +27,12 @@ public class Site implements Serializable {
private String name;
@OneToMany(mappedBy="site")
@JsonIgnore
@EqualsAndHashCode.Exclude
private Set<Tutor> tutors;
@OneToMany(mappedBy = "site")
@JsonIgnore
@EqualsAndHashCode.Exclude
private Set<Observation> observations;
}

View File

@ -1,8 +1,7 @@
package uk.co.neviyn.Observations.core;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.*;
import javax.persistence.*;
@ -15,7 +14,6 @@ import java.util.Set;
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Tutor implements Serializable {
@NonNull
@ -30,10 +28,12 @@ public class Tutor implements Serializable {
@ManyToOne
@JoinColumn(name="site_id", nullable=false)
@JsonIgnore
@EqualsAndHashCode.Exclude
private Site site;
@ManyToMany
@JsonIgnore
@JoinTable(
name = "TUTOR_OBSERVATION",
joinColumns = { @JoinColumn(name = "tutor_id")},

View File

@ -53,7 +53,7 @@ public class ObservationResource {
t.getObservations().add(observation);
}
observation = dao.persist(observation);
log.info("Created observation with ID " + observation.getId() + " at " + DateTime.now().toString());
log.info("Created observation with ID " + observation.getId());
return observation.getId();
}

View File

@ -3,6 +3,7 @@ package uk.co.neviyn.Observations.resources;
import io.dropwizard.auth.Auth;
import io.dropwizard.hibernate.UnitOfWork;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import uk.co.neviyn.Observations.api.SelectOption;
import uk.co.neviyn.Observations.core.Site;
import uk.co.neviyn.Observations.core.User;
@ -16,6 +17,7 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
@Produces(MediaType.APPLICATION_JSON)
@Path("/site")
@Slf4j
public class SiteResource {
private final SiteDao dao;
@ -23,7 +25,9 @@ public class SiteResource {
@POST
@UnitOfWork
public Site add(@Auth User user, String name) {
return dao.persist(Site.builder().name(name).build());
Site site = dao.persist(Site.builder().name(name).build());
log.info("Created site '" + site.getName() + "' with id " + site.getId());
return site;
}
@Path("/all")

View File

@ -7,6 +7,7 @@ import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import uk.co.neviyn.Observations.core.Observation;
import uk.co.neviyn.Observations.core.Site;
import uk.co.neviyn.Observations.core.Tutor;
@ -23,6 +24,7 @@ import java.util.Set;
@RequiredArgsConstructor
@Produces(MediaType.APPLICATION_JSON)
@Path("/tutor")
@Slf4j
public class TutorResource {
private final TutorDao dao;
@ -34,6 +36,7 @@ public class TutorResource {
final Site site = siteDao.get(newTutor.siteId);
final Tutor tutor = Tutor.builder().name(newTutor.name).site(site).build();
site.getTutors().add(tutor);
log.info("Created tutor '" + tutor.getName() + "' with id " + tutor.getId() + " at site " + site.getId());
return dao.persist(tutor);
}