WIP extra data
This commit is contained in:
@@ -31,37 +31,29 @@ public class DataTableApiResource {
|
|||||||
private ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
private ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{datatable}")
|
@Path("{datatable}/{id}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String extraData(@PathParam("datatable") final String datatable,
|
public String extraData(@PathParam("datatable") final String datatable,
|
||||||
|
@PathParam("id") final Long id,
|
||||||
@QueryParam("sqlFields") final String sqlFields,
|
@QueryParam("sqlFields") final String sqlFields,
|
||||||
@QueryParam("sqlSearch") final String sqlSearch,
|
@QueryParam("sqlSearch") final String sqlSearch,
|
||||||
@QueryParam("sqlOrder") final String sqlOrder
|
@QueryParam("sqlOrder") final String sqlOrder) {
|
||||||
// ,@Context final UriInfo uriInfo
|
|
||||||
) {
|
|
||||||
|
|
||||||
try {
|
return this.readWriteNonCoreDataService.retrieveDataTable(datatable, id,
|
||||||
// GenericResultsetData result =
|
sqlFields, sqlSearch, sqlOrder);
|
||||||
// this.readExtraDataAndReportingService.retrieveDataTable(datatable);
|
/*
|
||||||
return this.readWriteNonCoreDataService.retrieveDataTable(
|
* try { return this.readWriteNonCoreDataService.retrieveDataTable(
|
||||||
datatable, sqlFields, sqlSearch, sqlOrder);
|
* datatable, sqlFields, sqlSearch, sqlOrder); } catch
|
||||||
|
* (InvalidSqlException e) { List<ApiParameterError>
|
||||||
// boolean prettyPrint =
|
* dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
// ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
* ApiParameterError error = ApiParameterError.parameterError(
|
||||||
// return
|
* "extradata.invalid.sql", "The sql is invalid.", "sql", e.getSql());
|
||||||
// this.apiDataConversionService.convertGenericResultsetDataToJson(prettyPrint,
|
* dataValidationErrors.add(error); throw new
|
||||||
// result);
|
* PlatformApiDataValidationException(
|
||||||
} catch (InvalidSqlException e) {
|
* "validation.msg.validation.errors.exist", "Validation errors exist.",
|
||||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
* dataValidationErrors); }
|
||||||
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,
|
void updateExtraData(String type, String set, Long id,
|
||||||
Map<String, String> queryParams);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
+33
-9
@@ -15,6 +15,7 @@ import org.mifosng.platform.api.data.GenericResultsetData;
|
|||||||
import org.mifosng.platform.api.data.ResultsetColumnHeader;
|
import org.mifosng.platform.api.data.ResultsetColumnHeader;
|
||||||
import org.mifosng.platform.api.data.ResultsetDataRow;
|
import org.mifosng.platform.api.data.ResultsetDataRow;
|
||||||
import org.mifosng.platform.exceptions.AdditionalFieldsNotFoundException;
|
import org.mifosng.platform.exceptions.AdditionalFieldsNotFoundException;
|
||||||
|
import org.mifosng.platform.exceptions.DataTableNotFoundException;
|
||||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||||
import org.mifosng.platform.user.domain.AppUser;
|
import org.mifosng.platform.user.domain.AppUser;
|
||||||
@@ -423,19 +424,18 @@ public class ReadWriteNonCoreDataServiceImpl implements
|
|||||||
+ " not found");
|
+ " 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;
|
+ " t ${dataScopeCriteria} where t.id = " + id;
|
||||||
|
|
||||||
String sql = dataScopedSQL(unscopedSql, type);
|
String sql = dataScopedSQL(unscopedSql, tableName);
|
||||||
|
|
||||||
CachedRowSet rs = genericDataService.getCachedResultSet(sql, "SQL : "
|
CachedRowSet rs = genericDataService.getCachedResultSet(sql, "SQL : "
|
||||||
+ sql);
|
+ sql);
|
||||||
|
|
||||||
if (rs.size() == 0)
|
if (rs.size() == 0)
|
||||||
throw new AdditionalFieldsNotFoundException(type, id);
|
throw new DataTableNotFoundException(tableName, id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String dataScopedSQL(String unscopedSQL, String type) {
|
private String dataScopedSQL(String unscopedSQL, String type) {
|
||||||
@@ -475,23 +475,29 @@ public class ReadWriteNonCoreDataServiceImpl implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String retrieveDataTable(String datatable, String sqlFields,
|
public String retrieveDataTable(String datatable, Long id, String sqlFields,
|
||||||
String sqlSearch, String sqlOrder) {
|
String sqlSearch, String sqlOrder) {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
String applicationTableName = getApplicationTableName(datatable);
|
||||||
|
|
||||||
|
checkMainResourceExistsWithinScope(applicationTableName, id);
|
||||||
|
|
||||||
|
String fkField = applicationTableName.substring(2) + "_id";
|
||||||
|
|
||||||
String sql = "select ";
|
String sql = "select ";
|
||||||
if (sqlFields != null)
|
if (sqlFields != null)
|
||||||
sql = sql + sqlFields;
|
sql = sql + sqlFields;
|
||||||
else
|
else
|
||||||
sql = sql + " * ";
|
sql = sql + " * ";
|
||||||
|
|
||||||
sql = sql + " from " + datatable;
|
sql = sql + " from " + datatable + " where " + fkField + " = " + id;
|
||||||
|
|
||||||
if (sqlSearch != null)
|
if (sqlSearch != null)
|
||||||
sql = sql + " where " + sqlSearch;
|
sql = sql + " and ( " + sqlSearch + ")";
|
||||||
if (sqlOrder != null)
|
if (sqlOrder != null)
|
||||||
sql = sql + " order by " + sqlOrder;
|
sql = sql + " order by " + sqlOrder;
|
||||||
|
logger.info(sql);
|
||||||
GenericResultsetData result = genericDataService
|
GenericResultsetData result = genericDataService
|
||||||
.fillGenericResultSet(sql);
|
.fillGenericResultSet(sql);
|
||||||
|
|
||||||
@@ -504,6 +510,24 @@ public class ReadWriteNonCoreDataServiceImpl implements
|
|||||||
return jsonString;
|
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(
|
private static String generateJsonFromGenericResultsetData(
|
||||||
GenericResultsetData result) {
|
GenericResultsetData result) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user