@Test public void testSimpleCsvFileLookupServiceWithCharset() throws InitializationException, IOException, LookupFailureException { final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class); final CSVRecordLookupService service = new CSVRecordLookupService(); runner.addControllerService("csv-file-lookup-service", service); runner.setProperty(service, CSVRecordLookupService.CSV_FILE, "src/test/resources/test_Windows-31J.csv"); runner.setProperty(service, CSVRecordLookupService.CSV_FORMAT, "RFC4180"); runner.setProperty(service, CSVRecordLookupService.CHARSET, "Windows-31J"); runner.setProperty(service, CSVRecordLookupService.LOOKUP_KEY_COLUMN, "key"); runner.enableControllerService(service); runner.assertValid(service); final Optional<Record> property1 = service.lookup(Collections.singletonMap("key", "property.1")); assertThat(property1.isPresent(), is(true)); assertThat(property1.get().getAsString("value"), is("this is property \uff11")); assertThat(property1.get().getAsString("created_at"), is("2017-04-01")); }
@Override public Optional<Record> lookup(final Map<String, Object> coordinates) throws LookupFailureException { if (coordinates == null) { return Optional.empty(); } final String key = (String)coordinates.get(KEY); if (StringUtils.isBlank(key)) { return Optional.empty(); } try { if (watcher.checkAndReset()) { loadCache(); } } catch (final IllegalStateException | IOException e) { throw new LookupFailureException(e.getMessage(), e); } return Optional.ofNullable(cache.get(key)); }
CSVRecordLookupService extends AbstractControllerService implements RecordLookupService { @Override public Optional<Record> lookup(final Map<String, Object> coordinates) throws LookupFailureException { if (coordinates == null) { return Optional.empty(); } final String key = (String)coordinates.get(KEY); if (StringUtils.isBlank(key)) { return Optional.empty(); } try { if (watcher.checkAndReset()) { loadCache(); } } catch (final IllegalStateException | IOException e) { throw new LookupFailureException(e.getMessage(), e); } return Optional.ofNullable(cache.get(key)); } }
CSVRecordLookupService extends AbstractControllerService implements RecordLookupService { @Override public Optional<Record> lookup(final Map<String, Object> coordinates) throws LookupFailureException { if (coordinates == null) { return Optional.empty(); } final String key = (String)coordinates.get(KEY); if (StringUtils.isBlank(key)) { return Optional.empty(); } try { if (watcher.checkAndReset()) { loadCache(); } } catch (final IllegalStateException | IOException e) { throw new LookupFailureException(e.getMessage(), e); } return Optional.ofNullable(cache.get(key)); }  }
CSVRecordLookupService extends AbstractControllerService implements RecordLookupService { @Override public Optional<Record> lookup(final Map<String, Object> coordinates) throws LookupFailureException { if (coordinates == null) { return Optional.empty(); } final String key = (String)coordinates.get(KEY); if (StringUtils.isBlank(key)) { return Optional.empty(); } try { if (watcher.checkAndReset()) { loadCache(); } } catch (final IllegalStateException | IOException e) { throw new LookupFailureException(e.getMessage(), e); } return Optional.ofNullable(cache.get(key)); }  @OnEnabled void onEnabled(final ConfigurationContext context); @Override Optional<Record> lookup(final Map<String, Object> coordinates); @Override Set<String> getRequiredKeys(); }
CSVRecordLookupService extends AbstractControllerService implements RecordLookupService { @Override public Optional<Record> lookup(final Map<String, Object> coordinates) throws LookupFailureException { if (coordinates == null) { return Optional.empty(); } final String key = (String)coordinates.get(KEY); if (StringUtils.isBlank(key)) { return Optional.empty(); } try { if (watcher.checkAndReset()) { loadCache(); } } catch (final IllegalStateException | IOException e) { throw new LookupFailureException(e.getMessage(), e); } return Optional.ofNullable(cache.get(key)); }  @OnEnabled void onEnabled(final ConfigurationContext context); @Override Optional<Record> lookup(final Map<String, Object> coordinates); @Override Set<String> getRequiredKeys(); static final PropertyDescriptor CSV_FILE; static final PropertyDescriptor CHARSET; static final PropertyDescriptor LOOKUP_KEY_COLUMN; static final PropertyDescriptor IGNORE_DUPLICATES; }