I have simple data structure:
"Issue" has poiter to other class "Status" in field "status"
From doc we know include - take key name and pointed data should be avalible in result without any action. But then I try to access pointed data I get null.
ParseQuery<Issue> query = ParseQuery.getQuery("Issues");
query.include("status");
query.whereEqualTo("owner", user);
query.findInBackground(new FindCallback<Issue>() {
public void done(List<Issue> issueList, ParseException e) {
if (e == null) {
Log.d(TAG, "Retrieved " + issueList.size() + " issues");
ParseObject status = issueList.get(0).getParseObject("status"); //NULL!
} else {
Log.d(TAG, "Error: " + e.getMessage());
}
}
});
Manualy form console I can see valid data and jump from Issue to Status by pointer (I have only one record in both)
Parse lib version - 1.11
What I'm doing wrong?
I think it should work.. Check your security and ACL settings in Parse Status class (if you don't have the rights to get the status you won't get it), make sure issueList.get(0) is not null and make sure that the Status object you are pointing to really exist in Parse Status table.
Related
Objective: The document of the user who is signed in should be accessible by the user.
Collection Structure :
> root(collection_name)
> user1#gmail.com(document_name)
> "name" : "User One"(field key and value)
> user2#gmail.com
> "name" : "User TWO"
Android Code I Used
db.collection("/root/")
.get()
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : Objects.requireNonNull(task.getResult())) {
System.out.println(document.getId() + " => " + document.getData());
}
} else {
System.out.println(task.getException());
}
});
Database Rules I tried :
service cloud.firestore {
match /databases/{database}/documents {
match /root/{email} {
allow read, update, delete: if request.auth.token['email'] == email;
allow create: if request.auth != null;
}
}
}
Error I Get :
com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.
Listen for Query(target=Query(root order by name);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
I also tried using
service cloud.firestore {
match /databases/{database}/documents {
match /root/{email} {
allow read, update, delete: if request.auth!=null;
allow create: if request.auth != null;
}
}
}
The above rule returns me all the documents in the collection but I only want it to return the document of the specific user who is signed in. So I know that the issue is in checking the email of the user.
When you are using the following rules:
match /root/{email} {
allow read, update, delete: if request.auth.token['email'] == email;
allow create: if request.auth != null;
}
It means that you allow only the authenticated user to read, update or delete data at the location you are pointing to, which is the user's document. However, in your code, you request data from the entire "root" collection:
db.collection("/root/").get()
Hence that error message. To solve this, you either change the query in your code, or you change the rules. But most likely you should change the way you are getting the data by using the following reference:
db.collection("root").document(userEmail).get().addOnCompleteListener(/* ... /*);
I am trying to invoke a lambda function which is triggered by S3Event, I have created a bucket as well, also added two images into the bucket.
below are the specifications of bucket.
Below is my code which I have written in java
public String handleRequest(S3Event event, Context context) {
context.getLogger().log("Received event: " + event);
// Get the object from the event and show its content type
String bucket = event.getRecords().get(0).getS3().getBucket().getName();
String key = event.getRecords().get(0).getS3().getObject().getKey();
try {
S3Object response = s3.getObject(new GetObjectRequest(bucket, key));
String contentType = response.getObjectMetadata().getContentType();
context.getLogger().log("CONTENT TYPE: " + contentType);
return contentType;
} catch (Exception e) {
e.printStackTrace();
context.getLogger().log(String.format(
"Error getting object %s from bucket %s. Make sure they exist and"
+ " your bucket is in the same region as this function.", bucket, key));
throw e;
}
}
and below is the error I am getting
com.amazonaws.services.lambda.runtime.events.S3Event not present
Code looks fine, Confirm that you have this package imported :
com.amazonaws.services.lambda.runtime.events.S3Event
And implement the interface "RequestHandler" with your class.
If issue still persist follow this tutorial:
AWS Lambda with S3 for real-time data processing
Hope this will help !
In my endWorkout.java file, I am saving data into my Parse database using the following logic:
// Parse Storage
ParseObject testObject = new ParseObject("TestOne");
testObject.put("Device", ParseInstallation.getCurrentInstallation());
testObject.put("Reps", inputList);
testObject.saveInBackground();
Where I am first storing my Device ID for authentication purposes, and then storing inputList which is an ArrayList of integers.
In my Parse database, the data is properly saved, as shown below:
Now in my MainActivity.java, I would like to retrieve all the data in the Reps field of the Parse database for a single device. For example, the device yhmrKgokfS has 6 Arrays in the Parse database, I would like to sequentially retrieve each of them to display in a ListView on the screen.
Here is the logic I am trying to use:
List<ParseObject> importList = new ArrayList<ParseObject>();
//parse import list
ParseQuery<ParseObject> query = ParseQuery.getQuery("TestOne");
query.whereEqualTo("Device", ParseInstallation.getCurrentInstallation());
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> repList, ParseException e) {
if (e == null) {
Log.d("Reps", "Retrieved " + repList.size() + " reps");
} else {
Log.d("Reps", "Error: " + e.getMessage());
}
}
});
importList = repList;
I first want to make sure I'm importing from the current device, so I need to check if the Device field matches ParseInstallation.getCurrentInstallation(). Then I want to go ahead and get the first Reps array. However the last line importList = repList; does not work.
How can I go about achieving what I'm trying to do?
query.findInBackground works in asynchronous way. In other words, the line that you set the importList is executed after the line query.findInBackground. However, the query.findInBackground will make a network call that takes time. So if you want to use the repList when it is ready, you have to use it in done method where you are use the network call is done. Hope this helps.
Regards.
As #kinkspeech mentioned you need to move your line importList = repList; to your callback. And I suggest that you change it as follows:
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> repList, ParseException e) {
if (e == null) {
Log.d("Reps", "Retrieved " + repList.size() + " reps");
importList.addAll(replist);
} else {
Log.d("Reps", "Error: " + e.getMessage());
}
}
});
I have a problem, I have this structure in parse.com in "VerificationCode" db:
When someone inserts a code in my app, it automatically adds in the "attachedUser" column the id of the user who is stored locally and I call it "ParseInstallObject.codigo2" and I get the id of the user for example to see it in a textview, etc.
The problem is that I want to check if the user id exists in parse or not; and if it exists do something or if not exist do another thing.
I used a code that I see in the documentation of parse.com but it always shows that the code exists. This is my code:
ParseQuery<ParseObject> query2 = ParseQuery.getQuery("VerificationCode");
query2.whereEqualTo("attachedUser", ParseInstallObject.codigo2);
query2.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
comprobar.setText("exist");
comprobar2.setText("exist");
} else {
comprobar.setText("no exist");
comprobar2.setText("no exist");
}
}
});
How can I see if the user has a valid code or not?
e==null means that the call was successfully completed by the server. It does not imply that the user exists or not.
if(e==null){
if(scoreList == null || scoreList.isEmpty()){
// The user does not exist.
}else{
// the user exists.
}
}else {
// You have an exception (like HTTPTimeout, etc). Handle it as per requirement.
}
In crawler4j we can override a function boolean shouldVisit(WebUrl url) and control whether that particular url should be allowed to be crawled by returning 'true' and 'false'.
But can we add URL(s) at runtime ? if yes , what are ways to do that ?
Currently I can add URL(s) at beginning of program using addSeed(String url) function before the start(BasicCrawler.class, numberOfCrawlers) in CrawlController class and if I try to add new url using addSeed(String url), it gives error. Here is error image .
Any help will be appreciative and please let me know if any more detail about project is required to answer the question .
You can do this.
Use public void schedule(WebURL url) to add URLs to the crawler frontier which is a member of the Frontier.java class. But for this you need to have your url of type WebURL. If you want to make a WebURL out of your string. Please have a look at the addSeed() (below code) which is in the CrawlController.java class to see how it has converted the string (url) into a WebURL.
Also use the existing frontier instance.
Hope this helps..
public void addSeed(String pageUrl, int docId) {
String canonicalUrl = URLCanonicalizer.getCanonicalURL(pageUrl);
if (canonicalUrl == null) {
logger.error("Invalid seed URL: " + pageUrl);
return;
}
if (docId < 0) {
docId = docIdServer.getDocId(canonicalUrl);
if (docId > 0) {
// This URL is already seen.
return;
}
docId = docIdServer.getNewDocID(canonicalUrl);
} else {
try {
docIdServer.addUrlAndDocId(canonicalUrl, docId);
} catch (Exception e) {
logger.error("Could not add seed: " + e.getMessage());
}
}
WebURL webUrl = new WebURL();
webUrl.setURL(canonicalUrl);
webUrl.setDocid(docId);
webUrl.setDepth((short) 0);
if (!robotstxtServer.allows(webUrl)) {
logger.info("Robots.txt does not allow this seed: " + pageUrl);
} else {
frontier.schedule(webUrl); //method that adds URL to the frontier at run time
}
}
Presumably you can implement this function however you like, and have it depend on a list of URLs that should not be crawled. The implementation of shouldVisit is then going to involve asking if a given URL is in your list of forbidden URLs (or permitted URLs), and returning true or false on that basis.