GAE Datastore results to FlexTable using JDO - google-app-engine

This seems like a simple task, but somewhere in searching the docs- I've missed the connection.
I have a menu stored in GAE and can return the results of a query:
public String[] getMeals() throws NotLoggedInException {
checkLoggedIn();
PersistenceManager pm = getPersistenceManager();
List<String> meals = new ArrayList<String>();
try {
Query q = pm.newQuery(Meal.class, "user == u");
q.declareParameters("com.google.appengine.api.users.User u");
q.setOrdering("createDate");
List<Meal> myMeals = (List<Meal>) q.execute(getUser());
for (Meal myMeal : myMeals) {
meals.add(myMeal.getMealID());
}
} finally {
pm.close();
}
return (String[]) meals.toArray(new String[0]);
}
With those results, I'd like to bind it to a FlexTable. Using the stockwatcher sample, I've managed to get my ID bound to the FlexTable, but am missing the concept of how I tie the other fields in my result set to it. (The fields I have in the GAE are mealID, mealType and mealDate)
From above, we can see that I'm tossing mealID into a List.
I also know that my other fields must exist in the query because I haven't done anything to filter them. As a matter of fact, if I change my code to:
meals.Add(myMeal.getMealID(), myMeal.getMealType(), myMeal.getMealDate());
it returns all the data, but the flex table treats each item as a new row instead of the three fields on one row.
So my question is: how should I be capturing my records and sending them to my FlexTable so that I can bind the FlexTable to the resultset?
For reference, client side code:
private void loadMeals() {
// load meals from server service MealService
mealService.getMeals(new AsyncCallback<String[]>() {
public void onFailure(Throwable error) {
handleError(error);
}
public void onSuccess(String[] meals) {
displayMeals(meals);
}
});
}
private void displayMeals(String[] meals) {
for (String meal : meals) {
displayMenu(meal, meal, meal);
}
}
The flextable gets populated like this:
mealID | mealType | mealDate
1 | 1 | 1
2 | 2 | 2
3 | 3 | 3
I want it to populate like this:
mealID | mealType | mealDate
1 | Breakfast | 12/22/2012
2 | Lunch | 12/22/2012
3 | Snack | 12/23/2012
Thanks in advance for your input!

This question is a duplicate of Problems passing class objects through GWT RPC
Following the details in that link, and little hired help from oDesk got me going.
Main oversight was needing the entrypoint class in {appname}.gwt.xml and placing the model classes in shared packages.

Related

iterate an object array and create multiple records with the value from it

I have an Object Array scheduleTable__c, with the below fields:
Product | Description | Jan | Feb | Mar | ...
right now, it will create one record and filling all the fields accordingly. I would like to change this by creating one record for each month inside the Array. I guess the right way to do so is to create another array by iterating over the current array and insert that value.
Replace my function
#AuraEnabled
public static List<scheduleTable__c> createPSs(List<scheduleTable__c> psList){
insert psList;
return psList;
}
by that
#AuraEnabled
public static List<scheduleTable__c> createPSs(List<scheduleTable__c> psList){
String [] arraySC = new List<String>();
for(Integer i = 2; i < psList.size(); i++){
arraySC.push(psList[0]);
arraySC.push(psList[1]);
arraySC.push(psList[i]);
}
insert arraySC;
return arraySC;
}
It doesn't seems to like the fact that it is an array of an object and I am creating a String Array...
I then replaced the array with this but still not able to make it work...
List<scheduleTable__c> arraySC = new List<scheduleTable__c>();
any help will be appreciated.

Dynamic JSON Formatting Issue

My application reads JSON data in a particular format. I am pulling data from a database to dynamically create the data. I have the data, I just do not know the proper way to put it all in the following format.
Note: the first 2 sets are pulled from one query, and the "variables" section is what needs to be looped through to populate as the variable names AND values are in their own fields.
Sample Tables<br>
Master Table
ID | Custom_Col1 | Custom_Col2
1 custom_val1 custom_val2
Variables Table
ID | Name | Value
1 var_name1 var_value1
2 var_name2 var_value2
3 var_name3 var_value3
4 var_name4 var_value4
5 var_name5 var_value5
6 var_name6 var_value6
{"Custom_Col1":"custom_val1", "Custom_Col2":"custom_val2","variables":{"var_name1":"var_value1","var_name2":"var_value2","var_name3":"var_value3", "var_name4":"var_value4","var_name5":"var_value5","var_name6":"var_value6"}}
I was able to get the looped values in by using the following, but I just don't know how to get the other variables in. I'm sure it's simple, I've just never worked with JSON before. I've scoured the internet and have found examples, but they have only gotten me so far:
var json = {}
while loop
{
json[name]= value.toString();
}
var stringJson = JSON.stringify(json);
You can create a collection in the same way you did with the var json.
var json = {}
while loopMasterTable
{
json[name]= value.toString();
}
json['variables'] = {}
while loopVariableTable
{
json['variables'][name]= value.toString();
}
var stringJson = JSON.stringify(json);
This will give you the following JSON:
{
"Custom_Col1": "custom_val1",
"Custom_Col2": "custom_val2",
"variables": {
"var_name1": "var_value1",
"var_name2": "var_value2",
"var_name3": "var_value3",
"var_name4": "var_value4",
"var_name5": "var_value5",
"var_name6": "var_value6"
}
}

