Skip to content

Commit

Permalink
Include load/store properties only once.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbraconnier committed Jan 13, 2024
1 parent 271f8c0 commit f23349c
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.jodconverter.core.DocumentConverter;
import org.jodconverter.core.document.DefaultDocumentFormatRegistry;
import org.jodconverter.core.document.DocumentFormat;
Expand All @@ -26,12 +31,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
* Controller that will process conversion requests. The mapping is the same as LibreOffice Online
* (/lool/convert-to) so we can use the jodconverter-remote module to send request to this
Expand Down Expand Up @@ -153,14 +152,16 @@ private void addProperty(
}
}

private void addProperty(
private boolean addProperty(
final String key,
final String prefix,
final Map.Entry<String, String> param,
final Map<String, Object> properties) {
if (key.startsWith(prefix)) {
addProperty(prefix, param, properties);
return true;
}
return false;
}

private void decodeParameters(
Expand All @@ -176,10 +177,18 @@ private void decodeParameters(
final Map<String, Object> storeFilterDataProperties = new HashMap<>();
for (final Map.Entry<String, String> param : parameters.entrySet()) {
final String key = param.getKey().toLowerCase(Locale.ROOT);
addProperty(key, LOAD_FILTER_DATA_PREFIX_PARAM, param, loadFilterDataProperties);
addProperty(key, LOAD_PROPERTIES_PREFIX_PARAM, param, loadProperties);
addProperty(key, STORE_FILTER_DATA_PREFIX_PARAM, param, storeFilterDataProperties);
addProperty(key, STORE_PROPERTIES_PREFIX_PARAM, param, storeProperties);
if (addProperty(key, LOAD_FILTER_DATA_PREFIX_PARAM, param, loadFilterDataProperties)) {
break;

This comment has been minimized.

Copy link
@cuipengfei

cuipengfei Jan 13, 2024

Contributor

These probably should be continue instead of break, otherwise caller can not pass more than one parameters

@sbraconnier

}
if (addProperty(key, LOAD_PROPERTIES_PREFIX_PARAM, param, loadProperties)) {
break;
}
if (addProperty(key, STORE_FILTER_DATA_PREFIX_PARAM, param, storeFilterDataProperties)) {
break;
}
if (addProperty(key, STORE_PROPERTIES_PREFIX_PARAM, param, storeProperties)) {
break;
}
}

if (!loadFilterDataProperties.isEmpty()) {
Expand Down

0 comments on commit f23349c

Please sign in to comment.