@Test public void testProjectionParse() { final SelectParserSingle request = new SelectParserSingle(); final Select select = new Select(); try { request.projectionParse(select.getProjection()); assertEquals("Projection should be empty", 0, request.getRequest().getProjection().size()); select.addUsedProjection((String) null); request.projectionParse(select.getProjection()); assertEquals("Projection should not be empty", 0, request.getRequest().getProjection().size()); select.addUsedProjection("var"); request.projectionParse(select.getProjection()); assertEquals("Projection should not be empty", 1, request.getRequest().getProjection().size()); select.resetUsedProjection(); request.projectionParse(select.getProjection()); assertEquals("Projection should be empty", 0, request.getRequest().getProjection().size()); select.addUsedProjection("var1").addUnusedProjection("var2"); request.projectionParse(select.getProjection()); assertEquals("Projection should not be empty", 1, request.getRequest().getProjection().size()); assertEquals(2, request.getRequest().getProjection() .get(PROJECTION.FIELDS.exactToken()).size()); for (final Iterator<Entry<String, JsonNode>> iterator = request.getRequest().getProjection() .get(PROJECTION.FIELDS.exactToken()).fields(); iterator .hasNext();) { final Entry<String, JsonNode> entry = iterator.next(); if (entry.getKey().equals("var1")) { assertEquals(1, entry.getValue().asInt()); } if (entry.getKey().equals("var2")) { assertEquals(0, entry.getValue().asInt()); } } try { request.projectionParse(null); } catch (final InvalidParseOperationException e) { fail("Should not raized an exception"); } try { request.addProjection(DEFAULT_SLICE, null); fail("Should raized an exception"); } catch (final InvalidParseOperationException e) { } try { request.addProjection(null, DEFAULT_ALLKEYS); fail("Should raized an exception"); } catch (final InvalidParseOperationException e) { } new SelectToMongodb(request).getFinalProjection(); try { request.addProjection(DEFAULT_SLICE, DEFAULT_ALLKEYS); new SelectToMongodb(request).getFinalProjection(); } catch (final InvalidParseOperationException e) { fail("Should not raized an exception"); } request.projectionParse(JsonHandler.getFromString("{$fields: { var1: -1 }}")); new SelectToMongodb(request).getFinalProjection(); try { request.addProjection(DEFAULT_SLICE, DEFAULT_ALLKEYS); new SelectToMongodb(request).getFinalProjection(); } catch (final InvalidParseOperationException e) { fail("Should not raized an exception"); } request.projectionParse(JsonHandler.createObjectNode()); new SelectToMongodb(request).getFinalProjection(); try { request.addProjection(DEFAULT_SLICE, DEFAULT_ALLKEYS); new SelectToMongodb(request).getFinalProjection(); } catch (final InvalidParseOperationException e) { fail("Should not raized an exception"); } } catch (final InvalidParseOperationException e) { e.printStackTrace(); fail(e.getMessage()); } }
public void projectionParse(final JsonNode rootNode) throws InvalidParseOperationException { if (rootNode == null) { return; } GlobalDatas.sanityParametersCheck(rootNode.toString(), GlobalDatas.NB_PROJECTIONS); try { ((Select) request).resetUsedProjection(); final ObjectNode node = JsonHandler.createObjectNode(); if (rootNode.has(PROJECTION.FIELDS.exactToken())) { adapter.setVarsValue(node, rootNode.path(PROJECTION.FIELDS.exactToken())); ((ObjectNode) rootNode).set(PROJECTION.FIELDS.exactToken(), node); } ((Select) request).setProjection(rootNode); } catch (final Exception e) { throw new InvalidParseOperationException( "Parse in error for Projection: " + rootNode, e); } }
SelectParserSingle extends RequestParserSingle { public void projectionParse(final JsonNode rootNode) throws InvalidParseOperationException { if (rootNode == null) { return; } GlobalDatas.sanityParametersCheck(rootNode.toString(), GlobalDatas.NB_PROJECTIONS); try { ((Select) request).resetUsedProjection(); final ObjectNode node = JsonHandler.createObjectNode(); if (rootNode.has(PROJECTION.FIELDS.exactToken())) { adapter.setVarsValue(node, rootNode.path(PROJECTION.FIELDS.exactToken())); ((ObjectNode) rootNode).set(PROJECTION.FIELDS.exactToken(), node); } ((Select) request).setProjection(rootNode); } catch (final Exception e) { throw new InvalidParseOperationException( "Parse in error for Projection: " + rootNode, e); } } }
SelectParserSingle extends RequestParserSingle { public void projectionParse(final JsonNode rootNode) throws InvalidParseOperationException { if (rootNode == null) { return; } GlobalDatas.sanityParametersCheck(rootNode.toString(), GlobalDatas.NB_PROJECTIONS); try { ((Select) request).resetUsedProjection(); final ObjectNode node = JsonHandler.createObjectNode(); if (rootNode.has(PROJECTION.FIELDS.exactToken())) { adapter.setVarsValue(node, rootNode.path(PROJECTION.FIELDS.exactToken())); ((ObjectNode) rootNode).set(PROJECTION.FIELDS.exactToken(), node); } ((Select) request).setProjection(rootNode); } catch (final Exception e) { throw new InvalidParseOperationException( "Parse in error for Projection: " + rootNode, e); } } SelectParserSingle();  SelectParserSingle(VarNameAdapter adapter); }
SelectParserSingle extends RequestParserSingle { public void projectionParse(final JsonNode rootNode) throws InvalidParseOperationException { if (rootNode == null) { return; } GlobalDatas.sanityParametersCheck(rootNode.toString(), GlobalDatas.NB_PROJECTIONS); try { ((Select) request).resetUsedProjection(); final ObjectNode node = JsonHandler.createObjectNode(); if (rootNode.has(PROJECTION.FIELDS.exactToken())) { adapter.setVarsValue(node, rootNode.path(PROJECTION.FIELDS.exactToken())); ((ObjectNode) rootNode).set(PROJECTION.FIELDS.exactToken(), node); } ((Select) request).setProjection(rootNode); } catch (final Exception e) { throw new InvalidParseOperationException( "Parse in error for Projection: " + rootNode, e); } } SelectParserSingle();  SelectParserSingle(VarNameAdapter adapter); @Override void parse(final JsonNode request); @Override void parseQueryOnly(final String query); void projectionParse(final JsonNode rootNode); void addProjection(final ObjectNode slice, final ObjectNode allFields); @Override Select getRequest(); }
SelectParserSingle extends RequestParserSingle { public void projectionParse(final JsonNode rootNode) throws InvalidParseOperationException { if (rootNode == null) { return; } GlobalDatas.sanityParametersCheck(rootNode.toString(), GlobalDatas.NB_PROJECTIONS); try { ((Select) request).resetUsedProjection(); final ObjectNode node = JsonHandler.createObjectNode(); if (rootNode.has(PROJECTION.FIELDS.exactToken())) { adapter.setVarsValue(node, rootNode.path(PROJECTION.FIELDS.exactToken())); ((ObjectNode) rootNode).set(PROJECTION.FIELDS.exactToken(), node); } ((Select) request).setProjection(rootNode); } catch (final Exception e) { throw new InvalidParseOperationException( "Parse in error for Projection: " + rootNode, e); } } SelectParserSingle();  SelectParserSingle(VarNameAdapter adapter); @Override void parse(final JsonNode request); @Override void parseQueryOnly(final String query); void projectionParse(final JsonNode rootNode); void addProjection(final ObjectNode slice, final ObjectNode allFields); @Override Select getRequest();  }