use of com.vmware.xenon.services.common.QueryTask.Query.Occurance in project photon-model by vmware.
the class PhotonModelUtils method createOriginTagQuery.
/**
* @param external
* @param origin
* @return Returns a query with the needed terms for external and origin field
*/
public static Query createOriginTagQuery(Boolean external, Map<String, Occurance> origin) {
QueryTask.Query externalQuery = new Query().setTermPropertyName(TagService.TagState.FIELD_NAME_EXTERNAL).setTermMatchValue(external.toString());
externalQuery.occurance = Occurance.SHOULD_OCCUR;
QueryTask.Query.Builder originClauseBuilder = QueryTask.Query.Builder.create();
for (Map.Entry<String, Occurance> entry : origin.entrySet()) {
Occurance occurance = entry.getValue() == null ? Occurance.MUST_OCCUR : entry.getValue();
if (entry.getKey() != null) {
originClauseBuilder.addCollectionItemClause(TagService.TagState.FIELD_NAME_ORIGIN, entry.getKey(), occurance);
}
}
Query originQuery = originClauseBuilder.build().setOccurance(Occurance.SHOULD_OCCUR);
Query originOrExternalQuery = new Query().addBooleanClause(externalQuery).addBooleanClause(originQuery).setOccurance(Occurance.MUST_OCCUR);
return originOrExternalQuery;
}
Aggregations