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
@@ -33,143 +33,210 @@ import org.springframework.stereotype.Component;
@Scope("singleton") @Scope("singleton")
public class DataTableApiResource { public class DataTableApiResource {
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final GenericDataService genericDataService; private final GenericDataService genericDataService;
private final ReadWriteNonCoreDataService readWriteNonCoreDataService; private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
private final ToApiJsonSerializer<GenericResultsetData> toApiJsonSerializer; private final ToApiJsonSerializer<GenericResultsetData> toApiJsonSerializer;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired @Autowired
public DataTableApiResource(final PlatformSecurityContext context, final GenericDataService genericDataService, public DataTableApiResource(
final ReadWriteNonCoreDataService readWriteNonCoreDataService, final PlatformSecurityContext context,
final ToApiJsonSerializer<GenericResultsetData> toApiJsonSerializer, final GenericDataService genericDataService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { final ReadWriteNonCoreDataService readWriteNonCoreDataService,
this.context = context; final ToApiJsonSerializer<GenericResultsetData> toApiJsonSerializer,
this.genericDataService = genericDataService; final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.readWriteNonCoreDataService = readWriteNonCoreDataService; this.context = context;
this.toApiJsonSerializer = toApiJsonSerializer; this.genericDataService = genericDataService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.readWriteNonCoreDataService = readWriteNonCoreDataService;
} this.toApiJsonSerializer = toApiJsonSerializer;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@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
return this.toApiJsonSerializer.serializePretty(prettyPrint, result); .getQueryParameters());
} return this.toApiJsonSerializer.serializePretty(prettyPrint, result);
}
@POST @POST
@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);
return this.toApiJsonSerializer.serialize(EntityIdentifier.empty()); return this.toApiJsonSerializer.serialize(EntityIdentifier.empty());
} }
@POST @POST
@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);
return this.toApiJsonSerializer.serialize(EntityIdentifier.empty()); return this.toApiJsonSerializer.serialize(EntityIdentifier.empty());
} }
@GET @GET
@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
if (genericResultSet) { .genericResultSet(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); if (genericResultSet) {
json = this.toApiJsonSerializer.serializePretty(prettyPrint, results); final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo
} else { .getQueryParameters());
json = this.genericDataService.generateJsonFromGenericResultsetData(results); json = this.toApiJsonSerializer.serializePretty(prettyPrint,
} results);
} else {
json = this.genericDataService
.generateJsonFromGenericResultsetData(results);
}
return json; return json;
} }
@POST @GET
@Path("{datatable}/{apptableId}") @Path("{datatable}/{apptableId}/{datatableId}")
@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 getDatatableManyEntry(
final String apiRequestBodyAsJson) { @PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId,
@PathParam("datatableId") final Long datatableId,
@QueryParam("order") final String order,
@Context final UriInfo uriInfo) {
final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("CREATE", datatable, "CREATE", context.authenticatedUser().validateHasDatatableReadPermission(
"datatables/" + datatable, apptableId, apiRequestBodyAsJson); datatable);
return this.toApiJsonSerializer.serialize(entityIdentifier); GenericResultsetData results = this.readWriteNonCoreDataService
} .retrieveDataTableGenericResultSet(datatable, apptableId,
order, datatableId);
@PUT String json = "";
@Path("{datatable}/{apptableId}") final boolean genericResultSet = ApiParameterHelper
@Consumes({ MediaType.APPLICATION_JSON }) .genericResultSet(uriInfo.getQueryParameters());
@Produces({ MediaType.APPLICATION_JSON }) if (genericResultSet) {
public String updateDatatableEntryOnetoOne(@PathParam("datatable") final String datatable, final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo
@PathParam("apptableId") final Long apptableId, final String apiRequestBodyAsJson) { .getQueryParameters());
json = this.toApiJsonSerializer.serializePretty(prettyPrint,
results);
} else {
json = this.genericDataService
.generateJsonFromGenericResultsetData(results);
}
final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", datatable, "UPDATE", return json;
"datatables/" + datatable, apptableId, apiRequestBodyAsJson); }
return this.toApiJsonSerializer.serialize(entityIdentifier); @POST
} @Path("{datatable}/{apptableId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String newDatatableEntry(
@PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId,
final String apiRequestBodyAsJson) {
@PUT final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService
@Path("{datatable}/{apptableId}/{datatableId}") .logCommandSource("CREATE", datatable, "CREATE", "datatables/"
@Consumes({ MediaType.APPLICATION_JSON }) + datatable, apptableId, apiRequestBodyAsJson);
@Produces({ MediaType.APPLICATION_JSON })
public String updateDatatableEntryOneToMany(@PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId, @PathParam("datatableId") final Long datatableId,
final String apiRequestBodyAsJson) {
final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", datatable, return this.toApiJsonSerializer.serialize(entityIdentifier);
"UPDATE_MULTIPLE", "datatables/" + datatable, apptableId, "datatables/" + datatable, datatableId, apiRequestBodyAsJson); }
return this.toApiJsonSerializer.serialize(entityIdentifier); @PUT
} @Path("{datatable}/{apptableId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String updateDatatableEntryOnetoOne(
@PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId,
final String apiRequestBodyAsJson) {
@DELETE final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService
@Path("{datatable}/{apptableId}") .logCommandSource("UPDATE", datatable, "UPDATE", "datatables/"
@Consumes({ MediaType.APPLICATION_JSON }) + datatable, apptableId, apiRequestBodyAsJson);
@Produces({ MediaType.APPLICATION_JSON })
public String deleteDatatableEntries(@PathParam("datatable") final String datatable, @PathParam("apptableId") final Long apptableId) {
final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("DELETE", datatable, "DELETE", return this.toApiJsonSerializer.serialize(entityIdentifier);
"datatables/" + datatable, apptableId, "{}"); }
return this.toApiJsonSerializer.serialize(entityIdentifier); @PUT
} @Path("{datatable}/{apptableId}/{datatableId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String updateDatatableEntryOneToMany(
@PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId,
@PathParam("datatableId") final Long datatableId,
final String apiRequestBodyAsJson) {
@DELETE final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService
@Path("{datatable}/{apptableId}/{datatableId}") .logCommandSource("UPDATE", datatable, "UPDATE_MULTIPLE",
@Consumes({ MediaType.APPLICATION_JSON }) "datatables/" + datatable, apptableId, "datatables/"
@Produces({ MediaType.APPLICATION_JSON }) + datatable, datatableId, apiRequestBodyAsJson);
public String deleteDatatableEntries(@PathParam("datatable") final String datatable, @PathParam("apptableId") final Long apptableId,
@PathParam("datatableId") final Long datatableId) {
final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("DELETE", datatable, return this.toApiJsonSerializer.serialize(entityIdentifier);
"DELETE_MULTIPLE", "datatables/" + datatable, apptableId, "datatables/" + datatable, datatableId, "{}"); }
return this.toApiJsonSerializer.serialize(entityIdentifier); @DELETE
} @Path("{datatable}/{apptableId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String deleteDatatableEntries(
@PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId) {
final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService
.logCommandSource("DELETE", datatable, "DELETE", "datatables/"
+ datatable, apptableId, "{}");
return this.toApiJsonSerializer.serialize(entityIdentifier);
}
@DELETE
@Path("{datatable}/{apptableId}/{datatableId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String deleteDatatableEntries(
@PathParam("datatable") final String datatable,
@PathParam("apptableId") final Long apptableId,
@PathParam("datatableId") final Long datatableId) {
final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService
.logCommandSource("DELETE", datatable, "DELETE_MULTIPLE",
"datatables/" + datatable, apptableId, "datatables/"
+ datatable, datatableId, "{}");
return this.toApiJsonSerializer.serialize(entityIdentifier);
}
} }