use of ddf.catalog.operation.impl.QueryRequestImpl in project ddf by codice.
the class SolrProviderTest method queryXpathExists.
private SourceResponse queryXpathExists(String xpath) throws UnsupportedQueryException {
Filter filter = filterBuilder.xpath(xpath).exists();
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
return sourceResponse;
}
use of ddf.catalog.operation.impl.QueryRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testFederatedQueryPermissionsNoSubject.
@Test(expected = FederationException.class)
public void testFederatedQueryPermissionsNoSubject() throws Exception {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
Map<String, CatalogStore> storeMap = new HashMap<>();
Map<String, FederatedSource> sourceMap = new HashMap<>();
Map<String, Set<String>> securityAttributes = new HashMap<>();
securityAttributes.put("role", Collections.singleton("myRole"));
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true, securityAttributes);
storeMap.put(store.getId(), store);
sourceMap.put(store.getId(), store);
CatalogFramework framework = createDummyCatalogFramework(provider, storeMap, sourceMap, eventAdmin);
FilterBuilder builder = new GeotoolsFilterBuilder();
QueryImpl query = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().like().text("someType"));
QueryRequestImpl request = new QueryRequestImpl(query, Collections.singletonList("catalogStoreId-1"));
framework.query(request);
}
use of ddf.catalog.operation.impl.QueryRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testDeleteWithStores.
// TODO (DDF-2436) -
@Ignore
@Test
public void testDeleteWithStores() throws Exception {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
Map<String, CatalogStore> storeMap = new HashMap<>();
Map<String, FederatedSource> sourceMap = new HashMap<>();
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
storeMap.put(store.getId(), store);
sourceMap.put(store.getId(), store);
CatalogFramework framework = createDummyCatalogFramework(provider, storeMap, sourceMap, eventAdmin);
FilterFactory filterFactory = new FilterFactoryImpl();
Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "*", "*", "?", "/", false);
List<Metacard> metacards = new ArrayList<>();
String id = UUID.randomUUID().toString().replaceAll("-", "");
MetacardImpl newCard = new MetacardImpl();
newCard.setId(id);
newCard.setAttribute("myKey", "myValue1");
metacards.add(newCard);
Map<String, Serializable> reqProps = new HashMap<>();
HashSet<String> destinations = new HashSet<>();
destinations.add("mockMemoryProvider");
destinations.add("catalogStoreId-1");
framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
DeleteRequest deleteRequest = new DeleteRequestImpl(Collections.singletonList(id), Metacard.ID, new HashMap<>(), destinations);
DeleteResponse response = framework.delete(deleteRequest);
assertThat(response.getDeletedMetacards().size(), is(1));
QueryResponse queryResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), true));
assertThat(queryResponse.getResults().size(), is(0));
}
use of ddf.catalog.operation.impl.QueryRequestImpl in project ddf by codice.
the class RegistryStoreImpl method registryInfoQuery.
void registryInfoQuery() throws UnsupportedQueryException {
List<Filter> filters = new ArrayList<>();
filters.add(filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG));
filters.add(filterBuilder.not(filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE).empty()));
Filter filter = filterBuilder.allOf(filters);
Map<String, Serializable> queryProps = new HashMap<>();
queryProps.put(SecurityConstants.SECURITY_SUBJECT, getSystemSubject());
Query newQuery = new QueryImpl(filter);
QueryRequest queryRequest = new QueryRequestImpl(newQuery, queryProps);
SourceResponse identityMetacard = query(queryRequest);
if (identityMetacard.getResults().size() > 0) {
String metacardTitle = identityMetacard.getResults().get(0).getMetacard().getTitle();
registryId = RegistryUtility.getRegistryId(identityMetacard.getResults().get(0).getMetacard());
updateConfiguration(metacardTitle);
}
}
use of ddf.catalog.operation.impl.QueryRequestImpl in project ddf by codice.
the class RegistryStoreImpl method create.
@Override
public CreateResponse create(CreateRequest request) throws IngestException {
if (request.getMetacards().stream().map(RegistryUtility::getRegistryId).anyMatch(Objects::isNull)) {
throw new IngestException("One or more of the metacards is not a registry metacard");
}
validateOperation();
List<Filter> regIdFilters = request.getMetacards().stream().map(e -> filterBuilder.attribute(RegistryObjectMetacardType.REMOTE_METACARD_ID).is().equalTo().text(e.getId())).collect(Collectors.toList());
Filter tagFilter = filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG_INTERNAL);
Map<String, Serializable> queryProps = new HashMap<>();
queryProps.put(SecurityConstants.SECURITY_SUBJECT, request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT));
QueryImpl query = new QueryImpl(filterBuilder.allOf(tagFilter, filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE).empty(), filterBuilder.anyOf(regIdFilters)));
QueryRequest queryRequest = new QueryRequestImpl(query, queryProps);
try {
SourceResponse queryResponse = super.query(queryRequest);
Map<String, Metacard> responseMap = queryResponse.getResults().stream().collect(Collectors.toMap(e -> RegistryUtility.getRegistryId(e.getMetacard()), Result::getMetacard));
List<Metacard> metacardsToCreate = request.getMetacards().stream().filter(e -> !responseMap.containsKey(RegistryUtility.getRegistryId(e))).collect(Collectors.toList());
List<Metacard> allMetacards = new ArrayList<>(responseMap.values());
if (CollectionUtils.isNotEmpty(metacardsToCreate)) {
CreateResponse createResponse = super.create(new CreateRequestImpl(metacardsToCreate, request.getProperties()));
allMetacards.addAll(createResponse.getCreatedMetacards());
}
return new CreateResponseImpl(request, request.getProperties(), allMetacards);
} catch (UnsupportedQueryException e) {
LOGGER.warn("Unable to perform pre-create remote query. Proceeding with original query. Error was {}", e.getMessage());
}
return super.create(request);
}
Aggregations