ParseQuery Array to lowercase before search - java

I have issue with searching trough ParseQuery Array.
I need case insensitive search, so i need to convert my array to lowercase.
I tried query.whereMatches and query.whereContains without success.
My guess is to make new method that would convert all data from ParseQuery to lowercaseString Array.
Am i right with this one?
Here's the example code for setting search result list:
private void setList(boolean hardRefresh) {
// stop any ongoing progress dialog
cancelProgressDialog();
reloadTags();
reloadContents();
ParseQuery<Note> query = Note.getQuery()
.fromLocalDatastore()
.orderByDescending("date");
String searchStr = searchText.getText().toString().toLowerCase();
if (!searchStr.isEmpty()) {
query.whereMatches(Note.FIELD_DETAIL, searchStr);
}
try {
mNotes = query.find();
if (adapter == null) {
adapter = new ListAdapter();
notesGridView.setAdapter(adapter);
} else {
adapter.notifyDataSetChanged();
}
} catch (ParseException e) {
e.printStackTrace();
}

For case insensitive search try like this :
if (!searchStr.isEmpty()) {
query.whereMatches(Note.FIELD_DETAIL, searchStr,"i");
}

Related

Get data from query result and set them into list of objects in Spring Boot

I have an api to upload a file and save it's columns to database there is no problem for here. But i have to get some properties from database and set them into my list object and save all of them together. But when i trying to use foreach to set those results to my model i got same result for every one of them. Query result comes as list. I couldn't seperate them.
For example row[0] has 4 properties. and i couldn't reach row[0]'s third parameter. And set it to my model.
I want to reach that properties all for every coming list. How can i do it with foreach.
I want to set them all separately.
Query query2 = em.createNativeQuery(selectQuery);
List<Object[]> rows = new ArrayList<>();
try {
rows = query2.getResultList();
} catch (Exception e) {
e.printStackTrace();
}
for (DiscountFile discountFileModel : discountFileList) {
for (Object[] row : rows) {
if (row[0] != null) {
discountFileModel.setBtHesapId(row[0].toString());
} else {
discountFileModel.setBtHesapId(null);
}
if (row[1] != null) {
discountFileModel.setOzelKod(row[1].toString());
} else {
discountFileModel.setOzelKod(null);
}
if (row[2] != null) {
discountFileModel.setAktarildi(row[2].toString());
} else {
discountFileModel.setAktarildi(null);
}
if (row[3] != null) {
discountFileModel.setBtProductSerialNo(row[3].toString());
} else {
discountFileModel.setBtProductSerialNo(null);
}
if (row[4] != null) {
discountFileModel.setBtTmsAboneId(row[4].toString());
} else {
discountFileModel.setBtTmsAboneId(null);
}
if (row[5] != null) {
discountFileModel.setBtCrmHesapNo(row[5].toString());
} else {
discountFileModel.setBtCrmHesapNo(null);
}
discountFileModel.setBireyselKurumsal(listeTipi);
iDiscountFile.saveAll(discountFileList);
}
}

How to get followers and following list screen names (Twitter4J)?

I am trying to get my followers and following list via Twitter 4J.
I pass the configuration builder from the main method as a parameter to the method.
Here is the code:
try {
Twitter twitter = new TwitterFactory().getInstance();
long cursor = -1;
IDs ids;
System.out.println("Listing following ids.");
do {
if (0 < args.length) {
ids = twitter.getFriendsIDs(args[0], cursor);
} else {
ids = twitter.getFriendsIDs(cursor);
}
for (long id : ids.getIDs()) {
System.out.println(id);
}
} while ((cursor = ids.getNextCursor()) != 0);
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to get friends' ids: " + te.getMessage());
System.exit(-1);
}
So far this only returns IDS but it does not return the screen name of the followers. Does anyone have any idea? I am working in Java and printing to the terminal.
Thanks.
String twitterScreenName = twitter.getScreenName();
PagableResponseList<User> statuse = twitter.getFollowersList(twitterScreenName, -1);
for (User follower : statuse) {
System.out.println(follower.getName());
}

Storing all ParseFiles for a given ParseUser?

I'm new to Parse and was wondering if there is any way to store all the ParseFiles (in this case images) for a given ParseUser into something like an ArrayList?
Here's my code:
public ArrayList<ParseFile> getFiles() {
ArrayList<ParseFile> files = new ArrayList<ParseFile>();
//mUser is the current ParseUser
ParseQuery<ParseObject> query = ParseQuery.getQuery(mUser.getUsername());
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> fileList, ParseException e) {
if (e == null) {
Log.d("FILES", "Retrieved " + fileList.size() + " files");
for(ParseObject ch:fileList) {
image = ch.getParseFile("image");
files.add(image);
#Override
public void done(byte[] arg0, ParseException arg1) {
//nothing to do here
}
});
}
Log.i("TAG", ": " + files.size());
} else {
Log.d("FILES", "Error: " + e.getMessage());
}
}
});
Log.i("DONE", ": " + files.size());
return files;
}
When I'm inside done(), the 3 images I have for this particular user are added and I get an ArrayList of size 3 which is to be expected. When I'm outside of done(), the size of the ArrayList goes back to 0, which I'm assuming is because it's being referenced outside of the query. And sure enough it returns an empty ArrayList (not too shocking).
I feel like this should be an easy solution but I can't seem to figure it out. I've tried to make a static ArrayList variable but that doesn't seem to work either. Any idea on how to return the desired ArrayList?
I believe the problem is that the outside thread still continues before your background process is completed. In other words..
1. query.findInBackground(....);
2. Log.i("DONE" ....);
.. 2. is executed before 1. completes. The whole point of Parse "inBackground" is that it completes actions that your thread is not dependent on. If you need to do something with the List, you should do it in the same thread as the background thread or not do it "inBackground".
Try like this
ParseQuery<ParseObject> query = ParseQuery.getQuery(mUser.getUsername());
List<ParseObject>imageList=query.find();
try {
Arraylist<ParseFile> files = new Arraylist<ParseFile>files();
ParseFile image;
for(int i =0;i<imageList.size();i++)
{
image = imageList.get(i).getParseFile("image");
files.add(image);
}
}
catch()
{
}

