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;
}
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);
}
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);
}
}
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;
}
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);
}
Aggregations