Commit 092f1bad authored by Matija Obreza's avatar Matija Obreza
Browse files

Updated JSON serialization

- Minimize JSON response, ignore properties, use views
parent 4dda87bc
......@@ -21,6 +21,7 @@ import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys2.server.api.ApiBaseController;
......@@ -42,6 +43,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.HandlerMapping;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.Api;
/**
......@@ -71,6 +74,7 @@ public class AccessionController {
* @return the subset
*/
@GetMapping(value = "/{UUID:\\w{8}\\-\\w{4}.+}", produces = { MediaType.APPLICATION_JSON_VALUE })
@JsonView({ JsonViews.Protected.class })
public Accession getByUuid(@PathVariable("UUID") final UUID uuid) {
return accessionService.getByUuid(uuid);
}
......@@ -83,6 +87,7 @@ public class AccessionController {
* @return the subset
*/
@RequestMapping(value = "/10.{dummy:[0-9]+}/**", method=RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
@JsonView({ JsonViews.Protected.class })
public Accession getByDoi(HttpServletRequest request) {
final String fullpath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
final String doi = fullpath.substring(API_BASE.length()+1);
......@@ -104,6 +109,7 @@ public class AccessionController {
* @throws IOException
*/
@PostMapping(value = "/list", produces = { MediaType.APPLICATION_JSON_VALUE })
@JsonView({ JsonViews.Public.class })
public FilteredPage<Accession> list(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
......
......@@ -104,7 +104,7 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
@ManyToOne(cascade = {}, optional = true)
@JoinColumn(name = "orgCtyId", nullable = true)
@JsonView({ JsonViews.Minimal.class })
@JsonView({ JsonViews.Public.class })
private Country countryOfOrigin;
@Column(name = "sampStat", length = 3)
......
......@@ -92,7 +92,7 @@ public class Country extends BasicModel {
*/
@Lob
@Type(type = "org.hibernate.type.TextType")
@JsonView({ JsonViews.Public.class })
@JsonView({ JsonViews.Internal.class })
private String nameL;
@Lob
......@@ -106,7 +106,7 @@ public class Country extends BasicModel {
@ManyToOne(cascade = {}, optional = true)
@JoinColumn(name = "replacedBy")
@JsonView({ JsonViews.Public.class })
@JsonView({ JsonViews.Internal.class })
private Country replacedBy;
public Country() {
......
......@@ -40,10 +40,12 @@ import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys2.server.model.GlobalVersionedAuditedModel;
import org.hibernate.annotations.Type;
......@@ -70,6 +72,7 @@ public class Crop extends GlobalVersionedAuditedModel implements AclAwareModel {
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "cropname", joinColumns = @JoinColumn(name = "cropId", referencedColumnName = "id"), uniqueConstraints = { @UniqueConstraint(columnNames = "otherName") })
@OrderBy("otherName")
@JsonView({ JsonViews.Public.class })
private List<String> otherNames;
@Column(nullable = false, length = 200)
......@@ -81,6 +84,7 @@ public class Crop extends GlobalVersionedAuditedModel implements AclAwareModel {
@Lob
@Type(type = "org.hibernate.type.TextType")
@JsonView({ JsonViews.Internal.class })
private String i18n;
/**
......
......@@ -84,7 +84,7 @@ public class FaoInstitute extends BasicModel implements GeoReferencedEntity, Acl
@ManyToOne(cascade = {}, optional = true)
@JoinColumn(name = "countryId")
@JsonView({ JsonViews.Minimal.class })
@JsonView({ JsonViews.Public.class })
private Country country;
@JsonView({ JsonViews.Protected.class })
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment