From 40ad3717482a0416fed7ccd154a0345e6d0814d1 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Mon, 24 Sep 2018 21:59:59 +0100 Subject: [PATCH] Removed relational data from JSON serialization. --- .../java/uk/co/neviyn/Observations/core/Observation.java | 6 +++--- .../src/main/java/uk/co/neviyn/Observations/core/Site.java | 6 +++--- .../src/main/java/uk/co/neviyn/Observations/core/Tutor.java | 6 +++--- .../neviyn/Observations/resources/ObservationResource.java | 2 +- .../uk/co/neviyn/Observations/resources/SiteResource.java | 6 +++++- .../uk/co/neviyn/Observations/resources/TutorResource.java | 3 +++ 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/uk/co/neviyn/Observations/core/Observation.java b/backend/src/main/java/uk/co/neviyn/Observations/core/Observation.java index b6d7864..afb3cba 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/core/Observation.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/core/Observation.java @@ -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 tutors; diff --git a/backend/src/main/java/uk/co/neviyn/Observations/core/Site.java b/backend/src/main/java/uk/co/neviyn/Observations/core/Site.java index 7f42e74..88af7f6 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/core/Site.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/core/Site.java @@ -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 tutors; @OneToMany(mappedBy = "site") + @JsonIgnore @EqualsAndHashCode.Exclude private Set observations; } diff --git a/backend/src/main/java/uk/co/neviyn/Observations/core/Tutor.java b/backend/src/main/java/uk/co/neviyn/Observations/core/Tutor.java index e15c3bc..77e87a0 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/core/Tutor.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/core/Tutor.java @@ -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")}, diff --git a/backend/src/main/java/uk/co/neviyn/Observations/resources/ObservationResource.java b/backend/src/main/java/uk/co/neviyn/Observations/resources/ObservationResource.java index 346a5a9..175a33b 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/resources/ObservationResource.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/resources/ObservationResource.java @@ -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(); } diff --git a/backend/src/main/java/uk/co/neviyn/Observations/resources/SiteResource.java b/backend/src/main/java/uk/co/neviyn/Observations/resources/SiteResource.java index 682a67d..e3a6268 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/resources/SiteResource.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/resources/SiteResource.java @@ -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") diff --git a/backend/src/main/java/uk/co/neviyn/Observations/resources/TutorResource.java b/backend/src/main/java/uk/co/neviyn/Observations/resources/TutorResource.java index 2f5f4ff..51c72e2 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/resources/TutorResource.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/resources/TutorResource.java @@ -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); }