query on custom field via webservice - java

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.

Related

Collect all VersionOne assets and all their attributes using Java

I'm working on a task that requires me to export all assets and all their attribute values into a CSV file. I know that there is an option to export into Excel, but that one has its problems and we decide to give a chance to an API.
The problem I faced is that while I can get all assets of a specific type with the code
IServices services = new Services(connector);
IAssetType requestType = services.getMeta().getAssetType("Request");
Query query = new Query(requestType);
it isn't clean how to return all asset's attributes. There is a getAttributes() for the Asset object
QueryResult result = services.retrieve(query);
for (Asset asset : result.getAssets()) {
Map<String, Attribute> attributes = asset.getAttributes();
System.out.println(attributes.toString());
}
but it doesn't seem to return an attribute unless it is explicitly added into a query eg.
…
Query query = new Query(requestType);
IAttributeDefinition nameAttribute = requestType.getAttributeDefinition("Name");
IAttributeDefinition numberAttribute = requestType.getAttributeDefinition("Number");
query.getSelection().add(nameAttribute);
query.getSelection().add(numberAttribute);
QueryResult result = services.retrieve(query);
…
which doesn't make sense to me, since I may not even know all possible object's attributes!
I feel like getAttributes() method may not be suitable for this purpose, but what else to use then? Any ideas on how I can collect the data I need?
You can use Meta API query to retrieve metadata for specific asset type:
<Server Base URI>/meta.v1/Request
In general VersionOne APIs don't return all available attributes at once as a default. When using the VersionOne Rest api, the most important subset of attributes are returned and no custom fields. The VersionOne sdks are a wrapper around this api so it stands to reason that api business rules are fulfilled in the sdk. You will have to know the names of all possible attributes of an asset and explicitly request them. This includes custom fields (Custom_AttributeName). This can be queried by doing a meta query YourVersionOneInstance/meta.v1/YourAssetName. You then will have to iterate through this xml tree and get the attribute names and wrap the proper query plumbing around each attribute.

Converting an ActiveRecord:Relation to java array

I am running a 'where' query which is running on a table MyTable in my rails application.
I want to convert the results of a specific column from this query(ActiveRecord::Relation) to Java Array of String type.
This is what I am doing :
employeesJavaArray=MyTable.where("salary = ?",100).pluck(:columnName).to_java(java.lang.String)
However I am receiving this error in my logs :-
TypeError (could not coerce Fixnum to class java.lang.String):
Can you please help me out what could be wrong with the statement that I have written.
I would ensure that the array only includes string (by calling to_s) first:
employeesJavaArray = MyTable.where("salary = ?",100)
.pluck(:columnName)
.map(&:to_s)
.to_java(java.lang.String)

Get list of custom object in RemedyForce

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.

Category property in Google App Engine - Java

How to use com.google.appengine.api.datastore.Category property in Google App Engine - Java?
the Constructor of Category just takes String. I am not sure whether we can use Category for the Multi value property. Any input or example on this is appreciated.
Could not find an usage of Category property. So, I am trying to use List
Setting the property as mentioned below:
//tags can contain TAG1, TAG2, TAG3, etc
List<String> tags;
entity.setProperty("tags", tags);
Querying the property as mentioned below:
String tag = "TAG1";
Query q = new Query("EntityType").setAncestor(parentEntity.getKey()).setFilter(FilterOperator.EQUAL.of("tags", tag));
Getting the property as mentioned below:
List<String> tags = (List<String>)entity.getProperty("tags");

Get DB object from JDO/DataNucleus and MongoDB with a String _id

I am using JDO and DataNucleus to persist runtime-generated objects into MongoDB. The database objects have their own unique identifier, a string, which I put into Mongo's _id field. This works fine and I end up with, for instance, this object:
(in the mongo shell)
> db.CollectionName.find({"_id":"01e293bc-970d-e0b3-aac1-14109fdb7235_ZMUkU234ufY3opYPeov38T4EilNLURIb8ki"}).pretty()
{
"_id" : "01e293bc-970d-e0b3-aac1-14109fdb7235_ZMUkU234ufY3opYPeov38T4EilNLURIb8ki",
...
When I want to get an object back out of Mongo I make the call which I think should work:
PersistenceManager pm = pmf.getPersistenceManager();
String keyString = "01e293bc-970d-e0b3-aac1-14109fdb7235_ZMUkU234ufY3opYPeov38T4EilNLURIb8ki";
Object dbObject = pm.getObjectById(keyString);
But I don't get a dbObject, instead JDO throws a JDONotFoundException. I thought perhaps I needed to specify the class of the DB object which is tough because it is runtime generated, but I added a hack which saves a pointer to the class when I persist, so that I can use it later:
this.savedDBclass = obj.getClass();
pm.makePersistent(obj);
...
PersistenceManager pm = pmf.getPersistenceManager();
String keyString = "01e293bc-970d-e0b3-aac1-14109fdb7235_ZMUkU234ufY3opYPeov38T4EilNLURIb8ki";
Object dbObject = pm.getObjectById(this.savedDBclass, keyString);
and in that case I get a JDOFatalUserException "No metadata has been registered for class".
When I look at the documentation it seems like this procedure should be straightforward: "You can then go back to your data layer and retrieve the object as follows: Object obj = pm.getObjectById(id);"
I figure my problem is that I'm using a String instead of an ObjectId but I can't figure out the voodoo to make String IDs work. I read in the documentation "A DataNucleus extension is to pass in a String form of the identity to the above method" but we aren't using that extension, to the best of my knowledge.
Suggest you read the JDO spec which is very clear what is an "identity" (a String is not it), and what is a PK value. You don't post the class itself, so people are left to guesswork. To get an "identity" you can easily enough do
Object identity = pm.newObjectIdInstance(MyObject.class, "my_pk_value_when_string");
and that is what goes into pm.getObjectById(id). You then look at the log if having problems.

Categories