Skip to content

Commit

Permalink
Cb 4430 file extension for export (#2405)
Browse files Browse the repository at this point in the history
* CB-4430. Fixed file extention for export file json

* CB-4430. Fixed file extention for export file json

* CB-4430. Fixed checkstyle

* CB-4430. Refactor after review

---------

Co-authored-by: DenisSinelnikov <[email protected]>
Co-authored-by: Evgenia Bezborodova <[email protected]>
  • Loading branch information
3 people authored Feb 23, 2024
1 parent 8c2b2e5 commit 0877d07
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;

public class WebDataTransferServlet extends WebServiceServletBase {

Expand Down Expand Up @@ -67,7 +68,7 @@ protected void processServiceRequest(WebSession session, HttpServletRequest requ
}
String fileName = taskInfo.getExportFileName();
if (!CommonUtils.isEmpty(fileName)) {
fileName += "." + WebDataTransferUtils.getProcessorFileExtension(processor);
fileName += "." + WebDataTransferUtils.getProcessorFileExtension(processor, taskInfo.getParameters().getProcessorProperties());
} else {
fileName = taskInfo.getDataFileId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
import org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor;
import org.jkiss.utils.CommonUtils;

import java.util.Map;

class WebDataTransferUtils {

private static final Log log = Log.getLog(WebDataTransferUtils.class);
public static final String EXTENSION = "extension";


public static String getProcessorFileExtension(DataTransferProcessorDescriptor processor) {
Expand All @@ -34,6 +37,14 @@ public static String getProcessorFileExtension(DataTransferProcessorDescriptor p
return CommonUtils.isEmpty(ext) ? "data" : ext;
}

public static String getProcessorFileExtension(DataTransferProcessorDescriptor processor, Map<String, Object> processorProperties) {
if (processorProperties != null && processorProperties.get(EXTENSION) != null) {
return CommonUtils.toString(processorProperties.get(EXTENSION), "data");
}

return getProcessorFileExtension(processor);
}

public static String normalizeFileName(
@NotNull String fileName,
@NotNull WebDataTransferOutputSettings outputSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,15 @@ public WebAsyncTaskInfo dataTransferExportDataFromContainer(
}

@NotNull
private String makeUniqueFileName(WebSQLProcessor sqlProcessor, DataTransferProcessorDescriptor processor) {
private String makeUniqueFileName(
WebSQLProcessor sqlProcessor,
DataTransferProcessorDescriptor processor,
Map<String, Object> processorProperties
) {
if (processorProperties != null && processorProperties.get(StreamConsumerSettings.PROP_FILE_EXTENSION) != null) {
return sqlProcessor.getWebSession().getSessionId() + "_" + UUID.randomUUID() +
"." + processorProperties.get(StreamConsumerSettings.PROP_FILE_EXTENSION);
}
return sqlProcessor.getWebSession().getSessionId() + "_" + UUID.randomUUID() + "." + WebDataTransferUtils.getProcessorFileExtension(processor);
}

Expand Down Expand Up @@ -157,7 +165,8 @@ public void run(DBRProgressMonitor monitor) throws InvocationTargetException {
monitor.beginTask("Export data", 1);
try {
monitor.subTask("Export data using " + processor.getName());
Path exportFile = dataExportFolder.resolve(makeUniqueFileName(sqlProcessor, processor));
Path exportFile = dataExportFolder.resolve(
makeUniqueFileName(sqlProcessor, processor, parameters.getProcessorProperties()));
try {
exportData(monitor, processor, dataContainer, parameters, resultsInfo, exportFile);
} catch (Exception e) {
Expand Down

0 comments on commit 0877d07

Please sign in to comment.