/** * Registers a dataset given into the <code>resource</code> definition. * * @param resource The dataset definition resource. */ protected ElasticSearchDataSetDef _registerDataSet(String resource) throws Exception { // Register the SQL data set URL fileURL = Thread.currentThread().getContextClassLoader().getResource(resource); String json = IOUtils.toString(fileURL); ElasticSearchDataSetDef def = (ElasticSearchDataSetDef) jsonMarshaller.fromJson(json); dataSetDefRegistry.registerDataSetDef(def); return def; }
DataSetDef def = jsonMarshaller.fromJson(json); if (StringUtils.isBlank(def.getUUID())) def.setUUID(dsetFile.getName()); if (existingDef != null && jsonMarshaller.toJsonString(existingDef).equals(jsonMarshaller.toJsonString(def))) {
public String parseCodePoint(String codePoint) { try { if (!isBlank(codePoint)) { return String.valueOf(Character.toChars(Integer.parseInt(codePoint))); } } catch (Exception e) { // If is not a code point then return the string "as is" } return codePoint; }
public DataSetDef fromJson(String jsonString) throws Exception { JsonObject json = Json.parse(jsonString); DataSetProviderType type = readProviderType(json); DataSetDef dataSetDef = type.createDataSetDef(); dataSetDef.setProvider(type); readGeneralSettings(dataSetDef, json); DataSetDefJSONMarshallerExt marshaller = type.getJsonMarshaller(); if (marshaller != null) { marshaller.fromJson(dataSetDef, json); } else { for (String key : json.keys()) { if (!ROOT_KEYS.contains(key)) { String value = json.getString(key); dataSetDef.setProperty(key, value); } } } return dataSetDef; }
String defJson = getDataSetDefJsonMarshaller().toJsonString(def); Path defPath = resolveNioPath(def); ioService.write(defPath,
public String toJsonString(final DataSetDef dataSetDef) throws JsonException { return toJsonObject( dataSetDef ).toString(); }
String defJson = getDataSetDefJsonMarshaller().toJsonString(def); Path defPath = resolveNioPath(def); ioService.write(defPath,
public DataSetDef fromJson(String jsonString) throws Exception { JsonObject json = Json.parse(jsonString); DataSetProviderType type = readProviderType(json); DataSetDef dataSetDef = type.createDataSetDef(); dataSetDef.setProvider(type); readGeneralSettings(dataSetDef, json); DataSetDefJSONMarshallerExt marshaller = type.getJsonMarshaller(); if (marshaller != null) { marshaller.fromJson(dataSetDef, json); } else { for (String key : json.keys()) { if (!ROOT_KEYS.contains(key)) { String value = json.getString(key); dataSetDef.setProperty(key, value); } } } return dataSetDef; }
public String toJsonString(final DataSetDef dataSetDef) throws JsonException { return toJsonObject( dataSetDef ).toString(); }
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { try { checkNotNull("file", file); checkNotNull("attrs", attrs); if (file.getFileName().toString().endsWith(DATASET_EXT) && attrs.isRegularFile()) { String json = ioService.readAllString(file); DataSetDef def = getDataSetDefJsonMarshaller().fromJson(json); result.add(def); } } catch (final Exception e) { log.error("Data set definition read error: " + file.getFileName(), e); return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } });
@Test public void testCustom() throws Exception { final DataSetDef dataSetDef = new DataSetDef(); dataSetDef.setName("custom data set name"); dataSetDef.setUUID("custom-test-uuid"); dataSetDef.setProvider(CUSTOM_PROVIDER_TYPE); dataSetDef.setCacheEnabled(false); dataSetDef.setCacheMaxRows(100); dataSetDef.setPublic(true); dataSetDef.setPushEnabled(false); dataSetDef.setPushMaxSize(10); dataSetDef.setRefreshAlways(false); dataSetDef.setRefreshTime("1second"); dataSetDef.setProperty("prop1", "Hello"); String json = jsonMarshaller.toJsonString(dataSetDef); String customJSONContent = getFileAsString(CUSTOM_DEF_PATH); assertDataSetDef(json, customJSONContent); DataSetDef fromJson = jsonMarshaller.fromJson(customJSONContent); assertEquals(dataSetDef, fromJson); }
public String parseCodePoint(String codePoint) { try { if (!isBlank(codePoint)) { return String.valueOf(Character.toChars(Integer.parseInt(codePoint))); } } catch (Exception e) { // If is not a code point then return the string "as is" } return codePoint; }
dataSetDef.setDataSetFilter(filter); String json = jsonMarshaller.toJsonString(dataSetDef); String filteredDataSetDefJSONContent = getFileAsString(FILTER_DEF_PATH);
if (columns != null) final JsonArray columnsArray = toJsonObject(columns, dataSetDef); if (columnsArray != null)
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { try { checkNotNull("file", file); checkNotNull("attrs", attrs); if (file.getFileName().toString().endsWith(DATASET_EXT) && attrs.isRegularFile()) { String json = ioService.readAllString(file); DataSetDef def = getDataSetDefJsonMarshaller().fromJson(json); result.add(def); } } catch (final Exception e) { log.error("Data set definition read error: " + file.getFileName(), e); return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } });
@Test public void testCustom() throws Exception { final DataSetDef dataSetDef = new DataSetDef(); dataSetDef.setName("custom data set name"); dataSetDef.setUUID("custom-test-uuid"); dataSetDef.setProvider(CUSTOM_PROVIDER_TYPE); dataSetDef.setCacheEnabled(false); dataSetDef.setCacheMaxRows(100); dataSetDef.setPublic(true); dataSetDef.setPushEnabled(false); dataSetDef.setPushMaxSize(10); dataSetDef.setRefreshAlways(false); dataSetDef.setRefreshTime("1second"); dataSetDef.setProperty("prop1", "Hello"); String json = jsonMarshaller.toJsonString(dataSetDef); String customJSONContent = getFileAsString(CUSTOM_DEF_PATH); assertDataSetDef(json, customJSONContent); DataSetDef fromJson = jsonMarshaller.fromJson(customJSONContent); assertEquals(dataSetDef, fromJson); }
public DataSetProviderType readProviderType(JsonObject json) throws Exception { String provider = json.getString(PROVIDER); if (isBlank(provider)) { throw new IllegalArgumentException("Missing 'provider' property"); } DataSetProviderType type = dataSetProviderRegistry.getProviderTypeByName(provider); if (type == null) { throw new IllegalArgumentException("Provider not supported: " + provider); } return type; }
dataSetDef.setDataSetFilter(filter); String json = jsonMarshaller.toJsonString(dataSetDef); String filteredDataSetDefJSONContent = getFileAsString(FILTER_DEF_PATH);
if (columns != null) final JsonArray columnsArray = toJsonObject(columns, dataSetDef); if (columnsArray != null)
@Test public void testAllColumns() throws Exception { URL fileURL = Thread.currentThread().getContextClassLoader().getResource("expenseReports_allcolumns.dset"); String json = IOUtils.toString(fileURL, StandardCharsets.UTF_8); SQLDataSetDef def = (SQLDataSetDef) jsonMarshaller.fromJson(json); dataSetDefRegistry.registerDataSetDef(def); DataSetMetadata metadata = dataSetManager.getDataSetMetadata("expense_reports_allcolumns"); assertThat(metadata.getNumberOfColumns()).isEqualTo(6); assertThat(metadata.getEstimatedSize()).isEqualTo(6350); }