Search in sources :

Example 1 with Occurance

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;
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) Query(com.vmware.xenon.services.common.QueryTask.Query) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance)

Aggregations

QueryTask (com.vmware.xenon.services.common.QueryTask)1 Query (com.vmware.xenon.services.common.QueryTask.Query)1 Occurance (com.vmware.xenon.services.common.QueryTask.Query.Occurance)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Map (java.util.Map)1