use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class MetacardValidityMarkerPluginTest method testMetacardFailsEnforcedValidatorNoDescribable.
@Test
public void testMetacardFailsEnforcedValidatorNoDescribable() throws ValidationException, StopProcessingException, PluginExecutionException {
MetacardValidator mockValidator = getMockFailingValidatorNoDescribable();
metacardValidators.add(mockValidator);
enforcedMetacardValidators.add(mockValidator.getClass().getCanonicalName());
CreateRequest createRequest = getMockCreateRequest();
List<Metacard> createdMetacards = createRequest.getMetacards();
verifyEnforcedCreate(createRequest, createdMetacards.subList(1, createdMetacards.size()));
UpdateRequest updateRequest = getMockUpdateRequest();
List<Metacard> updatedMetacards = getUpdatedMetacards(updateRequest);
verifyEnforcedUpdate(updateRequest, updatedMetacards.subList(1, updatedMetacards.size()));
}
use of ddf.catalog.operation.CreateRequest 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.CreateRequest in project ddf by codice.
the class IdentificationPluginTest method testBothExtIdMissing.
//test ext IDs are not set (origin & local)
@Test
public void testBothExtIdMissing() throws Exception {
//unmarshal metacard.metadata and confirm both origin and local ext id are set to metacard.getId()
String xml = convert("/registry-no-extid.xml");
sampleData.setAttribute(Metacard.METADATA, xml);
CreateRequest result = identificationPlugin.process(new CreateRequestImpl(sampleData));
Metacard testMetacard = result.getMetacards().get(0);
String metadata = testMetacard.getMetadata();
InputStream inputStream = new ByteArrayInputStream(metadata.getBytes(Charsets.UTF_8));
JAXBElement<RegistryObjectType> registryObjectTypeJAXBElement = parser.unmarshal(configurator, JAXBElement.class, inputStream);
RegistryObjectType registryObjectType = registryObjectTypeJAXBElement.getValue();
List<ExternalIdentifierType> extIdList = registryObjectType.getExternalIdentifier();
for (ExternalIdentifierType singleExtId : extIdList) {
if (singleExtId.getId().equals(RegistryConstants.REGISTRY_MCARD_ID_LOCAL)) {
assertThat(singleExtId.getValue(), is(testMetacard.getId()));
} else if (singleExtId.getId().equals(RegistryConstants.REGISTRY_MCARD_ID_ORIGIN)) {
assertThat(singleExtId.getId(), is(RegistryConstants.REGISTRY_MCARD_ID_ORIGIN));
assertThat(singleExtId.getValue(), is(testMetacard.getId()));
}
}
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class PointOfContactUpdatePluginTest method testPassthroughMethods.
@Test
public void testPassthroughMethods() throws Exception {
CreateRequest createRequest = mock(CreateRequest.class);
DeleteRequest deleteRequest = mock(DeleteRequest.class);
QueryRequest queryRequest = mock(QueryRequest.class);
ResourceRequest resourceRequest = mock(ResourceRequest.class);
DeleteResponse deleteResponse = mock(DeleteResponse.class);
QueryResponse queryResponse = mock(QueryResponse.class);
ResourceResponse resourceResponse = mock(ResourceResponse.class);
assertThat(pointOfContactUpdatePlugin.processPreCreate(createRequest), is(createRequest));
assertThat(pointOfContactUpdatePlugin.processPreDelete(deleteRequest), is(deleteRequest));
assertThat(pointOfContactUpdatePlugin.processPostDelete(deleteResponse), is(deleteResponse));
assertThat(pointOfContactUpdatePlugin.processPreQuery(queryRequest), is(queryRequest));
assertThat(pointOfContactUpdatePlugin.processPostQuery(queryResponse), is(queryResponse));
assertThat(pointOfContactUpdatePlugin.processPreResource(resourceRequest), is(resourceRequest));
assertThat(pointOfContactUpdatePlugin.processPostResource(resourceResponse, mock(Metacard.class)), is(resourceResponse));
verifyZeroInteractions(createRequest, deleteRequest, queryRequest, resourceRequest, deleteResponse, queryResponse, resourceResponse);
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class MetacardIngestNetworkPluginTest method testApplySucceeds.
@Test
public void testApplySucceeds() throws Exception {
ThreadContext.put(CLIENT_INFO_KEY, INFO_MAP);
when(mockMetacardCondition.applies(INFO_MAP)).thenReturn(true);
CreateRequest createRequest = plugin.processPreCreate(mockCreateRequest);
verify(mockMetacardServices).setAttributesIfAbsent(metacards, mockParsedAttributes, mockAttributeFactory);
verifyNoMoreInteractions(mockMetacardServices);
assertThat(createRequest, is(not(mockCreateRequest)));
}
Aggregations