I'm trying to sort through ParseObjects created by different users (clubadmins) and presenting the results based on "clubAdmin" in a recyclerview. For some reason I can't put my finger on, the query is not yielding any results to populate my view.
The line that seems to be the problem is where I query to sort using whereEqualTo().
Any help with what might be the problem is much appreciated.
The .toString() was the latest addition which also did not resolve the issue.
ParseQuery<Club> query = ParseQuery.getQuery(Club.class);
query.whereEqualTo("clubAdmin",ParseUser.getCurrentUser().toString());
query.orderByAscending("createdAt");
query.setLimit(MAX_CLUBS_TO_SHOW);
query.findInBackground(new FindCallback<Group>() {
#Override
public void done(List<Club> objects, ParseException e) {
if(e == null) {
for (Club c : objects) {
Club createdClub = new Club();
createdClub.setClubName(c.getClubName());
createdClub.setObjectId(c.getObjectId());
listItems.add(createdClub);
I was aiming for a list with the clubs created by the logged in user barring all others. Now I do not see anything in my view. If I comment out the line containing whereEqualTo(), I get all the clubs created within the app populating my view set to the limit.
What is the type of clubAdmin field? Is it a pointer to user class or a String holding the objectId of a user? If it is the second case, you have to get the objectId of the user like ParseUser.getCurrentUser().getObjectId();
Related
Hello I'm having a problem to access to My Saved carts, I have a 500 error. Because a cart in the list of saved carts contains a product is coming null from /commercefacades/order/impl/DefaultSaveCartFacade.java, It no longer exists in our repository.
So, the problem happens when we want to convert SavedCartModel CartModel to SavedCartData CartData. The populator which populates the product data is called :
public class ProductBasicPopulator<SOURCE extends ProductModel, TARGET extends ProductData> extends
AbstractProductPopulator<SOURCE, TARGET>
{
private ProductConfigurableChecker productConfigurableChecker;
#Override
public void populate(final SOURCE productModel, final TARGET productData) throws ConversionException
{
productData.setName((String) getProductAttribute(productModel, ProductModel.NAME));
productData.setManufacturer((String) getProductAttribute(productModel, ProductModel.MANUFACTURERNAME));
productData.setAverageRating(productModel.getAverageRating());
if (productModel.getVariantType() != null)
{
productData.setVariantType(productModel.getVariantType().getCode());
}
if (productModel instanceof VariantProductModel)
{
final VariantProductModel variantProduct = (VariantProductModel) productModel;
productData.setBaseProduct(variantProduct.getBaseProduct() != null ? variantProduct.getBaseProduct().getCode() : null);
}
productData.setPurchasable(Boolean.valueOf(productModel.getVariantType() == null && isApproved(productModel)));
productData.setConfigurable(Boolean.valueOf(getProductConfigurableChecker().isProductConfigurable(productModel)));
productData.setConfiguratorType(getProductConfigurableChecker().getFirstConfiguratorType(productModel));
}
// code
}
ProductModel which is passed in the first parameter of the populate method is null and consequently a Null Pointer Exception is thrown.
How could I handle this case? Is there a method to remove products that no longer exist from saved carts ? Or another solution that could correct this problem without removing the saved cart.
Please help me how to resolve this issue.
Thanks in advance.
Regards,
How you delete product?
Generally we are checking existing carts and remove item, calculated = false before delete.
On the other hand, product deletion doesn't good concept. If you delete product, orders, consignments, etc getting problem. You need to mark these products as not sellable instead of delete.
Pardon me as I'm quite a beginner in coding. I have tried researching for ways to add some missing record into the lists but still can't seem to fit it correctly into my code.
I have two ArrayLists with different resultsets. Say, the first one is derived in other method and stored in abcList. This list is then used in my current fixChartStats method as a param.
In my code, I will check for the corresponding record in abcList with the second list I derive from the hql query in fixChartStats method.
If the record corresponds, then I'll do the necessary action as shown below to update the ApprovedCount number etc, else i set it to 0.
How do I go about adding the records that are missing in second list I got into the first arraylist (i.e. abcList)? Can anyone here shed some light? Do let me know if my questions are unclear. Thanks in advance, guys!
private void fixChartStats(List<TAbcModel> abcList, Map<String, Object> param, List<IssueModel> issueList, List<DestModel> destList) throws Exception {
//initialize the hql query
//translate all fields from Object[] into individual variable
firstRow = true;
for (TAbcModel abc : abcList) {
if (abc.getId().getAbcYear() = abcYear &&
abc.getId().getAbcMonthId() = abcMonthId &&
abc.getId().getAbcApplAccnId().getAccnId().equalsIgnoreCase(abcApplAccnId.getAccnId()) {
if (firstRow) {
abc.setApprovedCount(abcApprovedCount);
abc.setCancelledCount(abcCancelledCount);
firstRow = false;
} else {
abc.setApprovedCount(0);
abc.setCancelledCount(0);
}
}else{
// How to do the necessary here
// Below is what I've tried
abcList.add(abc);
}
}
}
When I debug, I noticed that it was added into the list. But soon after it was added, ConcurrentModificationException was thrown.
Create a local list and add missing records to it then add all elements from the local list to the abcList
List<TAbcModel> temp = new ArrayList<>();
in your loop:
} else {
temp.add(abc);
}
after loop
abcList.addAll(temp);
I am currently making a form for film database, using Vaadin. My problem is the whole situation with deep linking. I want to have a url with an id of movie in it, to make possible to get to the form of concrete movie.
localhost:port/filmView/idOfSelectedMovie
I am currently using pushState but there are couple of problems.
1) When I add string "Film/" before Id, the first selection works fine, however with following selections the url just keeps adding this.
http://localhost:8081/Film/Film/Film/Film/Film/4
2) The second option I tried was using just an id. The effect was that the url just keeps the host with port, and gets rid of ViewName
http://localhost:8801/4
I had already tried to use replaceState and Urifragment methods, the effect wasn't better at all.
the function handling selection of movie on the list
this.itemsList.addSelectionListener(selectionEvent -> {
if (selectionEvent.getFirstSelectedItem().isPresent()) {
Film selectedFilm = selectionEvent.getFirstSelectedItem().get();
this.setupForm(selectedFilm);
Page.getCurrent().pushState("Film/" + selectedFilm.getFilmId());
}
});
What you have to do while navigating between views this: let's say you have a View with a list of films, from you can select a film. When you select a film from that list, you move to the film View
getUI().getNavigator().navigateTo(FilmView + "/" + filmId); //let's say id 88
in this way, you will navigate to http://localhost:8081/Film/88
now, in your FilmView you can get and use this id, something like:
public class FilmView extends VerticalLayout implements View{
#Override
public void enter(ViewChangeEvent event) {
String yourPassedId = event.getParameters();
//do stuff with your id, for example loading from DB
}
}
In this way, you can reach every film you want with hard link, like http://localhost:8081/Film/88
I am implementing a Room database (because I want to move away from Loaders) and I have a query that selects objects based on the IN operator:
#Query(SELECT * FROM table WHERE icon IN(:icons))
LiveData<List<Result>> getResults(String[] icons);
The issue is that the :icons array is generated dynamically during runtime, first I generate placeholders for it and then replace them with the values, like so:
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String[] iconsArray = generateIconArray();
mViewModel = ViewModelProviders.of(this, new MyViewModelFactory(getActivity().getApplication(), iconsArray)).get(MyViewModel.class);
mViewModel.getResults().observe(this, new Observer<List<Result>>() {
#Override
public void onChanged(#Nullable List<Result> results) {
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getActivity(), 3);
mRecyclerView.setLayoutManager(layoutManager);
GridAdapter adapter = new GridAdapter(getActivity(), results);
mRecyclerView.setAdapter(adapter);
}
});
}
The problem is that I receive an empty RecyclerView, but when I pass an array with a single icon, the query works normally.
Is it not possible to achieve the same in Room because it checks queries during compile time?
And if not, instead of that should I just use db.query(...) in my repository constructor?
I know this sort of question was asked here, but it also says that they are working on it, and I couldn't find any signs of it.
EDIT:
In case someone stumbles upon this question, I made a small mistake while implementing this feature, the code provided in onActivityCreated actually works. It's also worth mentioning that it works with String[] and lists, but not with a single string: "ab,cd,ef".
I made a small mistake while implementing this feature, the code provided in onActivityCreated actually works. It's also worth mentioning that it works with String[] and List, but not with a single String: "ab,cd,ef", which was my mistake.
I am building a simple MCQ quiz app.
What I did was make a database on Parse.com and stored the questions, possible answers and the correct solution in it.
The Parse.com table can be seen in this image: http://i.imgur.com/yXQ2FX1.png
As you can see, each object has a question, with 4 possible options and the correct answer.
Now, I want to show the questions inside a TextView and the options inside four different buttons. The user will click on the correct button to answer and the app will check if the correct button was pressed.
How do I retrieve contents from a specific object's attributes into a textview or a button?
Note: I tried following the online documentation for Queries. Their example showed how to retrieve objects by queries, but not how to show those objects in TextViews or how to store those objects inside a local variable. For example, I know how to query for a particular object, but once I do get the object how do I retrieve a particular attribute of that object, how do I get what is stored inside "optionA" field and store it inside a string?
I know there is a ListView adapter, but as you can see I can't use a ListView here.
I tried the following code trying to convert the queried objects into strings, but that didn't work. I am really a newbie, so maybe I am doing something stupid. Please help me out.
Try something like:
query.whereEqualTo("ques",/*enter question number here*/);
query.findInBackground(new FindCallBack<ParseObject>(){
public void done(List<ParseObject> l; ParseException e){
if(e == null){
for(int i = 0; i <l.size();i++){
textView.setText(l.get(i).getString("optionA"))
}
}
else{//handle the error
}
}
});
Once you get the object (and you said you know how to), you access the properties like this:
String theQuestion = object.getString("question");
Putting it in a textview would then be like this:
yourTextView.setText(theQuestion);
You can get more info on object access in the Android guide:
https://parse.com/docs/android_guide#objects-retrieving
See if you wanna import the whole of the database you can proceed with the following code(The class structure has a simple BOY and GIRL records)-
ParseQuery<ParseObject> query = ParseQuery.getQuery("Friends");
//query.whereEqualTo("Boy", tf3.getText().toString()); //This is to filter things!
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
int len=scoreList.size();
for(int i=0;i<len;i++) {
ParseObject p = scoreList.get(i);
String boy = p.getString("Boy");
String girl = p.getString("Girl");
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});