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");
Related
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.
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.
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.
The situation:
I'm actually reading contact information from an Ldap source within a Java application. The found SearchResult contains all values I want, no trouble with that.
Once the SearchResult is available, I need to read its attributes - which attributes to read, is specified by the user in a config file.
The problem, explained on an example:
A user specifies to read the property 'stateOrProvinceName'. The Ldap handles this as 'st'. The returned Searchresult will contain a key=>value pair with 'st' as key. If I look up 'stateOrProvinceName' this will of cource not be found. I want that 'st' key - but I do not want to manually code a mappnig of alternative Ldap-Field names. The relevant code part:
Attributes ldapAttributes = foundContact.getAttributes();
Attribute wantedAttribute = ldapAttributes.get(ldapFieldName);
Explanation: 'foundContact' is the SearchResult, I store its Attributes in 'ldapAttributes'. The 'ldapFieldName' is the name, the user specified in the config file (like 'stateOrProvinceName'), I try to get this attribute and store it in 'wantedAttribute'. If 'stateOrProvinceName' is not contained, 'wantedAttribute' is of course null. But since 'st' exists, I do not want this to be null ;)
The question:
is there some 'easy' way to retrieve a list of all alternative names, given one name of an attribute?
Thanks for your time!
The rfc'ed approach for that is to locate the attribute definition in your entry's subschemaSubentry referenced schema definition. (p32 in RFC 4512)
E.g. OpenLDAP stores this information in cn=Subschema. Unfortunately this entry uses the attribute definition format which you first have to parse by yourself:
attributetype ( 2.5.4.8
NAME ( 'st' 'stateOrProvinceName' )
DESC 'RFC2256: state or province which this object resides in'
SUP name )
Iirc/maybe UnboundID's LDAP SDK has now a parser for this purspose.
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.