WIP extra data
This commit is contained in:
@@ -31,37 +31,29 @@ public class DataTableApiResource {
|
||||
private ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
||||
|
||||
@GET
|
||||
@Path("{datatable}")
|
||||
@Path("{datatable}/{id}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String extraData(@PathParam("datatable") final String datatable,
|
||||
@PathParam("id") final Long id,
|
||||
@QueryParam("sqlFields") final String sqlFields,
|
||||
@QueryParam("sqlSearch") final String sqlSearch,
|
||||
@QueryParam("sqlOrder") final String sqlOrder
|
||||
// ,@Context final UriInfo uriInfo
|
||||
) {
|
||||
@QueryParam("sqlOrder") final String sqlOrder) {
|
||||
|
||||
try {
|
||||
// GenericResultsetData result =
|
||||
// this.readExtraDataAndReportingService.retrieveDataTable(datatable);
|
||||
return this.readWriteNonCoreDataService.retrieveDataTable(
|
||||
datatable, sqlFields, sqlSearch, sqlOrder);
|
||||
|
||||
// boolean prettyPrint =
|
||||
// ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
// return
|
||||
// this.apiDataConversionService.convertGenericResultsetDataToJson(prettyPrint,
|
||||
// result);
|
||||
} catch (InvalidSqlException e) {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
ApiParameterError error = ApiParameterError.parameterError(
|
||||
"extradata.invalid.sql", "The sql is invalid.", "sql",
|
||||
e.getSql());
|
||||
dataValidationErrors.add(error);
|
||||
throw new PlatformApiDataValidationException(
|
||||
"validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors);
|
||||
}
|
||||
return this.readWriteNonCoreDataService.retrieveDataTable(datatable, id,
|
||||
sqlFields, sqlSearch, sqlOrder);
|
||||
/*
|
||||
* try { return this.readWriteNonCoreDataService.retrieveDataTable(
|
||||
* datatable, sqlFields, sqlSearch, sqlOrder); } catch
|
||||
* (InvalidSqlException e) { List<ApiParameterError>
|
||||
* dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
* ApiParameterError error = ApiParameterError.parameterError(
|
||||
* "extradata.invalid.sql", "The sql is invalid.", "sql", e.getSql());
|
||||
* dataValidationErrors.add(error); throw new
|
||||
* PlatformApiDataValidationException(
|
||||
* "validation.msg.validation.errors.exist", "Validation errors exist.",
|
||||
* dataValidationErrors); }
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package org.mifosng.platform.exceptions;
|
||||
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when client resources are not found.
|
||||
*/
|
||||
public class DataTableNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public DataTableNotFoundException(final String datatable, Long id) {
|
||||
super("error.msg.datatable.data.not.found", "Data Not Found for Data Table: ",
|
||||
datatable + " Id:" + id);
|
||||
}
|
||||
|
||||
public DataTableNotFoundException(final String datatable) {
|
||||
super("error.msg.datatable.not.found", "Data Table Not Found",
|
||||
datatable);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -15,6 +15,6 @@ public interface ReadWriteNonCoreDataService {
|
||||
void updateExtraData(String type, String set, Long id,
|
||||
Map<String, String> queryParams);
|
||||
|
||||
String retrieveDataTable(String datatable, String sqlFields, String sqlSearch, String sqlOrder);
|
||||
String retrieveDataTable(String datatable, Long id, String sqlFields, String sqlSearch, String sqlOrder);
|
||||
|
||||
}
|
||||
+35
-11
@@ -15,6 +15,7 @@ import org.mifosng.platform.api.data.GenericResultsetData;
|
||||
import org.mifosng.platform.api.data.ResultsetColumnHeader;
|
||||
import org.mifosng.platform.api.data.ResultsetDataRow;
|
||||
import org.mifosng.platform.exceptions.AdditionalFieldsNotFoundException;
|
||||
import org.mifosng.platform.exceptions.DataTableNotFoundException;
|
||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
import org.mifosng.platform.user.domain.AppUser;
|
||||
@@ -93,8 +94,8 @@ public class ReadWriteNonCoreDataServiceImpl implements
|
||||
|
||||
@Override
|
||||
public GenericResultsetData retrieveExtraData(String type, String set,
|
||||
Long id) {
|
||||
|
||||
Long id) {
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
checkMainResourceExistsWithinScope(type, id);
|
||||
@@ -423,19 +424,18 @@ public class ReadWriteNonCoreDataServiceImpl implements
|
||||
+ " not found");
|
||||
}
|
||||
|
||||
private void checkMainResourceExistsWithinScope(String type, Long id) {
|
||||
private void checkMainResourceExistsWithinScope(String tableName, Long id) {
|
||||
|
||||
String unscopedSql = "select t.id from " + type
|
||||
String unscopedSql = "select t.id from " + tableName
|
||||
+ " t ${dataScopeCriteria} where t.id = " + id;
|
||||
|
||||
String sql = dataScopedSQL(unscopedSql, type);
|
||||
String sql = dataScopedSQL(unscopedSql, tableName);
|
||||
|
||||
CachedRowSet rs = genericDataService.getCachedResultSet(sql, "SQL : "
|
||||
+ sql);
|
||||
|
||||
if (rs.size() == 0)
|
||||
throw new AdditionalFieldsNotFoundException(type, id);
|
||||
|
||||
throw new DataTableNotFoundException(tableName, id);
|
||||
}
|
||||
|
||||
private String dataScopedSQL(String unscopedSQL, String type) {
|
||||
@@ -475,23 +475,29 @@ public class ReadWriteNonCoreDataServiceImpl implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public String retrieveDataTable(String datatable, String sqlFields,
|
||||
public String retrieveDataTable(String datatable, Long id, String sqlFields,
|
||||
String sqlSearch, String sqlOrder) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
String applicationTableName = getApplicationTableName(datatable);
|
||||
|
||||
checkMainResourceExistsWithinScope(applicationTableName, id);
|
||||
|
||||
String fkField = applicationTableName.substring(2) + "_id";
|
||||
|
||||
String sql = "select ";
|
||||
if (sqlFields != null)
|
||||
sql = sql + sqlFields;
|
||||
else
|
||||
sql = sql + " * ";
|
||||
|
||||
sql = sql + " from " + datatable;
|
||||
sql = sql + " from " + datatable + " where " + fkField + " = " + id;
|
||||
|
||||
if (sqlSearch != null)
|
||||
sql = sql + " where " + sqlSearch;
|
||||
sql = sql + " and ( " + sqlSearch + ")";
|
||||
if (sqlOrder != null)
|
||||
sql = sql + " order by " + sqlOrder;
|
||||
|
||||
logger.info(sql);
|
||||
GenericResultsetData result = genericDataService
|
||||
.fillGenericResultSet(sql);
|
||||
|
||||
@@ -503,6 +509,24 @@ public class ReadWriteNonCoreDataServiceImpl implements
|
||||
+ elapsed);
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
private String getApplicationTableName(String datatable) {
|
||||
String sql = "SELECT application_table_name FROM x_registered_table where registered_table_name = '" + datatable + "'";
|
||||
|
||||
CachedRowSet rs = genericDataService.getCachedResultSet(sql, "SQL : "
|
||||
+ sql);
|
||||
|
||||
if (rs.size() == 0)
|
||||
throw new DataTableNotFoundException(datatable);
|
||||
|
||||
try {
|
||||
rs.next();
|
||||
return rs.getString("application_table_name");
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformDataIntegrityException("error.msg.sql.error",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static String generateJsonFromGenericResultsetData(
|
||||
GenericResultsetData result) {
|
||||
|
||||
Reference in New Issue
Block a user