Search in sources :

Example 1 with HintRequest

use of com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest in project cuba by cuba-platform.

the class JpqlSuggestionFactory method requestHint.

public static List<Suggestion> requestHint(String query, int queryPosition, AutoCompleteSupport sender, int senderCursorPosition, @Nullable HintProvider provider) {
    DomainModelBuilder builder = AppBeans.get(DomainModelWithCaptionsBuilder.NAME);
    DomainModel domainModel = builder.produce();
    if (provider == null) {
        provider = new HintProvider(domainModel);
    }
    try {
        HintRequest request = new HintRequest();
        request.setQuery(query);
        request.setPosition(queryPosition);
        HintResponse response = provider.requestHint(request);
        String prefix = response.getLastWord();
        List<Option> options = response.getOptionObjects();
        List<Suggestion> result = new ArrayList<>();
        for (Option option : options) {
            Suggestion suggestion = JpqlSuggestionFactory.produce(sender, option.getValue(), option.getDescription(), senderCursorPosition, prefix == null ? 0 : prefix.length());
            result.add(suggestion);
        }
        return result;
    } catch (org.antlr.runtime.RecognitionException e) {
        throw new RuntimeException(e);
    }
}
Also used : HintRequest(com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest) DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) ArrayList(java.util.ArrayList) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) DomainModelBuilder(com.haulmont.cuba.core.sys.jpql.DomainModelBuilder) Option(com.haulmont.cuba.gui.components.autocomplete.impl.Option)

Example 2 with HintRequest

use of com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest in project cuba by cuba-platform.

the class MacroProcessorTest method inlineFake_dateBefore.

@Test
public void inlineFake_dateBefore() {
    HintRequest request = processor.inlineFake("select p. from Player p where @dateBefore(p.joinDate, :d)", 8);
    assertEquals("select p. from Player p where p.joinDate = :d ", request.getQuery());
    assertEquals(8, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Any), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @dateBefore(p., :d)", 47);
    assertEquals("select p.name from Player p where p. = :d ", request.getQuery());
    assertEquals(35, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Date), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @dateBefore(p.joinDate, p.)", 59);
    assertEquals("select p.name from Player p where p.joinDate = p. ", request.getQuery());
    assertEquals(48, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Date), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @dateBefore(p.joinDate, :d) and p.", 67);
    assertEquals("select p.name from Player p where p.joinDate = :d  and p.", request.getQuery());
    assertEquals(56, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Any), request.getExpectedTypes());
}
Also used : HintRequest(com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest) Test(org.junit.Test)

Example 3 with HintRequest

use of com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest in project cuba by cuba-platform.

the class MacroProcessorTest method inlineFake_dateEquals.

@Test
public void inlineFake_dateEquals() {
    HintRequest request = processor.inlineFake("select p. from Player p where @dateEquals(p.joinDate, :d)", 8);
    assertEquals("select p. from Player p where p.joinDate = :d ", request.getQuery());
    assertEquals(8, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Any), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @dateEquals(p., :d)", 47);
    assertEquals("select p.name from Player p where p. = :d ", request.getQuery());
    assertEquals(35, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Date), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @dateEquals(p.joinDate, p.)", 59);
    assertEquals("select p.name from Player p where p.joinDate = p. ", request.getQuery());
    assertEquals(48, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Date), request.getExpectedTypes());
}
Also used : HintRequest(com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest) Test(org.junit.Test)

Example 4 with HintRequest

use of com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest in project cuba by cuba-platform.

the class MacroProcessorTest method inlineFake_dateAfter.

@Test
public void inlineFake_dateAfter() {
    HintRequest request = processor.inlineFake("select p. from Player p where @dateAfter(p.joinDate, :d)", 8);
    assertEquals("select p. from Player p where p.joinDate = :d ", request.getQuery());
    assertEquals(8, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Any), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @dateAfter(p., :d)", 46);
    assertEquals("select p.name from Player p where p. = :d ", request.getQuery());
    assertEquals(35, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Date), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @dateAfter(p.joinDate, p.)", 58);
    assertEquals("select p.name from Player p where p.joinDate = p. ", request.getQuery());
    assertEquals(48, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Date), request.getExpectedTypes());
}
Also used : HintRequest(com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest) Test(org.junit.Test)

Example 5 with HintRequest

use of com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest in project cuba by cuba-platform.

the class MacroProcessorTest method inlineFake_between.

@Test
public void inlineFake_between() {
    HintRequest request = processor.inlineFake("select p. from Player p where @between(p.joinDate, now, now+1, day)", 8);
    assertEquals("select p. from Player p where p.joinDate = :d ", request.getQuery());
    assertEquals(8, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Any), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @between(p., now, now+1, day)", 44);
    assertEquals("select p.name from Player p where p. = :d ", request.getQuery());
    assertEquals(35, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Date), request.getExpectedTypes());
    try {
        processor.inlineFake("select p.name from Player p where @between(p.joinDate, p., now + 1, day)", 44);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    }
    request = processor.inlineFake("select p.name from Player p where @between(p.joinDate, now, now+1, day) and p.", 77);
    assertEquals("select p.name from Player p where p.joinDate = :d  and p.", request.getQuery());
    assertEquals(56, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Any), request.getExpectedTypes());
}
Also used : HintRequest(com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest) Test(org.junit.Test)

Aggregations

HintRequest (com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest)8 Test (org.junit.Test)7 DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)1 DomainModelBuilder (com.haulmont.cuba.core.sys.jpql.DomainModelBuilder)1 AliasRemover (com.haulmont.cuba.gui.components.autocomplete.impl.AliasRemover)1 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)1 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)1 Option (com.haulmont.cuba.gui.components.autocomplete.impl.Option)1 ArrayList (java.util.ArrayList)1