Skip to content

Commit

Permalink
Core: include_childs for association lists (#699).
Browse files Browse the repository at this point in the history
All REST APIs: the Core's `JerseyResponseFilter` processes the `fetch_composite` query parameter also for Iterable<Association> responses.

In particular this works for the `GET /core/topic/{id}/related_assocs` request (see #672, see #707).

See #699.
  • Loading branch information
jri committed Oct 3, 2014
1 parent e58427c commit 29264e4
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,20 @@ public ContainerResponse filter(ContainerRequest request, ContainerResponse resp
Object entity = response.getEntity();
boolean includeChilds = getIncludeChilds(request);
if (entity != null) {
// 1) Loading child topics
if (entity instanceof DeepaMehtaObject) {
loadChildTopics((DeepaMehtaObject) entity, includeChilds);
} else if (isIterable(response, DeepaMehtaObject.class)) {
loadChildTopics((Iterable<DeepaMehtaObject>) entity, includeChilds);
}
// 2) Firing PRE_SEND events
if (entity instanceof TopicType) { // Note: must take precedence over topic
firePreSend((TopicType) entity);
} else if (entity instanceof AssociationType) {
firePreSend((AssociationType) entity); // Note: must take precedence over topic
} else if (entity instanceof Topic) {
loadChildTopics((Topic) entity, includeChilds);
firePreSend((Topic) entity);
} else if (entity instanceof Association) {
loadChildTopics((Association) entity, includeChilds);
firePreSend((Association) entity);
} else if (entity instanceof Directives) {
// Note: some plugins rely on the PRE_SEND event in order to enrich updated objects, others don't.
Expand All @@ -62,9 +67,8 @@ public ContainerResponse filter(ContainerRequest request, ContainerResponse resp
} else if (isIterable(response, AssociationType.class)) {
firePreSendAssociationTypes((Iterable<AssociationType>) entity);
} else if (isIterable(response, Topic.class)) {
loadChildTopics((Iterable<Topic>) entity, includeChilds);
firePreSendTopics((Iterable<Topic>) entity);
// ### FIXME: Iterable<Association> responses not yet handled
// ### FIXME: for Iterable<Association> no PRE_SEND_ASSOCIATION events are fired
}
}
//
Expand All @@ -87,10 +91,10 @@ private void loadChildTopics(DeepaMehtaObject object, boolean includeChilds) {
}
}

private void loadChildTopics(Iterable<Topic> topics, boolean includeChilds) {
private void loadChildTopics(Iterable<DeepaMehtaObject> objects, boolean includeChilds) {
if (includeChilds) {
for (Topic topic : topics) {
topic.loadChildTopics();
for (DeepaMehtaObject object : objects) {
object.loadChildTopics();
}
}
}
Expand Down

0 comments on commit 29264e4

Please sign in to comment.