Search in sources :

Example 36 with CreateResponseImpl

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

the class SolrCatalogProviderImpl method create.

@Override
public CreateResponse create(CreateRequest request) throws IngestException {
    nonNull(request);
    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);
    }
    long startTime = System.currentTimeMillis();
    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).", e);
    }
    LOGGER.debug("Time elapsed to create {} metacards is {} ms", metacards.size(), System.currentTimeMillis() - startTime);
    return new CreateResponseImpl(request, request.getProperties(), output);
}
Also used : MetacardCreationException(ddf.catalog.data.MetacardCreationException) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Metacard(ddf.catalog.data.Metacard) IngestException(ddf.catalog.source.IngestException) SolrException(org.apache.solr.common.SolrException) 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