Merge pull request #1553 from mgeiss/MIFOSX-SPM

initial push for spm framework
This commit is contained in:
Adi Narayana Raju
2015-12-02 11:28:44 +05:30
30 changed files with 2559 additions and 169 deletions
+642 -169
View File
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,104 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.api;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.spm.data.LookupTableData;
import org.mifosplatform.spm.domain.LookupTable;
import org.mifosplatform.spm.domain.Survey;
import org.mifosplatform.spm.exception.LookupTableNotFoundException;
import org.mifosplatform.spm.exception.SurveyNotFoundException;
import org.mifosplatform.spm.service.LookupTableService;
import org.mifosplatform.spm.service.SpmService;
import org.mifosplatform.spm.util.LookupTableMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.List;
@Path("/surveys/{surveyId}/lookuptables")
@Component
@Scope("singleton")
public class LookupTableApiResource {
private final PlatformSecurityContext securityContext;
private final SpmService spmService;
private final LookupTableService lookupTableService;
@Autowired
public LookupTableApiResource(final PlatformSecurityContext securityContext,
final SpmService spmService,
final LookupTableService lookupTableService) {
super();
this.securityContext = securityContext;
this.spmService = spmService;
this.lookupTableService = lookupTableService;
}
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public List<LookupTableData> fetchLookupTables(@PathParam("surveyId") final Long surveyId) {
this.securityContext.authenticatedUser();
final Survey survey = findSurvey(surveyId);
final List<LookupTableData> result = new ArrayList<>();
final List<LookupTable> lookupTables = this.lookupTableService.findBySurvey(survey);
if (lookupTables != null) {
for (final LookupTable lookupTable : lookupTables) {
result.add(LookupTableMapper.map(lookupTable));
}
}
return result;
}
@GET
@Path("/{id}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public LookupTableData findLookupTable(@PathParam("surveyId") final Long surveyId,
@PathParam("id") final Long id) {
this.securityContext.authenticatedUser();
findSurvey(surveyId);
final LookupTable lookupTable = this.lookupTableService.findById(id);
if (lookupTable == null) {
throw new LookupTableNotFoundException(id);
}
return LookupTableMapper.map(lookupTable);
}
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public void createLookupTable(@PathParam("surveyId") final Long surveyId,
final LookupTableData lookupTableData) {
this.securityContext.authenticatedUser();
final Survey survey = findSurvey(surveyId);
this.lookupTableService.createLookupTable(LookupTableMapper.map(lookupTableData, survey));
}
private Survey findSurvey(final Long surveyId) {
final Survey survey = this.spmService.findById(surveyId);
if (survey == null) {
throw new SurveyNotFoundException(surveyId);
}
return survey;
}
}
@@ -0,0 +1,105 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.api;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.staff.domain.Staff;
import org.mifosplatform.organisation.staff.domain.StaffRepository;
import org.mifosplatform.organisation.staff.exception.StaffNotFoundException;
import org.mifosplatform.portfolio.client.domain.Client;
import org.mifosplatform.portfolio.client.domain.ClientRepository;
import org.mifosplatform.portfolio.client.exception.ClientNotFoundException;
import org.mifosplatform.spm.data.ScorecardData;
import org.mifosplatform.spm.domain.Scorecard;
import org.mifosplatform.spm.domain.Survey;
import org.mifosplatform.spm.exception.SurveyNotFoundException;
import org.mifosplatform.spm.service.ScorecardService;
import org.mifosplatform.spm.service.SpmService;
import org.mifosplatform.spm.util.ScorecardMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.List;
@Path("/surveys/{surveyId}/scorecards")
@Component
@Scope("singleton")
public class ScorecardApiResource {
private final PlatformSecurityContext securityContext;
private final SpmService spmService;
private final ScorecardService scorecardService;
private final StaffRepository staffRepository;
private final ClientRepository clientRepository;
@Autowired
public ScorecardApiResource(final PlatformSecurityContext securityContext, final SpmService spmService,
final ScorecardService scorecardService, final StaffRepository staffRepository,
final ClientRepository clientRepository) {
super();
this.securityContext = securityContext;
this.spmService = spmService;
this.scorecardService = scorecardService;
this.staffRepository = staffRepository;
this.clientRepository = clientRepository;
}
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public List<ScorecardData> findBySurvey(@PathParam("surveyId") final Long surveyId) {
this.securityContext.authenticatedUser();
final Survey survey = findSurvey(surveyId);
final List<ScorecardData> result = new ArrayList<>();
final List<Scorecard> scorecards = this.scorecardService.findBySurvey(survey);
if (scorecards == null) {
for (final Scorecard scorecard : scorecards) {
result.add(ScorecardMapper.map(scorecard));
}
}
return result;
}
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public void createScorecard(@PathParam("surveyId") final Long surveyId, final ScorecardData scorecardData) {
this.securityContext.authenticatedUser();
final Survey survey = findSurvey(surveyId);
final Staff staff = this.staffRepository.findOne(scorecardData.getStaffId());
if (staff == null) {
throw new StaffNotFoundException(scorecardData.getStaffId());
}
final Client client = this.clientRepository.findOne(scorecardData.getClientId());
if (client == null) {
throw new ClientNotFoundException(scorecardData.getClientId());
}
this.scorecardService.createScorecard(ScorecardMapper.map(scorecardData, survey, staff, client));
}
private Survey findSurvey(final Long surveyId) {
final Survey survey = this.spmService.findById(surveyId);
if (survey == null) {
throw new SurveyNotFoundException(surveyId);
}
return survey;
}
}
@@ -0,0 +1,93 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.api;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.spm.data.SurveyData;
import org.mifosplatform.spm.domain.Survey;
import org.mifosplatform.spm.exception.SurveyNotFoundException;
import org.mifosplatform.spm.service.SpmService;
import org.mifosplatform.spm.util.SurveyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.List;
@Path("/surveys")
@Component
@Scope("singleton")
public class SpmApiResource {
private final PlatformSecurityContext securityContext;
private final SpmService spmService;
@Autowired
public SpmApiResource(final PlatformSecurityContext securityContext,
final SpmService spmService) {
this.securityContext = securityContext;
this.spmService = spmService;
}
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public List<SurveyData> fetchActiveSurveys() {
this.securityContext.authenticatedUser();
final List<SurveyData> result = new ArrayList<>();
final List<Survey> surveys = this.spmService.fetchValidSurveys();
if (surveys != null) {
for (final Survey survey : surveys) {
result.add(SurveyMapper.map(survey));
}
}
return result;
}
@GET
@Path("/{id}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public SurveyData findSurvey(@PathParam("id") final Long id) {
this.securityContext.authenticatedUser();
final Survey survey = this.spmService.findById(id);
if (survey == null) {
throw new SurveyNotFoundException(id);
}
return SurveyMapper.map(survey);
}
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public void createSurvey(final SurveyData surveyData) {
this.securityContext.authenticatedUser();
final Survey survey = SurveyMapper.map(surveyData);
this.spmService.createSurvey(survey);
}
@DELETE
@Path("/{id}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public void deactivateSurvey(@PathParam("id") final Long id) {
this.securityContext.authenticatedUser();
this.spmService.deactivateSurvey(id);
}
}
@@ -0,0 +1,59 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.data;
public class ComponentData {
private String key;
private String text;
private String description;
private Integer sequenceNo;
public ComponentData() {
super();
}
public ComponentData(final String key, final String text,
final String description, final Integer sequenceNo) {
super();
this.key = key;
this.text = text;
this.description = description;
this.sequenceNo = sequenceNo;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getText() {
return text;
}
public void setText(String title) {
this.text = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getSequenceNo() {
return sequenceNo;
}
public void setSequenceNo(Integer sequenceNo) {
this.sequenceNo = sequenceNo;
}
}
@@ -0,0 +1,79 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.data;
public class LookupTableData {
private Long id;
private String key;
private String description;
private Integer valueFrom;
private Integer valueTo;
private Double score;
public LookupTableData() {
super();
}
public LookupTableData(final Long id, final String key, final String description, final Integer valueFrom,
final Integer valueTo, final Double score) {
super();
this.id = id;
this.key = key;
this.description = description;
this.valueFrom = valueFrom;
this.valueTo = valueTo;
this.score = score;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getValueFrom() {
return valueFrom;
}
public void setValueFrom(Integer valueFrom) {
this.valueFrom = valueFrom;
}
public Integer getValueTo() {
return valueTo;
}
public void setValueTo(Integer valueTo) {
this.valueTo = valueTo;
}
public Double getScore() {
return score;
}
public void setScore(Double score) {
this.score = score;
}
}
@@ -0,0 +1,81 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.data;
import java.util.List;
public class QuestionData {
private List<ResponseData> responseDatas;
private String componentKey;
private String key;
private String text;
private String description;
private Integer sequenceNo;
public QuestionData() {
super();
}
public QuestionData(final List<ResponseData> responseDatas, final String componentKey, final String key,
final String text, final String description, final Integer sequenceNo) {
super();
this.responseDatas = responseDatas;
this.componentKey = componentKey;
this.key = key;
this.text = text;
this.description = description;
this.sequenceNo = sequenceNo;
}
public List<ResponseData> getResponseDatas() {
return responseDatas;
}
public void setResponseDatas(List<ResponseData> responseDatas) {
this.responseDatas = responseDatas;
}
public String getComponentKey() {
return componentKey;
}
public void setComponentKey(String componentKey) {
this.componentKey = componentKey;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getSequenceNo() {
return sequenceNo;
}
public void setSequenceNo(Integer sequenceNo) {
this.sequenceNo = sequenceNo;
}
}
@@ -0,0 +1,49 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.data;
public class ResponseData {
private String text;
private Integer value;
private Integer sequenceNo;
public ResponseData() {
super();
}
public ResponseData(final String text, final Integer value,
final Integer sequenceNo) {
super();
this.text = text;
this.value = value;
this.sequenceNo = sequenceNo;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public Integer getSequenceNo() {
return sequenceNo;
}
public void setSequenceNo(Integer sequenceNo) {
this.sequenceNo = sequenceNo;
}
}
@@ -0,0 +1,81 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.data;
import java.util.Date;
public class ScorecardData {
private Long questionId;
private Long responseId;
private Long staffId;
private Long clientId;
private Date createdOn;
private Integer value;
public ScorecardData() {
super();
}
public ScorecardData(final Long questionId, final Long responseId, final Long staffId, final Long clientId,
final Date createdOn, final Integer value) {
super();
this.questionId = questionId;
this.responseId = responseId;
this.staffId = staffId;
this.clientId = clientId;
this.createdOn = createdOn;
this.value = value;
}
public Long getQuestionId() {
return questionId;
}
public void setQuestionId(Long questionId) {
this.questionId = questionId;
}
public Long getResponseId() {
return responseId;
}
public void setResponseId(Long responseId) {
this.responseId = responseId;
}
public Long getStaffId() {
return staffId;
}
public void setStaffId(Long staffId) {
this.staffId = staffId;
}
public Long getClientId() {
return clientId;
}
public void setClientId(Long clientId) {
this.clientId = clientId;
}
public Date getCreatedOn() {
return createdOn;
}
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
}
@@ -0,0 +1,113 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.data;
import java.util.Date;
import java.util.List;
public class SurveyData {
private Long id;
private List<ComponentData> componentDatas;
private List<QuestionData> questionDatas;
private String key;
private String name;
private String description;
private String countryCode;
private Date validFrom;
private Date validTo;
public SurveyData() {
super();
}
public SurveyData(final Long id, final List<ComponentData> componentDatas, final List<QuestionData> questionDatas,
final String key, final String name, final String description, final String countryCode,
final Date validFrom, final Date validTo) {
super();
this.id = id;
this.componentDatas = componentDatas;
this.questionDatas = questionDatas;
this.key = key;
this.name = name;
this.description = description;
this.countryCode = countryCode;
this.validFrom = validFrom;
this.validTo = validTo;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<ComponentData> getComponentDatas() {
return componentDatas;
}
public void setComponentDatas(List<ComponentData> componentDatas) {
this.componentDatas = componentDatas;
}
public List<QuestionData> getQuestionDatas() {
return questionDatas;
}
public void setQuestionDatas(List<QuestionData> questionDatas) {
this.questionDatas = questionDatas;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public Date getValidFrom() {
return validFrom;
}
public void setValidFrom(Date validFrom) {
this.validFrom = validFrom;
}
public Date getValidTo() {
return validTo;
}
public void setValidTo(Date validTo) {
this.validTo = validTo;
}
}
@@ -0,0 +1,75 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.domain;
import org.springframework.data.jpa.domain.AbstractPersistable;
import javax.persistence.*;
@Entity
@Table(name = "m_survey_components")
public class Component extends AbstractPersistable<Long> {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "survey_id")
private Survey survey;
@Column(name = "a_key", length = 32)
private String key;
@Column(name = "a_text", length = 255)
private String text;
@Column(name = "description", length = 4096)
private String description;
@Column(name = "sequence_no", precision = 4)
private Integer sequenceNo;
public Component() {
super();
}
public Survey getSurvey() {
return survey;
}
public void setSurvey(Survey survey) {
this.survey = survey;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getText() {
return text;
}
public void setText(String title) {
this.text = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getSequenceNo() {
return sequenceNo;
}
public void setSequenceNo(Integer sequenceNo) {
this.sequenceNo = sequenceNo;
}
}
@@ -0,0 +1,86 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.domain;
import org.springframework.data.jpa.domain.AbstractPersistable;
import javax.persistence.*;
@Entity
@Table(name = "m_survey_lookup_tables")
public class LookupTable extends AbstractPersistable<Long> {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "survey_id")
private Survey survey;
@Column(name = "a_key", length = 32)
private String key;
@Column(name = "description", length = 4096)
private String description;
@Column(name = "value_from", precision = 4)
private Integer valueFrom;
@Column(name = "value_to", precision = 4)
private Integer valueTo;
@Column(name = "score", precision = 5, scale = 2)
private Double score;
public LookupTable() {
super();
}
public Survey getSurvey() {
return survey;
}
public void setSurvey(Survey survey) {
this.survey = survey;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getValueFrom() {
return valueFrom;
}
public void setValueFrom(Integer valueFrom) {
this.valueFrom = valueFrom;
}
public Integer getValueTo() {
return valueTo;
}
public void setValueTo(Integer valueTo) {
this.valueTo = valueTo;
}
public Double getScore() {
return score;
}
public void setScore(Double score) {
this.score = score;
}
}
@@ -0,0 +1,99 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.domain;
import org.springframework.data.jpa.domain.AbstractPersistable;
import javax.persistence.*;
import java.util.List;
@Entity
@Table(name = "m_survey_questions")
public class Question extends AbstractPersistable<Long> {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "survey_id")
private Survey survey;
@OneToMany(mappedBy = "question", fetch = FetchType.EAGER)
@OrderBy("sequenceNo")
private List<Response> responses;
@Column(name = "component_key", length = 32)
private String componentKey;
@Column(name = "a_key", length = 32)
private String key;
@Column(name = "a_text", length = 255)
private String text;
@Column(name = "description", length = 4096)
private String description;
@Column(name = "sequence_no", precision = 4)
private Integer sequenceNo;
public Question() {
super();
}
public Survey getSurvey() {
return survey;
}
public void setSurvey(Survey survey) {
this.survey = survey;
}
public List<Response> getResponses() {
return responses;
}
public void setResponses(List<Response> responses) {
this.responses = responses;
}
public String getComponentKey() {
return componentKey;
}
public void setComponentKey(String componentKey) {
this.componentKey = componentKey;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getSequenceNo() {
return sequenceNo;
}
public void setSequenceNo(Integer sequenceNo) {
this.sequenceNo = sequenceNo;
}
}
@@ -0,0 +1,64 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.domain;
import org.springframework.data.jpa.domain.AbstractPersistable;
import javax.persistence.*;
@Entity
@Table(name = "m_survey_responses")
public class Response extends AbstractPersistable<Long> {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "question_id")
private Question question;
@Column(name = "a_text", length = 255)
private String text;
@Column(name = "a_value", precision = 4)
private Integer value;
@Column(name = "sequence_no", precision = 4)
private Integer sequenceNo;
public Response() {
super();
}
public Question getQuestion() {
return question;
}
public void setQuestion(Question question) {
this.question = question;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public Integer getSequenceNo() {
return sequenceNo;
}
public void setSequenceNo(Integer sequenceNo) {
this.sequenceNo = sequenceNo;
}
}
@@ -0,0 +1,106 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.domain;
import org.mifosplatform.organisation.staff.domain.Staff;
import org.mifosplatform.portfolio.client.domain.Client;
import org.springframework.data.jpa.domain.AbstractPersistable;
import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name = "m_survey_scorecards")
public class Scorecard extends AbstractPersistable<Long> {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "survey_id")
private Survey survey;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "question_id")
private Question question;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "response_id")
private Response response;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "staff_id")
private Staff staff;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id")
private Client client;
@Column(name = "created_on")
@Temporal(value = TemporalType.TIMESTAMP)
@OrderBy("createdOn DESC")
private Date createdOn;
@Column(name = "a_value", precision = 4)
private Integer value;
public Scorecard() {
super();
}
public Survey getSurvey() {
return survey;
}
public void setSurvey(Survey survey) {
this.survey = survey;
}
public Question getQuestion() {
return question;
}
public void setQuestion(Question question) {
this.question = question;
}
public Response getResponse() {
return response;
}
public void setResponse(Response response) {
this.response = response;
}
public Staff getStaff() {
return staff;
}
public void setStaff(Staff staff) {
this.staff = staff;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public Date getCreatedOn() {
return createdOn;
}
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
}
@@ -0,0 +1,113 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.domain;
import org.springframework.data.jpa.domain.AbstractPersistable;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
@Entity
@Table(name = "m_surveys")
public class Survey extends AbstractPersistable<Long> {
@OneToMany(mappedBy = "survey", fetch = FetchType.EAGER)
@OrderBy("sequenceNo")
private List<Component> components;
@OneToMany(mappedBy = "survey", fetch = FetchType.EAGER)
@OrderBy("sequenceNo")
private List<Question> questions;
@Column(name = "a_key", length = 32)
private String key;
@Column(name = "a_name", length = 255)
private String name;
@Column(name = "description", length = 4096)
private String description;
@Column(name = "country_code", length = 2)
private String countryCode;
@Column(name = "valid_from")
@Temporal(value = TemporalType.TIMESTAMP)
private Date validFrom;
@Column(name = "valid_to")
@Temporal(value = TemporalType.TIMESTAMP)
private Date validTo;
public Survey() {
super();
}
public List<Component> getComponents() {
return components;
}
public void setComponents(List<Component> components) {
this.components = components;
}
public List<Question> getQuestions() {
return questions;
}
public void setQuestions(List<Question> questions) {
this.questions = questions;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public Date getValidFrom() {
return validFrom;
}
public void setValidFrom(Date validFrom) {
this.validFrom = validFrom;
}
public Date getValidTo() {
return validTo;
}
public void setValidTo(Date validTo) {
this.validTo = validTo;
}
}
@@ -0,0 +1,15 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.exception;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
public class LookupTableNotFoundException extends AbstractPlatformResourceNotFoundException {
public LookupTableNotFoundException(final Long id) {
super("error.msg.survey.lookuptable.id.notfound", "Lookup table with id " + id + " not found!", id);
}
}
@@ -0,0 +1,15 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.exception;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
public class SurveyNotFoundException extends AbstractPlatformResourceNotFoundException {
public SurveyNotFoundException(final Long id) {
super("error.msg.survey.id.notfound", "Survey with id " + id + " not found!", id);
}
}
@@ -0,0 +1,17 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.repository;
import org.mifosplatform.spm.domain.LookupTable;
import org.mifosplatform.spm.domain.Survey;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface LookupTableRepository extends JpaRepository<LookupTable, Long> {
List<LookupTable> findBySurvey(final Survey survey);
}
@@ -0,0 +1,19 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.repository;
import org.mifosplatform.portfolio.client.domain.Client;
import org.mifosplatform.spm.domain.Scorecard;
import org.mifosplatform.spm.domain.Survey;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface ScorecardRepository extends JpaRepository<Scorecard, Long> {
List<Scorecard> findBySurvey(final Survey survey);
List<Scorecard> findBySurveyAndClient(final Survey survey, final Client client);
}
@@ -0,0 +1,22 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.repository;
import org.mifosplatform.spm.domain.Survey;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.Date;
import java.util.List;
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);
}
@@ -0,0 +1,48 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.service;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.spm.domain.LookupTable;
import org.mifosplatform.spm.domain.Survey;
import org.mifosplatform.spm.repository.LookupTableRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class LookupTableService {
private final PlatformSecurityContext securityContext;
private final LookupTableRepository lookupTableRepository;
@Autowired
public LookupTableService(final PlatformSecurityContext securityContext,
final LookupTableRepository lookupTableRepository) {
super();
this.securityContext = securityContext;
this.lookupTableRepository = lookupTableRepository;
}
public LookupTable findById(final Long id) {
this.securityContext.authenticatedUser();
return this.lookupTableRepository.findOne(id);
}
public List<LookupTable> findBySurvey(final Survey survey) {
this.securityContext.authenticatedUser();
return this.lookupTableRepository.findBySurvey(survey);
}
public LookupTable createLookupTable(final LookupTable lookupTable) {
this.securityContext.authenticatedUser();
return this.lookupTableRepository.save(lookupTable);
}
}
@@ -0,0 +1,51 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.service;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.client.domain.Client;
import org.mifosplatform.spm.domain.Scorecard;
import org.mifosplatform.spm.domain.Survey;
import org.mifosplatform.spm.repository.ScorecardRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class ScorecardService {
private final PlatformSecurityContext securityContext;
private final ScorecardRepository scorecardRepository;
@Autowired
public ScorecardService(final PlatformSecurityContext securityContext,
final ScorecardRepository scorecardRepository) {
super();
this.securityContext = securityContext;
this.scorecardRepository = scorecardRepository;
}
@Transactional
public Scorecard createScorecard(final Scorecard scorecard) {
this.securityContext.authenticatedUser();
return this.scorecardRepository.save(scorecard);
}
public List<Scorecard> findBySurvey(final Survey survey) {
this.securityContext.authenticatedUser();
return this.scorecardRepository.findBySurvey(survey);
}
public List<Scorecard> findBySurveyAndClient(final Survey survey, final Client client) {
this.securityContext.authenticatedUser();
return this.scorecardRepository.findBySurveyAndClient(survey, client);
}
}
@@ -0,0 +1,100 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.service;
import org.joda.time.DateTime;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.spm.domain.Survey;
import org.mifosplatform.spm.repository.SurveyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
@Service
public class SpmService {
private final PlatformSecurityContext securityContext;
private final SurveyRepository surveyRepository;
@Autowired
public SpmService(final PlatformSecurityContext securityContext,
final SurveyRepository surveyRepository) {
super();
this.securityContext = securityContext;
this.surveyRepository = surveyRepository;
}
public List<Survey> fetchValidSurveys() {
this.securityContext.authenticatedUser();
return this.surveyRepository.fetchActiveSurveys(new Date());
}
public Survey findById(final Long id) {
this.securityContext.authenticatedUser();
return this.surveyRepository.findOne(id);
}
@Transactional
public Survey createSurvey(final Survey survey) {
this.securityContext.authenticatedUser();
final Survey previousSurvey = this.surveyRepository.findByKey(survey.getKey());
if (previousSurvey != null) {
this.deactivateSurvey(previousSurvey.getId());
}
// set valid from to start of today
final DateTime dateTime = DateTime
.now()
.withHourOfDay(0)
.withMinuteOfHour(0)
.withSecondOfMinute(0)
.withMillisOfSecond(0);
survey.setValidFrom(dateTime.toDate());
// set valid from to end in 100 years
dateTime
.withDayOfMonth(31)
.withMonthOfYear(12)
.withHourOfDay(23)
.withMinuteOfHour(59)
.withSecondOfMinute(59)
.withMillisOfSecond(999)
.plusYears(100);
survey.setValidTo(dateTime.toDate());
return this.surveyRepository.save(survey);
}
@Transactional
public void deactivateSurvey(final Long id) {
this.securityContext.authenticatedUser();
final Survey survey = this.surveyRepository.findOne(id);
if (survey != null) {
// set valid to to yesterday night
final DateTime dateTime = DateTime
.now()
.withHourOfDay(23)
.withMinuteOfHour(59)
.withSecondOfMinute(59)
.withMillisOfSecond(999)
.minusDays(1);
survey.setValidTo(dateTime.toDate());
this.surveyRepository.save(survey);
}
}
}
@@ -0,0 +1,36 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.util;
import org.mifosplatform.spm.data.LookupTableData;
import org.mifosplatform.spm.domain.LookupTable;
import org.mifosplatform.spm.domain.Survey;
public class LookupTableMapper {
private LookupTableMapper() {
super();
}
public static LookupTableData map(final LookupTable lookupTable) {
final LookupTableData lookupTableData = new LookupTableData(
lookupTable.getId(), lookupTable.getKey(), lookupTable.getDescription(), lookupTable.getValueFrom(),
lookupTable.getValueFrom(), lookupTable.getScore()
);
return lookupTableData;
}
public static LookupTable map(final LookupTableData lookupTableData, final Survey survey) {
final LookupTable lookupTable = new LookupTable();
lookupTable.setSurvey(survey);
lookupTable.setKey(lookupTableData.getKey());
lookupTable.setDescription(lookupTableData.getDescription());
lookupTable.setValueFrom(lookupTableData.getValueFrom());
lookupTable.setValueTo(lookupTableData.getValueTo());
lookupTable.setScore(lookupTableData.getScore());
return lookupTable;
}
}
@@ -0,0 +1,59 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.util;
import org.mifosplatform.organisation.staff.domain.Staff;
import org.mifosplatform.portfolio.client.domain.Client;
import org.mifosplatform.spm.data.ScorecardData;
import org.mifosplatform.spm.domain.Question;
import org.mifosplatform.spm.domain.Response;
import org.mifosplatform.spm.domain.Scorecard;
import org.mifosplatform.spm.domain.Survey;
import java.util.List;
public class ScorecardMapper {
private ScorecardMapper() {
super();
}
public static ScorecardData map(final Scorecard scorecard) {
final ScorecardData scorecardData = new ScorecardData(
scorecard.getQuestion().getId(), scorecard.getResponse().getId(), scorecard.getStaff().getId(),
scorecard.getClient().getId(), scorecard.getCreatedOn(), scorecard.getValue()
);
return scorecardData;
}
public static Scorecard map(final ScorecardData scorecardData, final Survey survey,
final Staff staff, final Client client) {
final Scorecard scorecard = new Scorecard();
ScorecardMapper.setQuestionAndResponse(scorecardData, scorecard, survey);
scorecard.setStaff(staff);
scorecard.setClient(client);
scorecard.setCreatedOn(scorecardData.getCreatedOn());
scorecard.setValue(scorecardData.getValue());
return scorecard;
}
private static void setQuestionAndResponse(final ScorecardData scorecardData, final Scorecard scorecard,
final Survey survey) {
final List<Question> questions = survey.getQuestions();
for (final Question question : questions) {
if (question.getId().equals(scorecardData.getQuestionId())) {
scorecard.setQuestion(question);
for (final Response response : question.getResponses()) {
if (response.getId().equals(scorecardData.getResponseId())) {
scorecard.setResponse(response);
break;
}
}
break;
}
}
}
}
@@ -0,0 +1,130 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.spm.util;
import org.mifosplatform.spm.data.ComponentData;
import org.mifosplatform.spm.data.QuestionData;
import org.mifosplatform.spm.data.ResponseData;
import org.mifosplatform.spm.data.SurveyData;
import org.mifosplatform.spm.domain.Component;
import org.mifosplatform.spm.domain.Question;
import org.mifosplatform.spm.domain.Response;
import org.mifosplatform.spm.domain.Survey;
import java.util.ArrayList;
import java.util.List;
public class SurveyMapper {
private SurveyMapper() {
super();
}
public static SurveyData map(final Survey survey) {
final SurveyData surveyData = new SurveyData(
survey.getId(), SurveyMapper.mapComponents(survey.getComponents()),
SurveyMapper.mapQuestions(survey.getQuestions()), survey.getKey(), survey.getName(),
survey.getDescription(), survey.getCountryCode(), survey.getValidFrom(), survey.getValidTo()
);
return surveyData;
}
public static Survey map(final SurveyData surveyData) {
final Survey survey = new Survey();
survey.setComponents(SurveyMapper.mapComponentDatas(surveyData.getComponentDatas()));
survey.setQuestions(SurveyMapper.mapQuestionDatas(surveyData.getQuestionDatas(), survey));
survey.setKey(surveyData.getKey());
survey.setName(surveyData.getName());
survey.setDescription(surveyData.getDescription());
survey.setCountryCode(surveyData.getCountryCode());
return survey;
}
private static List<ComponentData> mapComponents(final List<Component> components) {
final List<ComponentData> componentDatas = new ArrayList<>();
if (components != null) {
for (final Component component : components) {
componentDatas.add(new ComponentData(
component.getKey(), component.getText(), component.getDescription(), component.getSequenceNo()
));
}
}
return componentDatas;
}
private static List<Component> mapComponentDatas(final List<ComponentData> componentDatas) {
final List<Component> components = new ArrayList<>();
if (componentDatas != null) {
for (final ComponentData componentData : componentDatas) {
final Component component = new Component();
component.setKey(componentData.getKey());
component.setText(componentData.getText());
component.setDescription(componentData.getDescription());
component.setSequenceNo(componentData.getSequenceNo());
components.add(component);
}
}
return components;
}
private static List<QuestionData> mapQuestions(final List<Question> questions) {
final List<QuestionData> questionDatas = new ArrayList<>();
if (questions != null) {
for (final Question question : questions) {
questionDatas.add(new QuestionData(
SurveyMapper.mapResponses(question.getResponses()), question.getComponentKey(), question.getKey(),
question.getText(), question.getDescription(), question.getSequenceNo()
));
}
}
return questionDatas;
}
private static List<Question> mapQuestionDatas(final List<QuestionData> questionDatas, final Survey survey) {
final List<Question> questions = new ArrayList<>();
if (questionDatas != null) {
for (final QuestionData questionData : questionDatas) {
final Question question = new Question();
question.setSurvey(survey);
question.setComponentKey(questionData.getComponentKey());
question.setResponses(SurveyMapper.mapResponseDatas(questionData.getResponseDatas(), question));
question.setKey(questionData.getKey());
question.setText(questionData.getText());
question.setDescription(question.getDescription());
question.setSequenceNo(questionData.getSequenceNo());
questions.add(question);
}
}
return questions;
}
private static List<ResponseData> mapResponses(final List<Response> responses) {
final List<ResponseData> responseDatas = new ArrayList<>();
if (responses != null) {
for (final Response response : responses) {
responseDatas.add(new ResponseData(
response.getText(), response.getValue(), response.getSequenceNo()
));
}
}
return responseDatas;
}
private static List<Response> mapResponseDatas(final List<ResponseData> responseDatas, final Question question) {
final List<Response> responses = new ArrayList<>();
if (responseDatas != null) {
for (final ResponseData responseData : responseDatas) {
final Response response = new Response();
response.setQuestion(question);
response.setText(responseData.getText());
response.setValue(responseData.getValue());
response.setSequenceNo(responseData.getSequenceNo());
responses.add(response);
}
}
return responses;
}
}
@@ -85,4 +85,5 @@
</property>
</bean>
<import resource="spmContext.xml"/>
</beans>
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this file,
You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<tx:annotation-driven />
<context:component-scan base-package="org.mifosplatform.spm"/>
<jpa:repositories base-package="org.mifosplatform.spm.repository"/>
</beans>
@@ -0,0 +1,72 @@
CREATE TABLE `m_surveys` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`a_key` VARCHAR(32) NOT NULL,
`a_name` VARCHAR(255) NOT NULL,
`description` VARCHAR(4000) NULL,
`country_code` VARCHAR(2) NOT NULL,
`valid_from` DATETIME NULL DEFAULT NULL,
`valid_to` DATETIME NULL DEFAULT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `m_survey_components` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`survey_id` BIGINT(20) NOT NULL,
`a_key` VARCHAR(32) NOT NULL,
`a_text` VARCHAR(255) NOT NULL,
`description` VARCHAR(4000) NULL,
`sequence_no` INT(4) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`survey_id`) REFERENCES `m_surveys` (`id`)
);
CREATE TABLE `m_survey_questions` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`survey_id` BIGINT(20) NOT NULL,
`component_key` VARCHAR(32) NULL,
`a_key` VARCHAR(32) NOT NULL,
`a_text` VARCHAR(255) NOT NULL,
`description` VARCHAR(4000) NULL,
`sequence_no` INT(4) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`survey_id`) REFERENCES `m_surveys` (`id`)
);
CREATE TABLE `m_survey_responses` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`question_id` BIGINT(20) NOT NULL,
`a_text` VARCHAR(255) NOT NULL,
`a_value` INT(4) NOT NULL,
`sequence_no` INT(4) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`question_id`) REFERENCES `m_survey_questions` (`id`)
);
CREATE TABLE `m_survey_lookup_tables` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`survey_id` BIGINT(20) NOT NULL,
`a_key` VARCHAR(255) NOT NULL,
`description` INT(4) NULL,
`value_from` INT(4) NOT NULL,
`value_to` INT(4) NOT NULL,
`score` DECIMAL(5, 2) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`survey_id`) REFERENCES `m_surveys` (`id`)
);
CREATE TABLE `m_survey_scorecards` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`survey_id` BIGINT(20) NOT NULL,
`question_id` BIGINT(20) NOT NULL,
`response_id` BIGINT(20) NOT NULL,
`staff_id` BIGINT(20) NOT NULL,
`client_id` BIGINT(20) NOT NULL,
`created_on` DATETIME NULL DEFAULT NULL,
`a_value` INT(4) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`survey_id`) REFERENCES `m_surveys` (`id`),
FOREIGN KEY (`question_id`) REFERENCES `m_survey_questions` (`id`),
FOREIGN KEY (`response_id`) REFERENCES `m_survey_responses` (`id`),
FOREIGN KEY (`staff_id`) REFERENCES `m_staff` (`id`),
FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`)
);