Search in sources :

Example 11 with CreateResponseImpl

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));
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) CreateResponse(ddf.catalog.operation.CreateResponse) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 12 with CreateResponseImpl

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);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) ProcessingDetails(ddf.catalog.operation.ProcessingDetails) IngestException(ddf.catalog.source.IngestException) SimpleLiteral(net.opengis.cat.csw.v_2_0_2.dc.elements.SimpleLiteral) HashSet(java.util.HashSet) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) Subject(ddf.security.Subject) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertAction) Collection(java.util.Collection) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl)

Example 13 with CreateResponseImpl

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;
}
Also used : Metacard(ddf.catalog.data.Metacard) CreateRequest(ddf.catalog.operation.CreateRequest) CatalogFramework(ddf.catalog.CatalogFramework) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest)

Example 14 with CreateResponseImpl

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));
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Subject(ddf.security.Subject) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 15 with CreateResponseImpl

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));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) InputStream(java.io.InputStream) Subject(ddf.security.Subject) Metacard(ddf.catalog.data.Metacard) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) HashSet(java.util.HashSet) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Aggregations

CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)28 CreateResponse (ddf.catalog.operation.CreateResponse)24 Test (org.junit.Test)21 Metacard (ddf.catalog.data.Metacard)17 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)16 HashMap (java.util.HashMap)15 CreateRequest (ddf.catalog.operation.CreateRequest)14 ArrayList (java.util.ArrayList)10 Serializable (java.io.Serializable)9 List (java.util.List)7 Subject (ddf.security.Subject)6 Exchange (org.apache.camel.Exchange)6 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)6 IngestException (ddf.catalog.source.IngestException)5 InputStream (java.io.InputStream)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 DeleteResponse (ddf.catalog.operation.DeleteResponse)4 HashSet (java.util.HashSet)4 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)3 HttpHeaders (javax.ws.rs.core.HttpHeaders)3