Search in sources :

Example 1 with Condition

use of com.github.rutledgepaulv.qbuilders.conditions.Condition in project downlords-faf-client by FAForever.

the class SearchController method buildQuery.

/**
 * Builds the query string if possible, returns empty string if not. A query string can not be built if the user
 * selected no or invalid values.
 */
private String buildQuery(SpecificationController initialSpecification, List<LogicalNodeController> queryNodes) {
    QBuilder qBuilder = new QBuilder();
    Optional<Condition> condition = initialSpecification.appendTo(qBuilder);
    if (!condition.isPresent()) {
        return "";
    }
    for (LogicalNodeController queryNode : queryNodes) {
        Optional<Condition> currentCondition = queryNode.appendTo(condition.get());
        if (!currentCondition.isPresent()) {
            break;
        }
        condition = currentCondition;
    }
    return (String) condition.get().query(new RSQLVisitor());
}
Also used : Condition(com.github.rutledgepaulv.qbuilders.conditions.Condition) QBuilder(com.github.rutledgepaulv.qbuilders.builders.QBuilder) LogicalNodeController(com.faforever.client.query.LogicalNodeController) RSQLVisitor(com.github.rutledgepaulv.qbuilders.visitors.RSQLVisitor)

Example 2 with Condition

use of com.github.rutledgepaulv.qbuilders.conditions.Condition in project downlords-faf-client by FAForever.

the class SearchControllerTest method testBuildQuery.

@Test
public void testBuildQuery() throws Exception {
    instance.onAddCriteriaButtonClicked();
    Condition condition = mock(Condition.class);
    when(specificationController.appendTo(any())).thenReturn(Optional.of(condition));
    when(condition.query(any(RSQLVisitor.class))).thenReturn("name==JUnit");
    specificationController.propertyField.setValue("name");
    specificationController.operationField.getSelectionModel().select(0);
    specificationController.valueField.setValue("JUnit");
    assertThat(instance.queryTextField.getText(), is("name==JUnit"));
}
Also used : Condition(com.github.rutledgepaulv.qbuilders.conditions.Condition) RSQLVisitor(com.github.rutledgepaulv.qbuilders.visitors.RSQLVisitor) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 3 with Condition

use of com.github.rutledgepaulv.qbuilders.conditions.Condition in project downlords-faf-client by FAForever.

the class LogicalNodeControllerTest method testWithParams.

private void testWithParams(LogicalNodeController.LogicalOperator operator, String property, Object value, String expected) {
    instance.logicalOperatorField.setValue(operator);
    Condition condition = qBuilder.string(property).exists();
    when(specificationController.appendTo(any())).thenReturn(Optional.ofNullable(condition));
    Optional<Condition> optional = instance.appendTo(condition);
    assertThat(optional.isPresent(), is(true));
    assertThat(optional.get(), is(condition));
}
Also used : Condition(com.github.rutledgepaulv.qbuilders.conditions.Condition)

Aggregations

Condition (com.github.rutledgepaulv.qbuilders.conditions.Condition)3 RSQLVisitor (com.github.rutledgepaulv.qbuilders.visitors.RSQLVisitor)2 LogicalNodeController (com.faforever.client.query.LogicalNodeController)1 AbstractPlainJavaFxTest (com.faforever.client.test.AbstractPlainJavaFxTest)1 QBuilder (com.github.rutledgepaulv.qbuilders.builders.QBuilder)1 Test (org.junit.Test)1