At this moment I have a JTable I want to export to a .csv file.
I've had another question put on this site, but this one is specific to my Bindy problem.
With bindy it is possible to annotate all the classes and datafields you want to marshall or unmarshall. The problem is after the annotating I have no idea how to set up my app to create the CSV for me.
I've found explanations (partly), and examples (that didn't help me find out how it works).
http://camel.apache.org/csv.html
Especially with above link I had problems understanding this part below:
An example: if you send a message with this map...
Map<String, Object> body = new HashMap<String, Object>();
body.put("foo", "abc");
body.put("bar", 123);
... through this route ...
from("direct:start").
marshal().csv().
to("mock:result");
... you will end up with a String containing this CSV message
abc,123
http://camel.apache.org/bindy.html
Could anyone help me explain how this works, because I cannot seem to get the grasp of it.
The example you refer to on http://camel.apache.org/csv.html shows how to marshal one row of data to csv, being two columns named foo and bar with respective values abc and 123.
foo bar
abc 123
Since the headers are not output (in this example) you end up with
abc,123
If you want to output multiple rows of data, refer to the "Marshalling a List to CSV" heading on the same page:
If you have multiple rows of data you want to be marshalled into CSV
format you can now store the message payload as a List> object where the list contains a Map for each row.
Related
I have a Yaml file that's something like below:
rules:
- p_table:
["p_event/Name",
"p_fault/Name"]
- s_table:
["s_event/Name",
"s_fault/Name"]
- r_table:
["r_event/Name",
"r_fault/Name"]
So, I can already take the .yml file above and parse through it with YamlBeans and print it out with code like below:
System.out.println(map.get("rules"));
This gives this kind of result:
[{p_table=[p_event/Name, p_fault/Name]},
{s_table=[s_event/Name, s_fault/Name]},
{r_table=[r_event/Name, r_fault/Name]}]
What I would like to do is more on this sort of level, where I can store it in a HashMap and actually use the specifics within the map, with something like this:
HashMap<String, ArrayList<Strings>> Policies = (HashMap)(map.get("rules"));
But when I do that I either have an exception thrown or it just returns null, is there a solution for this should I not be using HashMaps... or can I just not translate objects in such a way? I plan on replacing the String with another type from a different library that uses Strings but wanted to start at the bottom and then go up from there.
The obvious solution would be to remove the sequence from the YAML file:
rules:
p_table:
["p_event/Name",
"p_fault/Name"]
s_table:
["s_event/Name",
"s_fault/Name"]
r_table:
["r_event/Name",
"r_fault/Name"]
If you can't change the YAML file, you need to transform the data after loading it.
To Preface this question is exactly what i'm looking for. The only difference is i'm using a fixed Length file.
My problem is using this method I seem to get a Iterator Object returned and not the file with the 3 lined header removed.
The Camel route should consume a .txt file, remove the first 3 lines and then send the result to a file endpoint.
I have tried different variations of the simple language to no avail. I can't find any specific case in the book, documentation or online.
See my Camel Route Below
from(inputFilePath).routeId("MyRoute")
.streamCaching()
.threads(threadPoolSize)
.log("${headers.CamelFileName}: Unmarshalling to Java POJO")
.log("${body} Body Before Transform")
.convertBodyTo(String.class)
.transform().simple("skip(3)")
.log("${body} Body After Transform")
.to(outputFilePath)
Im Expecting for a .txt file to be returned with the first 3 lines removed and the rest of the structure to not be changed.
Instead I get a reference to a iterator Object -->
2019-06-19 14:55:30.497 INFO 2868 --- [ad #2 - Threads] MyRoute : org.apache.camel.util.SkipIterator#4d894ea5 Body After Transform
Any help or suggestions would be greatly appreciated!
Simple function skip(n) is intended to skip n items in List, but your body is String.
You need to get List<String> of lines (Tokenize language) in order to use it.
To join this list back to String you can use eg Bean EIP to call org.apache.commons.lang3.StringUtils.
from(inputFilePath)
.transform(body().tokenize("\n"))
.transform(simple("${skip(3)}"))
.bean(StringUtils.class, "join(${body}, '\n')")
.to(outputFilePath);
I am trying to understand on how to perform queries in Redisearch strictly with "begins with" and I keep getting "contains".
For example if I have fields with values like 'football', 'myfootball', 'greenfootball' and would provide a search term like this:
> FT.SEARCH myIdx #myfield:foot*
I want just to get 'football' but I keep getting other fields that contain the word instead of beginning with that word.
Is there a way to avoid this?
I was trying to use VERBATIM and things like #myfield:^foot* but nothing.
I am using JRedisearch as a client but eventually I had to enter the DB and perform these queries manually in order to figure out what's happening. That being said, is this possible to do with this client at the moment?
Thanks
EDIT
A sample of my index setup:
Client client = new Client(INDEX_NAME, url, PORT);
Schema sc = new Schema().addSortableTextField("url", 1.0); // using this field for query
client.dropIndex(true);
client.createIndex(sc, Client.IndexOptions.Default());
return client;
Sample document:
id: // random uuid
urlPath: myfootbal
application: web
market: Europe
After checking the RDB provided I see that when searching foot* you are not getting myfootbal. The replies look like this: /dot-com/plp/football/x/index.html. You are getting those replies because this url is tokenized, and '/' is one of the tokenize chars. If you do not want those urls to be tokenized you need to declare them as TAGS and not as TEXT. This way the entire url will be indexed as is and when search for foot* it will not appear in the results.
For more information about TAGS see the FT.CREATE documentation: https://oss.redislabs.com/redisearch/Commands.html
I'm trying to create a PreferenceActicity.
I need that on of my preferences will be of type MultiSelectedListPreference.
I found this code on the internet:
<MultiSelectListPreference
android:dialogTitle="#string/mode_repeat"
android:key="mode_repeat"
android:summary=""
android:title="#string/mode_repeat"
android:entries="#array/weekdays"
android:entryValues="#array/weekdays_values"
android:defaultValue="#array/empty_array"
/>
The problem is I'm getting the entries and entryValues in runtime.
I'm building the ArrayList while my app is running, the question is how can I set my ArrayList as the entries and as the entryValues?
Do I need to create an empty xml file, which I will re-write during the building of my list?
You wouldn't be able to change the xml in runtime. The solution for your problem is to use the methods setEntries()and setEntryValues()from the MultiSelectListPreference class.
Here's a basic code snippet:
MultiSelectListPreference repeatModePreference = (MultiSelectListPreference) findPreference(Constants. mode_repeat);
repeatModePreference.setEntries(yourEntries); // This is human-readable strings
repeatModePreference.setEntryValues(yourEntryvalues) // The value corresponding to the human-readable string
Hope this helps.
I have a property file named "ABC.properties" having values such as
A="APPLE"
B="BALL"
C="CAT"
Now i need to get these values and load in my UI. Have iterate and then need to load because like wise there may be more than 50 values in that property file.
Can anyone please help me with this?
In your zk.xml file, give the path of properties file you wanted to read.
<zk>
<system-config>
<label-location>/path/to/ABC.properties</label-location>
</system-config>
</zk>
If you want to read them in zul file, for example you want to show label having value as A then
< label value="${labels.A}" />
If you want to read properties file's value in listener class then do
Labels.getLabel("A");
First of all, I don't know if there are more items in the property file then you need to fetch.
Note : Multiple properties files all readed in this way and are accessible in the same map.
If yes :
Convert the key's with subsections :
FRUIT.APPLE = apple
FRUIT.ORANGE = orange
TOYS.BALL = ball
TOYS.DOLL = doll
and so on.
The next thing is as #BhushanPatil already mentioned :
In your zk.xml file, give the path of properties file you wanted to read.
<zk>
<system-config>
<label-location>/path/to/ABC.properties</label-location>
</system-config>
</zk>
Then you have the following method getSegmentedLabels under Labels.
This is the method we will use.
So if you want to declare it only in the zul, the next step is what you have to do :
<?xel-method
prefix="prop" name="all" class="org.zkoss.util.resource.Labels"
signature="java.util.Map getSegmentedLabels()"?>
<vlayout forEach="${prop:all().get('FRUIT')}">
<label value="${each.key} : ${each.value}"/>
</vlayout>
The Xel-method is for declaring the static method (only way to acces a static method before ZK 8).
Now we want to get all our FRUIT labels, so we call the getSegmentedLabels with the Xel-method name all().
This return a Map<String,Object> where all the labels are in.
We are interested only in the subsection FRUIT so we get the value behind the key FRUIT.
This object is again a Map<String,Object> wich contains every key under the FRUIT.
In this example it contains <'APPLE','apple'>,<'ORANGE','orange'>.
The next thing we need to do is iterating over the Map and showing all the values of the Map.
This we do with the forEach attribute.
So the each object's value is now an Object of class Entry<String,Object>.
The only thing to show it now is showing the value, with is Entry.getValue().