use of ddf.catalog.operation.CreateResponse in project ddf by codice.
the class TestPlugin method testCreateNullParent.
@Test
@Ignore
public void testCreateNullParent() throws PluginExecutionException, IngestException, SourceUnavailableException {
// given
CreateResponse createResponse = new CreateResponseImpl(new CreateRequestImpl(metacard), null, Arrays.asList(metacard));
// when
plugin.process(createResponse);
// then
verify(endpoint, never()).addDocument(isA(HttpHeaders.class), isA(UriInfo.class), isA(InputStream.class));
}
use of ddf.catalog.operation.CreateResponse in project ddf by codice.
the class TestPlugin method testCreateNullTransformer.
@Test
@Ignore
public void testCreateNullTransformer() throws PluginExecutionException, IngestException, SourceUnavailableException {
// given
plugin = new RestReplicatorPlugin(null);
CreateResponse createResponse = new CreateResponseImpl(new CreateRequestImpl(metacard), null, Arrays.asList(metacard));
// when
plugin.process(createResponse);
// then
verify(endpoint, never()).addDocument(isA(HttpHeaders.class), isA(UriInfo.class), isA(InputStream.class));
}
use of ddf.catalog.operation.CreateResponse 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.CreateResponse in project ddf by codice.
the class RegistryIdPostIngestPluginTest method testProcessDeleteLocal.
@Test
public void testProcessDeleteLocal() throws Exception {
MetacardImpl metacard = getDefaultMetacard();
metacard.setAttribute(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE, true);
CreateResponse createResponse = new CreateResponseImpl(null, null, Collections.singletonList(metacard));
registryIdPostIngestPlugin.process(createResponse);
assertThat(registryIdPostIngestPlugin.getLocalRegistryIds().size(), equalTo(1));
DeleteResponse deleteResponse = new DeleteResponseImpl(null, null, Collections.singletonList(metacard));
registryIdPostIngestPlugin.process(deleteResponse);
assertThat(registryIdPostIngestPlugin.getLocalRegistryIds().size(), equalTo(0));
}
use of ddf.catalog.operation.CreateResponse in project ddf by codice.
the class RegistryIdPostIngestPluginTest method testProcessCreateLocal.
@Test
public void testProcessCreateLocal() throws Exception {
MetacardImpl metacard = getDefaultMetacard();
metacard.setAttribute(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE, true);
CreateResponse response = new CreateResponseImpl(null, null, Collections.singletonList(metacard));
registryIdPostIngestPlugin.process(response);
assertThat(registryIdPostIngestPlugin.getRegistryIds().size(), equalTo(1));
assertThat(registryIdPostIngestPlugin.getLocalRegistryIds().size(), equalTo(1));
assertThat(registryIdPostIngestPlugin.getLocalRegistryIds().iterator().next(), equalTo("regId"));
}
Aggregations