Skip to content

Commit

Permalink
changed fetch type, edited API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Geiss committed Dec 14, 2015
1 parent c50a45b commit 4444a8a
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 96 deletions.
156 changes: 80 additions & 76 deletions api-docs/apiLive.htm
Original file line number Diff line number Diff line change
Expand Up @@ -37724,24 +37724,24 @@ <h3>Create a Survey</h3>
"countryCode":"KE",
"validFrom":null,
"validTo":null,
"components":
"componentDatas":
[
{
"key":"Household",
"text":"Information about the household."
"text":"Information about the household.",
"description":null,
"sequenceNo":1
}
]
"questions":
],
"questionDatas":
[
{
"componentKey":"Household",
"key":"Familiy members",
"text":"How many persons live in the household?"
"text":"How many persons live in the household?",
"description":null,
"sequenceNo":1,
"responses":
"responseDatas":
[
{
"text":"1 to 3",
Expand All @@ -37761,7 +37761,8 @@ <h3>Create a Survey</h3>
]
}
]
} </code>
}
</code>
<code class="method-response">
200 OK
</code>
Expand All @@ -37784,50 +37785,52 @@ <h3>List all Surveys</h3>
<code class="method-response">
[
{
"id":1
"key":"ppi-kenya-2010",
"name":"PPI Survey for Kenya, version 2010",
"description":null,
"countryCode":"KE",
"validFrom":"2015-11-25T00:00:00.000Z",
"validTo":"2115-12-31T23:59:59.999Z",
"components":
[
"id": 1,
"componentDatas": [
{
"key":"Household",
"text":"Information about the household."
"description":null,
"sequenceNo":1
"id": 1,
"key": "Household",
"text": "Information about the household.",
"description": null,
"sequenceNo": 1
}
]
"questions":
[
],
"questionDatas": [
{
"componentKey":"Household",
"key":"Familiy members",
"text":"How many persons live in the household?"
"description":null,
"sequenceNo":1,
"responses":
[
"id": 1,
"responseDatas": [
{
"text":"1 to 3",
"value":1,
"sequenceNo":1
"id": 1,
"text": "1 to 3",
"value": 1,
"sequenceNo": 1
},
{
"text":"3 to 7",
"value":5,
"sequenceNo":2
"id": 2,
"text": "3 to 7",
"value": 5,
"sequenceNo": 2
},
{
"text":"more than 7",
"value":13,
"sequenceNo":3
"id": 3,
"text": "more than 7",
"value": 13,
"sequenceNo": 3
}
]
],
"componentKey": "Household",
"key": "Familiy members",
"text": "How many persons live in the household?",
"description": null,
"sequenceNo": 1
}
]
],
"key": "ppi-kenya-2010",
"name": "PPI Survey for Kenya, version 2010",
"description": null,
"countryCode": "KE",
"validFrom": 1450047600000,
"validTo": 4607276399000
}
]
</code>
Expand All @@ -37849,52 +37852,53 @@ <h3>Retrieve a Survey</h3>
</code>
<code class="method-response">
{
"id":1
"key":"ppi-kenya-2010",
"name":"PPI Survey for Kenya, version 2010",
"description":null,
"countryCode":"KE",
"validFrom":"2015-11-25T00:00:00.000Z",
"validTo":"2115-12-31T23:59:59.999Z",
"components":
[
"id": 1,
"componentDatas": [
{
"key":"Household",
"text":"Information about the household."
"description":null,
"sequenceNo":1
"id": 1,
"key": "Household",
"text": "Information about the household.",
"description": null,
"sequenceNo": 1
}
]
"questions":
[
],
"questionDatas": [
{
"componentKey":"Household",
"key":"Familiy members",
"text":"How many persons live in the household?"
"description":null,
"sequenceNo":1,
"responses":
[
"id": 1,
"responseDatas": [
{
"text":"1 to 3",
"value":1,
"sequenceNo":1
"id": 1,
"text": "1 to 3",
"value": 1,
"sequenceNo": 1
},
{
"text":"3 to 7",
"value":5,
"sequenceNo":2
"id": 2,
"text": "3 to 7",
"value": 5,
"sequenceNo": 2
},
{
"text":"more than 7",
"value":13,
"sequenceNo":3
"id": 3,
"text": "more than 7",
"value": 13,
"sequenceNo": 3
}
]
],
"componentKey": "Household",
"key": "Familiy members",
"text": "How many persons live in the household?",
"description": null,
"sequenceNo": 1
}
]
],
"key": "ppi-kenya-2010",
"name": "PPI Survey for Kenya, version 2010",
"description": null,
"countryCode": "KE",
"validFrom": 1450047600000,
"validTo": 4607276399000
}

