@Test public void shouldExportInstancesWithAdditionalOptionsAsCsv() throws Exception { when(response.getWriter()).thenReturn(writer); ArgumentCaptor<QueryParams> queryParamsCaptor = ArgumentCaptor.forClass(QueryParams.class); ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class); GridSettings gridSettings = new GridSettings(); gridSettings.setSortColumn("sortColumn"); gridSettings.setSortDirection("asc"); gridSettings.setSelectedFields(asList("id", "date")); gridSettings.setLookup("lookup"); instanceController.exportEntityInstances(1L, gridSettings, "50", "csv", response); verify(instanceService).verifyEntityAccess(1L); verify(csvImportExportService).exportCsv(eq(1L), eq(writer), eq("lookup"), queryParamsCaptor.capture(), listCaptor.capture(), any(Map.class)); verify(response).setContentType("text/csv"); verify(response).setHeader("Content-Disposition", "attachment; filename=Entity_1_instances.csv"); QueryParams captorValue = queryParamsCaptor.getValue(); assertEquals(Order.Direction.ASC, captorValue.getOrderList().get(0).getDirection()); assertEquals("sortColumn", captorValue.getOrderList().get(0).getField()); assertEquals(Integer.valueOf(1), captorValue.getPage()); assertEquals(Integer.valueOf(50), captorValue.getPageSize()); assertEquals(2, listCaptor.getValue().size()); assertTrue(listCaptor.getValue().contains("id")); assertTrue(listCaptor.getValue().contains("date")); }
@RequestMapping(value = "/entities/{entityId}/exportInstances", method = RequestMethod.GET) public void exportEntityInstances(@PathVariable Long entityId, GridSettings settings, @RequestParam String exportRecords, @RequestParam String outputFormat, HttpServletResponse response) throws IOException { if (!Constants.ExportFormat.isValidFormat(outputFormat)) { throw new IllegalArgumentException("Invalid export format: " + outputFormat); } instanceService.verifyEntityAccess(entityId); final String fileName = "Entity_" + entityId + "_instances"; response.setContentType("text/csv"); response.setCharacterEncoding(UTF_8); response.setHeader( "Content-Disposition", "attachment; filename=" + fileName + "." + outputFormat.toLowerCase()); final Integer pageSize = StringUtils.equalsIgnoreCase(exportRecords, "all") ? null : Integer.valueOf(exportRecords); final Map<String, Object> fieldMap = getFields(settings); QueryParams queryParams = new QueryParams(1, pageSize, QueryParamsBuilder.buildOrderList(settings, fieldMap)); if (Constants.ExportFormat.PDF.equals(outputFormat)) { csvImportExportService.exportPdf(entityId, response.getOutputStream(), settings.getLookup(), queryParams, settings.getSelectedFields(), fieldMap); } else { csvImportExportService.exportCsv(entityId, response.getWriter(), settings.getLookup(), queryParams, settings.getSelectedFields(), fieldMap); } }
InstanceController extends MdsController { @RequestMapping(value = "/entities/{entityId}/exportInstances", method = RequestMethod.GET) public void exportEntityInstances(@PathVariable Long entityId, GridSettings settings, @RequestParam String exportRecords, @RequestParam String outputFormat, HttpServletResponse response) throws IOException { if (!Constants.ExportFormat.isValidFormat(outputFormat)) { throw new IllegalArgumentException("Invalid export format: " + outputFormat); } instanceService.verifyEntityAccess(entityId); final String fileName = "Entity_" + entityId + "_instances"; response.setContentType("text/csv"); response.setCharacterEncoding(UTF_8); response.setHeader( "Content-Disposition", "attachment; filename=" + fileName + "." + outputFormat.toLowerCase()); final Integer pageSize = StringUtils.equalsIgnoreCase(exportRecords, "all") ? null : Integer.valueOf(exportRecords); final Map<String, Object> fieldMap = getFields(settings); QueryParams queryParams = new QueryParams(1, pageSize, QueryParamsBuilder.buildOrderList(settings, fieldMap)); if (Constants.ExportFormat.PDF.equals(outputFormat)) { csvImportExportService.exportPdf(entityId, response.getOutputStream(), settings.getLookup(), queryParams, settings.getSelectedFields(), fieldMap); } else { csvImportExportService.exportCsv(entityId, response.getWriter(), settings.getLookup(), queryParams, settings.getSelectedFields(), fieldMap); } } }
InstanceController extends MdsController { @RequestMapping(value = "/entities/{entityId}/exportInstances", method = RequestMethod.GET) public void exportEntityInstances(@PathVariable Long entityId, GridSettings settings, @RequestParam String exportRecords, @RequestParam String outputFormat, HttpServletResponse response) throws IOException { if (!Constants.ExportFormat.isValidFormat(outputFormat)) { throw new IllegalArgumentException("Invalid export format: " + outputFormat); } instanceService.verifyEntityAccess(entityId); final String fileName = "Entity_" + entityId + "_instances"; response.setContentType("text/csv"); response.setCharacterEncoding(UTF_8); response.setHeader( "Content-Disposition", "attachment; filename=" + fileName + "." + outputFormat.toLowerCase()); final Integer pageSize = StringUtils.equalsIgnoreCase(exportRecords, "all") ? null : Integer.valueOf(exportRecords); final Map<String, Object> fieldMap = getFields(settings); QueryParams queryParams = new QueryParams(1, pageSize, QueryParamsBuilder.buildOrderList(settings, fieldMap)); if (Constants.ExportFormat.PDF.equals(outputFormat)) { csvImportExportService.exportPdf(entityId, response.getOutputStream(), settings.getLookup(), queryParams, settings.getSelectedFields(), fieldMap); } else { csvImportExportService.exportCsv(entityId, response.getWriter(), settings.getLookup(), queryParams, settings.getSelectedFields(), fieldMap); } }  }
InstanceController extends MdsController { @RequestMapping(value = "/entities/{entityId}/exportInstances", method = RequestMethod.GET) public void exportEntityInstances(@PathVariable Long entityId, GridSettings settings, @RequestParam String exportRecords, @RequestParam String outputFormat, HttpServletResponse response) throws IOException { if (!Constants.ExportFormat.isValidFormat(outputFormat)) { throw new IllegalArgumentException("Invalid export format: " + outputFormat); } instanceService.verifyEntityAccess(entityId); final String fileName = "Entity_" + entityId + "_instances"; response.setContentType("text/csv"); response.setCharacterEncoding(UTF_8); response.setHeader( "Content-Disposition", "attachment; filename=" + fileName + "." + outputFormat.toLowerCase()); final Integer pageSize = StringUtils.equalsIgnoreCase(exportRecords, "all") ? null : Integer.valueOf(exportRecords); final Map<String, Object> fieldMap = getFields(settings); QueryParams queryParams = new QueryParams(1, pageSize, QueryParamsBuilder.buildOrderList(settings, fieldMap)); if (Constants.ExportFormat.PDF.equals(outputFormat)) { csvImportExportService.exportPdf(entityId, response.getOutputStream(), settings.getLookup(), queryParams, settings.getSelectedFields(), fieldMap); } else { csvImportExportService.exportCsv(entityId, response.getWriter(), settings.getLookup(), queryParams, settings.getSelectedFields(), fieldMap); } }  @RequestMapping(value = "/instances", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) void saveInstance(@RequestBody EntityRecord record); @RequestMapping(value = "/instances/{instanceId}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) void updateInstance(@RequestBody EntityRecord record); @RequestMapping(value = "/instances/deleteBlob/{entityId}/{instanceId}/{fieldId}", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) void deleteBlobContent(@PathVariable Long entityId, @PathVariable Long instanceId, @PathVariable Long fieldId); @RequestMapping(value = "/instances/{entityId}/new") @ResponseBody EntityRecord newInstance(@PathVariable Long entityId); @RequestMapping(value = "/instances/{entityId}/{instanceId}/fields", method = RequestMethod.GET) @ResponseBody List<FieldInstanceDto> getInstanceFields(@PathVariable Long entityId, @PathVariable Long instanceId); @RequestMapping(value = "/instances/{entityId}/{instanceId}/{fieldName}", method = RequestMethod.GET) @ResponseBody void getBlobField(@PathVariable Long entityId, @PathVariable Long instanceId,
                             @PathVariable String fieldName, HttpServletResponse response); @RequestMapping(value = "/instances/{entityId}/delete/{instanceId}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void deleteInstance(@PathVariable Long entityId, @PathVariable Long instanceId); @RequestMapping(value = "/instances/{entityId}/deleteAll", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void deleteAllInstances(@PathVariable Long entityId); @RequestMapping(value = "/instances/{entityId}/deleteSelected/{instanceIds}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void deleteSelectedInstances(@PathVariable Long entityId, @PathVariable String instanceIds); @RequestMapping(value = "/instances/{entityId}/revertFromTrash/{instanceId}", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) void revertInstanceFromTrash(@PathVariable Long entityId, @PathVariable Long instanceId); @RequestMapping(value = "/instances/{entityId}/{instanceId}/history", method = RequestMethod.GET) @ResponseBody Records<BasicHistoryRecord> getHistory(@PathVariable Long entityId, @PathVariable Long instanceId, GridSettings settings); @RequestMapping(value = "/instances/{entityId}/{instanceId}/previousVersion/{historyId}", method = RequestMethod.GET) @ResponseBody HistoryRecord getPreviousInstance(@PathVariable Long entityId, @PathVariable Long instanceId,
                                             @PathVariable Long historyId); @RequestMapping(value = "/instances/{entityId}/{instanceId}/revert/{historyId}", method = RequestMethod.GET) @ResponseBody void revertPreviousVersion(@PathVariable Long entityId, @PathVariable Long instanceId,
                                      @PathVariable Long historyId); @RequestMapping(value = "/instances/{entityId}/instance/{instanceId}", method = RequestMethod.GET) @ResponseBody EntityRecord getInstance(@PathVariable Long entityId, @PathVariable Long instanceId); @RequestMapping(value = "/instances/{entityId}/instance/new/{fieldName}", method = RequestMethod.POST) @ResponseBody Records<BasicEntityRecord> getRelatedValues(@PathVariable Long entityId, @PathVariable String fieldName, String filters, GridSettings settings); @RequestMapping(value = "/instances/{entityId}/instance/{instanceId}/{fieldName}", method = RequestMethod.POST) @ResponseBody Records<BasicEntityRecord> getRelatedValues(@PathVariable Long entityId, @PathVariable Long instanceId,
                                                       @PathVariable String fieldName, String filters, GridSettings settings); @RequestMapping(value = "/instances/{entityId}/field/{fieldId}/instance/{instanceId}", method = RequestMethod.GET) @ResponseBody FieldRecord getInstanceValueAsRelatedField(@PathVariable Long entityId, @PathVariable Long fieldId, @PathVariable Long instanceId); @RequestMapping(value = "/entities/{entityId}/trash", method = RequestMethod.GET) @ResponseBody Records<BasicEntityRecord> getTrash(@PathVariable Long entityId, GridSettings settings); @RequestMapping(value = "/entities/{entityId}/trash/{instanceId}", method = RequestMethod.GET) @ResponseBody EntityRecord getSingleTrashInstance(@PathVariable Long entityId, @PathVariable Long instanceId); @RequestMapping(value = "/entities/{entityId}/exportInstances", method = RequestMethod.GET) void exportEntityInstances(@PathVariable Long entityId, GridSettings settings,
                                      @RequestParam String exportRecords,
                                      @RequestParam String outputFormat,
                                      HttpServletResponse response); @RequestMapping(value = "/entities/{entityId}/instances", method = RequestMethod.POST) @ResponseBody Records<BasicEntityRecord> getInstances(@PathVariable Long entityId, GridSettings settings); @RequestMapping(value = "/instances/{entityId}/csvimport", method = RequestMethod.POST) @ResponseBody CsvImportResults importCsv(@PathVariable long entityId, @RequestParam(required = true)  MultipartFile file,
                          @RequestParam(required = false) boolean continueOnError, @RequestParam(required = false) boolean clearData); @RequestMapping(value = "/instances/generateUUID", method = RequestMethod.GET) @ResponseBody String generateRandomUUID(); }
InstanceController extends MdsController { @RequestMapping(value = "/entities/{entityId}/exportInstances", method = RequestMethod.GET) public void exportEntityInstances(@PathVariable Long entityId, GridSettings settings, @RequestParam String exportRecords, @RequestParam String outputFormat, HttpServletResponse response) throws IOException { if (!Constants.ExportFormat.isValidFormat(outputFormat)) { throw new IllegalArgumentException("Invalid export format: " + outputFormat); } instanceService.verifyEntityAccess(entityId); final String fileName = "Entity_" + entityId + "_instances"; response.setContentType("text/csv"); response.setCharacterEncoding(UTF_8); response.setHeader( "Content-Disposition", "attachment; filename=" + fileName + "." + outputFormat.toLowerCase()); final Integer pageSize = StringUtils.equalsIgnoreCase(exportRecords, "all") ? null : Integer.valueOf(exportRecords); final Map<String, Object> fieldMap = getFields(settings); QueryParams queryParams = new QueryParams(1, pageSize, QueryParamsBuilder.buildOrderList(settings, fieldMap)); if (Constants.ExportFormat.PDF.equals(outputFormat)) { csvImportExportService.exportPdf(entityId, response.getOutputStream(), settings.getLookup(), queryParams, settings.getSelectedFields(), fieldMap); } else { csvImportExportService.exportCsv(entityId, response.getWriter(), settings.getLookup(), queryParams, settings.getSelectedFields(), fieldMap); } }  @RequestMapping(value = "/instances", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) void saveInstance(@RequestBody EntityRecord record); @RequestMapping(value = "/instances/{instanceId}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) void updateInstance(@RequestBody EntityRecord record); @RequestMapping(value = "/instances/deleteBlob/{entityId}/{instanceId}/{fieldId}", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) void deleteBlobContent(@PathVariable Long entityId, @PathVariable Long instanceId, @PathVariable Long fieldId); @RequestMapping(value = "/instances/{entityId}/new") @ResponseBody EntityRecord newInstance(@PathVariable Long entityId); @RequestMapping(value = "/instances/{entityId}/{instanceId}/fields", method = RequestMethod.GET) @ResponseBody List<FieldInstanceDto> getInstanceFields(@PathVariable Long entityId, @PathVariable Long instanceId); @RequestMapping(value = "/instances/{entityId}/{instanceId}/{fieldName}", method = RequestMethod.GET) @ResponseBody void getBlobField(@PathVariable Long entityId, @PathVariable Long instanceId,
                             @PathVariable String fieldName, HttpServletResponse response); @RequestMapping(value = "/instances/{entityId}/delete/{instanceId}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void deleteInstance(@PathVariable Long entityId, @PathVariable Long instanceId); @RequestMapping(value = "/instances/{entityId}/deleteAll", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void deleteAllInstances(@PathVariable Long entityId); @RequestMapping(value = "/instances/{entityId}/deleteSelected/{instanceIds}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void deleteSelectedInstances(@PathVariable Long entityId, @PathVariable String instanceIds); @RequestMapping(value = "/instances/{entityId}/revertFromTrash/{instanceId}", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) void revertInstanceFromTrash(@PathVariable Long entityId, @PathVariable Long instanceId); @RequestMapping(value = "/instances/{entityId}/{instanceId}/history", method = RequestMethod.GET) @ResponseBody Records<BasicHistoryRecord> getHistory(@PathVariable Long entityId, @PathVariable Long instanceId, GridSettings settings); @RequestMapping(value = "/instances/{entityId}/{instanceId}/previousVersion/{historyId}", method = RequestMethod.GET) @ResponseBody HistoryRecord getPreviousInstance(@PathVariable Long entityId, @PathVariable Long instanceId,
                                             @PathVariable Long historyId); @RequestMapping(value = "/instances/{entityId}/{instanceId}/revert/{historyId}", method = RequestMethod.GET) @ResponseBody void revertPreviousVersion(@PathVariable Long entityId, @PathVariable Long instanceId,
                                      @PathVariable Long historyId); @RequestMapping(value = "/instances/{entityId}/instance/{instanceId}", method = RequestMethod.GET) @ResponseBody EntityRecord getInstance(@PathVariable Long entityId, @PathVariable Long instanceId); @RequestMapping(value = "/instances/{entityId}/instance/new/{fieldName}", method = RequestMethod.POST) @ResponseBody Records<BasicEntityRecord> getRelatedValues(@PathVariable Long entityId, @PathVariable String fieldName, String filters, GridSettings settings); @RequestMapping(value = "/instances/{entityId}/instance/{instanceId}/{fieldName}", method = RequestMethod.POST) @ResponseBody Records<BasicEntityRecord> getRelatedValues(@PathVariable Long entityId, @PathVariable Long instanceId,
                                                       @PathVariable String fieldName, String filters, GridSettings settings); @RequestMapping(value = "/instances/{entityId}/field/{fieldId}/instance/{instanceId}", method = RequestMethod.GET) @ResponseBody FieldRecord getInstanceValueAsRelatedField(@PathVariable Long entityId, @PathVariable Long fieldId, @PathVariable Long instanceId); @RequestMapping(value = "/entities/{entityId}/trash", method = RequestMethod.GET) @ResponseBody Records<BasicEntityRecord> getTrash(@PathVariable Long entityId, GridSettings settings); @RequestMapping(value = "/entities/{entityId}/trash/{instanceId}", method = RequestMethod.GET) @ResponseBody EntityRecord getSingleTrashInstance(@PathVariable Long entityId, @PathVariable Long instanceId); @RequestMapping(value = "/entities/{entityId}/exportInstances", method = RequestMethod.GET) void exportEntityInstances(@PathVariable Long entityId, GridSettings settings,
                                      @RequestParam String exportRecords,
                                      @RequestParam String outputFormat,
                                      HttpServletResponse response); @RequestMapping(value = "/entities/{entityId}/instances", method = RequestMethod.POST) @ResponseBody Records<BasicEntityRecord> getInstances(@PathVariable Long entityId, GridSettings settings); @RequestMapping(value = "/instances/{entityId}/csvimport", method = RequestMethod.POST) @ResponseBody CsvImportResults importCsv(@PathVariable long entityId, @RequestParam(required = true)  MultipartFile file,
                          @RequestParam(required = false) boolean continueOnError, @RequestParam(required = false) boolean clearData); @RequestMapping(value = "/instances/generateUUID", method = RequestMethod.GET) @ResponseBody String generateRandomUUID();  }