Search in sources :

Example 11 with HintProvider

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

the class HintProviderTest method requestHint_entityNameHint_simple.

@Test
public void requestHint_entityNameHint_simple() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModelImpl playerEntity = builder.produceImmediately("Player");
    DomainModel model = new DomainModel();
    model.add(playerEntity);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("SELECT p FROM P~");
    List<String> options = response.getOptions();
    assertEquals(1, options.size());
    assertEquals("Player", options.get(0));
    response = hintProvider.requestHint("FROM N~");
    options = response.getOptions();
    assertEquals(0, options.size());
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) JpqlEntityModelImpl(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Example 12 with HintProvider

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

the class HintProviderTest method requestHint_with_templateParam.

@Test
public void requestHint_with_templateParam() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModel driver = builder.produceImmediately("Driver", "name", "signal");
    builder.startNewEntity("Car");
    builder.addStringAttribute("model");
    builder.addCollectionReferenceAttribute("drivers", "Driver");
    JpqlEntityModel car = builder.produce();
    DomainModel model = new DomainModel(car, driver);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("select a.~ from Car a where a.model = ${param}");
    List<String> options = response.getOptions();
    assertEquals(2, options.size());
    assertEquals("drivers", options.get(0));
    assertEquals("model", options.get(1));
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Example 13 with HintProvider

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

the class HintProviderTest method requestHint_fieldNameHint_join_withCollections.

@Test
public void requestHint_fieldNameHint_join_withCollections() 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();
    builder.startNewEntity("League");
    builder.addStringAttribute("name");
    builder.addCollectionReferenceAttribute("teams", "Team");
    JpqlEntityModel leagueEntity = builder.produce();
    DomainModel model = new DomainModel();
    model.add(teamEntity);
    model.add(playerEntity);
    model.add(leagueEntity);
    model.add(personEntity);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("select m.~ from League l " + "left join l.teams as t " + "left join t.manager as m");
    List<String> options = response.getOptions();
    assertEquals(1, options.size());
    assertEquals("name", options.get(0));
    hintProvider = createTestHintProvider(model);
    response = hintProvider.requestHint("select l from League l " + "join l.teams as t " + "join t.~");
    options = response.getOptions();
    assertEquals(1, options.size());
    assertEquals("manager", options.get(0));
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Example 14 with HintProvider

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

the class HintProviderTest method requestHint_with_variableRebinding.

@Test
public void requestHint_with_variableRebinding() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModel driver = builder.produceImmediately("Driver", "name", "signal");
    builder.startNewEntity("Car");
    builder.addStringAttribute("model");
    builder.addCollectionReferenceAttribute("drivers", "Driver");
    JpqlEntityModel car = builder.produce();
    DomainModel model = new DomainModel(car, driver);
    HintProvider hintProvider = createTestHintProvider(model);
    try {
        hintProvider.requestHint("select a.~ from Car a, in(a.drivers) a where a.model = ?1");
        Assert.fail();
    } catch (IllegalArgumentException ignored) {
    }
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) Test(org.junit.Test)

Example 15 with HintProvider

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

the class HintProviderTest method requestHint_fieldNameHint_simple_referencedEntity_collections.

@Test
public void requestHint_fieldNameHint_simple_referencedEntity_collections() 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();
    builder.startNewEntity("League");
    builder.addStringAttribute("name");
    builder.addCollectionReferenceAttribute("teams", "Team");
    JpqlEntityModel leagueEntity = builder.produce();
    DomainModel model = new DomainModel();
    model.add(teamEntity);
    model.add(playerEntity);
    model.add(leagueEntity);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("SELECT l.teams.~ FROM League l");
    List<String> options = response.getOptions();
    assertEquals(0, options.size());
    assertEquals("Query error", response.getErrorMessage());
    assertEquals(1, response.getCauseErrorMessages().size());
    assertEquals("Cannot get attribute of collection [l.teams.]", response.getCauseErrorMessages().get(0));
    response = hintProvider.requestHint("SELECT l.name FROM League l where l.teams.~");
    options = response.getOptions();
    assertEquals(0, options.size());
    assertEquals("Query error", response.getErrorMessage());
    assertEquals(1, response.getCauseErrorMessages().size());
    assertEquals("Cannot get attribute of collection [l.teams.]", response.getCauseErrorMessages().get(0));
    response = hintProvider.requestHint("SELECT l.name FROM League l where exists (select 1 from Team t where t.name = l.teams.n~");
    options = response.getOptions();
    assertEquals(0, options.size());
    assertEquals("Query error", response.getErrorMessage());
    assertEquals(1, response.getCauseErrorMessages().size());
    assertEquals("Cannot get attribute of collection [l.teams.n]", response.getCauseErrorMessages().get(0));
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Aggregations

DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)21 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)21 EntityBuilder (com.haulmont.cuba.core.sys.jpql.model.EntityBuilder)20 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)20 Test (org.junit.Test)20 JpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)17 JpqlEntityModelImpl (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl)3 DomainModelBuilder (com.haulmont.cuba.core.sys.jpql.DomainModelBuilder)1 HintRequest (com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest)1 Option (com.haulmont.cuba.gui.components.autocomplete.impl.Option)1 ArrayList (java.util.ArrayList)1