List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:com.ikanow.aleph2.analytics.services.AnalyticsContext.java
/** Handles sending of objects to other parts of the system * @param external_bucket/*from ww w. j a va 2 s . c o m*/ * @param job * @param obj_json * @return */ protected Validation<BasicMessageBean, JsonNode> externalEmit(final DataBucketBean external_bucket, final AnalyticThreadJobBean job, final JsonNode obj_json) { // Do we already know about this object: final IAnalyticsContext sub_context = _mutable_state.sub_buckets.get(external_bucket.full_name()); if (null != sub_context) { //easy case, sub-buckets are constructed dynamically return sub_context.emitObject(sub_context.getBucket(), job, Either.left(obj_json), Optional.empty()); } else { // this is more complicated // First off - if this is a test bucket then we're not going to write anything, but we will do all the authentication final boolean is_test_bucket = BucketUtils.isTestBucket(_mutable_state.bucket.get()); final Either<Either<IBatchSubservice<JsonNode>, IDataWriteService<JsonNode>>, String> element = _mutable_state.external_buckets .computeIfAbsent(external_bucket.full_name(), s -> { // Check this is supported: final boolean matches_glob = Optionals .of(() -> _mutable_state.bucket.get().external_emit_paths()) .orElse(Collections.emptyList()).stream() .map(p -> FileSystems.getDefault().getPathMatcher("glob:" + p)) .anyMatch(matcher -> matcher.matches(FileSystems.getDefault().getPath(s))); return matches_glob ? getNewExternalEndpoint(s) : Either.right(null); }); return element.<Validation<BasicMessageBean, JsonNode>>either(e -> e.either(batch -> { if (!is_test_bucket) { _mutable_state.has_unflushed_data = true; batch.storeObject(obj_json); } return Validation.success(obj_json); }, slow -> { if (!is_test_bucket) { _mutable_state.has_unflushed_data = true; slow.storeObject(obj_json); } return Validation.success(obj_json); }), topic -> { if (null == topic) { // this hack means not present return Validation.fail(ErrorUtils.buildErrorMessage(this.getClass().getSimpleName(), "externalEmit", "Bucket {0} not found or not authorized", external_bucket.full_name())); } else if (_distributed_services.doesTopicExist(topic)) { // (ie someone is listening in on our output data, so duplicate it for their benefit) if (!is_test_bucket) { _mutable_state.has_unflushed_data = true; _distributed_services.produce(topic, obj_json.toString()); } return Validation.success(obj_json); } else { return Validation.fail(ErrorUtils.buildSuccessMessage(this.getClass().getSimpleName(), "sendObjectToStreamingPipeline", "Bucket:job {0}:{1} topic {2} has no listeners", external_bucket.full_name(), job.name(), topic)); } }); } }
From source file:com.redhat.lightblue.metadata.rdbms.parser.RDBMSPropertyParserImplTest.java
@Test public void convertAndParseBindingsJustIn() throws IOException { String json = "{\"rdbms\":{\"dialect\":\"oracle\",\"SQLMapping\": {\"columnToFieldMap\":[{\"table\":\"t\",\"column\":\"c\",\"field\":\"f\"}], \"joins\" :[{\"tables\":[{\"name\":\"n\",\"alias\":\"a\"}],\"joinTablesStatement\" : \"x\", \"projectionMappings\": [{\"column\":\"c\",\"field\":\"f\",\"sort\":\"s\"}]}]},\"delete\":{\"bindings\":{\"in\":[{\"column\":\"col\",\"field\":\"pat\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]},\"fetch\":{\"bindings\":{\"in\":[{\"column\":\"col\",\"field\":\"pat\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]},\"insert\":{\"bindings\":{\"in\":[{\"column\":\"col\",\"field\":\"pat\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]},\"save\":{\"bindings\":{\"in\":[{\"column\":\"col\",\"field\":\"pat\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]},\"update\":{\"bindings\":{\"in\":[{\"column\":\"col\",\"field\":\"pat\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]}}}"; JsonNode rJSON = p.newNode(); RDBMS r = new RDBMS(); r.setDialect("oracle"); r.setSQLMapping(new SQLMapping()); r.getSQLMapping().setJoins(new ArrayList<Join>()); r.getSQLMapping().getJoins().add(new Join()); r.getSQLMapping().getJoins().get(0).setJoinTablesStatement("x"); r.getSQLMapping().getJoins().get(0).setProjectionMappings(new ArrayList<ProjectionMapping>()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().add(new ProjectionMapping()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setColumn("c"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setField("f"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setSort("s"); r.getSQLMapping().getJoins().get(0).setTables(new ArrayList<Table>()); r.getSQLMapping().getJoins().get(0).getTables().add(new Table()); r.getSQLMapping().getJoins().get(0).getTables().get(0).setAlias("a"); r.getSQLMapping().getJoins().get(0).getTables().get(0).setName("n"); r.getSQLMapping().setColumnToFieldMap(new ArrayList<ColumnToField>()); r.getSQLMapping().getColumnToFieldMap().add(new ColumnToField()); r.getSQLMapping().getColumnToFieldMap().get(0).setColumn("c"); r.getSQLMapping().getColumnToFieldMap().get(0).setField("f"); r.getSQLMapping().getColumnToFieldMap().get(0).setTable("t"); Operation o = new Operation(); //With just In bindings Bindings b = new Bindings(); ArrayList<InOut> inList = new ArrayList<InOut>(); InOut e = new InOut(); e.setColumn("col"); e.setField(new Path("pat")); inList.add(e);/*from w w w. j a va 2 s . co m*/ b.setInList(inList); o.setBindings(b); ArrayList<Expression> expressionList = new ArrayList<Expression>(); Statement e1 = new Statement(); e1.setSQL("REQ EXPRESSION"); e1.setType("select"); expressionList.add(e1); o.setExpressionList(expressionList); r.setDelete(duplicate("delete", o)); r.setFetch(duplicate("fetch", o)); r.setInsert(duplicate("insert", o)); r.setSave(duplicate("save", o)); r.setUpdate(duplicate("update", o)); cut.convert(p, rJSON, r); assertEqualJson(json, rJSON.toString()); Object ro = cut.parse("rdbms", p, JsonUtils.json(json).get("rdbms")); JsonNode roJSON = p.newNode(); cut.convert(p, roJSON, ro); assertEqualJson(json, roJSON.toString()); assertEqualJson(roJSON.toString(), rJSON.toString()); }
From source file:com.redhat.lightblue.metadata.rdbms.parser.RDBMSPropertyParserImplTest.java
@Test public void convertAndParseBindingsJustOut() throws IOException { String json = "{\"rdbms\":{\"dialect\":\"oracle\",\"SQLMapping\": {\"columnToFieldMap\":[{\"table\":\"t\",\"column\":\"c\",\"field\":\"f\"}], \"joins\" :[{\"tables\":[{\"name\":\"n\",\"alias\":\"a\"}],\"joinTablesStatement\" : \"x\", \"projectionMappings\": [{\"column\":\"c\",\"field\":\"f\",\"sort\":\"s\"}]}]},\"delete\":{\"bindings\":{\"out\":[{\"column\":\"col\",\"field\":\"pat\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]},\"fetch\":{\"bindings\":{\"out\":[{\"column\":\"col\",\"field\":\"pat\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]},\"insert\":{\"bindings\":{\"out\":[{\"column\":\"col\",\"field\":\"pat\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]},\"save\":{\"bindings\":{\"out\":[{\"column\":\"col\",\"field\":\"pat\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]},\"update\":{\"bindings\":{\"out\":[{\"column\":\"col\",\"field\":\"pat\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]}}}"; JsonNode rJSON = p.newNode(); RDBMS r = new RDBMS(); r.setDialect("oracle"); r.setSQLMapping(new SQLMapping()); r.getSQLMapping().setJoins(new ArrayList<Join>()); r.getSQLMapping().getJoins().add(new Join()); r.getSQLMapping().getJoins().get(0).setJoinTablesStatement("x"); r.getSQLMapping().getJoins().get(0).setProjectionMappings(new ArrayList<ProjectionMapping>()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().add(new ProjectionMapping()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setColumn("c"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setField("f"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setSort("s"); r.getSQLMapping().getJoins().get(0).setTables(new ArrayList<Table>()); r.getSQLMapping().getJoins().get(0).getTables().add(new Table()); r.getSQLMapping().getJoins().get(0).getTables().get(0).setAlias("a"); r.getSQLMapping().getJoins().get(0).getTables().get(0).setName("n"); r.getSQLMapping().setColumnToFieldMap(new ArrayList<ColumnToField>()); r.getSQLMapping().getColumnToFieldMap().add(new ColumnToField()); r.getSQLMapping().getColumnToFieldMap().get(0).setColumn("c"); r.getSQLMapping().getColumnToFieldMap().get(0).setField("f"); r.getSQLMapping().getColumnToFieldMap().get(0).setTable("t"); Operation o = new Operation(); //With just Out bindings Bindings b = new Bindings(); ArrayList<InOut> inList = new ArrayList<InOut>(); InOut e = new InOut(); e.setColumn("col"); e.setField(new Path("pat")); inList.add(e);//from ww w. j a va2 s . c o m b.setOutList(inList); o.setBindings(b); ArrayList<Expression> expressionList = new ArrayList<Expression>(); Statement e1 = new Statement(); e1.setSQL("REQ EXPRESSION"); e1.setType("select"); expressionList.add(e1); o.setExpressionList(expressionList); r.setDelete(duplicate("delete", o)); r.setFetch(duplicate("fetch", o)); r.setInsert(duplicate("insert", o)); r.setSave(duplicate("save", o)); r.setUpdate(duplicate("update", o)); cut.convert(p, rJSON, r); assertEqualJson(json, rJSON.toString()); Object ro = cut.parse("rdbms", p, JsonUtils.json(json).get("rdbms")); JsonNode roJSON = p.newNode(); cut.convert(p, roJSON, ro); assertEqualJson(json, roJSON.toString()); assertEqualJson(roJSON.toString(), rJSON.toString()); }
From source file:com.redhat.lightblue.metadata.rdbms.parser.RDBMSPropertyParserImplTest.java
@Test public void convertAndParseForEachMissingExpressions() throws IOException { String json = "{\"rdbms\":{\"dialect\":\"oracle\",\"SQLMapping\": {\"columnToFieldMap\":[{\"table\":\"t\",\"column\":\"c\",\"field\":\"f\"}], \"joins\" :[{\"tables\":[{\"name\":\"n\",\"alias\":\"a\"}],\"joinTablesStatement\" : \"x\", \"projectionMappings\": [{\"column\":\"c\",\"field\":\"f\",\"sort\":\"s\"}]}]},\"delete\":{\"expressions\":[{\"foreach\":{\"iterateOverField\":\"*\"}}]},\"fetch\":{\"expressions\":[{\"foreach\":{\"iterateOverField\":\"*\"}}]},\"insert\":{\"expressions\":[{\"foreach\":{\"iterateOverField\":\"*\"}}]},\"save\":{\"expressions\":[{\"foreach\":{\"iterateOverField\":\"*\"}}]},\"update\":{\"expressions\":[{\"foreach\":{\"iterateOverField\":\"*\"}}]}}}"; JsonNode rJSON = p.newNode(); RDBMS r = new RDBMS(); r.setDialect("oracle"); r.setSQLMapping(new SQLMapping()); r.getSQLMapping().setJoins(new ArrayList<Join>()); r.getSQLMapping().getJoins().add(new Join()); r.getSQLMapping().getJoins().get(0).setJoinTablesStatement("x"); r.getSQLMapping().getJoins().get(0).setProjectionMappings(new ArrayList<ProjectionMapping>()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().add(new ProjectionMapping()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setColumn("c"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setField("f"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setSort("s"); r.getSQLMapping().getJoins().get(0).setTables(new ArrayList<Table>()); r.getSQLMapping().getJoins().get(0).getTables().add(new Table()); r.getSQLMapping().getJoins().get(0).getTables().get(0).setAlias("a"); r.getSQLMapping().getJoins().get(0).getTables().get(0).setName("n"); r.getSQLMapping().setColumnToFieldMap(new ArrayList<ColumnToField>()); r.getSQLMapping().getColumnToFieldMap().add(new ColumnToField()); r.getSQLMapping().getColumnToFieldMap().get(0).setColumn("c"); r.getSQLMapping().getColumnToFieldMap().get(0).setField("f"); r.getSQLMapping().getColumnToFieldMap().get(0).setTable("t"); Operation o = new Operation(); ArrayList<Expression> expressionList = new ArrayList<Expression>(); ForEach forEach = new ForEach(); forEach.setIterateOverField(Path.ANYPATH); Assert.assertEquals(Path.ANYPATH, forEach.getIterateOverField()); expressionList.add(forEach);/*from ww w . ja v a2 s . co m*/ o.setExpressionList(expressionList); r.setDelete(duplicate("delete", o)); r.setFetch(duplicate("fetch", o)); r.setInsert(duplicate("insert", o)); r.setSave(duplicate("save", o)); r.setUpdate(duplicate("update", o)); com.redhat.lightblue.util.Error xe = null; try { cut.convert(p, rJSON, r); } catch (com.redhat.lightblue.util.Error ex) { xe = ex; } catch (Throwable exx) { exx.printStackTrace(); } finally { Assert.assertNotNull(xe); } Assert.assertEquals("{}", rJSON.toString()); com.redhat.lightblue.util.Error error = null; try { Object ro = cut.parse("rdbms", p, JsonUtils.json(json).get("rdbms")); } catch (com.redhat.lightblue.util.Error ex) { error = ex; } catch (Throwable exx) { exx.printStackTrace(); } finally { Assert.assertNotNull(error); } }
From source file:com.redhat.lightblue.metadata.rdbms.parser.RDBMSPropertyParserImplTest.java
@Test public void convertAndParseIfFieldEmpty() throws IOException { String json = "{\"rdbms\":{\"dialect\":\"oracle\",\"SQLMapping\": {\"columnToFieldMap\":[{\"table\":\"t\",\"column\":\"c\",\"field\":\"f\"}], \"joins\" :[{\"tables\":[{\"name\":\"n\",\"alias\":\"a\"}],\"joinTablesStatement\" : \"x\", \"projectionMappings\": [{\"column\":\"c\",\"field\":\"f\",\"sort\":\"s\"}]}]},\"delete\":{\"expressions\":[{\"if\":{\"fieldEmpty\":{\"field\":\"*\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"fetch\":{\"expressions\":[{\"if\":{\"fieldEmpty\":{\"field\":\"*\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"insert\":{\"expressions\":[{\"if\":{\"fieldEmpty\":{\"field\":\"*\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"save\":{\"expressions\":[{\"if\":{\"fieldEmpty\":{\"field\":\"*\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"update\":{\"expressions\":[{\"if\":{\"fieldEmpty\":{\"field\":\"*\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]}}}"; JsonNode rJSON = p.newNode(); RDBMS r = new RDBMS(); r.setDialect("oracle"); r.setSQLMapping(new SQLMapping()); r.getSQLMapping().setJoins(new ArrayList<Join>()); r.getSQLMapping().getJoins().add(new Join()); r.getSQLMapping().getJoins().get(0).setJoinTablesStatement("x"); r.getSQLMapping().getJoins().get(0).setProjectionMappings(new ArrayList<ProjectionMapping>()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().add(new ProjectionMapping()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setColumn("c"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setField("f"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setSort("s"); r.getSQLMapping().getJoins().get(0).setTables(new ArrayList<Table>()); r.getSQLMapping().getJoins().get(0).getTables().add(new Table()); r.getSQLMapping().getJoins().get(0).getTables().get(0).setAlias("a"); r.getSQLMapping().getJoins().get(0).getTables().get(0).setName("n"); r.getSQLMapping().setColumnToFieldMap(new ArrayList<ColumnToField>()); r.getSQLMapping().getColumnToFieldMap().add(new ColumnToField()); r.getSQLMapping().getColumnToFieldMap().get(0).setColumn("c"); r.getSQLMapping().getColumnToFieldMap().get(0).setField("f"); r.getSQLMapping().getColumnToFieldMap().get(0).setTable("t"); Operation o = new Operation(); ArrayList<Expression> expressionList = new ArrayList<Expression>(); Conditional e4 = new Conditional(); IfFieldEmpty pe = new IfFieldEmpty(); pe.setField(Path.ANYPATH);/*from w w w . j a v a 2s .c o m*/ e4.setIf(pe); Then then = new Then(); ArrayList<Expression> expressions2 = new ArrayList<Expression>(); Statement e5 = new Statement(); e5.setType("delete"); e5.setSQL("DELETE FROM somewhere WHERE someColumn=someValue"); expressions2.add(e5); then.setExpressions(expressions2); e4.setThen(then); expressionList.add(e4); o.setExpressionList(expressionList); r.setDelete(duplicate("delete", o)); r.setFetch(duplicate("fetch", o)); r.setInsert(duplicate("insert", o)); r.setSave(duplicate("save", o)); r.setUpdate(duplicate("update", o)); cut.convert(p, rJSON, r); assertEqualJson(json, rJSON.toString()); Object ro = cut.parse("rdbms", p, JsonUtils.json(json).get("rdbms")); JsonNode roJSON = p.newNode(); cut.convert(p, roJSON, ro); assertEqualJson(json, roJSON.toString()); assertEqualJson(roJSON.toString(), rJSON.toString()); }
From source file:com.redhat.lightblue.metadata.rdbms.parser.RDBMSPropertyParserImplTest.java
@Test public void convertAndParseIfFieldRegex() throws IOException { String json = "{\"rdbms\":{\"dialect\":\"oracle\",\"SQLMapping\": {\"columnToFieldMap\":[{\"table\":\"t\",\"column\":\"c\",\"field\":\"f\"}], \"joins\" :[{\"tables\":[{\"name\":\"n\",\"alias\":\"a\"}],\"joinTablesStatement\" : \"x\", \"projectionMappings\": [{\"column\":\"c\",\"field\":\"f\",\"sort\":\"s\"}]}]},\"delete\":{\"expressions\":[{\"if\":{\"fieldRegex\":{\"field\":\"*\",\"regex\":\"*\",\"caseInsensitive\":\"false\",\"multiline\":\"false\",\"extended\":\"false\",\"dotall\":\"false\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"fetch\":{\"expressions\":[{\"if\":{\"fieldRegex\":{\"field\":\"*\",\"regex\":\"*\",\"caseInsensitive\":\"false\",\"multiline\":\"false\",\"extended\":\"false\",\"dotall\":\"false\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"insert\":{\"expressions\":[{\"if\":{\"fieldRegex\":{\"field\":\"*\",\"regex\":\"*\",\"caseInsensitive\":\"false\",\"multiline\":\"false\",\"extended\":\"false\",\"dotall\":\"false\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"save\":{\"expressions\":[{\"if\":{\"fieldRegex\":{\"field\":\"*\",\"regex\":\"*\",\"caseInsensitive\":\"false\",\"multiline\":\"false\",\"extended\":\"false\",\"dotall\":\"false\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"update\":{\"expressions\":[{\"if\":{\"fieldRegex\":{\"field\":\"*\",\"regex\":\"*\",\"caseInsensitive\":\"false\",\"multiline\":\"false\",\"extended\":\"false\",\"dotall\":\"false\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]}}}"; JsonNode rJSON = p.newNode(); RDBMS r = new RDBMS(); r.setDialect("oracle"); r.setSQLMapping(new SQLMapping()); r.getSQLMapping().setJoins(new ArrayList<Join>()); r.getSQLMapping().getJoins().add(new Join()); r.getSQLMapping().getJoins().get(0).setJoinTablesStatement("x"); r.getSQLMapping().getJoins().get(0).setProjectionMappings(new ArrayList<ProjectionMapping>()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().add(new ProjectionMapping()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setColumn("c"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setField("f"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setSort("s"); r.getSQLMapping().getJoins().get(0).setTables(new ArrayList<Table>()); r.getSQLMapping().getJoins().get(0).getTables().add(new Table()); r.getSQLMapping().getJoins().get(0).getTables().get(0).setAlias("a"); r.getSQLMapping().getJoins().get(0).getTables().get(0).setName("n"); r.getSQLMapping().setColumnToFieldMap(new ArrayList<ColumnToField>()); r.getSQLMapping().getColumnToFieldMap().add(new ColumnToField()); r.getSQLMapping().getColumnToFieldMap().get(0).setColumn("c"); r.getSQLMapping().getColumnToFieldMap().get(0).setField("f"); r.getSQLMapping().getColumnToFieldMap().get(0).setTable("t"); Operation o = new Operation(); ArrayList<Expression> expressionList = new ArrayList<Expression>(); Conditional e4 = new Conditional(); IfFieldRegex pe = new IfFieldRegex(); pe.setField(Path.ANYPATH);//from w ww. ja v a 2s .c o m pe.setRegex("*"); e4.setIf(pe); Then then = new Then(); ArrayList<Expression> expressions2 = new ArrayList<Expression>(); Statement e5 = new Statement(); e5.setType("delete"); e5.setSQL("DELETE FROM somewhere WHERE someColumn=someValue"); expressions2.add(e5); then.setExpressions(expressions2); e4.setThen(then); expressionList.add(e4); o.setExpressionList(expressionList); r.setDelete(duplicate("delete", o)); r.setFetch(duplicate("fetch", o)); r.setInsert(duplicate("insert", o)); r.setSave(duplicate("save", o)); r.setUpdate(duplicate("update", o)); cut.convert(p, rJSON, r); assertEqualJson(json, rJSON.toString()); Object ro = cut.parse("rdbms", p, JsonUtils.json(json).get("rdbms")); JsonNode roJSON = p.newNode(); cut.convert(p, roJSON, ro); assertEqualJson(json, roJSON.toString()); assertEqualJson(roJSON.toString(), rJSON.toString()); }
From source file:com.redhat.lightblue.metadata.rdbms.parser.RDBMSPropertyParserImplTest.java
@Test public void convertAndParseIfFieldCheckValue() throws IOException { String json = "{\"rdbms\":{\"dialect\":\"oracle\",\"SQLMapping\": {\"columnToFieldMap\":[{\"table\":\"t\",\"column\":\"c\",\"field\":\"f\"}], \"joins\" :[{\"tables\":[{\"name\":\"n\",\"alias\":\"a\"}],\"joinTablesStatement\" : \"x\", \"projectionMappings\": [{\"column\":\"c\",\"field\":\"f\",\"sort\":\"s\"}]}]},\"delete\":{\"expressions\":[{\"if\":{\"fieldCheckValue\":{\"field\":\"*\",\"value\":\"1\",\"op\":\"eq\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"fetch\":{\"expressions\":[{\"if\":{\"fieldCheckValue\":{\"field\":\"*\",\"value\":\"1\",\"op\":\"eq\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"insert\":{\"expressions\":[{\"if\":{\"fieldCheckValue\":{\"field\":\"*\",\"value\":\"1\",\"op\":\"eq\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"save\":{\"expressions\":[{\"if\":{\"fieldCheckValue\":{\"field\":\"*\",\"value\":\"1\",\"op\":\"eq\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"update\":{\"expressions\":[{\"if\":{\"fieldCheckValue\":{\"field\":\"*\",\"value\":\"1\",\"op\":\"eq\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]}}}"; JsonNode rJSON = p.newNode(); RDBMS r = new RDBMS(); r.setDialect("oracle"); r.setSQLMapping(new SQLMapping()); r.getSQLMapping().setJoins(new ArrayList<Join>()); r.getSQLMapping().getJoins().add(new Join()); r.getSQLMapping().getJoins().get(0).setJoinTablesStatement("x"); r.getSQLMapping().getJoins().get(0).setProjectionMappings(new ArrayList<ProjectionMapping>()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().add(new ProjectionMapping()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setColumn("c"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setField("f"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setSort("s"); r.getSQLMapping().getJoins().get(0).setTables(new ArrayList<Table>()); r.getSQLMapping().getJoins().get(0).getTables().add(new Table()); r.getSQLMapping().getJoins().get(0).getTables().get(0).setAlias("a"); r.getSQLMapping().getJoins().get(0).getTables().get(0).setName("n"); r.getSQLMapping().setColumnToFieldMap(new ArrayList<ColumnToField>()); r.getSQLMapping().getColumnToFieldMap().add(new ColumnToField()); r.getSQLMapping().getColumnToFieldMap().get(0).setColumn("c"); r.getSQLMapping().getColumnToFieldMap().get(0).setField("f"); r.getSQLMapping().getColumnToFieldMap().get(0).setTable("t"); Operation o = new Operation(); ArrayList<Expression> expressionList = new ArrayList<Expression>(); Conditional e4 = new Conditional(); IfFieldCheckValue pe = new IfFieldCheckValue(); pe.setOp("eq"); pe.setField(Path.ANYPATH);/* w w w. ja v a2 s.c o m*/ pe.setValue("1"); e4.setIf(pe); Then then = new Then(); ArrayList<Expression> expressions2 = new ArrayList<Expression>(); Statement e5 = new Statement(); e5.setType("delete"); e5.setSQL("DELETE FROM somewhere WHERE someColumn=someValue"); expressions2.add(e5); then.setExpressions(expressions2); e4.setThen(then); expressionList.add(e4); o.setExpressionList(expressionList); r.setDelete(duplicate("delete", o)); r.setFetch(duplicate("fetch", o)); r.setInsert(duplicate("insert", o)); r.setSave(duplicate("save", o)); r.setUpdate(duplicate("update", o)); cut.convert(p, rJSON, r); assertEqualJson(json, rJSON.toString()); Object ro = cut.parse("rdbms", p, JsonUtils.json(json).get("rdbms")); JsonNode roJSON = p.newNode(); cut.convert(p, roJSON, ro); assertEqualJson(json, roJSON.toString()); assertEqualJson(roJSON.toString(), rJSON.toString()); }
From source file:com.redhat.lightblue.metadata.rdbms.parser.RDBMSPropertyParserImplTest.java
@Test public void convertAndParseIfFieldCheckField() throws IOException { String json = "{\"rdbms\":{\"dialect\":\"oracle\",\"SQLMapping\": {\"columnToFieldMap\":[{\"table\":\"t\",\"column\":\"c\",\"field\":\"f\"}], \"joins\" :[{\"tables\":[{\"name\":\"n\",\"alias\":\"a\"}],\"joinTablesStatement\" : \"x\", \"projectionMappings\": [{\"column\":\"c\",\"field\":\"f\",\"sort\":\"s\"}]}]},\"delete\":{\"expressions\":[{\"if\":{\"fieldCheckField\":{\"field\":\"*\",\"rfield\":\"*\",\"op\":\"eq\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"fetch\":{\"expressions\":[{\"if\":{\"fieldCheckField\":{\"field\":\"*\",\"rfield\":\"*\",\"op\":\"eq\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"insert\":{\"expressions\":[{\"if\":{\"fieldCheckField\":{\"field\":\"*\",\"rfield\":\"*\",\"op\":\"eq\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"save\":{\"expressions\":[{\"if\":{\"fieldCheckField\":{\"field\":\"*\",\"rfield\":\"*\",\"op\":\"eq\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]},\"update\":{\"expressions\":[{\"if\":{\"fieldCheckField\":{\"field\":\"*\",\"rfield\":\"*\",\"op\":\"eq\"}},\"then\":[{\"statement\":{\"sql\":\"DELETE FROM somewhere WHERE someColumn=someValue\",\"type\":\"delete\"}}]}]}}}"; JsonNode rJSON = p.newNode(); RDBMS r = new RDBMS(); r.setDialect("oracle"); r.setSQLMapping(new SQLMapping()); r.getSQLMapping().setJoins(new ArrayList<Join>()); r.getSQLMapping().getJoins().add(new Join()); r.getSQLMapping().getJoins().get(0).setJoinTablesStatement("x"); r.getSQLMapping().getJoins().get(0).setProjectionMappings(new ArrayList<ProjectionMapping>()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().add(new ProjectionMapping()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setColumn("c"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setField("f"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setSort("s"); r.getSQLMapping().getJoins().get(0).setTables(new ArrayList<Table>()); r.getSQLMapping().getJoins().get(0).getTables().add(new Table()); r.getSQLMapping().getJoins().get(0).getTables().get(0).setAlias("a"); r.getSQLMapping().getJoins().get(0).getTables().get(0).setName("n"); r.getSQLMapping().setColumnToFieldMap(new ArrayList<ColumnToField>()); r.getSQLMapping().getColumnToFieldMap().add(new ColumnToField()); r.getSQLMapping().getColumnToFieldMap().get(0).setColumn("c"); r.getSQLMapping().getColumnToFieldMap().get(0).setField("f"); r.getSQLMapping().getColumnToFieldMap().get(0).setTable("t"); Operation o = new Operation(); ArrayList<Expression> expressionList = new ArrayList<Expression>(); Conditional e4 = new Conditional(); IfFieldCheckField pe = new IfFieldCheckField(); pe.setOp("eq"); pe.setField(Path.ANYPATH);/*ww w . j a v a2 s. c o m*/ pe.setRfield(Path.ANYPATH); e4.setIf(pe); Then then = new Then(); ArrayList<Expression> expressions2 = new ArrayList<Expression>(); Statement e5 = new Statement(); e5.setType("delete"); e5.setSQL("DELETE FROM somewhere WHERE someColumn=someValue"); expressions2.add(e5); then.setExpressions(expressions2); e4.setThen(then); expressionList.add(e4); o.setExpressionList(expressionList); r.setDelete(duplicate("delete", o)); r.setFetch(duplicate("fetch", o)); r.setInsert(duplicate("insert", o)); r.setSave(duplicate("save", o)); r.setUpdate(duplicate("update", o)); cut.convert(p, rJSON, r); assertEqualJson(json, rJSON.toString()); Object ro = cut.parse("rdbms", p, JsonUtils.json(json).get("rdbms")); JsonNode roJSON = p.newNode(); cut.convert(p, roJSON, ro); assertEqualJson(json, roJSON.toString()); assertEqualJson(roJSON.toString(), rJSON.toString()); }
From source file:com.redhat.lightblue.metadata.rdbms.parser.RDBMSPropertyParserImplTest.java
@Test public void convertAndParseForEachMissingIterateOverPath() throws IOException { String json = "{\"rdbms\":{\"dialect\":\"oracle\",\"SQLMapping\": {\"columnToFieldMap\":[{\"table\":\"t\",\"column\":\"c\",\"field\":\"f\"}], \"joins\" :[{\"tables\":[{\"name\":\"n\",\"alias\":\"a\"}],\"joinTablesStatement\" : \"x\", \"projectionMappings\": [{\"column\":\"c\",\"field\":\"f\",\"sort\":\"s\"}]}]},\"delete\":{\"expressions\":[{\"foreach\":{\"expressions\":[{\"statement\":{\"sql\":\"X\",\"type\":\"select\"}}]}}]},\"fetch\":{\"expressions\":[{\"foreach\":{\"expressions\":[{\"statement\":{\"sql\":\"X\",\"type\":\"select\"}}]}}]},\"insert\":{\"expressions\":[{\"foreach\":{\"expressions\":[{\"statement\":{\"sql\":\"X\",\"type\":\"select\"}}]}}]},\"save\":{\"expressions\":[{\"foreach\":{\"expressions\":[{\"statement\":{\"sql\":\"X\",\"type\":\"select\"}}]}}]},\"update\":{\"expressions\":[{\"foreach\":{\"expressions\":[{\"statement\":{\"sql\":\"X\",\"type\":\"select\"}}]}}]}}}"; JsonNode rJSON = p.newNode(); RDBMS r = new RDBMS(); r.setDialect("oracle"); r.setSQLMapping(new SQLMapping()); r.getSQLMapping().setJoins(new ArrayList<Join>()); r.getSQLMapping().getJoins().add(new Join()); r.getSQLMapping().getJoins().get(0).setJoinTablesStatement("x"); r.getSQLMapping().getJoins().get(0).setProjectionMappings(new ArrayList<ProjectionMapping>()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().add(new ProjectionMapping()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setColumn("c"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setField("f"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setSort("s"); r.getSQLMapping().getJoins().get(0).setTables(new ArrayList<Table>()); r.getSQLMapping().getJoins().get(0).getTables().add(new Table()); r.getSQLMapping().getJoins().get(0).getTables().get(0).setAlias("a"); r.getSQLMapping().getJoins().get(0).getTables().get(0).setName("n"); r.getSQLMapping().setColumnToFieldMap(new ArrayList<ColumnToField>()); r.getSQLMapping().getColumnToFieldMap().add(new ColumnToField()); r.getSQLMapping().getColumnToFieldMap().get(0).setColumn("c"); r.getSQLMapping().getColumnToFieldMap().get(0).setField("f"); r.getSQLMapping().getColumnToFieldMap().get(0).setTable("t"); Operation o = new Operation(); ArrayList<Expression> expressionList = new ArrayList<Expression>(); ForEach forEach = new ForEach(); ArrayList<Expression> el = new ArrayList<Expression>(); Statement es = new Statement(); es.setSQL("X"); es.setType("select"); el.add(es);/* w ww . jav a2 s .co m*/ forEach.setExpressions(el); Assert.assertEquals(el, forEach.getExpressions()); expressionList.add(forEach); o.setExpressionList(expressionList); r.setDelete(duplicate("delete", o)); r.setFetch(duplicate("fetch", o)); r.setInsert(duplicate("insert", o)); r.setSave(duplicate("save", o)); r.setUpdate(duplicate("update", o)); com.redhat.lightblue.util.Error xe = null; try { cut.convert(p, rJSON, r); } catch (com.redhat.lightblue.util.Error ex) { xe = ex; } catch (Throwable exx) { exx.printStackTrace(); } finally { Assert.assertNotNull(xe); } Assert.assertEquals("{}", rJSON.toString()); com.redhat.lightblue.util.Error error = null; try { Object ro = cut.parse("rdbms", p, JsonUtils.json(json).get("rdbms")); } catch (com.redhat.lightblue.util.Error ex) { error = ex; } catch (Throwable exx) { exx.printStackTrace(); } finally { Assert.assertNotNull(error); } }
From source file:com.redhat.lightblue.metadata.rdbms.parser.RDBMSPropertyParserImplTest.java
@Test public void convertAndParseBindingsBoth() throws IOException { String json = "{\"rdbms\":{\"dialect\":\"oracle\",\"SQLMapping\": {\"columnToFieldMap\":[{\"table\":\"t\",\"column\":\"c\",\"field\":\"f\"}], \"joins\" :[{\"tables\":[{\"name\":\"n\",\"alias\":\"a\"}],\"joinTablesStatement\" : \"x\", \"projectionMappings\": [{\"column\":\"c\",\"field\":\"f\",\"sort\":\"s\"}]}]},\"delete\":{\"bindings\":{\"in\":[{\"column\":\"col\",\"field\":\"pat\"}],\"out\":[{\"column\":\"col1\",\"field\":\"pat1\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]},\"fetch\":{\"bindings\":{\"in\":[{\"column\":\"col\",\"field\":\"pat\"}],\"out\":[{\"column\":\"col1\",\"field\":\"pat1\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]},\"insert\":{\"bindings\":{\"in\":[{\"column\":\"col\",\"field\":\"pat\"}],\"out\":[{\"column\":\"col1\",\"field\":\"pat1\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]},\"save\":{\"bindings\":{\"in\":[{\"column\":\"col\",\"field\":\"pat\"}],\"out\":[{\"column\":\"col1\",\"field\":\"pat1\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]},\"update\":{\"bindings\":{\"in\":[{\"column\":\"col\",\"field\":\"pat\"}],\"out\":[{\"column\":\"col1\",\"field\":\"pat1\"}]},\"expressions\":[{\"statement\":{\"sql\":\"REQ EXPRESSION\",\"type\":\"select\"}}]}}}"; JsonNode rJSON = p.newNode(); RDBMS r = new RDBMS(); r.setDialect("oracle"); r.setSQLMapping(new SQLMapping()); r.getSQLMapping().setJoins(new ArrayList<Join>()); r.getSQLMapping().getJoins().add(new Join()); r.getSQLMapping().getJoins().get(0).setJoinTablesStatement("x"); r.getSQLMapping().getJoins().get(0).setProjectionMappings(new ArrayList<ProjectionMapping>()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().add(new ProjectionMapping()); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setColumn("c"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setField("f"); r.getSQLMapping().getJoins().get(0).getProjectionMappings().get(0).setSort("s"); r.getSQLMapping().getJoins().get(0).setTables(new ArrayList<Table>()); r.getSQLMapping().getJoins().get(0).getTables().add(new Table()); r.getSQLMapping().getJoins().get(0).getTables().get(0).setAlias("a"); r.getSQLMapping().getJoins().get(0).getTables().get(0).setName("n"); r.getSQLMapping().setColumnToFieldMap(new ArrayList<ColumnToField>()); r.getSQLMapping().getColumnToFieldMap().add(new ColumnToField()); r.getSQLMapping().getColumnToFieldMap().get(0).setColumn("c"); r.getSQLMapping().getColumnToFieldMap().get(0).setField("f"); r.getSQLMapping().getColumnToFieldMap().get(0).setTable("t"); Operation o = new Operation(); //No bindings Bindings b = new Bindings(); ArrayList<InOut> inList = new ArrayList<InOut>(); InOut e = new InOut(); e.setColumn("col"); e.setField(new Path("pat")); inList.add(e);// ww w . ja va2s .c om b.setInList(inList); ArrayList<InOut> outList = new ArrayList<InOut>(); InOut ou = new InOut(); ou.setColumn("col1"); ou.setField(new Path("pat1")); outList.add(ou); b.setOutList(outList); o.setBindings(b); ArrayList<Expression> expressionList = new ArrayList<Expression>(); Statement e1 = new Statement(); e1.setSQL("REQ EXPRESSION"); e1.setType("select"); expressionList.add(e1); o.setExpressionList(expressionList); r.setDelete(duplicate("delete", o)); r.setFetch(duplicate("fetch", o)); r.setInsert(duplicate("insert", o)); r.setSave(duplicate("save", o)); r.setUpdate(duplicate("update", o)); cut.convert(p, rJSON, r); assertEqualJson(json, rJSON.toString()); Object ro = cut.parse("rdbms", p, JsonUtils.json(json).get("rdbms")); JsonNode roJSON = p.newNode(); cut.convert(p, roJSON, ro); assertEqualJson(json, roJSON.toString()); assertEqualJson(roJSON.toString(), rJSON.toString()); }