use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.
the class RegistryIdPostIngestPluginTest method testProcessDelete.
@Test
public void testProcessDelete() throws Exception {
CreateResponse createResponse = new CreateResponseImpl(null, null, Collections.singletonList(getDefaultMetacard()));
registryIdPostIngestPlugin.process(createResponse);
DeleteResponse deleteResponse = new DeleteResponseImpl(null, null, Collections.singletonList(getDefaultMetacard()));
registryIdPostIngestPlugin.process(deleteResponse);
assertThat(registryIdPostIngestPlugin.getRegistryIds().size(), equalTo(0));
}
use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.
the class AbstractCswStore method create.
@Override
public CreateResponse create(CreateRequest createRequest) throws IngestException {
Map<String, Serializable> properties = new HashMap<>();
validateOperation();
Subject subject = (Subject) createRequest.getPropertyValue(SecurityConstants.SECURITY_SUBJECT);
Csw csw = factory.getClientForSubject(subject);
CswTransactionRequest transactionRequest = getTransactionRequest();
List<Metacard> metacards = createRequest.getMetacards();
List<String> metacardIds = metacards.stream().map(Metacard::getId).collect(Collectors.toList());
List<Metacard> createdMetacards = new ArrayList<>();
List<Filter> createdMetacardFilters;
HashSet<ProcessingDetails> errors = new HashSet<>();
String insertTypeName = schemaTransformerManager.getTransformerIdForSchema(cswSourceConfiguration.getOutputSchema());
if (insertTypeName == null) {
throw new IngestException("Could not find transformer for output schema " + cswSourceConfiguration.getOutputSchema());
}
transactionRequest.getInsertActions().add(new InsertAction(insertTypeName, null, metacards));
try {
TransactionResponseType response = csw.transaction(transactionRequest);
Set<String> processedIds = new HashSet<>();
//dive down into the response to get the created ID's. We need these so we can query
//the source again to get the created metacards and put them in the result
createdMetacardFilters = response.getInsertResult().stream().map(InsertResultType::getBriefRecord).flatMap(Collection::stream).map(BriefRecordType::getIdentifier).flatMap(Collection::stream).map(JAXBElement::getValue).map(SimpleLiteral::getContent).flatMap(Collection::stream).map(id -> {
processedIds.add(id);
return filterBuilder.attribute(Core.ID).is().equalTo().text(id);
}).collect(Collectors.toList());
metacardIds.removeAll(processedIds);
errors.addAll(metacardIds.stream().map(id -> new ProcessingDetailsImpl(id, null, "Failed to create metacard")).collect(Collectors.toList()));
} catch (CswException e) {
throw new IngestException("Csw Transaction Failed : ", e);
}
try {
createdMetacards = transactionQuery(createdMetacardFilters, subject);
} catch (UnsupportedQueryException e) {
errors.add(new ProcessingDetailsImpl(this.getId(), e, "Failed to retrieve newly created metacards"));
}
return new CreateResponseImpl(createRequest, properties, createdMetacards, errors);
}
use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.
the class TestRestEndpoint method givenCatalogFramework.
protected CatalogFramework givenCatalogFramework(String returnId) throws IngestException, SourceUnavailableException {
CatalogFramework framework = mock(CatalogFramework.class);
Metacard returnMetacard = mock(Metacard.class);
when(returnMetacard.getId()).thenReturn(returnId);
when(framework.create(isA(CreateRequest.class))).thenReturn(new CreateResponseImpl(null, null, Arrays.asList(returnMetacard)));
when(framework.create(isA(CreateStorageRequest.class))).thenReturn(new CreateResponseImpl(null, null, Arrays.asList(returnMetacard)));
return framework;
}
use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.
the class FederationAdminServiceImplTest method testAddRegistryEntryMetacard.
@Test
public void testAddRegistryEntryMetacard() throws Exception {
Metacard metacard = testMetacard;
Metacard createdMetacard = testMetacard;
Subject systemSubject = security.getSystemSubject();
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, systemSubject);
CreateRequest request = new CreateRequestImpl(Collections.singletonList(metacard), properties, null);
CreateResponse response = new CreateResponseImpl(request, null, Collections.singletonList(createdMetacard));
when(catalogFramework.create(any(CreateRequest.class))).thenReturn(response);
String createdMetacardId = federationAdminServiceImpl.addRegistryEntry(metacard);
assertThat(createdMetacardId, is(equalTo(RegistryObjectMetacardType.REGISTRY_ID)));
verify(catalogFramework).create(any(CreateRequest.class));
}
use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.
the class FederationAdminServiceImplTest method testAddRegistryEntryStringWithDestinations.
@Test
public void testAddRegistryEntryStringWithDestinations() throws Exception {
Metacard metacard = testMetacard;
Metacard createdMetacard = testMetacard;
Set<String> destinations = new HashSet<>();
destinations.add(TEST_DESTINATION);
Subject systemSubject = security.getSystemSubject();
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, systemSubject);
CreateRequest request = new CreateRequestImpl(Collections.singletonList(metacard), properties, destinations);
CreateResponse response = new CreateResponseImpl(request, null, Collections.singletonList(createdMetacard));
when(registryTransformer.transform(any(InputStream.class))).thenReturn(metacard);
when(catalogFramework.create(any(CreateRequest.class))).thenReturn(response);
String createdMetacardId = federationAdminServiceImpl.addRegistryEntry(TEST_XML_STRING, destinations);
assertThat(createdMetacardId, is(equalTo(RegistryObjectMetacardType.REGISTRY_ID)));
verify(registryTransformer).transform(any(InputStream.class));
verify(catalogFramework).create(any(CreateRequest.class));
}
Aggregations