</code>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
Expand All @@ -38,6 +39,7 @@ public SpmApiResource(final PlatformSecurityContext securityContext,
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Transactional
public List<SurveyData> fetchActiveSurveys() {
this.securityContext.authenticatedUser();

Expand All @@ -58,6 +60,7 @@ public List<SurveyData> fetchActiveSurveys() {
@Path("/{id}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Transactional
public SurveyData findSurvey(@PathParam("id") final Long id) {
this.securityContext.authenticatedUser();

Expand All @@ -73,6 +76,7 @@ public SurveyData findSurvey(@PathParam("id") final Long id) {
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Transactional
public void createSurvey(final SurveyData surveyData) {
this.securityContext.authenticatedUser();

Expand All @@ -85,6 +89,7 @@ public void createSurvey(final SurveyData surveyData) {
@Path("/{id}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Transactional
public void deactivateSurvey(@PathParam("id") final Long id) {
this.securityContext.authenticatedUser();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

public class ComponentData {

private Long id;
private String key;
private String text;
private String description;
Expand All @@ -16,15 +17,20 @@ public ComponentData() {
super();
}

public ComponentData(final String key, final String text,
public ComponentData(final Long id, final String key, final String text,
final String description, final Integer sequenceNo) {
super();
this.id = id;
this.key = key;
this.text = text;
this.description = description;
this.sequenceNo = sequenceNo;
}

public Long getId() {
return id;
}

public String getKey() {
return key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public class QuestionData {

private Long id;
private List<ResponseData> responseDatas;
private String componentKey;
private String key;
Expand All @@ -20,9 +21,10 @@ public QuestionData() {
super();
}

public QuestionData(final List<ResponseData> responseDatas, final String componentKey, final String key,
public QuestionData(final Long id, final List<ResponseData> responseDatas, final String componentKey, final String key,
final String text, final String description, final Integer sequenceNo) {
super();
this.id = id;
this.responseDatas = responseDatas;
this.componentKey = componentKey;
this.key = key;
Expand All @@ -31,6 +33,10 @@ public QuestionData(final List<ResponseData> responseDatas, final String compone
this.sequenceNo = sequenceNo;
}

public Long getId() {
return id;
}

public List<ResponseData> getResponseDatas() {
return responseDatas;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

public class ResponseData {

private Long id;
private String text;
private Integer value;
private Integer sequenceNo;
Expand All @@ -15,14 +16,19 @@ public ResponseData() {
super();
}

public ResponseData(final String text, final Integer value,
public ResponseData(final Long id, final String text, final Integer value,
final Integer sequenceNo) {
super();
this.id = id;
this.text = text;
this.value = value;
this.sequenceNo = sequenceNo;
}

public Long getId() {
return id;
}

public String getText() {
return text;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Question extends AbstractPersistable<Long> {
@JoinColumn(name = "survey_id")
private Survey survey;

@OneToMany(mappedBy = "question", fetch = FetchType.EAGER)
@OneToMany(mappedBy = "question", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@OrderBy("sequenceNo")
private List<Response> responses;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
@Table(name = "m_surveys")
public class Survey extends AbstractPersistable<Long> {

@OneToMany(mappedBy = "survey", fetch = FetchType.EAGER)
@OneToMany(mappedBy = "survey", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@OrderBy("sequenceNo")
private List<Component> components;

@OneToMany(mappedBy = "survey", fetch = FetchType.EAGER)
@OneToMany(mappedBy = "survey", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@OrderBy("sequenceNo")
private List<Question> questions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public interface SurveyRepository extends JpaRepository<Survey, Long> {
@Query("select s from Survey s where :pointInTime between s.validFrom and s.validTo")
List<Survey> fetchActiveSurveys(@Param("pointInTime") final Date pointInTime);

Survey findByKey(final String key);
@Query("select s from Survey s where s.key = :key and :pointInTime between s.validFrom and s.validTo")
Survey findByKey(@Param("key") final String key, @Param("pointInTime") final Date pointInTime);
}
Loading

0 comments on commit 4444a8a

Please sign in to comment.