Search in sources :

Example 21 with MetacardCreationException

use of ddf.catalog.data.MetacardCreationException in project ddf by codice.

the class AbstractCatalogService method parseMetacard.

private Metacard parseMetacard(String transformerParam, Metacard metacard, Part part, InputStream inputStream) {
    String transformer = "xml";
    if (transformerParam != null) {
        transformer = transformerParam;
    }
    try {
        MimeType mimeType = new MimeType(part.getContentType());
        metacard = generateMetacard(mimeType, null, inputStream, transformer);
    } catch (MimeTypeParseException | MetacardCreationException e) {
        LOGGER.debug("Unable to parse metadata {}", part.getContentType());
    }
    return metacard;
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) MetacardCreationException(ddf.catalog.data.MetacardCreationException) MimeType(javax.activation.MimeType)

Example 22 with MetacardCreationException

use of ddf.catalog.data.MetacardCreationException in project ddf by codice.

the class ExceptionsTest method testMetacardCreationException.

@Test
public void testMetacardCreationException() {
    MetacardCreationException mce = new MetacardCreationException();
    assertNotNull(mce);
    mce = new MetacardCreationException(msg);
    assertEquals(mce.getMessage(), msg);
    mce = new MetacardCreationException(testCause);
    assertEquals(mce.getCause(), testCause);
    mce = new MetacardCreationException(msg, testCause);
    assertEquals(mce.getMessage(), msg);
    assertEquals(mce.getCause(), testCause);
}
Also used : MetacardCreationException(ddf.catalog.data.MetacardCreationException) Test(org.junit.Test)

Example 23 with MetacardCreationException

use of ddf.catalog.data.MetacardCreationException in project ddf by codice.

the class SolrMetacardClientImpl method addDocsToResults.

private void addDocsToResults(SolrDocumentList docs, List<Result> results) throws UnsupportedQueryException {
    for (SolrDocument doc : docs) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("SOLR DOC: {}", doc.getFieldValue(Metacard.ID + SchemaFields.TEXT_SUFFIX));
        }
        ResultImpl tmpResult;
        try {
            tmpResult = createResult(doc);
        } catch (MetacardCreationException e) {
            throw new UnsupportedQueryException("Could not create result metacard(s).", e);
        }
        results.add(tmpResult);
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) MetacardCreationException(ddf.catalog.data.MetacardCreationException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ResultImpl(ddf.catalog.data.impl.ResultImpl) FacetAttributeResultImpl(ddf.catalog.operation.impl.FacetAttributeResultImpl)

Example 24 with MetacardCreationException

use of ddf.catalog.data.MetacardCreationException in project ddf by codice.

the class DynamicSchemaResolver method getMetacardType.

@SuppressWarnings("squid:S2093")
public MetacardType getMetacardType(SolrDocument doc) throws MetacardCreationException {
    String mTypeFieldName = doc.getFirstValue(SchemaFields.METACARD_TYPE_FIELD_NAME).toString();
    MetacardType cachedMetacardType = metacardTypesCache.getIfPresent(mTypeFieldName);
    if (cachedMetacardType != null) {
        return cachedMetacardType;
    }
    byte[] bytes = (byte[]) doc.getFirstValue(SchemaFields.METACARD_TYPE_OBJECT_FIELD_NAME);
    try {
        cachedMetacardType = METACARD_TYPE_MAPPER.readValue(bytes, MetacardType.class);
    } catch (IOException e) {
        LOGGER.info("IO exception loading cached metacard type", e);
        throw new MetacardCreationException(COULD_NOT_READ_METACARD_TYPE_MESSAGE);
    }
    metacardTypeNameToSerialCache.put(mTypeFieldName, bytes);
    metacardTypesCache.put(mTypeFieldName, cachedMetacardType);
    addToFieldsCache(cachedMetacardType.getAttributeDescriptors());
    return cachedMetacardType;
}
Also used : MetacardCreationException(ddf.catalog.data.MetacardCreationException) IOException(java.io.IOException) MetacardType(ddf.catalog.data.MetacardType)

Example 25 with MetacardCreationException

use of ddf.catalog.data.MetacardCreationException 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

MetacardCreationException (ddf.catalog.data.MetacardCreationException)25 Metacard (ddf.catalog.data.Metacard)13 IOException (java.io.IOException)13 ArrayList (java.util.ArrayList)10 MimeType (javax.activation.MimeType)9 IngestException (ddf.catalog.source.IngestException)8 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)6 SolrServerException (org.apache.solr.client.solrj.SolrServerException)6 SolrException (org.apache.solr.common.SolrException)6 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)5 InputStream (java.io.InputStream)5 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)4 InputTransformer (ddf.catalog.transform.InputTransformer)4 List (java.util.List)4 MimeTypeParseException (javax.activation.MimeTypeParseException)4 SolrQuery (org.apache.solr.client.solrj.SolrQuery)4 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)4 SolrDocument (org.apache.solr.common.SolrDocument)4 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3 InternalIngestException (ddf.catalog.source.InternalIngestException)3