Merge pull request #1582 from mgeiss/MIFOSX-SPM-3
retrofitted SPM API to ease the usage
This commit is contained in:
+205
-49
@@ -4007,12 +4007,12 @@ Successful transaction response:
|
||||
<div class="method-description">
|
||||
<h3>Self Service API Overview</h3>
|
||||
<p>
|
||||
Self Service APIs are a set of APIs with restricted data scope. Functional specifications and design can be viewed
|
||||
<a href="https://mifosforge.jira.com/wiki/display/MIFOSX/Customer+Self+Service">here</a>.
|
||||
Self Service APIs are a set of APIs with restricted data scope. Functional specifications and design can be viewed
|
||||
<a href="https://mifosforge.jira.com/wiki/display/MIFOSX/Customer+Self+Service">here</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
While creating an <a href="#users_create">user</a>, user can be tagged as self service user. Also you can associate
|
||||
While creating an <a href="#users_create">user</a>, user can be tagged as self service user. Also you can associate
|
||||
clients that this user has access to. Data scope is restricted to these linked clients.
|
||||
</p>
|
||||
<p>
|
||||
@@ -11812,7 +11812,7 @@ Request Body:
|
||||
<tr>
|
||||
<td class=fielddesc>contains exception data for variations(modifiedinstallments,newinstallments and deletedinstallments described below) </td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
<p>Exception object fields</p>
|
||||
<p>Modifiedinstallments Array fields</p>
|
||||
@@ -12239,7 +12239,7 @@ Request Body:
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a id="loans_update_variations" name="loans_update_variations" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
@@ -12346,8 +12346,8 @@ Request Body:
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<a id="loans_delete_variations" name="loans_delete_variations" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
@@ -12382,10 +12382,10 @@ Request Body:
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- End Loan Term variations-->
|
||||
</div>
|
||||
|
||||
|
||||
<!-- End Loan Term variations-->
|
||||
<!-- start of offices content -->
|
||||
<a id="offices" name="offices" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
@@ -38826,11 +38826,30 @@ POST surveys/1/lookuptables
|
||||
Content-Type: application/json
|
||||
Request Body:
|
||||
{
|
||||
"key":"lookup-table-1",
|
||||
"description":null,
|
||||
"valueFrom":0,
|
||||
"valueTo":5,
|
||||
"score":100.00
|
||||
"key": "test-table",
|
||||
"description": null,
|
||||
"entries": [
|
||||
{
|
||||
"valueFrom": 0,
|
||||
"valueTo": 25,
|
||||
"score": 100
|
||||
},
|
||||
{
|
||||
"valueFrom": 26,
|
||||
"valueTo": 50,
|
||||
"score": 50
|
||||
},
|
||||
{
|
||||
"valueFrom": 51,
|
||||
"valueTo": 75,
|
||||
"score": 25
|
||||
},
|
||||
{
|
||||
"valueFrom": 76,
|
||||
"valueTo": 100,
|
||||
"score": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
</code>
|
||||
<code class="method-response">
|
||||
@@ -38856,12 +38875,30 @@ No Request Body
|
||||
<code class="method-response">
|
||||
[
|
||||
{
|
||||
"id":1
|
||||
"key":"lookup-table-1",
|
||||
"description":null,
|
||||
"valueFrom":0,
|
||||
"valueTo":5,
|
||||
"score":100.00
|
||||
"key": "test-table",
|
||||
"description": null,
|
||||
"entries": [
|
||||
{
|
||||
"valueFrom": 0,
|
||||
"valueTo": 25,
|
||||
"score": 100
|
||||
},
|
||||
{
|
||||
"valueFrom": 26,
|
||||
"valueTo": 50,
|
||||
"score": 50
|
||||
},
|
||||
{
|
||||
"valueFrom": 51,
|
||||
"valueTo": 75,
|
||||
"score": 25
|
||||
},
|
||||
{
|
||||
"valueFrom": 76,
|
||||
"valueTo": 100,
|
||||
"score": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
</code>
|
||||
@@ -38878,18 +38915,36 @@ No Request Body
|
||||
GET https://DomainName/api/v1/surveys/1/lookuptables/1
|
||||
</code>
|
||||
<code class="method-request">
|
||||
GET surveys/1/lookuptables/1
|
||||
GET surveys/1/lookuptables/test-table
|
||||
Content-Type: application/json
|
||||
No Request Body
|
||||
</code>
|
||||
<code class="method-response">
|
||||
{
|
||||
"id":1,
|
||||
"key":"lookup-table-1",
|
||||
"description":null,
|
||||
"valueFrom":0,
|
||||
"valueTo":5,
|
||||
"score":100.00
|
||||
"key": "test-table",
|
||||
"description": null,
|
||||
"entries": [
|
||||
{
|
||||
"valueFrom": 0,
|
||||
"valueTo": 25,
|
||||
"score": 100
|
||||
},
|
||||
{
|
||||
"valueFrom": 26,
|
||||
"valueTo": 50,
|
||||
"score": 50
|
||||
},
|
||||
{
|
||||
"valueFrom": 51,
|
||||
"valueTo": 75,
|
||||
"score": 25
|
||||
},
|
||||
{
|
||||
"valueFrom": 76,
|
||||
"valueTo": 100,
|
||||
"score": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
@@ -38918,13 +38973,63 @@ POST surveys/1/scorecards
|
||||
Content-Type: application/json
|
||||
Request Body:
|
||||
{
|
||||
"questionId":1,
|
||||
"responseId":1,
|
||||
"staffId":1,
|
||||
"clientId":1,
|
||||
"createdOn":"2015-11-26T09:50:34.647Z"
|
||||
}
|
||||
</code>
|
||||
"staffId": 1,
|
||||
"clientId": 1,
|
||||
"createdOn": 1451905784553,
|
||||
"scorecardValues":
|
||||
[
|
||||
{
|
||||
"questionId": 1,
|
||||
"responseId": 1,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"questionId": 2,
|
||||
"responseId": 8,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"questionId": 3,
|
||||
"responseId": 12,
|
||||
"value": 7
|
||||
},
|
||||
{
|
||||
"questionId": 4,
|
||||
"responseId": 16,
|
||||
"value": 4
|
||||
},
|
||||
{
|
||||
"questionId": 5,
|
||||
"responseId": 21,
|
||||
"value": 2
|
||||
},
|
||||
{
|
||||
"questionId": 6,
|
||||
"responseId": 25,
|
||||
"value": 2
|
||||
},
|
||||
{
|
||||
"questionId": 7,
|
||||
"responseId": 28,
|
||||
"value": 3
|
||||
},
|
||||
{
|
||||
"questionId": 8,
|
||||
"responseId": 30,
|
||||
"value": 6
|
||||
},
|
||||
{
|
||||
"questionId": 9,
|
||||
"responseId": 33,
|
||||
"value": 4
|
||||
},
|
||||
{
|
||||
"questionId": 10,
|
||||
"responseId": 37,
|
||||
"value": 7
|
||||
}
|
||||
]
|
||||
} </code>
|
||||
<code class="method-response">
|
||||
200 OK
|
||||
</code>
|
||||
@@ -38947,19 +39052,70 @@ No Request Body
|
||||
</code>
|
||||
<code class="method-response">
|
||||
[
|
||||
{
|
||||
"questionId":1,
|
||||
"responseId":1,
|
||||
"staffId":1,
|
||||
"clientId":1,
|
||||
"createdOn":"2015-11-26T09:50:34.647Z"
|
||||
}
|
||||
{
|
||||
"staffId": 1,
|
||||
"clientId": 1,
|
||||
"createdOn": 1451905784553,
|
||||
"scorecardValues":
|
||||
[
|
||||
{
|
||||
"questionId": 1,
|
||||
"responseId": 1,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"questionId": 2,
|
||||
"responseId": 8,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"questionId": 3,
|
||||
"responseId": 12,
|
||||
"value": 7
|
||||
},
|
||||
{
|
||||
"questionId": 4,
|
||||
"responseId": 16,
|
||||
"value": 4
|
||||
},
|
||||
{
|
||||
"questionId": 5,
|
||||
"responseId": 21,
|
||||
"value": 2
|
||||
},
|
||||
{
|
||||
"questionId": 6,
|
||||
"responseId": 25,
|
||||
"value": 2
|
||||
},
|
||||
{
|
||||
"questionId": 7,
|
||||
"responseId": 28,
|
||||
"value": 3
|
||||
},
|
||||
{
|
||||
"questionId": 8,
|
||||
"responseId": 30,
|
||||
"value": 6
|
||||
},
|
||||
{
|
||||
"questionId": 9,
|
||||
"responseId": 33,
|
||||
"value": 4
|
||||
},
|
||||
{
|
||||
"questionId": 10,
|
||||
"responseId": 37,
|
||||
"value": 7
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end of SPM API docs -->
|
||||
|
||||
|
||||
<!-- Customer Self Service APIs-->
|
||||
<div class="method-section">
|
||||
<div class="method-description">
|
||||
@@ -39029,7 +39185,7 @@ No Request Body
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<a id="selfoauth" name="selfoauth" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
<div class="method-description">
|
||||
@@ -39199,7 +39355,7 @@ GET https://DomainName/api/v1/self/clients
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<a id="selfclient" name="selfclient" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
<div class="method-description">
|
||||
@@ -39387,8 +39543,8 @@ GET https://DomainName/api/v1/self/clients/{clientId}/accounts
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<a id="selfclientsimages" name="selfclientsimages"
|
||||
class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
@@ -40729,7 +40885,7 @@ No Request Body:
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- end of Customer Self Service APIs-->
|
||||
</div>
|
||||
<!-- main-content-wrapper -->
|
||||
|
||||
+13
-12
@@ -17,10 +17,12 @@ 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 org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Path("/surveys/{surveyId}/lookuptables")
|
||||
@@ -45,46 +47,45 @@ public class LookupTableApiResource {
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Transactional
|
||||
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 LookupTableMapper.map(lookupTables);
|
||||
}
|
||||
|
||||
return result;
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
@Path("/{key}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Transactional
|
||||
public LookupTableData findLookupTable(@PathParam("surveyId") final Long surveyId,
|
||||
@PathParam("id") final Long id) {
|
||||
@PathParam("key") final String key) {
|
||||
this.securityContext.authenticatedUser();
|
||||
|
||||
findSurvey(surveyId);
|
||||
|
||||
final LookupTable lookupTable = this.lookupTableService.findById(id);
|
||||
final List<LookupTable> lookupTables = this.lookupTableService.findByKey(key);
|
||||
|
||||
if (lookupTable == null) {
|
||||
throw new LookupTableNotFoundException(id);
|
||||
if (lookupTables == null || lookupTables.isEmpty()) {
|
||||
throw new LookupTableNotFoundException(key);
|
||||
}
|
||||
|
||||
return LookupTableMapper.map(lookupTable);
|
||||
return LookupTableMapper.map(lookupTables).get(0);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Transactional
|
||||
public void createLookupTable(@PathParam("surveyId") final Long surveyId,
|
||||
final LookupTableData lookupTableData) {
|
||||
this.securityContext.authenticatedUser();
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.data.ScorecardValue;
|
||||
import org.mifosplatform.spm.domain.Scorecard;
|
||||
import org.mifosplatform.spm.domain.Survey;
|
||||
import org.mifosplatform.spm.exception.SurveyNotFoundException;
|
||||
@@ -22,10 +23,12 @@ 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 org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Path("/surveys/{surveyId}/scorecards")
|
||||
@@ -54,27 +57,25 @@ public class ScorecardApiResource {
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Transactional
|
||||
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 ScorecardMapper.map(scorecards);
|
||||
}
|
||||
|
||||
return result;
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Transactional
|
||||
public void createScorecard(@PathParam("surveyId") final Long surveyId, final ScorecardData scorecardData) {
|
||||
this.securityContext.authenticatedUser();
|
||||
|
||||
@@ -95,6 +96,32 @@ public class ScorecardApiResource {
|
||||
this.scorecardService.createScorecard(ScorecardMapper.map(scorecardData, survey, staff, client));
|
||||
}
|
||||
|
||||
@Path("/clients/{clientId}")
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Transactional
|
||||
public List<ScorecardData> findBySurveyClient(@PathParam("surveyId") final Long surveyId,
|
||||
@PathParam("clientId") final Long clientId) {
|
||||
this.securityContext.authenticatedUser();
|
||||
|
||||
final Survey survey = findSurvey(surveyId);
|
||||
|
||||
final Client client = this.clientRepository.findOne(clientId);
|
||||
|
||||
if (client == null) {
|
||||
throw new ClientNotFoundException(clientId);
|
||||
}
|
||||
|
||||
final List<Scorecard> scorecards = this.scorecardService.findBySurveyAndClient(survey, client);
|
||||
|
||||
if (scorecards == null) {
|
||||
return ScorecardMapper.map(scorecards);
|
||||
}
|
||||
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
private Survey findSurvey(final Long surveyId) {
|
||||
final Survey survey = this.spmService.findById(surveyId);
|
||||
if (survey == null) {
|
||||
|
||||
@@ -5,36 +5,24 @@
|
||||
*/
|
||||
package org.mifosplatform.spm.data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LookupTableData {
|
||||
|
||||
private Long id;
|
||||
private String key;
|
||||
private String description;
|
||||
private Integer valueFrom;
|
||||
private Integer valueTo;
|
||||
private Double score;
|
||||
private List<LookupTableEntry> entries;
|
||||
|
||||
public LookupTableData() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LookupTableData(final Long id, final String key, final String description, final Integer valueFrom,
|
||||
final Integer valueTo, final Double score) {
|
||||
public LookupTableData(final String key, final String description,
|
||||
final List<LookupTableEntry> entries) {
|
||||
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;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
@@ -53,27 +41,11 @@ public class LookupTableData {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Integer getValueFrom() {
|
||||
return valueFrom;
|
||||
public List<LookupTableEntry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
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;
|
||||
public void setEntries(List<LookupTableEntry> entries) {
|
||||
this.entries = entries;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.data;
|
||||
|
||||
public class LookupTableEntry {
|
||||
|
||||
private Integer valueFrom;
|
||||
private Integer valueTo;
|
||||
private Double score;
|
||||
|
||||
public LookupTableEntry() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LookupTableEntry(final Integer valueFrom, final Integer valueTo, final Double score) {
|
||||
super();
|
||||
this.valueFrom = valueFrom;
|
||||
this.valueTo = valueTo;
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -6,45 +6,26 @@
|
||||
package org.mifosplatform.spm.data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class ScorecardData {
|
||||
|
||||
private Long questionId;
|
||||
private Long responseId;
|
||||
private Long staffId;
|
||||
private Long clientId;
|
||||
private Date createdOn;
|
||||
private Integer value;
|
||||
private List<ScorecardValue> scorecardValues;
|
||||
|
||||
public ScorecardData() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ScorecardData(final Long questionId, final Long responseId, final Long staffId, final Long clientId,
|
||||
final Date createdOn, final Integer value) {
|
||||
public ScorecardData(final Long staffId, final Long clientId, final Date createdOn,
|
||||
final List<ScorecardValue> scorecardValues) {
|
||||
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;
|
||||
this.scorecardValues = scorecardValues;
|
||||
}
|
||||
|
||||
public Long getStaffId() {
|
||||
@@ -71,11 +52,11 @@ public class ScorecardData {
|
||||
this.createdOn = createdOn;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
public List<ScorecardValue> getScorecardValues() {
|
||||
return scorecardValues;
|
||||
}
|
||||
|
||||
public void setValue(Integer value) {
|
||||
this.value = value;
|
||||
public void setScorecardValues(List<ScorecardValue> scorecardValues) {
|
||||
this.scorecardValues = scorecardValues;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.data;
|
||||
|
||||
public class ScorecardValue {
|
||||
|
||||
private Long questionId;
|
||||
private Long responseId;
|
||||
private Integer value;
|
||||
|
||||
public ScorecardValue() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ScorecardValue(final Long questionId, final Long responseId, final Integer value) {
|
||||
super();
|
||||
this.questionId = questionId;
|
||||
this.responseId = responseId;
|
||||
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 Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -9,7 +9,7 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN
|
||||
|
||||
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);
|
||||
public LookupTableNotFoundException(final String key) {
|
||||
super("error.msg.survey.lookuptable.notfound", "Lookup table with id " + key + " not found!", key);
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -14,4 +14,5 @@ import java.util.List;
|
||||
public interface LookupTableRepository extends JpaRepository<LookupTable, Long> {
|
||||
|
||||
List<LookupTable> findBySurvey(final Survey survey);
|
||||
List<LookupTable> findByKey(final String key);
|
||||
}
|
||||
|
||||
+3
-3
@@ -28,10 +28,10 @@ public class LookupTableService {
|
||||
this.lookupTableRepository = lookupTableRepository;
|
||||
}
|
||||
|
||||
public LookupTable findById(final Long id) {
|
||||
public List<LookupTable> findByKey(final String key) {
|
||||
this.securityContext.authenticatedUser();
|
||||
|
||||
return this.lookupTableRepository.findOne(id);
|
||||
return this.lookupTableRepository.findByKey(key);
|
||||
}
|
||||
|
||||
public List<LookupTable> findBySurvey(final Survey survey) {
|
||||
@@ -40,7 +40,7 @@ public class LookupTableService {
|
||||
return this.lookupTableRepository.findBySurvey(survey);
|
||||
}
|
||||
|
||||
public LookupTable createLookupTable(final LookupTable lookupTable) {
|
||||
public List<LookupTable> createLookupTable(final List<LookupTable> lookupTable) {
|
||||
this.securityContext.authenticatedUser();
|
||||
|
||||
return this.lookupTableRepository.save(lookupTable);
|
||||
|
||||
@@ -30,11 +30,10 @@ public class ScorecardService {
|
||||
this.scorecardRepository = scorecardRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Scorecard createScorecard(final Scorecard scorecard) {
|
||||
public List<Scorecard> createScorecard(final List<Scorecard> scorecards) {
|
||||
this.securityContext.authenticatedUser();
|
||||
|
||||
return this.scorecardRepository.save(scorecard);
|
||||
return this.scorecardRepository.save(scorecards);
|
||||
}
|
||||
|
||||
public List<Scorecard> findBySurvey(final Survey survey) {
|
||||
|
||||
@@ -6,31 +6,58 @@
|
||||
package org.mifosplatform.spm.util;
|
||||
|
||||
import org.mifosplatform.spm.data.LookupTableData;
|
||||
import org.mifosplatform.spm.data.LookupTableEntry;
|
||||
import org.mifosplatform.spm.domain.LookupTable;
|
||||
import org.mifosplatform.spm.domain.Survey;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
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 List<LookupTableData> map(final List<LookupTable> lookupTables) {
|
||||
|
||||
final Map<String, LookupTableData> lookupTableDataMap = new HashMap<>();
|
||||
LookupTableData lookupTableData = null;
|
||||
if (lookupTables != null && !lookupTables.isEmpty()) {
|
||||
for (LookupTable lookupTable : lookupTables) {
|
||||
if ((lookupTableData = lookupTableDataMap.get(lookupTable.getKey())) == null) {
|
||||
lookupTableData = new LookupTableData();
|
||||
lookupTableDataMap.put(lookupTable.getKey(), lookupTableData);
|
||||
lookupTableData.setKey(lookupTable.getKey());
|
||||
lookupTableData.setDescription(lookupTable.getDescription());
|
||||
lookupTableData.setEntries(new ArrayList<LookupTableEntry>());
|
||||
}
|
||||
lookupTableData.getEntries().add(new LookupTableEntry(lookupTable.getValueFrom(),
|
||||
lookupTable.getValueTo(), lookupTable.getScore()));
|
||||
}
|
||||
return new ArrayList<>(lookupTableDataMap.values());
|
||||
}
|
||||
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
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;
|
||||
public static List<LookupTable> map(final LookupTableData lookupTableData, final Survey survey) {
|
||||
final List<LookupTable> lookupTables = new ArrayList<>();
|
||||
|
||||
final List<LookupTableEntry> entries = lookupTableData.getEntries();
|
||||
|
||||
if (entries != null) {
|
||||
for (LookupTableEntry entry : entries) {
|
||||
final LookupTable lookupTable = new LookupTable();
|
||||
lookupTables.add(lookupTable);
|
||||
lookupTable.setSurvey(survey);
|
||||
lookupTable.setKey(lookupTableData.getKey());
|
||||
lookupTable.setDescription(lookupTableData.getDescription());
|
||||
lookupTable.setValueFrom(entry.getValueFrom());
|
||||
lookupTable.setValueTo(entry.getValueTo());
|
||||
lookupTable.setScore(entry.getScore());
|
||||
}
|
||||
}
|
||||
|
||||
return lookupTables;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,13 @@ 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.data.ScorecardValue;
|
||||
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;
|
||||
import java.util.*;
|
||||
|
||||
public class ScorecardMapper {
|
||||
|
||||
@@ -21,33 +22,58 @@ public class 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 List<ScorecardData> map(final List<Scorecard> scorecards) {
|
||||
final Map<Date, ScorecardData> scorecardDataMap = new HashMap<>();
|
||||
ScorecardData scorecardData = null;
|
||||
if (scorecards != null && scorecards.isEmpty()) {
|
||||
for (Scorecard scorecard : scorecards) {
|
||||
if ((scorecardData = scorecardDataMap.get(scorecard.getCreatedOn())) == null) {
|
||||
scorecardData = new ScorecardData();
|
||||
scorecardDataMap.put(scorecard.getCreatedOn(), scorecardData);
|
||||
scorecardData.setStaffId(scorecard.getStaff().getId());
|
||||
scorecardData.setClientId(scorecard.getClient().getId());
|
||||
scorecardData.setCreatedOn(scorecard.getCreatedOn());
|
||||
scorecardData.setScorecardValues(new ArrayList<ScorecardValue>());
|
||||
}
|
||||
|
||||
scorecardData.getScorecardValues().add(new ScorecardValue(scorecard.getQuestion().getId(), scorecard.getResponse().getId(),
|
||||
scorecard.getValue()));
|
||||
}
|
||||
|
||||
return new ArrayList<>(scorecardDataMap.values());
|
||||
}
|
||||
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
public static Scorecard map(final ScorecardData scorecardData, final Survey survey,
|
||||
public static List<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;
|
||||
final List<Scorecard> scorecards = new ArrayList<>();
|
||||
|
||||
final List<ScorecardValue> scorecardValues = scorecardData.getScorecardValues();
|
||||
|
||||
if (scorecardValues != null) {
|
||||
for (ScorecardValue scorecardValue : scorecardValues) {
|
||||
final Scorecard scorecard = new Scorecard();
|
||||
scorecards.add(scorecard);
|
||||
ScorecardMapper.setQuestionAndResponse(scorecardValue, scorecard, survey);
|
||||
scorecard.setStaff(staff);
|
||||
scorecard.setClient(client);
|
||||
scorecard.setCreatedOn(scorecardData.getCreatedOn());
|
||||
scorecard.setValue(scorecardValue.getValue());
|
||||
}
|
||||
}
|
||||
return scorecards;
|
||||
}
|
||||
|
||||
private static void setQuestionAndResponse(final ScorecardData scorecardData, final Scorecard scorecard,
|
||||
private static void setQuestionAndResponse(final ScorecardValue scorecardValue, final Scorecard scorecard,
|
||||
final Survey survey) {
|
||||
final List<Question> questions = survey.getQuestions();
|
||||
for (final Question question : questions) {
|
||||
if (question.getId().equals(scorecardData.getQuestionId())) {
|
||||
if (question.getId().equals(scorecardValue.getQuestionId())) {
|
||||
scorecard.setQuestion(question);
|
||||
for (final Response response : question.getResponses()) {
|
||||
if (response.getId().equals(scorecardData.getResponseId())) {
|
||||
if (response.getId().equals(scorecardValue.getResponseId())) {
|
||||
scorecard.setResponse(response);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user