@SuppressWarnings("rawtypes") private void addCollectionIndexableFieldToDocument(Object v, PropertyDescription pd, String fieldNamePrefix) { fieldNamePrefix = QuerySpecification.buildCollectionItemName(fieldNamePrefix); Collection c; if (v instanceof Collection) { c = (Collection) v; } else { c = Arrays.asList((Object[]) v); } if (pd.indexingOptions.contains(PropertyIndexingOption.SORT)) { pd.elementDescription.indexingOptions.add(PropertyIndexingOption.SORT); } for (Object cv : c) { if (cv == null) { continue; } addIndexableFieldToDocument(cv, pd.elementDescription, fieldNamePrefix, true, true); } }
public static Query addTenantClause(List<String> tenantLinks) { Query groupClause = null; String propertyName = QueryTask.QuerySpecification .buildCollectionItemName(MultiTenantDocument.FIELD_NAME_TENANT_LINKS); // if a tenant is not specified, search global only if (tenantLinks == null || tenantLinks.isEmpty()) { groupClause = new Query() .setTermPropertyName(propertyName); groupClause.setTermMatchType(MatchType.WILDCARD) .setTermMatchValue(UriUtils.URI_WILDCARD_CHAR); groupClause.occurance = Occurance.MUST_NOT_OCCUR; } else { groupClause = addListValueClause(propertyName, tenantLinks.stream() .filter(tenantLink -> tenantLink.startsWith(MultiTenantDocument.TENANTS_PREFIX) || tenantLink.startsWith(MultiTenantDocument.PROJECTS_IDENTIFIER)) .filter(tenantLink -> !tenantLink.contains( MultiTenantDocument.GROUP_IDENTIFIER)) .collect(Collectors.toList()), MatchType.TERM); } return groupClause; }
public static Query addTenantAndGroupClause(List<String> tenantLinks) { Query groupClause = null; String propertyName = QueryTask.QuerySpecification .buildCollectionItemName(MultiTenantDocument.FIELD_NAME_TENANT_LINKS); // if a tenant is not specified, search global only if (tenantLinks == null || tenantLinks.isEmpty()) { groupClause = new Query() .setTermPropertyName(propertyName); groupClause.setTermMatchType(MatchType.WILDCARD) .setTermMatchValue(UriUtils.URI_WILDCARD_CHAR); groupClause.occurance = Occurance.MUST_NOT_OCCUR; } else { groupClause = addListValueClause(propertyName, tenantLinks.stream() .filter(tenantLink -> !tenantLink.startsWith(MultiTenantDocument.USERS_PREFIX)) .collect(Collectors.toList()), MatchType.TERM); } return groupClause; }
.setTermPropertyName(QueryTask.QuerySpecification.buildCollectionItemName( fieldName)) .setTermMatchType(QueryTask.QueryTerm.MatchType.WILDCARD)
@Test public void testIndexingPodoNestedInCollection() { ServiceDocumentDescription sdd = ServiceDocumentDescription.Builder.create() .buildDescription(StateWithPodoNestedInCollection.class); InnerPodo podo1 = new InnerPodo(); podo1.podoField = "value-1"; InnerPodo podo2 = new InnerPodo(); podo2.podoField = "second"; StateWithPodoNestedInCollection state = new StateWithPodoNestedInCollection(); state.collectionOfPodos = Arrays.asList(podo1, podo2); LuceneIndexDocumentHelper helper = new LuceneIndexDocumentHelper(); helper.addIndexableFieldsToDocument(state, sdd); final String nestedFieldName = QuerySpecification.buildCompositeFieldName( QuerySpecification.buildCollectionItemName("collectionOfPodos"), "podoField"); Set<String> indexedInnerValues = helper.getDoc().getFields().stream() .filter(f -> nestedFieldName.equals(f.name())) .map(f -> f.stringValue()) .collect(Collectors.toSet()); assertEquals(new HashSet<>(Arrays.asList(podo1.podoField, podo2.podoField)), indexedInnerValues); } }
private void validateExpandLinksResults(QueryTask page) { assertEquals(page.results.documentLinks.size(), page.results.selectedLinksPerDocument.size()); assertEquals(page.results.documentLinks.size(), page.results.selectedLinks.size()); // since QueryValidationServiceState contains a single "serviceLink" field, we expect // a single Map, per document. The map should contain the link property name, and the // expanded value of the link, in this case a ExampleService state instance. Set<String> uniqueLinks = new HashSet<>(); for (Map<String, String> selectedLinksPerDocument : page.results.selectedLinksPerDocument.values()) { for (Entry<String, String> entry : selectedLinksPerDocument.entrySet()) { String key = entry.getKey(); if (!key.equals(QueryValidationServiceState.FIELD_NAME_SERVICE_LINK) && !key.startsWith(QuerySpecification.buildCollectionItemName( QueryValidationServiceState.FIELD_NAME_SERVICE_LINKS))) { continue; } String link = entry.getValue(); uniqueLinks.add(link); Object doc = page.results.selectedDocuments.get(link); ExampleServiceState expandedState = Utils.fromJson(doc, ExampleServiceState.class); assertEquals(Utils.buildKind(ExampleServiceState.class), expandedState.documentKind); } } assertEquals(page.results.documentLinks.size(), uniqueLinks.size()); }
@Test public void testIndexingPodoNestedInCollection() { ServiceDocumentDescription sdd = ServiceDocumentDescription.Builder.create() .buildDescription(StateWithPodoNestedInCollection.class); InnerPodo podo1 = new InnerPodo(); podo1.podoField = "value-1"; InnerPodo podo2 = new InnerPodo(); podo2.podoField = "second"; StateWithPodoNestedInCollection state = new StateWithPodoNestedInCollection(); state.collectionOfPodos = Arrays.asList(podo1, podo2); LuceneIndexDocumentHelper helper = new LuceneIndexDocumentHelper(); helper.addIndexableFieldsToDocument(state, sdd); final String nestedFieldName = QuerySpecification.buildCompositeFieldName( QuerySpecification.buildCollectionItemName("collectionOfPodos"), "podoField"); Set<String> indexedInnerValues = helper.getDoc().getFields().stream() .filter(f -> nestedFieldName.equals(f.name())) .map(f -> f.stringValue()) .collect(Collectors.toSet()); assertEquals(new HashSet<>(Arrays.asList(podo1.podoField, podo2.podoField)), indexedInnerValues); }
private void validateExpandLinksResults(QueryTask page) { assertEquals(page.results.documentLinks.size(), page.results.selectedLinksPerDocument.size()); assertEquals(page.results.documentLinks.size(), page.results.selectedLinks.size()); // since QueryValidationServiceState contains a single "serviceLink" field, we expect // a single Map, per document. The map should contain the link property name, and the // expanded value of the link, in this case a ExampleService state instance. Set<String> uniqueLinks = new HashSet<>(); for (Map<String, String> selectedLinksPerDocument : page.results.selectedLinksPerDocument.values()) { for (Entry<String, String> entry : selectedLinksPerDocument.entrySet()) { String key = entry.getKey(); if (!key.equals(QueryValidationServiceState.FIELD_NAME_SERVICE_LINK) && !key.startsWith(QuerySpecification.buildCollectionItemName( QueryValidationServiceState.FIELD_NAME_SERVICE_LINKS))) { continue; } String link = entry.getValue(); uniqueLinks.add(link); Object doc = page.results.selectedDocuments.get(link); ExampleServiceState expandedState = Utils.fromJson(doc, ExampleServiceState.class); assertEquals(Utils.buildKind(ExampleServiceState.class), expandedState.documentKind); } } assertEquals(page.results.documentLinks.size(), uniqueLinks.size()); }
public static Query addTenantAndUserClause(List<String> tenantLinks) { Query groupClause = null; String propertyName = QueryTask.QuerySpecification .buildCollectionItemName(MultiTenantDocument.FIELD_NAME_TENANT_LINKS); // if a tenant is not specified, search global only if (tenantLinks == null || tenantLinks.isEmpty()) { groupClause = new Query() .setTermPropertyName(propertyName); groupClause.setTermMatchType(MatchType.WILDCARD) .setTermMatchValue(UriUtils.URI_WILDCARD_CHAR); groupClause.occurance = Occurance.MUST_NOT_OCCUR; } else { groupClause = addListValueClause(propertyName, tenantLinks.stream() .filter(tenantLink -> !tenantLink.contains( MultiTenantDocument.GROUP_IDENTIFIER)) .collect(Collectors.toList()), MatchType.TERM); } return groupClause; }
public static Query addTenantGroupAndUserClause(Collection<String> tenantLinks) { Query groupClause = null; String propertyName = QueryTask.QuerySpecification .buildCollectionItemName(MultiTenantDocument.FIELD_NAME_TENANT_LINKS); // if a tenant is not specified, search global only if (tenantLinks == null || tenantLinks.isEmpty()) { groupClause = new Query() .setTermPropertyName(propertyName); groupClause.setTermMatchType(MatchType.WILDCARD) .setTermMatchValue(UriUtils.URI_WILDCARD_CHAR); groupClause.occurance = Occurance.MUST_NOT_OCCUR; } else { groupClause = addListValueClause(propertyName, tenantLinks, MatchType.TERM); } return groupClause; }
protected QueryTask getDescQuery(List<String> descriptionLinks) { // get container descriptions for descriptionLinks having a service link to // the container description which is being clustered QueryTask q = QueryUtil.buildQuery(ContainerDescription.class, false); String linksItemField = QueryTask.QuerySpecification.buildCollectionItemName( ContainerDescription.FIELD_NAME_LINKS); QueryUtil.addListValueClause(q, linksItemField, Arrays.asList(containerDescriptionName + ":*", containerDescriptionName), MatchType.WILDCARD); QueryUtil.addListValueClause(q, ContainerDescription.FIELD_NAME_SELF_LINK, descriptionLinks); QueryUtil.addExpandOption(q); return q; }
/** * Add a clause with the given occurance which matches a collection containing at least one of several * specified values (analogous to a SQL "IN" or "NOT IN" statements). * @param collectionFieldName the collection field name. * @param itemNames the item names in the collection to match. * @param occurance the occurance for this clause. * @return a reference to this object. */ public Builder addInCollectionItemClause(String collectionFieldName, Collection<String> itemNames, Occurance occurance) { String collectionItemFieldName = QuerySpecification.buildCollectionItemName( collectionFieldName); return addInClause(collectionItemFieldName, itemNames, occurance); }
/** * Add a clause with the specified occurance which matches a collection item. * @param collectionFieldName the collection field name. * @param itemName the item name in the collection to match. * @param occurance the occurance for this clause. * @return a reference to this object. */ public Builder addCollectionItemClause(String collectionFieldName, String itemName, Occurance occurance) { return addFieldClause( QuerySpecification.buildCollectionItemName(collectionFieldName), itemName, occurance); }
/** * Add a clause which matches a collection containing at least one of several specified * values (analogous to a SQL "IN" or "NOT IN" statements). * @param collectionFieldName the collection field name. * @param itemNames the item names in the collection to match. * @return a reference to this object. */ public Builder addInCollectionItemClause(String collectionFieldName, Collection<String> itemNames) { String collectionItemFieldName = QuerySpecification.buildCollectionItemName( collectionFieldName); return addInClause(collectionItemFieldName, itemNames); }
Query createWithListOfStringQuery() { String n1 = QueryTask.QuerySpecification.buildCollectionItemName("l1"); String n2 = QueryTask.QuerySpecification.buildCollectionItemName("l2"); Query t1 = createTerm(n1, "v2", Occurance.MUST_OCCUR); Query t2 = createTerm(n2, "v3", Occurance.MUST_NOT_OCCUR); Query q = new Query(); q.addBooleanClause(t1); q.addBooleanClause(t2); return q; }
/** * Add a clause which matches a collection item. * @param collectionFieldName the collection field name. * @param itemName the item name in the collection to match. * @return a reference to this object. */ public Builder addCollectionItemClause(String collectionFieldName, String itemName) { return addFieldClause( QuerySpecification.buildCollectionItemName(collectionFieldName), itemName); }
private QueryTask createDockerComputeDescriptionQuery() { QueryTask q = QueryUtil.buildQuery(ComputeDescription.class, true); QueryTask.Query hostTypeClause = new QueryTask.Query() .setTermPropertyName(QuerySpecification.buildCollectionItemName( ComputeDescription.FIELD_NAME_SUPPORTED_CHILDREN)) .setTermMatchValue(ComputeType.DOCKER_CONTAINER.name()); q.querySpec.query.addBooleanClause(hostTypeClause); q.querySpec.resultLimit = ServiceDocumentQuery.DEFAULT_QUERY_RESULT_LIMIT; q.documentExpirationTimeMicros = ServiceDocumentQuery.getDefaultQueryExpiration(); return q; }
Query createWithListOfStringWithPrefixQuery() { String n1 = QueryTask.QuerySpecification.buildCollectionItemName("l1"); Query t1 = createTerm(n1, "v2", Occurance.MUST_OCCUR, MatchType.PREFIX); Query q = new Query(); q.addBooleanClause(t1); return q; }
Query createWithListOfStringWithPrefixQuery() { String n1 = QueryTask.QuerySpecification.buildCollectionItemName("l1"); Query t1 = createTerm(n1, "v2", Occurance.MUST_OCCUR, MatchType.PREFIX); Query q = new Query(); q.addBooleanClause(t1); return q; }
Query createWithListOfStringQuery() { String n1 = QueryTask.QuerySpecification.buildCollectionItemName("l1"); String n2 = QueryTask.QuerySpecification.buildCollectionItemName("l2"); Query t1 = createTerm(n1, "v2", Occurance.MUST_OCCUR); Query t2 = createTerm(n2, "v3", Occurance.MUST_NOT_OCCUR); Query q = new Query(); q.addBooleanClause(t1); q.addBooleanClause(t2); return q; }