use of ddf.catalog.operation.SourceResponse in project ddf by codice.
the class SolrProviderTest method assertNotFilter.
private void assertNotFilter(Filter filter) throws UnsupportedQueryException {
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("Found a metacard and should not have.", 0, sourceResponse.getResults().size());
}
use of ddf.catalog.operation.SourceResponse 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.SourceResponse 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.SourceResponse 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);
}
use of ddf.catalog.operation.SourceResponse in project ddf by codice.
the class RefreshRegistryEntriesTest method testSubscriptionEntityRemoval.
@Test
public void testSubscriptionEntityRemoval() throws Exception {
Metacard localMetacard = getPopulatedTestRegistryMetacard("mcardId", "testRegId", 0, true);
when(federationAdminService.getInternalRegistryMetacards()).thenReturn(Collections.singletonList(localMetacard));
Metacard remoteMetacard = getPopulatedTestRegistryMetacard("mcardId2", "testRegId2", 0, true);
SourceResponse response = new SourceResponseImpl(null, Collections.singletonList(new ResultImpl(remoteMetacard)));
when(registryStore.query(any(QueryRequest.class))).thenReturn(response);
when(registryStore.isPullAllowed()).thenReturn(true);
when(registryStore.getId()).thenReturn(TEST_ID);
when(registryStore.getRegistryId()).thenReturn("remoteRegId");
when(registryStore.isAvailable()).thenReturn(true);
refreshRegistryEntries.setRegistryStores(Collections.singletonList(registryStore));
refreshRegistryEntries.refreshRegistryEntries();
verify(federationAdminService).deleteRegistryEntriesByMetacardIds(Collections.singletonList(localMetacard.getId()));
}
Aggregations