Comments (6)
Hi, how do you recommend we change ImportingUtilities to accommodate the new changes?
If we are unable to modify the existing methods through refactoring, we could potentially face significant code duplication issues. For instance, in the case of the retrieveContentFromPostRequest method, it appears that only a single line of code needs to be modified within a method spanning 227 lines.
Any suggestions?
from openrefine.
from openrefine.
Okay, I think the problem is that the code that needs to be changed is nested very deep inside retrieveContentFromPostRequest, so I don't think that a refactoring of it would help that much to avoid code duplication.
Is it acceptable to modify the public method retrieveContentFromPostRequest as long as it doesn't change the signature and functionality of the method?
If so, my solution would be create a new method that takes Map<String,String> and from the original method simply convert Properties parameters to a Map<String, String> and call the new method. Like this:
// Original method
static public void retrieveContentFromPostRequest(
HttpServletRequest request,
Properties parameters,
File rawDataDir,
ObjectNode retrievalRecord,
final Progress progress) throws IOException, FileUploadException {
Map<String, String> parametersMap = new HashMap<>();
for (String key : parameters.stringPropertyNames()) {
String value = parameters.getProperty(key);
parametersMap.put(key, value);
}
retrieveContentFromPostRequest(request, parametersMap, rawDataDir, retrievalRecord, progress);
}
// New method which takes map instead of properties
static public void retrieveContentFromPostRequest(
HttpServletRequest request,
Map<String, String> parameters,
File rawDataDir,
ObjectNode retrievalRecord,
final Progress progress) throws IOException, FileUploadException {
// Same code as before
}
Is that a viable solution?
from openrefine.
Yes, exactly. I suspect you'll need to do that for multiple methods, so you might want to extract your property remapping code into a separate utility method that you can reuse. Pleased also add an @Deprecated
annotation to the original method so that people know not to use it for new code.
from openrefine.
p.s. you can use Java 8 Streams to make your remapping a little more concise:
private static Map<String, String> mapProps(Properties properties) {
return properties.entrySet().stream().collect(Collectors.toMap(e -> (String) e.getKey(), e -> (String) e.getValue()));
}
from openrefine.
Great, thanks for your tips, will do that!
from openrefine.
Related Issues (20)
- Java tests: ease comparison of project grid with expected state
- Integer divide by zero returns null instead of error or infinity HOT 2
- Support scientific / exponential notation in GREL HOT 3
- Get rid of most/all uses of java.util.Properties HOT 14
- Get() or array indexing of numbers & dates should be an error
- Add an evaluate() GREL function which interprets a string as GREL
- Add an icon in line with the new visual guidelines of MacOS HOT 2
- Replace use of java.util.Properties in Bindings HOT 2
- Log Java version during Server startup to help troubleshooting from users
- beta: deleting single cell contents and pressing enter repopulates textbox HOT 14
- Document operations which don't respect facets HOT 5
- Operation logos
- Excel importer doesn't work from URL HOT 6
- Replace Properties with Map<String, String> in Exporters interfaces HOT 1
- Incorrect export of escaped quotation marks HOT 2
- Refresh dependency licenses in the About page HOT 4
- Null pointer exception in Wikibase edits operation
- Require Developer Certificate of Origin (DCO) signoff on all commits? HOT 1
- Sample extension's About page errors HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openrefine.