query in a custom policy
I need to query for another asset as part of a custom policy. I noticed there is the AssetManager class that accepts a String text query. What is the format of the query?
I essentially need the query to look like this (using SQL-like syntax)
select * from assets where (type="TypeA") and (community="CommunityA") and (Category="Domain.SuperCat.SubCat") and (Category="Team.SuperTeam.SubTeam")
So essentially I need to find an asset of a certain type and of a certain community that has 2 different particular Category Schema values.
I essentially need the query to look like this (using SQL-like syntax)
select * from assets where (type="TypeA") and (community="CommunityA") and (Category="Domain.SuperCat.SubCat") and (Category="Team.SuperTeam.SubTeam")
So essentially I need to find an asset of a certain type and of a certain community that has 2 different particular Category Schema values.
3 answers
I have tried everything but nothing works. I have tried every permutation of the query string I can think of such as replacing %2c with a comma, removing the ramSearch prefix, etc. and nothing works. Actually, the string as it exists from the search page causes the policy to throw an exception. Always returns zero assets.
Here is my snippet:
AssetManager am = AssetManager.getInstance();
String query = "ramSearch:(1fType%2Cmapping)";
SearchResults sr;
try {
sr = am.searchAssets(user, query, false, false);
} catch (InvalidQueryException e) {
String message = (new StringBuilder("Unable to search for mapping asset")).toString();
result.setMessage(message);
result.setReturnCode(ResultDetail.ERROR);
return result;
}
AbstractSearchAsset assets[] = sr.getAssets();
if (assets.length < 1) {
String message = (new StringBuilder("Search for mapping asset did not return a result")).toString();
result.setMessage(message);
result.setReturnCode(ResultDetail.ERROR);
return result;
}
Here is my snippet:
AssetManager am = AssetManager.getInstance();
String query = "ramSearch:(1fType%2Cmapping)";
SearchResults sr;
try {
sr = am.searchAssets(user, query, false, false);
} catch (InvalidQueryException e) {
String message = (new StringBuilder("Unable to search for mapping asset")).toString();
result.setMessage(message);
result.setReturnCode(ResultDetail.ERROR);
return result;
}
AbstractSearchAsset assets[] = sr.getAssets();
if (assets.length < 1) {
String message = (new StringBuilder("Search for mapping asset did not return a result")).toString();
result.setMessage(message);
result.setReturnCode(ResultDetail.ERROR);
return result;
}