package com.hp.autonomy.frontend.find.idol.export; import com.autonomy.aci.client.services.AciErrorException; import com.hp.autonomy.frontend.find.core.export.service.ExportFormat; import com.hp.autonomy.frontend.find.core.export.service.ExportServiceFactory; import com.hp.autonomy.frontend.find.core.web.ControllerUtils; import com.hp.autonomy.frontend.find.core.web.RequestMapper; import com.hp.autonomy.searchcomponents.idol.search.IdolDocumentsService; import com.hp.autonomy.searchcomponents.idol.search.IdolQueryRequest; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import java.io.IOException; import java.util.Collection; import static com.hp.autonomy.frontend.find.core.export.ExportController.EXPORT_PATH; @Controller @RequestMapping(EXPORT_PATH) public class IdolCsvExportController extends IdolExportController { public IdolCsvExportController(final RequestMapper<IdolQueryRequest> requestMapper, final ControllerUtils controllerUtils, final ExportServiceFactory<IdolQueryRequest, AciErrorException> exportServiceFactory, final IdolDocumentsService documentsService) { super(requestMapper, controllerUtils, exportServiceFactory, documentsService); } @Override protected ExportFormat getExportFormat() { return ExportFormat.CSV; } @Override @RequestMapping(value = CSV_PATH, method = RequestMethod.POST) @ResponseBody public ResponseEntity<byte[]> exportQueryResults( @RequestParam(QUERY_REQUEST_PARAM) final String queryRequestJSON, // required = false to prevent Spring errors if the user asks for a CSV with no fields marked for exportQueryResults. // The UI should not allow the User to send a request for a CSV with nothing in it. @RequestParam(value = SELECTED_EXPORT_FIELDS_PARAM, required = false) final Collection<String> selectedFieldNames ) throws IOException, AciErrorException { return super.exportQueryResults(queryRequestJSON, selectedFieldNames); } }