是否允许 crnk 子关系过滤?
crnk subrelation filtering allowed?
我们将 crnk 用于 json-api 服务器端和客户端实现。
jpa 绑定的服务器实现是否支持子关系过滤器?
我们想过滤所有在特定开始时间之后有事件的系列。
我们分离了 json-api 和 JPA 实体 类。请参阅下面的 json-api 作为实体 类
例如我使用的url(由crnk客户端代码生成):
EpgShow?include[EpgShow]=titles&filter[EpgShow][titles.startTime][GE]=2018-05-04T12:30:22+02:00
我们收到的错误是:
{
errors: [
{
status: "500",
title: "INTERNAL_SERVER_ERROR",
detail: "failed to resolve path [titles, startTime]"
}
]
}
Class 实施:
@JsonApiResource(type = "EpgShow")
public class EpgSeriesDto {
@JsonApiId
private Integer serieId;
@JsonApiRelation(opposite = "epgShow", lookUp = LookupIncludeBehavior.AUTOMATICALLY_WHEN_NULL, serialize = SerializeType.ONLY_ID, repositoryBehavior = RelationshipRepositoryBehavior.FORWARD_OWNER)
private Set<EpgTitleDto> titles;
}
@JsonApiResource(type = "EpgTitle")
@Data
public class EpgTitleDto {
@JsonApiId
private Long id;
@JsonApiRelation(opposite = "titles", lookUp = LookupIncludeBehavior.AUTOMATICALLY_WHEN_NULL, serialize = SerializeType.ONLY_ID)
private EpgSeriesDto epgShow;
}
@Entity
public class Serie {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "serie_id", unique = true, nullable = false)
private Integer serieId;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "epgShow")
private Set<Event> titles = new HashSet<Event>(0);
}
@Entity
public class Event {
@Column(name = "start_time")
private ZonedDateTime startTime;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "serie_id")
private Serie epgShow;
}
共有三种不同的过滤器:
- 过滤包含的关系(但不是 requested/main 资源)
- 基于位于单值关系上的属性过滤请求资源类型。
- 基于位于多值关系上的属性过滤请求资源类型。
前两个支持,暂时不支持直接最后一个。对于后者,到目前为止它支持 "computed" 属性,其中值是从 Criteria API 或 QueryDSL 表达式派生的,它允许任意复杂的 SQL。那些又可以 return 再次得到一个可以过滤和排序的简单结果。在此示例中,这可能是主要资源上的 minStartTime 和 maxStartTime。
但如果需要,也可以添加对过滤多值关系的支持。一种可能性是使用 EXISTS 子查询。或者更高级的可能支持不同的策略。欢迎在这方面提出 PR。
我们将 crnk 用于 json-api 服务器端和客户端实现。
jpa 绑定的服务器实现是否支持子关系过滤器?
我们想过滤所有在特定开始时间之后有事件的系列。
我们分离了 json-api 和 JPA 实体 类。请参阅下面的 json-api 作为实体 类
例如我使用的url(由crnk客户端代码生成):
EpgShow?include[EpgShow]=titles&filter[EpgShow][titles.startTime][GE]=2018-05-04T12:30:22+02:00
我们收到的错误是:
{
errors: [
{
status: "500",
title: "INTERNAL_SERVER_ERROR",
detail: "failed to resolve path [titles, startTime]"
}
]
}
Class 实施:
@JsonApiResource(type = "EpgShow")
public class EpgSeriesDto {
@JsonApiId
private Integer serieId;
@JsonApiRelation(opposite = "epgShow", lookUp = LookupIncludeBehavior.AUTOMATICALLY_WHEN_NULL, serialize = SerializeType.ONLY_ID, repositoryBehavior = RelationshipRepositoryBehavior.FORWARD_OWNER)
private Set<EpgTitleDto> titles;
}
@JsonApiResource(type = "EpgTitle")
@Data
public class EpgTitleDto {
@JsonApiId
private Long id;
@JsonApiRelation(opposite = "titles", lookUp = LookupIncludeBehavior.AUTOMATICALLY_WHEN_NULL, serialize = SerializeType.ONLY_ID)
private EpgSeriesDto epgShow;
}
@Entity
public class Serie {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "serie_id", unique = true, nullable = false)
private Integer serieId;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "epgShow")
private Set<Event> titles = new HashSet<Event>(0);
}
@Entity
public class Event {
@Column(name = "start_time")
private ZonedDateTime startTime;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "serie_id")
private Serie epgShow;
}
共有三种不同的过滤器:
- 过滤包含的关系(但不是 requested/main 资源)
- 基于位于单值关系上的属性过滤请求资源类型。
- 基于位于多值关系上的属性过滤请求资源类型。
前两个支持,暂时不支持直接最后一个。对于后者,到目前为止它支持 "computed" 属性,其中值是从 Criteria API 或 QueryDSL 表达式派生的,它允许任意复杂的 SQL。那些又可以 return 再次得到一个可以过滤和排序的简单结果。在此示例中,这可能是主要资源上的 minStartTime 和 maxStartTime。
但如果需要,也可以添加对过滤多值关系的支持。一种可能性是使用 EXISTS 子查询。或者更高级的可能支持不同的策略。欢迎在这方面提出 PR。