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);
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations