I am developing a restful webapp.
In this the parameters i take are userid and orderid.
The userid can be null.
The URI is #Path("api/user/userid/order/orderid")
My method is,
void add(#PathParam("userid") String userId, #PathParam("orderid") String orderId);
I want to pass null value for userId in the URI.
I tried api/user//order/1234. But in this case, the userid takes the value of orderId (i.e 1234 and orderId is null. (which is wrong)
I also tried changing the path as #Path("api/user/userid: .*/order/orderid"). Yet the same result as previous.
The other ways for solving this could be, using #QueryParam for userid or creating another method for userid null.
But I would like to know if there is a way to have userId as PathParameter instead of QueryParam and pass the value of userid as null?
Having a URL param as null is not a valid case.
POSTing to the URL api/user/userid/order/orderid is saying "create an order for this user". GETting to that same URL would be saying "retrieve me this specific order for this user". Both are in the context of a user.
For doing order creation or retrieval outside of the context of a user, just remove those two parts of your URL...
api/order/orderid
This would allow you to create and get orders outside of the bounds of a customer. This would also work for in the context of a user. If you POST an order with no userID, nobody cares, but one can be specified. And if you GET an order, it shouldn't care which customer it is for, unless your orderID isn't unique across customers but that is probably not a good idea but that is a separate discussion.
Related
I've been trying to get the email of the user that submitted a response to a short answer assignment. In all of my other experiences using the Google Classroom API, the "userId" parameter has been the student's email address, but when I call getUserId on the StudentSubmission object, I get a weird string of numbers. How do I get the email associated with the submitted response?
Here's my code for reference:
ListStudentSubmissionsResponse submissionResponse = service.courses().courseWork().studentSubmissions().list(courseId, assignmentId).execute();
List<StudentSubmission> submissions = submissionResponse.getStudentSubmissions();
for (StudentSubmission sub : submissions)
{
System.out.println(sub.getId() + "\t" + sub.getUserId() + "\t" + sub.getState());
}
And this is the response that I am getting:
Cg4I2vWq_8IDEIWck4DDAw 108878473486432178050 CREATED
Does anyone know what is going on here?
There is published documentation on this API... no need to ask here: https://developers.google.com/classroom/reference/rest
More specifically, there are userProfile APIs that differentiate an "id" from an "emailAddress".
https://developers.google.com/classroom/reference/rest/v1/userProfiles
Now that said, there are no guarantees according to the JSON schema, being just a "String" type ... as to what the value might be.
"emailAddress" should be just that but "id" could be whatever the local system uses to identify principals - which is almost definitely NOT going to be the email address. It will instead be some global identifier for whatever principal management system is being used.
Don't not read the docs: retrieve_student_responses
Students are identified by the unique ID or email address of the user, as returned by the Google Admin SDK.
So there's clearly no guarantee it will return the email..
If you read the docs you can find how to properly retrieve the email for a student id: retrieve_a_users_profile
To retrieve the abridged profile, including ID and name, for a user, call userProfiles.get() with the user's ID, email, or "me" for the requesting user.
To retrieve the emailAddress field, you must include the classroom.profile.emails scope.
I have a field that I can insert a certain name and find the user with the correspondent name,that was developed in react.
My code works when that name is like "test", but if the name is like "this test" (if the name has a space on it), my backend receives the name in this format ("this%20test") and when I am searching for that name on the database, the entry returns null.
How can I solve this? I want to solve this on my frontend because I think it´s the best option.
Any parameters passed as query params will be url-encoded and passed to your backend.
You need to url decode parameters in your backend.
See this to url decode in java
https://stackoverflow.com/a/6138183/3295987
So I have this function to store user into Firestore after he successfully registers.
//User class
id: String
email: String?
displayName: String?
photoUrl: String?
//updateOrInsertUser method
collectionReference.document(user.id)
.set(
user,
SetOptions.mergeFields(
FIELD_photoUrl,
FIELD_email,
FIELD_displayName
)
)
But when I call updateOrInsertUser(user) only fields that are in SetOptions are stored in Firestore, therefore id is not stored.
Is there a simple way to override old values defined in SetOptions if the document already exists and if there is not doc store everything?
I don't want to fetch old document before updating :(
No I don't want to add id into SetOptions(imagine other use cases when you don't want to override field that already exists in database)
But when I call updateOrInsertUser(user) only fields that are in SetOptions are stored in firestore, therefore id is not stored.
This is the normal behaviour since you aren't passing the id to the SetOptions's mergeFields() method.
Is there a simple way to override old values defined in SetOptions if the document already exists and if there is not doc store everything? I don't want to fetch old document before updating :(
The simplest way would be to get the "old" document, change its values and write it back to the database but there is also another approach that can help you change the values within a document and this is by using a Map along with a update() method call. In code, might look like this:
Map<String, Object> user = new HashMap<>();
user.put("photoUrl", FIELD_photoUrl);
user.put("email", FIELD_email);
user.put("displayName", FIELD_displayName);
userDocumentReference.update(user);
I have custom object in my RemedyForce abc__c and would like to get list of it.
Tried this code:
SearchResult sr = con.search(
"FIND {00008137} IN abc__c FIELDS RETURNING abc__c(Id, Name)");
but it returns
[InvalidSObjectFault [ApiQueryFault [ApiFault
exceptionCode='INVALID_TYPE' exceptionMessage='sObject type
'abc__c' is not supported. If you are attempting
to use a custom object, be sure to append the '__c' after the entity
name. Please reference your WSDL or the describe call for the
appropriate names.'
Tried this code too and it returns:
String sql = "SELECT Id, Name FROM abc__c LIMIT 10";
QueryResult result = con.query(sql);
[InvalidSObjectFault [ApiQueryFault [ApiFault
exceptionCode='INVALID_TYPE' exceptionMessage='sObject type
'abc__c' is not supported.'] row='-1' column='-1'
]]
Anyone can advise how to get list of my custom object?
Your code looks good. This exception can happen if the user making the request doesn't have a permission to the specified object.
I have written a program that reads a webservice, retrieving user data, and then is supposed to push that data to ActiveDirectory, thus updating the user's title, address, phone numbers, etc.
The problem is that when I perform the search using the Unboundid Connection class the requested attributes are not returned. Below is the search code:
SearchResult result = connection.search( properties.getProperty("ldap.search.baseDN"),
SearchScope.SUB, "(cn=" + userId + ")",
"personalTitle", "department", "company", "manager", "telephoneNumber",
"streetAddress", "I", "st", "postalCode", "c", "pager", "mobile",
"fax", "cn");
The above code locates the desired user and the cn attribute is returned as expected, but the other attributes all fail to return. If I connect to AD using JXplorer using the same connection credentials, I'm able to see all the desired attributes exist, but are simply not being returned.
I have tried substituting SearchRequest.ALL_OPERATIONAL_ATTRIBUTES, SearchRequest.ALL_USER_ATTRIBUTES and SearchRequest.REQUEST_ATTRS_DEFAULT rather than listing the fields explicitly, but with no success.
I have also looked at the 'Schema' object returned from 'connection.getSchema()' and can see that personalTitle should exist:
connection.getSchema().getAttributeType("personalTitle")
The above code returns:
1.2.840.113556.1.2.615 NAME 'personalTitle' SYNTAX '1.3.6.1.4.1.1466.115.121.1.15' SINGLE-VALUE
So maybe this is a user permission issue? Has anyone experienced this and know how to resolve it?
Thanks,
Mike
LDAP search result entries only include attributes that actually have values, so the behavior you are seeing from the UnboundID LDAP SDK is appropriate and correct. Even if you explicitly request a particular attribute, that attribute will only be included in the entry if it has one or more values.
I think that you're confused by JXplorer because it's reading the schema to determine what attributes could possibly be included in the entry based on its object classes and is showing them to you so that you can set values for those attributes in the editor. But that doesn't mean that the entry returned by the server actually includes any information about those attributes.
To verify this, you can use the ldap-debugger tool provided with the LDAP SDK to see the actual LDAP communication that occurs. Just run a command like:
tools/ldap-debugger --hostname {directory-server-address} \
--port {directory-server-port} --listenPort {listen-port}
This will create a very simple LDAP proxy server that decodes all requests and responses that pass through it. To use it, simply point JXplorer at the specified listen-port. You will see that when JXplorer retrieves the entry, the entry returned by the server will only contain attributes that actually have values.
If you want to figure out what all the possible attributes are that you can include in a given entry, then use the LDAPConnection.getSchema method to retrieve the server schema, then Schema.getObjectClass for each of the object classes in the target entry, and finally use the ObjectClassDefinition.getRequiredAttributes and ObjectClassDefinition.getOptionalAttributes methods to see what attribute types must and may be used in entries with that object class.