add get api for single entry of a 'many' datatable

This commit is contained in:
John Woodlock
2013-01-03 18:01:07 +00:00
parent 48c40b5170
commit 6d2151f4db
@@ -40,7 +40,9 @@ public class DataTableApiResource {
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired @Autowired
public DataTableApiResource(final PlatformSecurityContext context, final GenericDataService genericDataService, public DataTableApiResource(
final PlatformSecurityContext context,
final GenericDataService genericDataService,
final ReadWriteNonCoreDataService readWriteNonCoreDataService, final ReadWriteNonCoreDataService readWriteNonCoreDataService,
final ToApiJsonSerializer<GenericResultsetData> toApiJsonSerializer, final ToApiJsonSerializer<GenericResultsetData> toApiJsonSerializer,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
@@ -54,11 +56,14 @@ public class DataTableApiResource {
@GET @GET
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String getDatatables(@QueryParam("apptable") final String apptable, @Context final UriInfo uriInfo) { public String getDatatables(@QueryParam("apptable") final String apptable,
@Context final UriInfo uriInfo) {
final List<DatatableData> result = this.readWriteNonCoreDataService.retrieveDatatableNames(apptable); final List<DatatableData> result = this.readWriteNonCoreDataService
.retrieveDatatableNames(apptable);
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo
.getQueryParameters());
return this.toApiJsonSerializer.serializePretty(prettyPrint, result); return this.toApiJsonSerializer.serializePretty(prettyPrint, result);
} }
@@ -66,7 +71,9 @@ public class DataTableApiResource {
@Path("register/{datatable}/{apptable}") @Path("register/{datatable}/{apptable}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String registerDatatable(@PathParam("datatable") final String datatable, @PathParam("apptable") final String apptable) { public String registerDatatable(
@PathParam("datatable") final String datatable,
@PathParam("apptable") final String apptable) {
this.readWriteNonCoreDataService.registerDatatable(datatable, apptable); this.readWriteNonCoreDataService.registerDatatable(datatable, apptable);
@@ -77,7 +84,8 @@ public class DataTableApiResource {
@Path("deregister/{datatable}") @Path("deregister/{datatable}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String deregisterDatatable(@PathParam("datatable") final String datatable) { public String deregisterDatatable(
@PathParam("datatable") final String datatable) {
this.readWriteNonCoreDataService.deregisterDatatable(datatable); this.readWriteNonCoreDataService.deregisterDatatable(datatable);
@@ -88,21 +96,63 @@ public class DataTableApiResource {
@Path("{datatable}/{apptableId}") @Path("{datatable}/{apptableId}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String getDatatable(@PathParam("datatable") final String datatable, @PathParam("apptableId") final Long apptableId, public String getDatatable(@PathParam("datatable") final String datatable,
@QueryParam("order") final String order, @Context final UriInfo uriInfo) { @PathParam("apptableId") final Long apptableId,
@QueryParam("order") final String order,
@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasDatatableReadPermission(datatable); context.authenticatedUser().validateHasDatatableReadPermission(
datatable);
GenericResultsetData results = this.readWriteNonCoreDataService.retrieveDataTableGenericResultSet(datatable, apptableId, order, GenericResultsetData results = this.readWriteNonCoreDataService
null); .retrieveDataTableGenericResultSet(datatable, apptableId,
order, null);
String json = ""; String json = "";
final boolean genericResultSet = ApiParameterHelper.genericResultSet(uriInfo.getQueryParameters()); final boolean genericResultSet = ApiParameterHelper
.genericResultSet(uriInfo.getQueryParameters());
if (genericResultSet) { if (genericResultSet) {
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo
json = this.toApiJsonSerializer.serializePretty(prettyPrint, results); .getQueryParameters());
json = this.toApiJsonSerializer.serializePretty(prettyPrint,
results);
} else { } else {
json = this.genericDataService.generateJsonFromGenericResultsetData(results); json = this.genericDataService
.generateJsonFromGenericResultsetData(results);
}
return json;
}
@GET
@Path("{datatable}/{apptableId}/{datatableId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String getDatatableManyEntry(
@PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId,
@PathParam("datatableId") final Long datatableId,
@QueryParam("order") final String order,
@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasDatatableReadPermission(
datatable);
GenericResultsetData results = this.readWriteNonCoreDataService
.retrieveDataTableGenericResultSet(datatable, apptableId,
order, datatableId);
String json = "";
final boolean genericResultSet = ApiParameterHelper
.genericResultSet(uriInfo.getQueryParameters());
if (genericResultSet) {
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo
.getQueryParameters());
json = this.toApiJsonSerializer.serializePretty(prettyPrint,
results);
} else {
json = this.genericDataService
.generateJsonFromGenericResultsetData(results);
} }
return json; return json;
@@ -112,11 +162,14 @@ public class DataTableApiResource {
@Path("{datatable}/{apptableId}") @Path("{datatable}/{apptableId}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String newDatatableEntry(@PathParam("datatable") final String datatable, @PathParam("apptableId") final Long apptableId, public String newDatatableEntry(
@PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId,
final String apiRequestBodyAsJson) { final String apiRequestBodyAsJson) {
final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("CREATE", datatable, "CREATE", final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService
"datatables/" + datatable, apptableId, apiRequestBodyAsJson); .logCommandSource("CREATE", datatable, "CREATE", "datatables/"
+ datatable, apptableId, apiRequestBodyAsJson);
return this.toApiJsonSerializer.serialize(entityIdentifier); return this.toApiJsonSerializer.serialize(entityIdentifier);
} }
@@ -125,11 +178,14 @@ public class DataTableApiResource {
@Path("{datatable}/{apptableId}") @Path("{datatable}/{apptableId}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String updateDatatableEntryOnetoOne(@PathParam("datatable") final String datatable, public String updateDatatableEntryOnetoOne(
@PathParam("apptableId") final Long apptableId, final String apiRequestBodyAsJson) { @PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId,
final String apiRequestBodyAsJson) {
final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", datatable, "UPDATE", final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService
"datatables/" + datatable, apptableId, apiRequestBodyAsJson); .logCommandSource("UPDATE", datatable, "UPDATE", "datatables/"
+ datatable, apptableId, apiRequestBodyAsJson);
return this.toApiJsonSerializer.serialize(entityIdentifier); return this.toApiJsonSerializer.serialize(entityIdentifier);
} }
@@ -138,12 +194,16 @@ public class DataTableApiResource {
@Path("{datatable}/{apptableId}/{datatableId}") @Path("{datatable}/{apptableId}/{datatableId}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String updateDatatableEntryOneToMany(@PathParam("datatable") final String datatable, public String updateDatatableEntryOneToMany(
@PathParam("apptableId") final Long apptableId, @PathParam("datatableId") final Long datatableId, @PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId,
@PathParam("datatableId") final Long datatableId,
final String apiRequestBodyAsJson) { final String apiRequestBodyAsJson) {
final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", datatable, final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService
"UPDATE_MULTIPLE", "datatables/" + datatable, apptableId, "datatables/" + datatable, datatableId, apiRequestBodyAsJson); .logCommandSource("UPDATE", datatable, "UPDATE_MULTIPLE",
"datatables/" + datatable, apptableId, "datatables/"
+ datatable, datatableId, apiRequestBodyAsJson);
return this.toApiJsonSerializer.serialize(entityIdentifier); return this.toApiJsonSerializer.serialize(entityIdentifier);
} }
@@ -152,10 +212,13 @@ public class DataTableApiResource {
@Path("{datatable}/{apptableId}") @Path("{datatable}/{apptableId}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String deleteDatatableEntries(@PathParam("datatable") final String datatable, @PathParam("apptableId") final Long apptableId) { public String deleteDatatableEntries(
@PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId) {
final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("DELETE", datatable, "DELETE", final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService
"datatables/" + datatable, apptableId, "{}"); .logCommandSource("DELETE", datatable, "DELETE", "datatables/"
+ datatable, apptableId, "{}");
return this.toApiJsonSerializer.serialize(entityIdentifier); return this.toApiJsonSerializer.serialize(entityIdentifier);
} }
@@ -164,11 +227,15 @@ public class DataTableApiResource {
@Path("{datatable}/{apptableId}/{datatableId}") @Path("{datatable}/{apptableId}/{datatableId}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String deleteDatatableEntries(@PathParam("datatable") final String datatable, @PathParam("apptableId") final Long apptableId, public String deleteDatatableEntries(
@PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId,
@PathParam("datatableId") final Long datatableId) { @PathParam("datatableId") final Long datatableId) {
final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("DELETE", datatable, final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService
"DELETE_MULTIPLE", "datatables/" + datatable, apptableId, "datatables/" + datatable, datatableId, "{}"); .logCommandSource("DELETE", datatable, "DELETE_MULTIPLE",
"datatables/" + datatable, apptableId, "datatables/"
+ datatable, datatableId, "{}");
return this.toApiJsonSerializer.serialize(entityIdentifier); return this.toApiJsonSerializer.serialize(entityIdentifier);
} }