Search in sources :

Example 1 with CreateResponseImpl

use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.

the class SolrCatalogProvider method create.

@Override
public CreateResponse create(CreateRequest request) throws IngestException {
    if (request == null) {
        throw new IngestException(REQUEST_MUST_NOT_BE_NULL_MESSAGE);
    }
    List<Metacard> metacards = request.getMetacards();
    List<Metacard> output = new ArrayList<>();
    if (metacards == null) {
        return new CreateResponseImpl(request, null, output);
    }
    for (Metacard metacard : metacards) {
        boolean isSourceIdSet = (metacard.getSourceId() != null && !"".equals(metacard.getSourceId()));
        /*
             * If an ID is not provided, then one is generated so that documents are unique. Solr
             * will not accept documents unless the id is unique.
             */
        if (metacard.getId() == null || metacard.getId().equals("")) {
            if (isSourceIdSet) {
                throw new IngestException("Metacard from a separate distribution must have ID");
            }
            metacard.setAttribute(new AttributeImpl(Metacard.ID, generatePrimaryKey()));
        }
        if (!isSourceIdSet) {
            metacard.setSourceId(getId());
        }
        output.add(metacard);
    }
    try {
        client.add(output, isForcedAutoCommit());
    } catch (SolrServerException | SolrException | IOException | MetacardCreationException e) {
        LOGGER.info("Solr could not ingest metacard(s) during create.", e);
        throw new IngestException("Could not ingest metacard(s).");
    }
    pendingNrtIndex.putAll(output.stream().collect(Collectors.toMap(Metacard::getId, m -> copyMetacard(m))));
    return new CreateResponseImpl(request, request.getProperties(), output);
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardCreationException(ddf.catalog.data.MetacardCreationException) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl)

Example 2 with CreateResponseImpl

use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.

the class TestPlugin method testCreateBadTransform.

@Test(expected = PluginExecutionException.class)
public void testCreateBadTransform() throws PluginExecutionException, CatalogTransformerException, IOException, IngestException, SourceUnavailableException {
    // given
    when(transformer.transform(isA(Metacard.class), isA(Map.class))).thenThrow(CatalogTransformerException.class);
    CreateResponse createResponse = new CreateResponseImpl(new CreateRequestImpl(metacard), null, Arrays.asList(metacard));
    // when
    plugin.process(createResponse);
}
Also used : Metacard(ddf.catalog.data.Metacard) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Map(java.util.Map) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 3 with CreateResponseImpl

use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.

the class TestPlugin method testCreateNullParent.

@Test
@Ignore
public void testCreateNullParent() throws PluginExecutionException, IngestException, SourceUnavailableException {
    // given
    CreateResponse createResponse = new CreateResponseImpl(new CreateRequestImpl(metacard), null, Arrays.asList(metacard));
    // when
    plugin.process(createResponse);
    // then
    verify(endpoint, never()).addDocument(isA(HttpHeaders.class), isA(UriInfo.class), isA(InputStream.class));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) CreateResponse(ddf.catalog.operation.CreateResponse) InputStream(java.io.InputStream) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) UriInfo(javax.ws.rs.core.UriInfo) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with CreateResponseImpl

use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.

the class TestPlugin method testCreateNullTransformer.

@Test
@Ignore
public void testCreateNullTransformer() throws PluginExecutionException, IngestException, SourceUnavailableException {
    // given
    plugin = new RestReplicatorPlugin(null);
    CreateResponse createResponse = new CreateResponseImpl(new CreateRequestImpl(metacard), null, Arrays.asList(metacard));
    // when
    plugin.process(createResponse);
    // then
    verify(endpoint, never()).addDocument(isA(HttpHeaders.class), isA(UriInfo.class), isA(InputStream.class));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) RestReplicatorPlugin(ddf.catalog.federation.layered.replication.RestReplicatorPlugin) CreateResponse(ddf.catalog.operation.CreateResponse) InputStream(java.io.InputStream) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) UriInfo(javax.ws.rs.core.UriInfo) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with CreateResponseImpl

use of ddf.catalog.operation.impl.CreateResponseImpl 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);
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) LoggerFactory(org.slf4j.LoggerFactory) TagsFilterDelegate(ddf.catalog.filter.delegate.TagsFilterDelegate) Locale(java.util.Locale) Map(java.util.Map) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) URI(java.net.URI) Bundle(org.osgi.framework.Bundle) Converter(com.thoughtworks.xstream.converters.Converter) ImmutableSet(com.google.common.collect.ImmutableSet) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) SourceMonitor(ddf.catalog.source.SourceMonitor) ParserException(org.codice.ddf.parser.ParserException) AbstractCswStore(org.codice.ddf.spatial.ogc.csw.catalog.common.source.AbstractCswStore) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) Serializable(java.io.Serializable) Objects(java.util.Objects) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) DeleteRequest(ddf.catalog.operation.DeleteRequest) List(java.util.List) ExternalIdentifierType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) UpdateResponse(ddf.catalog.operation.UpdateResponse) Dictionary(java.util.Dictionary) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) HashMap(java.util.HashMap) DeleteResponse(ddf.catalog.operation.DeleteResponse) OperationTransaction(ddf.catalog.operation.OperationTransaction) MetaTypeInformation(org.osgi.service.metatype.MetaTypeInformation) ArrayList(java.util.ArrayList) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) Configuration(org.osgi.service.cm.Configuration) CreateResponse(ddf.catalog.operation.CreateResponse) CollectionUtils(org.apache.commons.collections.CollectionUtils) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) SecurityConstants(ddf.security.SecurityConstants) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) EncryptionService(ddf.security.encryption.EncryptionService) RegistryConstants(org.codice.ddf.registry.common.RegistryConstants) Result(ddf.catalog.data.Result) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Logger(org.slf4j.Logger) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) IngestException(ddf.catalog.source.IngestException) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) IOException(java.io.IOException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) MetaTypeService(org.osgi.service.metatype.MetaTypeService) Consumer(java.util.function.Consumer) Query(ddf.catalog.operation.Query) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) Serializable(java.io.Serializable) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Objects(java.util.Objects) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl)

Aggregations

CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)36 CreateResponse (ddf.catalog.operation.CreateResponse)27 Test (org.junit.Test)24 Metacard (ddf.catalog.data.Metacard)20 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)19 CreateRequest (ddf.catalog.operation.CreateRequest)16 HashMap (java.util.HashMap)14 ArrayList (java.util.ArrayList)11 Serializable (java.io.Serializable)9 InputStream (java.io.InputStream)8 HttpHeaders (javax.ws.rs.core.HttpHeaders)7 Subject (ddf.security.Subject)6 List (java.util.List)6 UriInfo (javax.ws.rs.core.UriInfo)6 Ignore (org.junit.Ignore)6 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)5 IngestException (ddf.catalog.source.IngestException)5 Exchange (org.apache.camel.Exchange)5 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)5 CatalogFramework (ddf.catalog.CatalogFramework)4