Passing arrays of variable in specflow

Is there a way to pass an array of parameters instead of passing each parameter individually?
For example I have the following scenarios:
When i login to a site
then <firstname>, <lastname>, <middleName>, <Desingation>, <Street>, <Apartmentno> are valid
The list can go on above. Instead can I pass all the above variables in an array?
You can pass a comma separated string and then transform it into a list:
When i login to a site
then 'Joe,Bloggs,Peter,Mr,Some street,15' are valid
[Then("'(.*)' are valid")]
public void ValuesAreValid(List<String> values)
{
}
[StepArgumentTransformation]
public List<String> TransformToListOfString(string commaSeparatedList)
{
return commaSeparatedList.Split(",").ToList();
}
if you want the values to come from examples then you could do this instead:
When I login to a site
then '<values>' are valid
Examples
| values |
| Joe,Bloggs,Peter,Mr,Some street,15|
| Joe,Bloggs,Peter,Mr,Some street,16,SomethingElse,Blah|
If you want to use a table then you could do this instead:
When I login to a site
then the following values are valid
| FirstName | LastName | MiddleName | Greeting| Etc | Etc |
| Joe | Bloggs | Peter | Mr | you get| The Idea|
(you could omit the headers if you want and just use the row values I think)
you can also use examples with this:
When I login to a site
then the following values are valid
| FirstName | LastName | MiddleName | Greeting | Etc | Etc |
| <name> | <lastName>| <middleName>| <greeting>| <etc> | <etc> |
This might be of help:
https://github.com/techtalk/SpecFlow/wiki/Step-Argument-Conversions
Add the following code snippet to your Common Step Definition File:
[StepArgumentTransformation]
public string[] TransformToArrayOfStrings(string commaSeparatedStepArgumentValues)
{
string sourceString = commaSeparatedStepArgumentValues;
string[] stringSeparators = new string[] { "," };
return sourceString.Split(stringSeparators, StringSplitOptions.None);
}
SpecFlow will then automatically convert all comma-separated values in the SpecFlow Steps data table into an array of strings.
Then in your individual step binding function, change the type of the input parameter as string[] as in snippet below:
[Then(#"the expected value is '(.*)'")]
public void ThenTheExpectedValueIs(string[] p0)
{
//ScenarioContext.Current.Pending();
Assert.AreEqual(25, Convert.ToInt32(p0[0]));
Assert.AreEqual(36, Convert.ToInt32(p0[1]));
Assert.AreEqual(79, Convert.ToInt32(p0[2]));
}
Then, based on your expected value for a test step, you may want to apply the appropriate type conversion.
Just transfer the data as a string Example:
Then LEDS 0, 1, 7 are on
[Then(#"LEDS (.*) are on(.*)]
public void ThenLEDAreOn(string p0)
{
int count = p0.Split(',').Length - 1;
string[] Leds_on = p0.Split(',');
foreach (string s in LEDs_on)
{
int.TryParse(s, out LEDS[index]);
index++;
}
}
Then you have your values as integers in an array

SSIS - import file with columns populated like sub-headers (omitted on some rows)

I am importing an Excel file which is formatted like a report - that is some columns are only populated once for each group of rows that it belongs to, such as:
CaseID |Date |Code
157207 | |
|8/1/2012 |64479
|8/1/2012 |Q9967
|8/1/2012 |99203
I need to capture one of these group headers (CaseID, in the example above) and use it for subsequent rows where the field is blank, then save the next value that I encounter.
I have added a variable (User::CurrentCaseId) and a Script transform, with the following code:
public class ScriptMain : UserComponent
{
string newCaseId;
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
if (!Row.CaseIDName_IsNull && Row.CaseIDName.Length > 0)
newCaseId = Row.CaseIDName;
else
newCaseId = "DetailRow";
}
public override void PostExecute()
{
base.PostExecute();
if (newClaimNumber != "DetailRow")
Variables.CurrentCaseId = newCaseId;
}
Basically, I am trying to read the value when present and save it in this variable. I use a conditional split to ditch the rows that only have the CaseID and then use a derived column to put the variable value into a new column to complete the detail row.
Alas, the value is always blank (placed a data viewer after the derived column). I modified the script to always set the variable to a fixed string - the derived column is still blank.
This seemed like a good plan... I received some feedback in the MS forums that you can't set a variable value and use its new value within the same Data Flow Task. If that is so, the only solution I can think of is to write the CaseID out to a table when present and read it back in when absent. I really hate to do that with several million rows (multiple Excel worksheets). Any better ideas?
Best,
Scott
This can be a good starting point for you.
I used the following file as the source. Saved it into C:\Temp\5.TXT
CaseID |Date |Code
157207 | |
|8/1/2012 |64479
|8/1/2012 |Q9967
|8/1/2012 |99203
157208 | |
|9/1/2012 |77779
|9/2/2012 |R9967
|9/3/2012 |11203
Put a DFT on the Control Flow surface.
Put Script Component as Source on the DFT
3.1. Go to Inputs and Outputs section
3.2. Add Output. Change it name to MyOutput.
3.2.1 Add the following output columns - CaseID, Date, Code
3.2.1 The data types are four-byte unsigned integer [DT_UI4], string [DT_STR], string [DT_STR]
Now go to Scripts // Edit Script. Put the following code. Make sure to add
using System.IO;
to the namespace area.
public override void CreateNewOutputRows()
{
string[] lines = File.ReadAllLines(#"C:\temp\5.txt");
int iRowCount = 0;
string[] fields = null;
int iCaseID = 0;
string sDate = string.Empty;
string sCode = string.Empty;
foreach (string line in lines)
{
if (iRowCount == 0)
{
iRowCount++;
}
else
{
fields = line.Split('|');
//trim the field values
for (int i = 0; i < fields.Length; i++)
{
fields[i] = fields[i].Trim();
}
if (!fields[0].Equals(string.Empty))
{
iCaseID = Convert.ToInt32(fields[0]);
}
else
{
MyOutputBuffer.AddRow();
MyOutputBuffer.CaseID = iCaseID;
MyOutputBuffer.Date = fields[1];
MyOutputBuffer.Code = fields[2];
}
}
}
}
}
Testing your code: Add a Union All components right beneath where you put the Script component. Connect the output of the Script component to the Union All component. Put data viewer.
Hopefully this should help you. Please let us know. I responded to a similar question today; please check that one out as well. That may help in solidfying the concept - IMHO.

How can I specify a bitmask/bitfield WHERE clause using NHibernate's Criterion API [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to query flags stored as enum in NHibernate
I have three tables - Recipient, Message, MessageType
MessageType looks like this:
| ID | Description |
|====|==============|
| 1 | JobAlert |
| 2 | Newsletter |
| 3 | SpecialOffer |
| 4 | Survey |
Recipient contains an integer column which is used as a bitfield; recipients can choose what types of message they want to receive; If a recipient wants to receive newsletters and special offers, we'll set their bitfield to (2 ^ 2) | (2 ^ 3)
Message contains a reference to MessageTypeId, and computed column MessageTypeBitFlag which is defined as POWER(2, MessageTypeId)
My query expressed in SQL looks something like:
SELECT * FROM Message, Recipient
WHERE Recipient.MessageTypeBitField & Message.MessageTypeBitFlag > 0
by doing a bitwise-AND on the bitfield and bitflag columns, it's easy to select only the messages that a particular recipient is interested in.
Problem is, I'm not doing this in SQL - I need to add this as an additional option to a fairly rich system built on the NHibernate Criteria API.
Is there any way to express this criteria via the NHibernate API - either using the API or by adding an SQL/HQL clause to the existing criteria?
OK, here's a specific implementation based on this linked post submitted by Firo, because I had to adapt this a little to make it work:
/// <summary>An NHibernate criterion that does bitwise comparison to match a bit flag against a bitmask.</summary>
public class BitMask : LogicalExpression {
private BitMask(string propertyName, object value, string op) :
base(new SimpleExpression(propertyName, value, op), Expression.Sql("?", 0, NHibernateUtil.Int64)) {
}
protected override string Op {
get { return ">"; }
}
/// <summary>Create a bitwise filter criterion - i.e. one that will be satisified if <code><paramref name="propertyName"/> & <paramref name="bits"/> > 0</code></summary>
public static BitMask Matches(string propertyName, long bits) {
return new BitMask(propertyName, bits, " & ");
}
}
and then use it via the Criteria API as follows:
public IEnumerable<Message> GetMessagesForRecipient(Recipient r) {
var messages = session.CreateCriteria<Message>()
.Add(BitMask.Matches("MessageTypeBitFlag ", r.MessageTypeBitField))
.List<Message>();
return(messages);
}

Resources