Search in sources :

Example 1 with CreateRequest

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));
}
Also used : Metacard(ddf.catalog.data.Metacard) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) SimpleLiteral(net.opengis.cat.csw.v_2_0_2.dc.elements.SimpleLiteral) ResultImpl(ddf.catalog.data.impl.ResultImpl) JAXBElement(javax.xml.bind.JAXBElement) InsertResultType(net.opengis.cat.csw.v_2_0_2.InsertResultType) BriefRecordType(net.opengis.cat.csw.v_2_0_2.BriefRecordType) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) Test(org.junit.Test)

Example 2 with CreateRequest

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);
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 3 with CreateRequest

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;
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Serializable(java.io.Serializable) SecurityServiceException(ddf.security.service.SecurityServiceException) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) InvocationTargetException(java.lang.reflect.InvocationTargetException) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl)

Example 4 with CreateRequest

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));
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) Test(org.junit.Test)

Example 5 with CreateRequest

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());
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) Test(org.junit.Test)

Aggregations

CreateRequest (ddf.catalog.operation.CreateRequest)80 Test (org.junit.Test)62 Metacard (ddf.catalog.data.Metacard)44 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)39 CreateResponse (ddf.catalog.operation.CreateResponse)29 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)17 Subject (ddf.security.Subject)14 Serializable (java.io.Serializable)12 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)11 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)11 IngestException (ddf.catalog.source.IngestException)11 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)9 List (java.util.List)9 HashSet (java.util.HashSet)7 UpdateRequest (ddf.catalog.operation.UpdateRequest)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 Map (java.util.Map)5 CatalogFramework (ddf.catalog.CatalogFramework)4