diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm
index ee6fbe284..c3b0eb748 100644
--- a/api-docs/apiLive.htm
+++ b/api-docs/apiLive.htm
@@ -2417,12 +2417,12 @@ Request Body:
Arguments
- - appTable
+ - apptable
- optional
- The Mifos X core application table.
Example Requests:
- datatables?appTable=m_client
+ datatables?apptable=m_client
datatables
@@ -2451,112 +2451,242 @@ Request Body:
Register Data Table
- Registers a data table with the Mifos X Core application table.
+ Registers a data table with the Mifos X Core application table. This allows the data table to be maintained through the API.
- POST https://Domain Name/api/v1/datatable/{datatable}/{set}/{id}
- POST additionalfields/portfolio_client/Additional Information/2
+ POST https://Domain Name/api/v1/datatables/register/{datatable}/{apptable}
+ POST datatables/register/New Table/m_client
Content-Type: application/json
Request Body:
{
- "Ethnic_Group":"Berber",
- "Ethnic_Group_Other":"",
- "Household_Location":"East Sikkim",
- "Household_Location_Other":"",
- "Religion":"Animist",
- "Religion_Other":"jjjjjjj",
- "Knowledge_of_Person":"Son/daughter of staff member",
- "Gender":"Female",
- "Whois":"its\r\nme of\r\ncourse\r\nyes\r\nend and the end of it all"
}
{
- "entityId": 2
+ "entityId": null
}
-
+
-
Retrieve Additional Fields
-
- Returns the Set of Additional Fields data for the ID provided. The ID is the id field of the Type table e.g. portfolio_client might have an id value of 4. The output is a JSON formatted "Generic Resultset". The Generic Resultset contains Column Heading as well as Data information. The Column Heading information may include allowed values (columnValues array).
-
-
Example Request:
-
additionalfields/m_client/Additional Information/2
-
+
Deregister Data Table
+
+ Deregisters a data table. It will no longer be available through the API.
+
- GET https://Domain Name/api/v1/additionalfields/{type}/{set}/{id}
+ POST https://Domain Name/api/v1/datatables/deregister/{datatable}
+ POST datatables/register/New Table
+Content-Type: application/json
+Request Body:
+{
+}
+
{
- "columnHeaders" : [ {
- "columnName" : "Ethnic Group",
- "columnType" : "String",
- "columnLength" : 50,
- "columnDisplayType" : "List",
- "columnValues" : [ "Bedouin", "Berber", "Italian", "Miknasa", "Mrazig", "Other", "Unknown" ]
- }, {
- "columnName" : "Ethnic Group Other",
- "columnType" : "String",
- "columnLength" : 50,
- "columnDisplayType" : null,
- "columnValues" : [ ]
- }, {
- "columnName" : "Household Location",
- "columnType" : "String",
- "columnLength" : 50,
- "columnDisplayType" : "List",
- "columnValues" : [ "East Sikkim", "North Sikkim", "South Sikkim", "West Sikkim", "Other" ]
- }, {
- "columnName" : "Household Location Other",
- "columnType" : "String",
- "columnLength" : 50,
- "columnDisplayType" : null,
- "columnValues" : [ ]
- }, {
- "columnName" : "Religion",
- "columnType" : "String",
- "columnLength" : 50,
- "columnDisplayType" : "List",
- "columnValues" : [ "Protestant", "Catholic", "Muslim", "Animist", "Atheist", "Other", "Unknown" ]
- }, {
- "columnName" : "Religion Other",
- "columnType" : "String",
- "columnLength" : 50,
- "columnDisplayType" : null,
- "columnValues" : [ ]
- }, {
- "columnName" : "Knowledge of Person",
- "columnType" : "String",
- "columnLength" : 50,
- "columnDisplayType" : "List",
- "columnValues" : [ "Staff member", "Spouse of staff member", "Son/daughter of staff member", "Friend of staff member", "Not known by any staff member", "Other" ]
- }, {
- "columnName" : "Gender",
- "columnType" : "String",
- "columnLength" : 10,
- "columnDisplayType" : "List",
- "columnValues" : [ "Female", "Male" ]
- }, {
- "columnName" : "Whois",
- "columnType" : "Text",
- "columnLength" : null,
- "columnDisplayType" : null,
- "columnValues" : [ ]
- } ],
- "data" : [ {
- "row" : [ "Bedouin", null, "East Sikkim", null, "Animist", "Agnostic", "Friend of staff member", "Female", "A person of honesty & clear thought" ]
- } ]
+ "entityId": null
}
+
+
+
+
+
Create Entry in Data Table
+
+ Adds a row to the data table.
+
+
+ Note that the default datatable UI functionality converts any field name containing spaces to underscores when using the API.
+ This means the field name "Business Description" is considered the same as "Business_Description".
+ So you shouldn't have both "versions" in any data table.
+
+
+
+ POST https://Domain Name/api/v1/datatables/{datatable}/{apptableId}
+ POST datatables/Additional Client Fields Data/1
+Content-Type: application/json
+Request Body:
+{
+ "Business Description": "Livestock sales",
+ Comment: "First comment\nmade",
+ Education_cv: "Trade",
+ Gender_cd: "21",
+ "Highest Rate Paid": "8.5",
+ "Next Visit": "01 October 2012",
+ "Years in Business": "5",
+ dateFormat: "dd MMMM yyyy",
+ locale: "en"
+}
+
+ {
+ "entityId": 1
+}
+
+
+
+
+
+
+
Retrieve Entry(s) from Data Table
+
+ Gets the entry (if it exists) for data tables that are one to one with the application table.
+ Gets the entries (if they exist) for data tables that are one to many with the application table.
+
+
Note: The 'fields' parameter is not available for datatables.
+
+
Arguments
+
+ - order
+ - optional
+ - Specifies the order in which data is returned.
+ - genericResultSet
+ - optional
+ - If 'true' a Generic Result Set JSON format is returned.
+ This format is used by the default data tables UI functionality.
+
+
+
Example Requests:
+
datatables/Additional Client Fields Data/1
+
+
datatables/Extra Family Details Data/1?order=`Date of Birth` desc
+
+
datatables/Additional Client Fields Data/1?genericResultSet=true
+
+
+ GET https://Domain Name/api/v1/datatables/{datatable}/{apptableId}
+ [
+{"client_id": 1,
+"Business Description": "Livestock sales",
+"Years in Business": 5,
+"Gender_cd": "21",
+"Education_cv": "Trade",
+"Next Visit": [2012, 10, 1],
+"Highest Rate Paid": 8.500000,
+"Comment": "First comment
+made"}
+]
+
+
+
+
+
+
+
+
+
Update Entry in Data Table (One to One)
+
+ Updates the row (if it exists) of the data table.
+
+
+
+ PUT https://Domain Name/api/v1/datatables/{datatable}/{apptableId}
+ PUT datatables/Additional Client Fields Data/1
+Content-Type: application/json
+Request Body:
+{
+ "Business Description": "Livestock sales updated",
+ Comment: "First comment\nmade",
+ Education_cv: "Trade",
+ Gender_cd: "21",
+ "Highest Rate Paid": "8.5",
+ "Next Visit": "01 October 2012",
+ "Years in Business": "5",
+ dateFormat: "dd MMMM yyyy",
+ locale: "en"
+}
+
+ {
+ "entityId": 1
+}
+
+
+
+
+
+
+
+
Update Entry in Data Table (One to Many)
+
+ Updates the row (if it exists) of the data table.
+
+
+
+ PUT https://Domain Name/api/v1/datatables/{datatable}/{apptableId}/{datatableId}
+ PUT datatables/Extra Family Details Data/1/2
+Content-Type: application/json
+Request Body:
+{
+ "Date of Birth": "01 June 1982",
+ Education_cdHighest: "5",
+ Name: "June",
+ "Other Notes": "More\nnotes",
+ "Points Score": "20",
+ dateFormat: "dd MMMM yyyy",
+ locale: "en"
+}
+
+ {
+ "entityId": 1
+}
+
+
+
+
+
+
+
+
Delete Entry(s) in Data Table
+
+ Deletes the entry (if it exists) for data tables that are one to one with the application table.
+ Deletes the entries (if they exist) for data tables that are one to many with the application table.
+
+
+
+ DELETE https://Domain Name/api/v1/datatables/{datatable}/{apptableId}
+ DELETE datatables/Additional Client Fields Data/1
+Content-Type: application/json
+Request Body:
+{
+}
+
+ {
+ "entityId": 1
+}
+
+
+
+
+
+
+
+
Delete Entry in Data Table (One to Many)
+
+ Deletes the entry (if it exists) for data tables that are one to many with the application table.
+
+
+
+ DELETE https://Domain Name/api/v1/datatables/{datatable}/{apptableId}/{datatableId}
+ DELETE datatables/Extra Family Details Data/1/2
+Content-Type: application/json
+Request Body:
+{
+}
+
+ {
+ "entityId": 1
+}
+
+
+
+
+
diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/DataTableApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/DataTableApiResource.java
index 61e460415..83ceace3b 100644
--- a/mifosng-provider/src/main/java/org/mifosng/platform/api/DataTableApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/DataTableApiResource.java
@@ -66,11 +66,11 @@ public class DataTableApiResource {
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
- public String getDatatables(@QueryParam("appTable") final String appTable,
+ public String getDatatables(@QueryParam("apptable") final String apptable,
@Context final UriInfo uriInfo) {
List
result = this.readWriteNonCoreDataService
- .retrieveDatatableNames(appTable);
+ .retrieveDatatableNames(apptable);
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo
.getQueryParameters());
@@ -79,14 +79,14 @@ public class DataTableApiResource {
}
@POST
- @Path("register/{datatable}/{appTable}")
+ @Path("register/{datatable}/{apptable}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response registerDatatable(
@PathParam("datatable") final String datatable,
- @PathParam("appTable") final String appTable) {
+ @PathParam("apptable") final String apptable) {
- this.readWriteNonCoreDataService.registerDatatable(datatable, appTable);
+ this.readWriteNonCoreDataService.registerDatatable(datatable, apptable);
EntityIdentifier entityIdentifier = new EntityIdentifier();
return Response.ok().entity(entityIdentifier).build();
@@ -106,20 +106,19 @@ public class DataTableApiResource {
}
@GET
- @Path("{datatable}/{appTableId}")
+ @Path("{datatable}/{apptableId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String getDatatable(@PathParam("datatable") final String datatable,
- @PathParam("appTableId") final Long appTableId,
- @QueryParam("sqlFields") final String sqlFields,
- @QueryParam("sqlOrder") final String sqlOrder,
+ @PathParam("apptableId") final Long apptableId,
+ @QueryParam("order") final String order,
@Context final UriInfo uriInfo) {
checkUserPermissionForDatatable(datatable, "READ");
GenericResultsetData results = this.readWriteNonCoreDataService
- .retrieveDataTableGenericResultSet(datatable, appTableId,
- sqlFields, sqlOrder, null);
+ .retrieveDataTableGenericResultSet(datatable, apptableId,
+ order, null);
String json = "";
final boolean genericResultSet = ApiParameterHelper.genericResultSet(uriInfo.getQueryParameters());
@@ -134,34 +133,34 @@ public class DataTableApiResource {
}
@POST
- @Path("{datatable}/{appTableId}")
+ @Path("{datatable}/{apptableId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response newDatatableEntry(
@PathParam("datatable") final String datatable,
- @PathParam("appTableId") final Long appTableId,
+ @PathParam("apptableId") final Long apptableId,
final String jsonRequestBody) {
checkUserPermissionForDatatable(datatable, "CREATE");
Map queryParams = getQueryParamsFromJsonRequestBody(jsonRequestBody);
this.readWriteNonCoreDataService.newDatatableEntry(datatable,
- appTableId, queryParams);
+ apptableId, queryParams);
EntityIdentifier entityIdentifier = new EntityIdentifier(
- Long.valueOf(appTableId));
+ Long.valueOf(apptableId));
return Response.ok().entity(entityIdentifier).build();
}
@PUT
- @Path("{datatable}/{appTableId}")
+ @Path("{datatable}/{apptableId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response updateDatatableEntryOnetoOne(
@PathParam("datatable") final String datatable,
- @PathParam("appTableId") final Long appTableId,
+ @PathParam("apptableId") final Long apptableId,
final String jsonRequestBody) {
/*
* for updating one to one relationships (where foreign key is the
@@ -171,22 +170,22 @@ public class DataTableApiResource {
Map queryParams = getQueryParamsFromJsonRequestBody(jsonRequestBody);
this.readWriteNonCoreDataService.updateDatatableEntryOnetoOne(
- datatable, appTableId, queryParams);
+ datatable, apptableId, queryParams);
EntityIdentifier entityIdentifier = new EntityIdentifier(
- Long.valueOf(appTableId));
+ Long.valueOf(apptableId));
return Response.ok().entity(entityIdentifier).build();
}
@PUT
- @Path("{datatable}/{appTableId}/{datatableId}")
+ @Path("{datatable}/{apptableId}/{datatableId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response updateDatatableEntryOnetoOne(
@PathParam("datatable") final String datatable,
- @PathParam("appTableId") final Long appTableId,
+ @PathParam("apptableId") final Long apptableId,
@PathParam("datatableId") final Long datatableId,
final String jsonRequestBody) {
/*
@@ -197,51 +196,51 @@ public class DataTableApiResource {
Map queryParams = getQueryParamsFromJsonRequestBody(jsonRequestBody);
this.readWriteNonCoreDataService.updateDatatableEntryOnetoMany(
- datatable, appTableId, datatableId, queryParams);
+ datatable, apptableId, datatableId, queryParams);
EntityIdentifier entityIdentifier = new EntityIdentifier(
- Long.valueOf(appTableId));
+ Long.valueOf(apptableId));
return Response.ok().entity(entityIdentifier).build();
}
@DELETE
- @Path("{datatable}/{appTableId}")
+ @Path("{datatable}/{apptableId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response deleteDatatableEntries(
@PathParam("datatable") final String datatable,
- @PathParam("appTableId") final Long appTableId) {
+ @PathParam("apptableId") final Long apptableId) {
checkUserPermissionForDatatable(datatable, "DELETE");
this.readWriteNonCoreDataService.deleteDatatableEntries(datatable,
- appTableId);
+ apptableId);
EntityIdentifier entityIdentifier = new EntityIdentifier(
- Long.valueOf(appTableId));
+ Long.valueOf(apptableId));
return Response.ok().entity(entityIdentifier).build();
}
@DELETE
- @Path("{datatable}/{appTableId}/{datatableId}")
+ @Path("{datatable}/{apptableId}/{datatableId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response deleteDatatableEntries(
@PathParam("datatable") final String datatable,
- @PathParam("appTableId") final Long appTableId,
+ @PathParam("apptableId") final Long apptableId,
@PathParam("datatableId") final Long datatableId) {
checkUserPermissionForDatatable(datatable, "DELETE");
this.readWriteNonCoreDataService.deleteDatatableEntry(datatable,
- appTableId, datatableId);
+ apptableId, datatableId);
EntityIdentifier entityIdentifier = new EntityIdentifier(
- Long.valueOf(appTableId));
+ Long.valueOf(apptableId));
return Response.ok().entity(entityIdentifier).build();
diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/noncore/ReadWriteNonCoreDataService.java b/mifosng-provider/src/main/java/org/mifosng/platform/noncore/ReadWriteNonCoreDataService.java
index 53cb65d2a..62c1d5e6a 100644
--- a/mifosng-provider/src/main/java/org/mifosng/platform/noncore/ReadWriteNonCoreDataService.java
+++ b/mifosng-provider/src/main/java/org/mifosng/platform/noncore/ReadWriteNonCoreDataService.java
@@ -18,7 +18,7 @@ public interface ReadWriteNonCoreDataService {
void deregisterDatatable(String datatable);
GenericResultsetData retrieveDataTableGenericResultSet(String datatable,
- Long appTableId, String sqlFields, String sqlOrder, Long id);
+ Long appTableId, String order, Long id);
void newDatatableEntry(String datatable, Long appTableId,
Map queryParams);
diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/noncore/ReadWriteNonCoreDataServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/noncore/ReadWriteNonCoreDataServiceImpl.java
index 24f7ec1b8..011dae82a 100644
--- a/mifosng-provider/src/main/java/org/mifosng/platform/noncore/ReadWriteNonCoreDataServiceImpl.java
+++ b/mifosng-provider/src/main/java/org/mifosng/platform/noncore/ReadWriteNonCoreDataServiceImpl.java
@@ -203,7 +203,7 @@ public class ReadWriteNonCoreDataServiceImpl implements
long startTime = System.currentTimeMillis();
GenericResultsetData grs = retrieveDataTableGenericResultSet(datatable,
- appTableId, null, null, null);
+ appTableId, null, null);
if (grs.getData().size() == 0)
throw new DataTableNotFoundException(datatable, appTableId);
@@ -240,7 +240,7 @@ public class ReadWriteNonCoreDataServiceImpl implements
long startTime = System.currentTimeMillis();
GenericResultsetData grs = retrieveDataTableGenericResultSet(datatable,
- appTableId, null, null, datatableId);
+ appTableId, null, datatableId);
if (grs.getData().size() == 0)
throw new DataTableNotFoundException(datatable, appTableId);
@@ -302,8 +302,7 @@ public class ReadWriteNonCoreDataServiceImpl implements
@Override
public GenericResultsetData retrieveDataTableGenericResultSet(
- String datatable, Long appTableId, String sqlFields,
- String sqlOrder, Long id) {
+ String datatable, Long appTableId, String order, Long id) {
long startTime = System.currentTimeMillis();
@@ -312,23 +311,19 @@ public class ReadWriteNonCoreDataServiceImpl implements
List columnHeaders = getDatatableResultsetColumnHeaders(datatable);
- String sql = "select ";
- if (sqlFields != null)
- sql = sql + sqlFields;
- else
- sql = sql + " * ";
+ String sql = "";
// id only used for reading a specific entry in a one to many datatable
// (when updating)
if (id == null) {
- sql = sql + " from `" + datatable + "` where "
+ sql = sql + "select * from `" + datatable + "` where "
+ getFKField(appTable) + " = " + appTableId;
} else {
- sql = sql + " from `" + datatable + "` where id = " + id;
+ sql = sql + "select * from `" + datatable + "` where id = " + id;
}
- if (sqlOrder != null)
- sql = sql + " order by " + sqlOrder;
+ if (order != null)
+ sql = sql + " order by " + order;
List result = fillDatatableResultSetDataRows(sql);
@@ -806,7 +801,8 @@ public class ReadWriteNonCoreDataServiceImpl implements
List dataValidationErrors = new ArrayList();
ApiParameterError error = ApiParameterError.parameterError(
"error.msg.invalid.columnValue",
- "Value not found in Allowed Value list", columnHeader.getColumnName(), paramValue);
+ "Value not found in Allowed Value list",
+ columnHeader.getColumnName(), paramValue);
dataValidationErrors.add(error);
throw new PlatformApiDataValidationException(
"validation.msg.validation.errors.exist",
@@ -822,7 +818,8 @@ public class ReadWriteNonCoreDataServiceImpl implements
List dataValidationErrors = new ArrayList();
ApiParameterError error = ApiParameterError.parameterError(
"error.msg.invalid.columnValue",
- "Value not found in Allowed Value list", columnHeader.getColumnName(), paramValue);
+ "Value not found in Allowed Value list",
+ columnHeader.getColumnName(), paramValue);
dataValidationErrors.add(error);
throw new PlatformApiDataValidationException(
"validation.msg.validation.errors.exist",