@Test public void testFacetsParse() { ArrayNode facetsArray = JsonHandler.createArrayNode(); final SelectParserMultiple request = new SelectParserMultiple(); try { request.facetsParse(facetsArray); assertEquals("Facets should be empty", 0, request.getRequest().getFacets().size()); facetsArray.add(terms("mafacet", "mavar1", 1, FacetOrder.ASC).getCurrentFacet()); request.facetsParse(facetsArray); assertEquals("Facets should have 1 facet", 1, request.getRequest().getFacets().size()); facetsArray.add(terms("mafacet2", "mavar1", 5, FacetOrder.DESC).getCurrentFacet()); request.facetsParse(facetsArray); assertEquals("Facets should have 2 facet", 2, request.getRequest().getFacets().size()); assertThatCode(() -> { final ArrayNode arrayNode = null; request.facetsParse(arrayNode); }).doesNotThrowAnyException(); assertThatThrownBy(() -> { ObjectNode fakeFacet = JsonHandler.createObjectNode(); facetsArray.removeAll(); facetsArray.add(fakeFacet); request.facetsParse(facetsArray); }).isInstanceOf(InvalidParseOperationException.class); assertThatThrownBy(() -> { ObjectNode fakeFacet = JsonHandler.createObjectNode(); fakeFacet.put("name", "mafacet"); facetsArray.removeAll(); facetsArray.add(fakeFacet); request.facetsParse(facetsArray); }).isInstanceOf(InvalidParseOperationException.class); assertThatThrownBy(() -> { ObjectNode fakeFacet = JsonHandler.createObjectNode(); fakeFacet.put("$name", "mafacet"); fakeFacet.put("$wrong", "wrong"); facetsArray.removeAll(); facetsArray.add(fakeFacet); request.facetsParse(facetsArray); }).isInstanceOf(InvalidParseOperationException.class); assertThatThrownBy(() -> { ObjectNode fakeFacet = JsonHandler.createObjectNode(); fakeFacet.put("$name", "mafacet"); fakeFacet.put("$terms", "not valid"); facetsArray.removeAll(); facetsArray.add(fakeFacet); request.facetsParse(facetsArray); }).isInstanceOf(InvalidParseOperationException.class); assertThatThrownBy(() -> { ObjectNode fakeFacet = JsonHandler.createObjectNode(); fakeFacet.put("$name", "mafacet"); ObjectNode fakeQueryFilter = JsonHandler.createObjectNode(); fakeQueryFilter.set("$query_filters", JsonHandler.createObjectNode()); fakeFacet.set("$filters", fakeQueryFilter); facetsArray.removeAll(); facetsArray.add(fakeFacet); request.facetsParse(facetsArray); }).isInstanceOf(InvalidParseOperationException.class); } catch (final InvalidParseOperationException | InvalidCreateOperationException e) { e.printStackTrace(); fail(e.getMessage()); } }
protected void facetsParse(final JsonNode rootNode) throws InvalidParseOperationException { if (rootNode == null) { return; } if (!rootNode.isArray()) { throw new InvalidParseOperationException("Parse in error for Field: should be an array"); } GlobalDatas.sanityParametersCheck(rootNode.toString(), GlobalDatas.NB_FACETS); try { ((SelectMultiQuery) request).resetFacets(); for (final JsonNode facet : rootNode) { if (!facet.has(FACETARGS.NAME.exactToken())) { throw new InvalidParseOperationException("Invalid parse: name is mandatory"); } FACET facetCommand = getFacetCommand(facet); ((SelectMultiQuery) request).addFacets(analyzeOneFacet(facet, facetCommand)); } } catch (final Exception e) { throw new InvalidParseOperationException( "Parse in error for Field: " + rootNode, e); } }
SelectParserMultiple extends RequestParserMultiple { protected void facetsParse(final JsonNode rootNode) throws InvalidParseOperationException { if (rootNode == null) { return; } if (!rootNode.isArray()) { throw new InvalidParseOperationException("Parse in error for Field: should be an array"); } GlobalDatas.sanityParametersCheck(rootNode.toString(), GlobalDatas.NB_FACETS); try { ((SelectMultiQuery) request).resetFacets(); for (final JsonNode facet : rootNode) { if (!facet.has(FACETARGS.NAME.exactToken())) { throw new InvalidParseOperationException("Invalid parse: name is mandatory"); } FACET facetCommand = getFacetCommand(facet); ((SelectMultiQuery) request).addFacets(analyzeOneFacet(facet, facetCommand)); } } catch (final Exception e) { throw new InvalidParseOperationException( "Parse in error for Field: " + rootNode, e); } } }
SelectParserMultiple extends RequestParserMultiple { protected void facetsParse(final JsonNode rootNode) throws InvalidParseOperationException { if (rootNode == null) { return; } if (!rootNode.isArray()) { throw new InvalidParseOperationException("Parse in error for Field: should be an array"); } GlobalDatas.sanityParametersCheck(rootNode.toString(), GlobalDatas.NB_FACETS); try { ((SelectMultiQuery) request).resetFacets(); for (final JsonNode facet : rootNode) { if (!facet.has(FACETARGS.NAME.exactToken())) { throw new InvalidParseOperationException("Invalid parse: name is mandatory"); } FACET facetCommand = getFacetCommand(facet); ((SelectMultiQuery) request).addFacets(analyzeOneFacet(facet, facetCommand)); } } catch (final Exception e) { throw new InvalidParseOperationException( "Parse in error for Field: " + rootNode, e); } } SelectParserMultiple();  SelectParserMultiple(VarNameAdapter adapter); }
SelectParserMultiple extends RequestParserMultiple { protected void facetsParse(final JsonNode rootNode) throws InvalidParseOperationException { if (rootNode == null) { return; } if (!rootNode.isArray()) { throw new InvalidParseOperationException("Parse in error for Field: should be an array"); } GlobalDatas.sanityParametersCheck(rootNode.toString(), GlobalDatas.NB_FACETS); try { ((SelectMultiQuery) request).resetFacets(); for (final JsonNode facet : rootNode) { if (!facet.has(FACETARGS.NAME.exactToken())) { throw new InvalidParseOperationException("Invalid parse: name is mandatory"); } FACET facetCommand = getFacetCommand(facet); ((SelectMultiQuery) request).addFacets(analyzeOneFacet(facet, facetCommand)); } } catch (final Exception e) { throw new InvalidParseOperationException( "Parse in error for Field: " + rootNode, e); } } SelectParserMultiple();  SelectParserMultiple(VarNameAdapter adapter); @Override void parse(final JsonNode request); @Override void parseQueryOnly(final String query); static final FACET getFacetCommand(final JsonNode facet); @Override SelectMultiQuery getRequest(); }
SelectParserMultiple extends RequestParserMultiple { protected void facetsParse(final JsonNode rootNode) throws InvalidParseOperationException { if (rootNode == null) { return; } if (!rootNode.isArray()) { throw new InvalidParseOperationException("Parse in error for Field: should be an array"); } GlobalDatas.sanityParametersCheck(rootNode.toString(), GlobalDatas.NB_FACETS); try { ((SelectMultiQuery) request).resetFacets(); for (final JsonNode facet : rootNode) { if (!facet.has(FACETARGS.NAME.exactToken())) { throw new InvalidParseOperationException("Invalid parse: name is mandatory"); } FACET facetCommand = getFacetCommand(facet); ((SelectMultiQuery) request).addFacets(analyzeOneFacet(facet, facetCommand)); } } catch (final Exception e) { throw new InvalidParseOperationException( "Parse in error for Field: " + rootNode, e); } } SelectParserMultiple();  SelectParserMultiple(VarNameAdapter adapter); @Override void parse(final JsonNode request); @Override void parseQueryOnly(final String query); static final FACET getFacetCommand(final JsonNode facet); @Override SelectMultiQuery getRequest();  }