use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class TestRegistryStore method testCreateNoExistingMetacard.
@Test
public void testCreateNoExistingMetacard() throws Exception {
Metacard mcard = getDefaultMetacard();
Csw csw = mock(Csw.class);
TransactionResponseType responseType = mock(TransactionResponseType.class);
InsertResultType insertResultType = mock(InsertResultType.class);
BriefRecordType briefRecord = mock(BriefRecordType.class);
JAXBElement identifier = mock(JAXBElement.class);
SimpleLiteral literal = mock(SimpleLiteral.class);
when(literal.getContent()).thenReturn(Collections.singletonList(mcard.getId()));
when(identifier.getValue()).thenReturn(literal);
when(briefRecord.getIdentifier()).thenReturn(Collections.singletonList(identifier));
when(insertResultType.getBriefRecord()).thenReturn(Collections.singletonList(briefRecord));
when(responseType.getInsertResult()).thenReturn(Collections.singletonList(insertResultType));
when(factory.getClientForSubject(any())).thenReturn(csw);
when(csw.transaction(any())).thenReturn(responseType);
when(transformer.getTransformerIdForSchema(any())).thenReturn("myInsertType");
queryResults.add(new ResultImpl(mcard));
CreateRequest request = new CreateRequestImpl(mcard);
CreateResponse response = registryStore.create(request);
assertThat(response.getCreatedMetacards().get(0), is(mcard));
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class TestRegistryStore method testCreateNonRegistryMetacard.
@Test(expected = IngestException.class)
public void testCreateNonRegistryMetacard() throws Exception {
MetacardImpl mcard = getDefaultMetacard();
mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, null);
CreateRequest request = new CreateRequestImpl(mcard);
registryStore.create(request);
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class FederationAdminServiceImpl method addRegistryEntries.
@Override
public List<String> addRegistryEntries(List<Metacard> metacards, Set<String> destinations) throws FederationAdminException {
validateRegistryMetacards(metacards);
List<String> registryIds;
Map<String, Serializable> properties = new HashMap<>();
CreateRequest createRequest = new CreateRequestImpl(metacards, properties, destinations);
try {
CreateResponse createResponse = security.runWithSubjectOrElevate(() -> catalogFramework.create(createRequest));
//loop through to get id's
if (!createResponse.getProcessingErrors().isEmpty()) {
throw new FederationAdminException("Processing error occurred while creating registry entry. Details:" + System.lineSeparator() + stringifyProcessingErrors(createResponse.getProcessingErrors()));
}
registryIds = createResponse.getCreatedMetacards().stream().filter(RegistryUtility::isRegistryMetacard).map(RegistryUtility::getRegistryId).collect(Collectors.toList());
} catch (SecurityServiceException | InvocationTargetException e) {
throw new FederationAdminException("Error adding local registry entry.", e);
}
return registryIds;
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class TestMetacardGroomerPlugin method testCreateWithNoRecords.
@Test
public void testCreateWithNoRecords() throws PluginExecutionException, StopProcessingException {
CreateRequest request = mock(CreateRequest.class);
when(request.getMetacards()).thenReturn(new ArrayList<>());
CreateRequest returnedRequest = plugin.process(request);
assertThat(returnedRequest, not(nullValue()));
assertThat(returnedRequest.getMetacards(), not(nullValue()));
assertThat(returnedRequest.getMetacards().size(), is(0));
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class TestMetacardGroomerPlugin method testCreateWithNullRequest.
@Test
public void testCreateWithNullRequest() throws PluginExecutionException, StopProcessingException {
CreateRequest returnedRequest = plugin.process((CreateRequest) null);
assertThat(returnedRequest, nullValue());
}
Aggregations