diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm
index 720597eed..5698f1f16 100644
--- a/api-docs/apiLive.htm
+++ b/api-docs/apiLive.htm
@@ -4007,12 +4007,12 @@ Successful transaction response:
Self Service API Overview
- Self Service APIs are a set of APIs with restricted data scope. Functional specifications and design can be viewed
- here.
+ Self Service APIs are a set of APIs with restricted data scope. Functional specifications and design can be viewed
+ here.
- While creating an user, user can be tagged as self service user. Also you can associate
+ While creating an user, 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.
@@ -11812,7 +11812,7 @@ Request Body:
| contains exception data for variations(modifiedinstallments,newinstallments and deletedinstallments described below) |
-
+
Exception object fields
Modifiedinstallments Array fields
@@ -12239,7 +12239,7 @@ Request Body:
}
-
+
@@ -12346,8 +12346,8 @@ Request Body:
}
-
-
+
+
@@ -12382,10 +12382,10 @@ Request Body:
}
-
-
-
-
+
+
+
+
@@ -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
+ }
+ ]
}
@@ -38856,12 +38875,30 @@ No Request Body
[
{
- "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
+ }
+ ]
}
]
@@ -38878,18 +38915,36 @@ No Request Body
GET https://DomainName/api/v1/surveys/1/lookuptables/1
-GET surveys/1/lookuptables/1
+GET surveys/1/lookuptables/test-table
Content-Type: application/json
No Request Body
{
- "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
+ }
+ ]
}
@@ -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"
-}
-
+ "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
+ }
+ ]
+}
200 OK
@@ -38947,19 +39052,70 @@ No Request Body
[
- {
- "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
+ }
+ ]
+ }
]
-
+
@@ -39029,7 +39185,7 @@ No Request Body
-
+
@@ -39199,7 +39355,7 @@ GET https://DomainName/api/v1/self/clients
-
+
@@ -39387,8 +39543,8 @@ GET https://DomainName/api/v1/self/clients/{clientId}/accounts
}
-
-
+
+
@@ -40729,7 +40885,7 @@ No Request Body:
-
+
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/api/LookupTableApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/api/LookupTableApiResource.java
index e70ceb271..25d92eb01 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/spm/api/LookupTableApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/api/LookupTableApiResource.java
@@ -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 fetchLookupTables(@PathParam("surveyId") final Long surveyId) {
this.securityContext.authenticatedUser();
final Survey survey = findSurvey(surveyId);
- final List result = new ArrayList<>();
-
final List 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 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();
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/api/ScorecardApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/api/ScorecardApiResource.java
index 3bb7dd7f2..c70c94ed9 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/spm/api/ScorecardApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/api/ScorecardApiResource.java
@@ -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 findBySurvey(@PathParam("surveyId") final Long surveyId) {
this.securityContext.authenticatedUser();
final Survey survey = findSurvey(surveyId);
- final List result = new ArrayList<>();
-
final List 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 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 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) {
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/data/LookupTableData.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/LookupTableData.java
index 005f57610..130b939fb 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/spm/data/LookupTableData.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/LookupTableData.java
@@ -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 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 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 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 entries) {
+ this.entries = entries;
}
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/data/LookupTableEntry.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/LookupTableEntry.java
new file mode 100644
index 000000000..8aeee4cff
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/LookupTableEntry.java
@@ -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;
+ }
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ScorecardData.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ScorecardData.java
index fd1d511b3..78a4311db 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ScorecardData.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ScorecardData.java
@@ -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 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 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 getScorecardValues() {
+ return scorecardValues;
}
- public void setValue(Integer value) {
- this.value = value;
+ public void setScorecardValues(List scorecardValues) {
+ this.scorecardValues = scorecardValues;
}
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ScorecardValue.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ScorecardValue.java
new file mode 100644
index 000000000..1f96d7bbe
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/data/ScorecardValue.java
@@ -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;
+ }
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/exception/LookupTableNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/exception/LookupTableNotFoundException.java
index 560d147df..a9487635b 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/spm/exception/LookupTableNotFoundException.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/exception/LookupTableNotFoundException.java
@@ -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);
}
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/LookupTableRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/LookupTableRepository.java
index 5b0e78dd1..0c7677c68 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/LookupTableRepository.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/repository/LookupTableRepository.java
@@ -14,4 +14,5 @@ import java.util.List;
public interface LookupTableRepository extends JpaRepository {
List findBySurvey(final Survey survey);
+ List findByKey(final String key);
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/service/LookupTableService.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/service/LookupTableService.java
index 6b62fe86e..67175db61 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/spm/service/LookupTableService.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/service/LookupTableService.java
@@ -28,10 +28,10 @@ public class LookupTableService {
this.lookupTableRepository = lookupTableRepository;
}
- public LookupTable findById(final Long id) {
+ public List findByKey(final String key) {
this.securityContext.authenticatedUser();
- return this.lookupTableRepository.findOne(id);
+ return this.lookupTableRepository.findByKey(key);
}
public List findBySurvey(final Survey survey) {
@@ -40,7 +40,7 @@ public class LookupTableService {
return this.lookupTableRepository.findBySurvey(survey);
}
- public LookupTable createLookupTable(final LookupTable lookupTable) {
+ public List createLookupTable(final List lookupTable) {
this.securityContext.authenticatedUser();
return this.lookupTableRepository.save(lookupTable);
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/service/ScorecardService.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/service/ScorecardService.java
index d19e0fb70..6af9be7ee 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/spm/service/ScorecardService.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/service/ScorecardService.java
@@ -30,11 +30,10 @@ public class ScorecardService {
this.scorecardRepository = scorecardRepository;
}
- @Transactional
- public Scorecard createScorecard(final Scorecard scorecard) {
+ public List createScorecard(final List scorecards) {
this.securityContext.authenticatedUser();
- return this.scorecardRepository.save(scorecard);
+ return this.scorecardRepository.save(scorecards);
}
public List findBySurvey(final Survey survey) {
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/util/LookupTableMapper.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/util/LookupTableMapper.java
index 05f84b148..3a3e0a2a7 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/spm/util/LookupTableMapper.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/util/LookupTableMapper.java
@@ -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 map(final List lookupTables) {
+
+ final Map 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());
+ }
+ 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 map(final LookupTableData lookupTableData, final Survey survey) {
+ final List lookupTables = new ArrayList<>();
+
+ final List 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;
}
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/spm/util/ScorecardMapper.java b/mifosng-provider/src/main/java/org/mifosplatform/spm/util/ScorecardMapper.java
index 1fbd26dde..bc918c3ea 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/spm/util/ScorecardMapper.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/spm/util/ScorecardMapper.java
@@ -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 map(final List scorecards) {
+ final Map 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());
+ }
+
+ 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 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 scorecards = new ArrayList<>();
+
+ final List 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 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;
}