Merge pull request #1582 from mgeiss/MIFOSX-SPM-3

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