@Override public void handleException(Throwable t, Record record) { if (t instanceof Error) { throw (Error) t; } throw new MorphlineRuntimeException(t); }
@Override public void handleException(Throwable t, Record record) { if (t instanceof Error) { throw (Error) t; } throw new MorphlineRuntimeException(t); }
@Override protected boolean doProcess(Record inputRecord, InputStream stream) throws IOException { try { return doProcess2(inputRecord, stream); } catch (SAXNotRecognizedException e) { throw new MorphlineRuntimeException(e); } catch (SAXNotSupportedException e) { throw new MorphlineRuntimeException(e); } catch (SAXException e) { throw new MorphlineRuntimeException(e); } }
@Override protected final boolean doProcess(Record inputRecord, InputStream stream) throws IOException { try { return doProcess2(inputRecord, stream); } catch (SaxonApiException e) { throw new MorphlineRuntimeException(e); } catch (XMLStreamException e) { throw new MorphlineRuntimeException(e); } }
protected Charset detectCharset(Record record, Charset charset) { if (charset != null) { return charset; } List charsets = record.get(Fields.ATTACHMENT_CHARSET); if (charsets.size() == 0) { // TODO try autodetection (AutoDetectReader) throw new MorphlineRuntimeException("Missing charset for record: " + record); } String charsetName = (String) charsets.get(0); return Charset.forName(charsetName); }
private Schema getSchema(GenericContainer datum, Schema lastSchema) { Schema schema = datum.getSchema(); if (lastSchema != null && lastSchema != schema) { throw new MorphlineRuntimeException("Schemas must be identical: " + schema + ", lastSchema: " + lastSchema); } return schema; }
protected Charset detectCharset(Record record, Charset charset) { if (charset != null) { return charset; } List charsets = record.get(Fields.ATTACHMENT_CHARSET); if (charsets.size() == 0) { // TODO try autodetection (AutoDetectReader) throw new MorphlineRuntimeException("Missing charset for record: " + record); } String charsetName = (String) charsets.get(0); return Charset.forName(charsetName); }
private Schema getSchema(GenericContainer datum, Schema lastSchema) { Schema schema = datum.getSchema(); if (lastSchema != null && lastSchema != schema) { throw new MorphlineRuntimeException("Schemas must be identical: " + schema + ", lastSchema: " + lastSchema); } return schema; }
@Override protected void doNotify(Record notification) { for (Object event : Notifications.getLifecycleEvents(notification)) { if (event == Notifications.LifecycleEvent.SHUTDOWN) { synchronized (SERVERS) { Server server = SERVERS.remove(port); if (server != null) { try { server.stop(); server.join(); } catch (Exception e) { throw new MorphlineRuntimeException(e); } } } } } super.doNotify(notification); }
@Override protected void doNotify(Record notification) { for (Object event : Notifications.getLifecycleEvents(notification)) { if (event == Notifications.LifecycleEvent.SHUTDOWN) { synchronized (SERVERS) { Server server = SERVERS.remove(port); if (server != null) { try { server.stop(); server.join(); } catch (Exception e) { throw new MorphlineRuntimeException(e); } } } } } super.doNotify(notification); }
@Override protected boolean doProcess(Record record) { Timer.Context timerContext = elapsedTime.time(); SolrInputDocument doc = convert(record); try { loader.load(doc); } catch (IOException | SolrServerException e) { throw new MorphlineRuntimeException(e); } finally { timerContext.stop(); } // pass record to next command in chain: return super.doProcess(record); }
@Override public void handleException(Throwable t, Record record) { if (t instanceof Error) { throw (Error) t; // never ignore errors } if (isProductionMode()) { if (!isRecoverableException(t)) { LOG.warn("Ignoring unrecoverable exception in production mode for record: " + record, t); return; } else if (isIgnoringRecoverableExceptions()) { LOG.warn("Ignoring recoverable exception in production mode for record: " + record, t); return; } } throw new MorphlineRuntimeException(t); }
@Override public void handleException(Throwable t, Record record) { if (t instanceof Error) { throw (Error) t; // never ignore errors } if (isProductionMode()) { if (!isRecoverableException(t)) { LOG.warn("Ignoring unrecoverable exception in production mode for record: " + record, t); return; } else if (isIgnoringRecoverableExceptions()) { LOG.warn("Ignoring recoverable exception in production mode for record: " + record, t); return; } } throw new MorphlineRuntimeException(t); }
private SolrInputDocument convert(Record record) { Map<String, Collection<Object>> map = record.getFields().asMap(); SolrInputDocument doc = new SolrInputDocument(new HashMap(2 * map.size())); for (Map.Entry<String, Collection<Object>> entry : map.entrySet()) { String key = entry.getKey(); if (LOAD_SOLR_CHILD_DOCUMENTS.equals(key)) { for (Object value : entry.getValue()) { if (value instanceof Record) { value = convert((Record) value); // recurse } if (value instanceof SolrInputDocument) { doc.addChildDocument((SolrInputDocument) value); } else { throw new MorphlineRuntimeException("Child document must be of class " + Record.class.getName() + " or " + SolrInputDocument.class.getName() + ": " + value); } } } else { doc.setField(key, entry.getValue(), getBoost(key)); } } return doc; }
@Override protected boolean doProcess(Record record) { try { return script.evaluate(record, getConfig(), this, getChild(), getContext(), LOG); } catch (ScriptException e) { throw new MorphlineRuntimeException("Cannot execute script", e); } } }
@Override protected boolean doProcess(Record record) { try { return script.evaluate(record, getConfig(), this, getChild(), getContext(), LOG); } catch (ScriptException e) { throw new MorphlineRuntimeException("Cannot execute script", e); } } }
@Override protected boolean doProcess(Record record) { try { List outputValues = record.get(outputFieldName); for (Object value : record.get(inputFieldName)) { reader.setValue(value.toString()); TokenStream tokenStream = analyzer.tokenStream("content", reader); tokenStream.reset(); while (tokenStream.incrementToken()) { if (token.length() > 0) { // incrementToken() updates the token! String tokenStr = new String(token.buffer(), 0, token.length()); outputValues.add(tokenStr); } } tokenStream.end(); tokenStream.close(); } } catch (IOException e) { throw new MorphlineRuntimeException(e); } // pass record to next command in chain: return super.doProcess(record); }
@Override protected boolean doProcess(Record record) { try { List outputValues = record.get(outputFieldName); for (Object value : record.get(inputFieldName)) { reader.setValue(value.toString()); TokenStream tokenStream = analyzer.tokenStream("content", reader); tokenStream.reset(); while (tokenStream.incrementToken()) { if (token.length() > 0) { // incrementToken() updates the token! String tokenStr = new String(token.buffer(), 0, token.length()); outputValues.add(tokenStr); } } tokenStream.end(); tokenStream.close(); } } catch (IOException e) { throw new MorphlineRuntimeException(e); } // pass record to next command in chain: return super.doProcess(record); }
@Override protected boolean doProcess(Record record) { if (!hasAtLeastOneAttachment(record)) { return false; } // TODO: make field for stream configurable String streamMediaType = (String) record.getFirstValue(Fields.ATTACHMENT_MIME_TYPE); if (!isMimeTypeSupported(streamMediaType, record)) { return false; } InputStream stream = getAttachmentInputStream(record); try { return doProcess(record, stream); } catch (IOException e) { throw new MorphlineRuntimeException(e); } finally { Closeables.closeQuietly(stream); } }
@Override protected boolean doProcess(Record record) { if (!hasAtLeastOneAttachment(record)) { return false; } // TODO: make field for stream configurable String streamMediaType = (String) record.getFirstValue(Fields.ATTACHMENT_MIME_TYPE); if (!isMimeTypeSupported(streamMediaType, record)) { return false; } InputStream stream = getAttachmentInputStream(record); try { return doProcess(record, stream); } catch (IOException e) { throw new MorphlineRuntimeException(e); } finally { Closeables.closeQuietly(stream); } }