Get list of custom object in RemedyForce - java

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.

Related

how to get value from entity with have in iterable

I have code like this for getting all data from my DB
Iterable<ProductParameter> result = service.getAllProductParameter();
I need to get value from one of productParameter Entity, how to get them? if I use iterable to get all data in my DB`
I have tried using this code
String uuid = result.getProductParameterId; but this got error
You should explain more details. But
Iterable<ProductParameter> result = service.getAllProductParameter();
return a list of object so you need to filter or loop to get what you need.For example:
result.forEach(x -> {System.out.println(x.getProductParameterId());});

How to write query using spring-data-solr which return list of all values of specific field

I want to write a query that gets list of all values of one field in the documents (no conditions at all).
I try the following code:
#Query(fields = { "car_company_s" })
List<Car> findAllCarCompeny();
But it didn't work, I got the following error:
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAllCarCompeny found for type Car!
Is there any way to do this?
What you want is a "Term". Basically it returns all values of a field. You need solr template, as said in description .
Example we are using:
#Resource
private SolrTemplate solrTemplate;
...
query = SimpleTermsQuery.queryBuilder()
.fields(key)
.prefix(startsWith.toLowerCase(Locale.ROOT)) // we have some search prefix
.sort(TermsOptions.Sort.INDEX)
.build();
TermsPage page = solrTemplate.queryForTermsPage(query);
Iterable<TermsFieldEntry> terms = page.getTermsForField(key);
Terms are basically your values. Note, that you have to optimize core to remove values, that are from already deleted documents.

Google App Engine Query Not Working in Java

Riddle me this Stackoverflow:
I have a query that I am sending to GAE. The query (When in String format) looks like this:
SELECT * FROM USER WHERE USER_ID = 5884677008
If I go to the GAE console and type it in via a manual GQL query, it returns the item just fine. If I browse via the GUI and scroll to it, I can see it just fine. But when I call it from the Java code, it returns nothing every time.
code:
I have already confirmed the query is correct as I printed it out as a String just so I can test it.
Anyone have any idea what is going on with this?
q = new Query(entityName); //entityName = "User", confirmed
q.setFilter(filter); //filter = "USER_ID = 5884677008", confirmed
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
PreparedQuery pq = datastore.prepare(q);
/*
This always is empty here. Calling either pq.countEntities()); or
pq.toString()); returns size 0 or a String of nothing.
*/
Thanks!
-Sil
Edit: I Do have an index built, but it did not seem to help with the problem.
From the docs, you don't necessarily need to do toString. Have you tried asIterable or asSingleEntity on pq? Something like:
PreparedQuery pq = datastore.prepare(q);
for (Entity result : pq.asIterable()) {
String test = (String) result.getProperty("prop1");
}
That's if you have multiple entries. In the event you only have one:
PreparedQuery pq = datastore.prepare(q);
Entity result = pq.asSingleEntity();
String test = (String) result.getProperty("prop1");
Basically, if you don't call asIterable or asSingleEntity, the query is JUST prepared and doesn't run
Took quite a bit of testing, but found the issue.
The problem revolved around the filter being set. If I removed the filter, it worked fine (but returned everything). Turns out, what was being passed as a filter was a String version of the user_id as opposed to the Long version of it. There was really no way to tell as the exact SQL query DID NOT read ( SELECT * FROM USER WHERE USER_ID = "5884677008" ) when I printed it, which would have been a dead giveaway.
I changed the passed filter parameter (which I had stored in a hashmap of (String, Object) btw) from a String to a Long and that solved the issue.
One thing to point out though, as #Patrice brought up (And as I excluded from my code while posting to save space), to actually iterate through the list of results, you do need to call a method against it (Either .asIterable() or .asSingleEntity() ).
You actually can check against the number of returned entities / results by calling pq.countEntities() and it will return the correct number even before you call a formatting method against the pq, but as #tx802 pointed out, it is deprecated, and despite the fact that it worked for me, someone in the future using this post as a reference may not have it work for them.

REST how to pass empty path parameter in the URI?

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.

query on custom field via webservice

I customized the content of Defect in my Rally workspace adding a new custom field.
This custom field is of type string, its name is CustomTest and its display name is CustomAttribute.
I added the value "test" on a defect, but I can't create a working query on that custom field (I'm developing in Java and using the ws api for rally).
the query I tried are
String query8 = "(CustomAttribute = \"test\")";
String query9 = "(CustomAttribute = \"test\")";
In Rally queries, you must reference the actual field name rather than the Display Name. Thus, if you do:
String query8 = "(CustomTest = \"test\")"; String query9 = "(CustomTest = \"test\")";
Then I'd expect your query to work. The info in my comment re: using WSAPI docs to assist running/testing queries outside code should still be useful to you.

Categories