use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class CacheQueryRunnable method run.
@Override
public void run() {
// check if there are any currently cached results
QueryResponse response = queryCatalog(null, request, subject, new HashMap<>(CACHE_PROPERTIES));
search.update(response);
try {
searchController.publishResults(request.getId(), search.transform(request.getId()), session);
} catch (CatalogTransformerException e) {
LOGGER.debug("Failed to transform cached search results.", e);
}
addResults(response.getResults());
indexResults(response);
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class KMLTransformerImpl method getKmlGeoFromWkt.
private Geometry getKmlGeoFromWkt(final String wkt) throws CatalogTransformerException {
if (StringUtils.isBlank(wkt)) {
throw new CatalogTransformerException("WKT was null or empty. Unable to preform KML Transform on Metacard.");
}
com.vividsolutions.jts.geom.Geometry geo = readGeoFromWkt(wkt);
Geometry kmlGeo = createKmlGeo(geo);
if (!Point.class.getSimpleName().equals(geo.getGeometryType())) {
kmlGeo = addPointToKmlGeo(kmlGeo, geo.getCoordinate());
}
return kmlGeo;
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class RESTEndpoint method generateMetacard.
private Metacard generateMetacard(MimeType mimeType, String id, InputStream message, String transformerId) throws MetacardCreationException {
Metacard generatedMetacard = null;
List<InputTransformer> listOfCandidates = mimeTypeToTransformerMapper.findMatches(InputTransformer.class, mimeType);
List<String> stackTraceList = new ArrayList<>();
LOGGER.trace("Entering generateMetacard.");
LOGGER.debug("List of matches for mimeType [{}]: {}", mimeType, listOfCandidates);
try (TemporaryFileBackedOutputStream fileBackedOutputStream = new TemporaryFileBackedOutputStream()) {
try {
if (null != message) {
IOUtils.copy(message, fileBackedOutputStream);
} else {
throw new MetacardCreationException("Could not copy bytes of content message. Message was NULL.");
}
} catch (IOException e) {
throw new MetacardCreationException("Could not copy bytes of content message.", e);
}
Iterator<InputTransformer> it = listOfCandidates.iterator();
if (StringUtils.isNotEmpty(transformerId)) {
BundleContext bundleContext = getBundleContext();
Collection<ServiceReference<InputTransformer>> serviceReferences = bundleContext.getServiceReferences(InputTransformer.class, "(id=" + transformerId + ")");
it = serviceReferences.stream().map(bundleContext::getService).iterator();
}
while (it.hasNext()) {
InputTransformer transformer = it.next();
try (InputStream inputStreamMessageCopy = fileBackedOutputStream.asByteSource().openStream()) {
generatedMetacard = transformer.transform(inputStreamMessageCopy);
} catch (CatalogTransformerException | IOException e) {
List<String> stackTraces = Arrays.asList(ExceptionUtils.getRootCauseStackTrace(e));
stackTraceList.add(String.format("Transformer [%s] could not create metacard.", transformer));
stackTraceList.addAll(stackTraces);
LOGGER.debug("Transformer [{}] could not create metacard.", transformer, e);
}
if (generatedMetacard != null) {
break;
}
}
if (generatedMetacard == null) {
throw new MetacardCreationException(String.format("Could not create metacard with mimeType %s : %s", mimeType, StringUtils.join(stackTraceList, "\n")));
}
if (id != null) {
generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, id));
} else {
LOGGER.debug("Metacard had a null id");
}
} catch (IOException e) {
throw new MetacardCreationException("Could not create metacard.", e);
} catch (InvalidSyntaxException e) {
throw new MetacardCreationException("Could not determine transformer", e);
}
return generatedMetacard;
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class QueryResponseTransformerProducer method transform.
protected Object transform(Message in, Object obj, String mimeType, String transformerId, MimeTypeToTransformerMapper mapper) throws MimeTypeParseException, CatalogTransformerException {
// Look up the QueryResponseTransformer for the request's mime type.
// If a transformer is found, then transform the request's payload into a BinaryContent
// Otherwise, throw an exception.
MimeType derivedMimeType = new MimeType(mimeType);
if (transformerId != null) {
derivedMimeType = new MimeType(mimeType + ";" + MimeTypeToTransformerMapper.ID_KEY + "=" + transformerId);
}
List<QueryResponseTransformer> matches = mapper.findMatches(QueryResponseTransformer.class, derivedMimeType);
Object binaryContent = null;
if (matches != null && matches.size() == 1) {
Map<String, Serializable> arguments = new HashMap<String, Serializable>();
for (Entry<String, Object> entry : in.getHeaders().entrySet()) {
if (entry.getValue() instanceof Serializable) {
arguments.put(entry.getKey(), (Serializable) entry.getValue());
}
}
LOGGER.debug("Found a matching QueryResponseTransformer for [{}]", transformerId);
QueryResponseTransformer transformer = matches.get(0);
SourceResponse srcResp = in.getBody(SourceResponse.class);
if (null != srcResp) {
binaryContent = transformer.transform(srcResp, arguments);
}
} else {
LOGGER.debug("Did not find an QueryResponseTransformer for [{}]", transformerId);
throw new CatalogTransformerException("Did not find an QueryResponseTransformer for [" + transformerId + "]");
}
return binaryContent;
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class CqlResult method metacardToMap.
private Map<String, Object> metacardToMap(Result result) {
Map<String, Object> geoJson = null;
MetacardImpl resultMetacard = new MetacardImpl(result.getMetacard(), result.getMetacard().getMetacardType());
try {
for (AttributeDescriptor descriptor : resultMetacard.getMetacardType().getAttributeDescriptors()) {
switch(descriptor.getType().getAttributeFormat()) {
case BINARY:
case XML:
case OBJECT:
resultMetacard.setAttribute(descriptor.getName(), null);
default:
break;
}
}
geoJson = PropertyJsonMetacardTransformer.convertToJSON(resultMetacard, ImmutableList.of(AttributeType.AttributeFormat.BINARY, AttributeType.AttributeFormat.XML, AttributeType.AttributeFormat.OBJECT));
addCachedDate(resultMetacard, geoJson);
} catch (CatalogTransformerException e) {
LOGGER.debug("Unable to convert metacard to GeoJSON", e);
}
return geoJson;
}
Aggregations