diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm
index db355742c..a602a8078 100644
--- a/api-docs/apiLive.htm
+++ b/api-docs/apiLive.htm
@@ -1409,11 +1409,37 @@
| AdHoc Search |
search/advance |
- Advance Search |
+ Advance Search |
|
|
|
+
+ | Survey |
+ survey/ |
+ |
+ List surveys |
+ |
+ |
+
+
+ |
+ survey/{surveyName} |
+ |
+ Retreivesurvey details |
+ |
+ |
+
+
+ |
+ survey/{surveyName}/{clientId} |
+ Create Entry in the survey table |
+ |
+ |
+ |
+
+
+
@@ -10268,6 +10294,39 @@ GET https://DomainName/api/v1/configurations
+
+
+
+
Retrieve Global Configuration for surveys
+
Returns the list global enable/disable survey configurations.
+
Example Requests:
+
configurations/survey
+
+
+
+ GET https://DomainName/api/v1/configurations/survey
+
+
+ {
+ "ppi_kenya_2005": [
+ {
+ "name": "maker-checker",
+ "enabled": true,
+ "value": 0,
+ "id": 1
+ },
+ {
+ "name": "ppi_tanzania_20012",
+ "enabled": false,
+ "value": 0,
+ "id": 2
+ },
+ ]
+ }
+
+
+
+
@@ -17373,7 +17432,10 @@ No Request Body
Register Data Table
Registers a data table with the Mifos X Core application
table. This allows the data table to be maintained through the
- API.
+ API.
+ In case the datatable is a PPI (survey table)a parameter category should be pass along with the request.
+ The API currently support one category (200)
+
@@ -17384,7 +17446,10 @@ POST datatables/register/extra_client_details/m_client
Content-Type: application/json
Request Body:
-{}
+{
+ category:200
+ locale:"en_GB"
+}
{
@@ -17738,7 +17803,262 @@ Request Body:
-
+
+
+
+
+
+
+
Retreive surveys
+
Retrieve surveys. This allows to retrieve the list of survey tables registered .
+
+
+
+
+ GET https://DomainName/api/v1/survey/
+
+
+ GET survey/
+
+ Content-Type: application/json
+ Request Body:
+ {}
+
+
+ [
+ {
+ "datatableData": {
+ "applicationTableName": "m_client",
+ "registeredTableName": "ppi_kenya_2005",
+ "columnHeaderData": [
+ {
+ "columnName": "id",
+ "columnType": "bigint",
+ "columnLength": 0,
+ "columnDisplayType": "INTEGER",
+ "isColumnNullable": false,
+ "isColumnPrimaryKey": true,
+ "columnValues": []
+ },
+ {
+ "columnName": "client_id",
+ "columnType": "int",
+ "columnLength": 0,
+ "columnDisplayType": "INTEGER",
+ "isColumnNullable": false,
+ "isColumnPrimaryKey": false,
+ "columnValues": []
+ },
+ {
+ "columnName": "ppi_household_members_cd_q1_householdmembers",
+ "columnType": "int",
+ "columnLength": 0,
+ "columnDisplayType": "CODELOOKUP",
+ "isColumnNullable": false,
+ "isColumnPrimaryKey": false,
+ "columnValues": [
+ {
+ "id": 167,
+ "value": "Nine or More",
+ "score": 0
+ },
+ {
+ "id": 168,
+ "value": "Seven or eight",
+ "score": 5
+ },
+ {
+ "id": 169,
+ "value": "Six",
+ "score": 8
+ },
+
+ ],
+ "columnCode": "ppi_household_members"
+ },
+ {
+ "columnName": "date",
+ "columnType": "datetime",
+ "columnLength": 0,
+ "columnDisplayType": "DATETIME",
+ "isColumnNullable": false,
+ "isColumnPrimaryKey": false,
+ "columnValues": []
+ }
+ ]
+ },
+ "enabled": false
+ },
+ {
+ "datatableData": {
+ "applicationTableName": "m_client",
+ "registeredTableName": "ppi_tanzania_20012",
+ "columnHeaderData": [
+ {
+ "columnName": "id",
+ "columnType": "bigint",
+ "columnLength": 0,
+ "columnDisplayType": "INTEGER",
+ "isColumnNullable": false,
+ "isColumnPrimaryKey": true,
+ "columnValues": []
+ },
+ {
+ "columnName": "client_id",
+ "columnType": "int",
+ "columnLength": 0,
+ "columnDisplayType": "INTEGER",
+ "isColumnNullable": false,
+ "isColumnPrimaryKey": false,
+ "columnValues": []
+ },
+ {
+ "columnName": "ppi_youngerthan17_cd_q1_youngerthan17",
+ "columnType": "int",
+ "columnLength": 0,
+ "columnDisplayType": "CODELOOKUP",
+ "isColumnNullable": false,
+ "isColumnPrimaryKey": false,
+ "columnValues": [
+ {
+ "id": 204,
+ "value": "four or More",
+ "score": 0
+ },
+
+ ],
+ "columnCode": "ppi_youngerthan17"
+ },
+ ],
+ "columnCode": "ppi_how_many_tables"
+ },
+ ]
+ },
+ "enabled": true
+ }
+ ]
+
+
+
+
+
+
+
+
+
Retreive survey
+
Lists a registered survey table details and the Mifos X Core application table they are registered to.
+
+
+
+
+ GET https://DomainName/api/v1/survey/ppi_kenya_2005
+
+
+ GET survey/{surveyName}
+
+ Content-Type: application/json
+ Request Body:
+ {}
+
+
+ {
+ "applicationTableName": "m_client",
+ "registeredTableName": "extra_client_details",
+ "columnHeaderData": [
+ {
+ "columnName": "client_id",
+ "columnType": "bigint",
+ "columnLength": 0,
+ "columnDisplayType": "INTEGER",
+ "isColumnNullable": false,
+ "isColumnPrimaryKey": true,
+ "columnValues": []
+ },
+ {
+ "columnName": "Gender_cd_Question",
+ "columnType": "int",
+ "columnLength": 0,
+ "columnDisplayType": "INTEGER",
+ "isColumnNullable": true,
+ "isColumnPrimaryKey": false,
+ "columnValues": []
+ },
+ {
+ "columnName": "Some Decimal",
+ "columnType": "decimal",
+ "columnLength": 0,
+ "columnDisplayType": "DECIMAL",
+ "isColumnNullable": true,
+ "isColumnPrimaryKey": false,
+ "columnValues": []
+ },
+ {
+ "columnName": "Birth Date",
+ "columnType": "date",
+ "columnLength": 0,
+ "columnDisplayType": "DATE",
+ "isColumnNullable": true,
+ "isColumnPrimaryKey": false,
+ "columnValues": []
+ }
+ enabled:false
+ ]
+ }
+
+
+
+
+
+
+
+
Create an entry in the survey table
+
Insert and entry in a survey table (full fill the survey).
+
+
+
+
+
+ POST https://DomainName/api/v1/survey/ppi_kenya_2005/87
+
+
+ POST survey/{surveyName}/{clientId}
+
+ Content-Type: application/json
+ Request Body:
+ {
+
+ ppi_household_members_cd_q1_householdmembers : 167,
+ ppi_highestschool_cd_q2_highestschool : 174 ,
+ ppi_businessoccupation_cd_q3_businessoccupation : 180,
+ ppi_habitablerooms_cd_q4_habitablerooms :184,
+ ppi_floortype_cd_q5_floortype : 188,
+ ppi_lightingsource_cd_q6_lightingsource :190,
+ ppi_irons_cd_q7_irons:193,
+ ppi_mosquitonets_cd_q8_mosquitonets:195,
+ ppi_towels_cd_q9_towels:198,
+ ppi_fryingpans_cd_q10_fryingpans:201,
+ date:"2014-12-02 20:30:00",
+ dateFormat:"Y-m-d H:i:s",
+ locale:"en_GB"
+
+ }
+
+
+ {
+ "officeId": 2,
+ "clientId": 87,
+ "resourceId": 87
+ }
+
+
+
+
+
+
+
@@ -22473,6 +22793,16 @@ No Request Body:
Update Global Configuration |
|
+
+
+ |
+ |
+ |
+ Retrieve Surveys Global Configuration |
+ |
+ |
+
+
| Codes |
codes |
diff --git a/mifosng-db/migrations/core_db/V148__x_registered_table_category.sql b/mifosng-db/migrations/core_db/V148__x_registered_table_category.sql
new file mode 100644
index 000000000..88903f444
--- /dev/null
+++ b/mifosng-db/migrations/core_db/V148__x_registered_table_category.sql
@@ -0,0 +1 @@
+ALTER TABLE `x_registered_table` ADD `category` INT NOT NULL ;
\ No newline at end of file
diff --git a/mifosng-db/migrations/core_db/V149__addScrore_Column_to_code_value.sql b/mifosng-db/migrations/core_db/V149__addScrore_Column_to_code_value.sql
new file mode 100644
index 000000000..fabbec3a4
--- /dev/null
+++ b/mifosng-db/migrations/core_db/V149__addScrore_Column_to_code_value.sql
@@ -0,0 +1,2 @@
+ALTER TABLE `m_code_value`
+ADD COLUMN `code_score` INT(11) NULL AFTER `order_position`;
\ No newline at end of file
diff --git a/mifosng-db/migrations/core_db/V150__ppi_permision.sql b/mifosng-db/migrations/core_db/V150__ppi_permision.sql
new file mode 100644
index 000000000..b9a75a63f
--- /dev/null
+++ b/mifosng-db/migrations/core_db/V150__ppi_permision.sql
@@ -0,0 +1,3 @@
+INSERT INTO `m_permission` (`id`, `grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES (NULL, 'datatable', 'UPDATE_LIKELIHOOD', 'likelihood', 'UPDATE', '0');
+
+INSERT INTO `m_permission` (`id`, `grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES (NULL, 'survey', 'REGISTER_SURVEY', 'survey', 'CREATE', '0');
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java
index d9278f271..1c67fc64d 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java
@@ -123,6 +123,10 @@ public class CommandWrapper {
public boolean isUpdateDatatable() {
return this.actionName.equalsIgnoreCase("UPDATE") && this.href.startsWith("/datatables/") && this.entityId == null;
}
+ public boolean isRegisterDatatable() {
+ return this.actionName.equalsIgnoreCase("REGISTER") && this.href.startsWith("/datatables/") && this.entityId == null;
+ }
+
public String getTaskPermissionName() {
return this.taskPermissionName;
@@ -683,4 +687,24 @@ public class CommandWrapper {
public boolean isCacheResource() {
return this.entityName.equalsIgnoreCase("CACHE");
}
+
+ public boolean isLikelihoodResource() {
+ return this.entityName.equalsIgnoreCase("Likelihood");
+ }
+ public boolean isSurveyResource() {
+
+ return this.href.startsWith("/survey/");
+
+ }
+ public boolean isUpdateLikelihood() {
+ return this.actionName.equalsIgnoreCase("UPDATE");
+ }
+ public boolean isRegisterSurvey() {
+ return this.actionName.equalsIgnoreCase("REGISTER");
+ }
+ public boolean isFullFilSurvey() {
+ return this.actionName.equalsIgnoreCase("CREATE");
+ }
+
+
}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java
index bcac311f6..08a9ad596 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java
@@ -500,6 +500,39 @@ public class CommandWrapperBuilder {
}
}
+ public CommandWrapperBuilder registerDBDatatable(final String datatable,final String apptable)
+ {
+ this.actionName = "REGISTER";
+ this.entityName = "DATATABLE";
+ this.entityId = null;
+ this.href = "/datatables/register/" + datatable+"/"+apptable;
+
+ return this;
+
+ }
+
+ public CommandWrapperBuilder registerSurvey(final String datatable,final String apptable)
+ {
+ this.actionName = "REGISTER";
+ this.entityName = "SURVEY";
+ this.entityId = null;
+ this.href = "/survey/register/" + datatable+"/"+apptable;
+
+ return this;
+
+ }
+
+ public CommandWrapperBuilder fullFilSurvey(final String datatable, final Long apptableId) {
+
+ this.entityName =datatable;
+ this.entityId = apptableId;
+ this.actionName = "CREATE";
+
+ this.href = "/survey/" + datatable + "/" + apptableId;
+
+ return this;
+ }
+
public CommandWrapperBuilder createLoanCharge(final Long loanId) {
this.actionName = "CREATE";
this.entityName = "LOANCHARGE";
@@ -1510,4 +1543,12 @@ public class CommandWrapperBuilder {
this.href = "/cache";
return this;
}
+
+ public CommandWrapperBuilder updateLikelihood(final Long entityId) {
+ this.actionName = "UPDATE";
+ this.entityName = "LIKELIHOOD";
+ this.href = "/likelihood/"+entityId;
+ this.entityId = entityId;
+ return this;
+ }
}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java
index 4d4c20649..14716b37d 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java
@@ -7,6 +7,7 @@ package org.mifosplatform.commands.service;
import java.util.Map;
+import com.jcraft.jsch.Logger;
import org.joda.time.DateTime;
import org.mifosplatform.commands.domain.CommandSource;
import org.mifosplatform.commands.domain.CommandSourceRepository;
@@ -19,8 +20,10 @@ import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
+import org.mifosplatform.infrastructure.dataqueries.handler.RegisterDatatableCommandHandler;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.useradministration.domain.AppUser;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
@@ -34,6 +37,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
private final ToApiJsonSerializer