use of com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse 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.HintResponse in project cuba by cuba-platform.
the class HintProviderTest method requestHint_fieldNameHint_join.
// The following functions are not supported by JPA2 JPQL (see jpql21.bnf)
// @Test
// public void requestHint_fieldNameHint_wherein_subquerywhere() throws RecognitionException {
// EntityBuilder builder = new EntityBuilder();
// JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name", "owner");
// JpqlEntityModel playerEntity = builder.produceImmediately("Player", "nickname", "name");
// DomainModel model = new DomainModel();
// model.add(playerEntity);
// model.add(teamEntity);
//
// HintProvider hintProvider = createTestHintProvider(model);
// HintResponse response = hintProvider.requestHint("select p.name from Player p where p.team in (select a from Team a where a.~)");
// List<String> options = response.getOptions();
// assertEquals(2, options.size());
// assertEquals("name", options.get(0));
// assertEquals("owner", options.get(1));
//
// hintProvider = createTestHintProvider(model);
// response = hintProvider.requestHint("select p.name from Player p where p.team in (select a from Team a where a.name = p.n~)");
// options = response.getOptions();
// assertEquals(2, options.size());
// assertEquals("name", options.get(0));
// assertEquals("nickname", options.get(1));
// }
@Test
public void requestHint_fieldNameHint_join() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel personEntity = builder.produceImmediately("Person", "name");
builder.startNewEntity("Team");
builder.addStringAttribute("name");
builder.addStringAttribute("owner");
builder.addReferenceAttribute("manager", "Person");
JpqlEntityModel teamEntity = builder.produce();
builder.startNewEntity("Player");
builder.addStringAttribute("name");
builder.addStringAttribute("nickname");
builder.addReferenceAttribute("team", "Team");
builder.addReferenceAttribute("agent", "Person");
JpqlEntityModel playerEntity = builder.produce();
DomainModel model = new DomainModel();
model.add(teamEntity);
model.add(playerEntity);
model.add(personEntity);
HintProvider hintProvider = createTestHintProvider(model);
HintResponse response = hintProvider.requestHint("select p.name, t.o~ from Player p join p.team as t");
List<String> options = response.getOptions();
assertEquals(1, options.size());
assertEquals("owner", options.get(0));
hintProvider = createTestHintProvider(model);
response = hintProvider.requestHint("select p from Player p join p.team as t where t.~");
options = response.getOptions();
assertEquals(3, options.size());
assertEquals("manager", options.get(0));
assertEquals("name", options.get(1));
assertEquals("owner", options.get(2));
hintProvider = createTestHintProvider(model);
response = hintProvider.requestHint("select p from Player p join p.~ ");
options = response.getOptions();
assertEquals(2, options.size());
assertEquals("agent", options.get(0));
assertEquals("team", options.get(1));
hintProvider = createTestHintProvider(model);
response = hintProvider.requestHint("select p from Player p join p.team as t where t.~");
options = response.getOptions();
assertEquals(3, options.size());
assertEquals("manager", options.get(0));
assertEquals("name", options.get(1));
assertEquals("owner", options.get(2));
hintProvider = createTestHintProvider(model);
response = hintProvider.requestHint("select m.~ from Player p " + "join p.team as t " + "join t.manager as m");
options = response.getOptions();
assertEquals(1, options.size());
assertEquals("name", options.get(0));
hintProvider = createTestHintProvider(model);
response = hintProvider.requestHint("select t from Player p " + "join p.team as t " + "join t.~");
options = response.getOptions();
assertEquals(1, options.size());
assertEquals("manager", options.get(0));
hintProvider = createTestHintProvider(model);
response = hintProvider.requestHint("select t from Player p join Team t on t.~ = p.agent.id");
options = response.getOptions();
assertEquals(3, options.size());
assertEquals("manager", options.get(0));
}
use of com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse in project cuba by cuba-platform.
the class HintProviderTest method requestHint_fieldNameHint_simple_referencedEntity.
@Test
public void requestHint_fieldNameHint_simple_referencedEntity() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name");
builder.startNewEntity("Player");
builder.addStringAttribute("name");
builder.addStringAttribute("nickname");
builder.addReferenceAttribute("team", "Team");
JpqlEntityModel playerEntity = builder.produce();
DomainModel model = new DomainModel();
model.add(teamEntity);
model.add(playerEntity);
HintProvider hintProvider = createTestHintProvider(model);
HintResponse response = hintProvider.requestHint("SELECT p.te~ FROM Player p");
List<String> options = response.getOptions();
assertEquals(1, options.size());
assertEquals("team", options.get(0));
response = hintProvider.requestHint("SELECT p.team.~ FROM Player p");
options = response.getOptions();
assertEquals(1, options.size());
assertEquals("name", options.get(0));
response = hintProvider.requestHint("SELECT p.team.ni~ FROM Player p");
options = response.getOptions();
assertEquals(0, options.size());
}
use of com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse in project cuba by cuba-platform.
the class HintProviderTest method requestHint_entityNameHint_order.
@Test
public void requestHint_entityNameHint_order() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModelImpl playerEntity = builder.produceImmediately("Player");
JpqlEntityModelImpl parentEntity = builder.produceImmediately("Parent");
DomainModel model = new DomainModel();
model.add(playerEntity);
model.add(parentEntity);
HintProvider hintProvider = createTestHintProvider(model);
HintResponse response = hintProvider.requestHint("SELECT p FROM P~");
List<String> options = response.getOptions();
assertEquals(2, options.size());
assertEquals("Parent", options.get(0));
assertEquals("Player", options.get(1));
}
use of com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse in project cuba by cuba-platform.
the class HintProviderTest method requestHint_fieldNameHint_simple_wherePart.
@Test
public void requestHint_fieldNameHint_simple_wherePart() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name", "owner");
DomainModel model = new DomainModel();
model.add(teamEntity);
HintProvider hintProvider = createTestHintProvider(model);
HintResponse response = hintProvider.requestHint("select t from Team t where t.~");
List<String> options = response.getOptions();
assertEquals(2, options.size());
assertEquals("name", options.get(0));
assertEquals("owner", options.get(1));
hintProvider = createTestHintProvider(model);
response = hintProvider.requestHint("select t.~ from Team t where t.name = 'KS'");
options = response.getOptions();
assertEquals(2, options.size());
assertEquals("name", options.get(0));
assertEquals("owner", options.get(1));
hintProvider = createTestHintProvider(model);
response = hintProvider.requestHint("select t.name from Team t where t.~");
options = response.getOptions();
assertEquals(2, options.size());
assertEquals("name", options.get(0));
assertEquals("owner", options.get(1));
hintProvider = createTestHintProvider(model);
response = hintProvider.requestHint("select t.~ from Team t where t.name in ('KS', 'Zenit')");
options = response.getOptions();
assertEquals(2, options.size());
assertEquals("name", options.get(0));
assertEquals("owner", options.get(1));
}
Aggregations