+
+
Retrieve Data Table Details
+
Lists a registered data table details and the Mifos X Core
+ application table they are registered to.
+
+
+
+GET https://DomainName/api/v1/datatables/{datatable}
+
+
+{
+ "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": []
+ }
+ ]
+}
+
+
+
+
+
+
+
Update Data Table
+
Modifies fields of a data table. If the apptableName parameter is passed,
+ data table is deregistered and registered with the new application table.
+
+
+
+PUT https://DomainName/api/v1/datatables/{datatables}
+
+
+PUT https://DomainName/api/v1/datatables/extra_client_details
+
+Content-Type: application/json
+Request Body:
+{
+ "apptableName": "m_client",
+ "columns": [
+ {
+ "name": "Gender",
+ "type": "Dropdown",
+ "code": "Gender"
+ },
+ {
+ "name": "Some Decimal",
+ "type": "Decimal",
+ "mandatory": true
+ },
+ {
+ "name": "Birth Date",
+ "type": "Date"
+ },
+ {
+ "name": "Question 2",
+ "type": "String",
+ "length": 100,
+ "mandatory": false
+ }
+ ]
+}
+
+
+{
+ "resourceIdentifier": "extra_client_details"
+}
+
+
+
+
+
+
+
Delete Data Table
+
Deletes a data table and unregisters it from the Mifos X Core
+ application table.
+
+
+
+DELETE https://DomainName/api/v1/datatables/{datatables}
+
+
+DELETE https://DomainName/api/v1/datatables/extra_client_details
+
+Content-Type: application/json
+No Request Body
+
+
+{
+ "resourceIdentifier": "extra_client_details"
+}
+
+
+
+
@@ -15357,11 +15582,19 @@ GET https://DomainName/api/v1/search?query=000000111
| Data Table |
datatables |
- |
+ Create Data Table |
List Data Tables |
|
|
+
+ |
+ datatables/{datatable} |
+ |
+ Retrieve Data Table Details |
+ Update Data Table |
+ Delete Data Table |
+
|
datatables/register/{datatable}/{apptable} |
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/serialization/DatatableCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/serialization/DatatableCommandFromApiJsonDeserializer.java
index db1f74a08..1a214ca61 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/serialization/DatatableCommandFromApiJsonDeserializer.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/serialization/DatatableCommandFromApiJsonDeserializer.java
@@ -18,6 +18,7 @@ import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
+import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -29,22 +30,23 @@ import com.google.gson.reflect.TypeToken;
public class DatatableCommandFromApiJsonDeserializer {
private final static String DATATABLE_NAME_REGEX_PATTERN = "^[a-zA-Z][a-zA-Z0-9\\-_\\s]{0,48}[a-zA-Z0-9]$";
+ private final static String DATATABLE_COLUMN_NAME_REGEX_PATTERN = "^[a-zA-Z][a-zA-Z0-9\\-_\\s]{0,}[a-zA-Z0-9]$";
/**
* The parameters supported for this command.
*/
private final Set supportedParametersForCreate = new HashSet(Arrays.asList(
"datatableName", "apptableName", "multiRow", "columns"));
private final Set supportedParametersForCreateColumns = new HashSet(Arrays.asList(
- "name", "type", "length", "mandatory"));
+ "name", "type", "length", "mandatory", "code"));
private final Set supportedParametersForUpdate = new HashSet(Arrays.asList(
"apptableName", "changeColumns", "addColumns", "dropColumns"));
private final Set supportedParametersForAddColumns = new HashSet(Arrays.asList(
- "name", "type", "length", "mandatory", "after"));
+ "name", "type", "length", "mandatory", "after", "code"));
private final Set supportedParametersForChangeColumns = new HashSet(Arrays.asList(
- "name", "newName", "type", "length", "mandatory", "after"));
+ "name", "newName", "mandatory", "after", "code", "newCode"));
private final Set supportedParametersForDropColumns = new HashSet(Arrays.asList(
"name"));
- private final Object[] supportedColumnTypes = { "String", "Number", "Decimal", "Date", "Text" };
+ private final Object[] supportedColumnTypes = { "String", "Number", "Decimal", "Date", "Text", "Dropdown" };
private final Object[] supportedApptableNames = { "m_loan", "m_savings_account", "m_client", "m_group", "m_office" };
private final FromJsonHelper fromApiJsonHelper;
@@ -54,6 +56,35 @@ public class DatatableCommandFromApiJsonDeserializer {
this.fromApiJsonHelper = fromApiJsonHelper;
}
+ private void validateType(final DataValidatorBuilder baseDataValidator, final JsonElement column) {
+ final String type = fromApiJsonHelper.extractStringNamed("type", column);
+ baseDataValidator.reset().parameter("type").value(type).notBlank()
+ .isOneOfTheseValues(supportedColumnTypes);
+
+ final Integer length = fromApiJsonHelper.extractIntegerSansLocaleNamed("length", column);
+ if (type != null && type.equals("String")) {
+ if (length != null) {
+ baseDataValidator.reset().parameter("length").value(length).notBlank()
+ .zeroOrPositiveAmount();
+ } else {
+ baseDataValidator.reset().parameter("length").value(length)
+ .cantBeBlankWhenParameterProvidedIs("type", type);
+ }
+ } else {
+ baseDataValidator.reset().parameter("length").value(length)
+ .mustBeBlankWhenParameterProvidedIs("type", type);
+ }
+
+ final String code = fromApiJsonHelper.extractStringNamed("code", column);
+
+ if (type != null && type.equals("Dropdown")) {
+ baseDataValidator.reset().parameter("code").value(code).notBlank()
+ .matchesRegularExpression(DATATABLE_NAME_REGEX_PATTERN);
+ } else {
+ baseDataValidator.reset().parameter("code").value(code).mustBeBlankWhenParameterProvided("type", type);
+ }
+ }
+
public void validateForCreate(final String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
@@ -83,28 +114,16 @@ public class DatatableCommandFromApiJsonDeserializer {
if (columns != null) {
for (JsonElement column : columns) {
fromApiJsonHelper.checkForUnsupportedParameters(column.getAsJsonObject(), supportedParametersForCreateColumns);
-
+
final String name = fromApiJsonHelper.extractStringNamed("name", column);
- baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(50)
- .isNotOneOfTheseValues("id", fkColumnName).matchesRegularExpression(DATATABLE_NAME_REGEX_PATTERN);
-
+ baseDataValidator.reset().parameter("name").value(name).notBlank()
+ .isNotOneOfTheseValues("id", fkColumnName).matchesRegularExpression(DATATABLE_COLUMN_NAME_REGEX_PATTERN);
+
final String type = fromApiJsonHelper.extractStringNamed("type", column);
baseDataValidator.reset().parameter("type").value(type).notBlank().isOneOfTheseValues(supportedColumnTypes);
-
- final Integer length = fromApiJsonHelper.extractIntegerSansLocaleNamed("length", column);
- if (type != null && (type.equals("String") || type.equals("Text"))) {
- if (length != null) {
- baseDataValidator.reset().parameter("length").value(length).notBlank()
- .zeroOrPositiveAmount();
- } else if (!type.equals("Text")) {
- baseDataValidator.reset().parameter("length").value(length)
- .cantBeBlankWhenParameterProvidedIs("type", type);
- }
- } else if (type != null && length != null) {
- baseDataValidator.reset().parameter("length").value(length)
- .mustBeBlankWhenParameterProvidedIs("type", type);
- }
-
+
+ validateType(baseDataValidator, column);
+
final Boolean mandatory = fromApiJsonHelper.extractBooleanNamed("mandatory", column);
baseDataValidator.reset().parameter("mandatory").value(mandatory).ignoreIfNull().notBlank()
.isOneOfTheseValues(true, false);
@@ -118,7 +137,10 @@ public class DatatableCommandFromApiJsonDeserializer {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
// Because all parameters are optional, a check to see if at least one parameter
// has been specified is necessary in order to avoid JSON requests with no parameters
- if (!json.matches("(?s)\\A\\{.*?(\\\".*?\\\"\\s*?:\\s*?)+.*?\\}\\z")) { throw new InvalidJsonException(); }
+ if (!json.matches("(?s)\\A\\{.*?(\\\".*?\\\"\\s*?:\\s*?)+.*?\\}\\z")) {
+ throw new PlatformDataIntegrityException("error.msg.invalid.request.body.no.parameters",
+ "Provided JSON request body does not have any parameters.");
+ }
final Type typeOfMap = new TypeToken