Reordering an array from parse.com

I am getting an array from parse.com. I am using an array, to retrieve an array:
fightList.whereContainedIn("objectId", itemListCard);
fightList.findInBackground(new FindCallback<ParseObject>() ....
My first array; itemListCard is in a specific order. After I findInBackground, my array from online, (objectId), is completely out of order. This is because I am getting it from Parse.com, so it is added to the array as it is retrieved. I need to:
1. Re-order array objectId to match itemListCard or
2. Retrieve objectId in order of itemListCard
Java code:
HomeItemList = new ArrayList<HomeItem>();
fightList.whereContainedIn("objectId", itemListCard);
fightList.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objectId, ParseException e) {
if (e == null) {
for (int i = 0; i < objectId.size(); i = i + 2) {
HomeItem homeItem = new HomeItem();
homeItem.setHomeItemID(k);
k++;
//set Red Array
homeItem.setHomeItemRedName(objectId.get(i).getString("Name"));
homeItem.setHomeItemRedAge(objectId.get(i).getString("Age"));
homeItem.setHomeItemRedRecord(objectId.get(i).getString("Record"));
homeItem.setHomeItemRedHeight(objectId.get(i).getString("Height"));
homeItem.setHomeItemRedWeight(objectId.get(i).getString("Weight"));
homeItem.setHomeItemRedCity(objectId.get(i).getString("Location"));
homeItem.setHomeItemRedExp(objectId.get(i).getString("Experience"));
//set blue Array
homeItem.setHomeItemBlueName(objectId.get(i+1).getString("Name"));
homeItem.setHomeItemBlueAge(objectId.get(i+1).getString("Age"));
homeItem.setHomeItemBlueRecord(objectId.get(i+1).getString("Record"));
homeItem.setHomeItemBlueHeight(objectId.get(i+1).getString("Height"));
homeItem.setHomeItemBlueWeight(objectId.get(i+1).getString("Weight"));
homeItem.setHomeItemBlueCity(objectId.get(i+1).getString("Location"));
homeItem.setHomeItemBlueExp(objectId.get(i+1).getString("Experience"));
HomeItemList.add(homeItem);
}
HomeListAdapter = new HomeListAdapter(getApplicationContext(), 0, HomeItemList);
adapter.addSection(" Fight Card ", HomeListAdapter);
} else {
progressDialog.dismiss();
Log.d("Display Card", "Error parsing Card");
Log.d("Card Error:", e.getMessage());
Toast.makeText(databaseFightCard.this, "Could not retrieve parse info. Try again later", Toast.LENGTH_LONG).show();
}
listView.setAdapter(adapter);
progressDialog.dismiss();
}
});
Note
The for loop is counting by 2 because this is the structure I am going for:
objectId[0] vs objectId[1]
objectId[2] vs objectId[3]
objectId[4] vs objectId[5]
objectId[6] vs objectId[7]
....and so on
Hence the need for a specific order.
You can control the order in which the items are returned using orderByAscending() and orderByDescending().
In your case:
fightList.whereContainedIn("objectId", itemListCard);
fightList.orderByAscending("objectId");
fightList.findInBackground(new FindCallback<ParseObject>() ....
See Query Constraints section of the the Parse Android Guide.

How to query value of column that is set as pointer to other table in Parse

I am using Parse for my app. I want to query a table with column that set to be a pointer to other table. Here is the query:
ParseQuery query = new ParseQuery("CategoryAttribute");
query.whereEqualTo("categoryId", categoryId);
query.findInBackground(new FindCallback() {
#Override
public void done(List<ParseObject> categoryAttributes, ParseException e) {
if (e == null) {
for (int i = 0; i < categoryAttributes.size(); i++){
String atributeCategoryId = categoryAttributes.get(i).getString("categoryId");
String attributeKey = categoryAttributes.get(i).getString("attributeKey");
String attributeValue = categoryAttributes.get(i).getString("attributeValue");
setCategoryAtributeRow(atributeCategoryId, attributeKey, attributeValue);
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
So the categoryId column is a pointer to other table. Other columns work fine.
I tried to scan the API and the guides but couldn't find needed solution. Help would be much appreciated!
Here is the solution to this one:
First you need to create a ParseObject from the type of your table:
ParseObject sale = ParseObject.createParseObject("Sale");
Then you need to get the ParseObject from the result:
sale = result.getParseObject(pointer_field);
Now you can pull from sale any field that it has just as you would do it normally, for example:
sale.getString("some_field")
Note:
When you are doing your query you must to include the pointer field if you want to be able to extract the data from it after the query will be returned. The result:
query.include("pointer_field")
Hope it helps
#Akshat Agarwal, here is a example in JavaScript:
var parseObj = Parse.Object.extend('parseObj');
new Parse.Query(parseObj)
.include('pointerField')
.find(function (data) {
data.get('pointerField').get('fieldName');
});
For iOS
PFQuery *parseQuery = [PFQuery queryWithClassName:#"MyClass"];
[parseQuery whereKey:#"categoryId" equalTo:categoryId];
[parseQuery includeKey:#"pinter_field"];
[parseQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
//
}];

Categories

Resources