Search in sources :

Example 1 with WebQuery

use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.

the class DynamicQueryTest method testEqRefReturnsValue.

@Test
public void testEqRefReturnsValue() throws Exception {
    ParentEntity obj = new ParentEntity();
    obj.setName("Name");
    obj.setOtherObject(new ChildEntity());
    obj.getOtherObject().setName("Name");
    childDao.save(obj.getOtherObject());
    dao.save(obj);
    assertEquals(1, dao.findByUriQuery(new WebQuery().eqRef("name", "otherObject.name")).getList().size());
    assertEquals(0, dao.findByUriQuery(new WebQuery().neqRef("name", "otherObject.name")).getList().size());
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Test(org.junit.Test)

Example 2 with WebQuery

use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.

the class DynamicQueryTest method testOrderAsc.

@Test
public void testOrderAsc() throws Exception {
    ParentEntity obj1 = new ParentEntity();
    obj1.setName("Name1");
    dao.save(obj1);
    ParentEntity obj2 = new ParentEntity();
    obj2.setName("Name2");
    dao.save(obj2);
    assertEquals(getIds(Arrays.asList(obj1, obj2)), getIds(dao.findByUriQuery(new WebQuery().orderAsc("id")).getList()));
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Test(org.junit.Test)

Example 3 with WebQuery

use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.

the class DynamicQueryTest method testByBooleanField.

@Test
public void testByBooleanField() throws Exception {
    {
        ParentEntity obj1 = new ParentEntity();
        obj1.setName("Name1");
        obj1.setDeprecated(true);
        dao.save(obj1);
        ParentEntity obj2 = new ParentEntity();
        obj2.setName("Name2");
        obj2.setDeprecated(true);
        dao.save(obj2);
    }
    assertEquals("deprecated=true matches 2 rows", 2, dao.findByUriQuery(new WebQuery().eq("deprecated", true)).getList().size());
    assertEquals("deprecated=false matches nothing", 0, dao.findByUriQuery(new WebQuery().eq("deprecated", false)).getList().size());
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Test(org.junit.Test)

Example 4 with WebQuery

use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.

the class DynamicQueryTest method testGetUsingPropertiesOfEmbeddedCollection.

@Test
public void testGetUsingPropertiesOfEmbeddedCollection() throws Exception {
    // Hibernate will throw if the property doesn't work
    WebQuery q = new WebQuery();
    q.eq("friends[r0].firstName", "Firstname");
    q.eq("friends[r0].lastName", "Surname");
    dao.findByUriQuery(q);
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Test(org.junit.Test)

Example 5 with WebQuery

use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.

the class ResultSetConstraintBuilder method buildQuery.

/**
 * Construct a WebQueryDefinition from this, applying the web query semantics
 *
 * @return
 */
public WebQuery buildQuery() {
    Map<String, List<String>> map = new HashMap<>(constraints);
    applyDefault(WQUriControlField.FETCH, map, defaultFetch);
    applyDefault(WQUriControlField.EXPAND, map, defaultExpand);
    applyDefault(WQUriControlField.ORDER, map, defaultOrder);
    applyDefault(WQUriControlField.OFFSET, map, "0");
    applyDefault(WQUriControlField.LIMIT, map, Integer.toString(defaultLimit));
    return new WebQuery().decode(map);
}
Also used : HashMap(java.util.HashMap) WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

WebQuery (com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery)24 Test (org.junit.Test)15 Transactional (com.peterphi.std.guice.database.annotation.Transactional)12 TemplateCall (com.peterphi.std.guice.web.rest.templating.TemplateCall)4 OAuthSessionEntity (com.peterphi.usermanager.db.entity.OAuthSessionEntity)2 RoleEntity (com.peterphi.usermanager.db.entity.RoleEntity)2 UserEntity (com.peterphi.usermanager.db.entity.UserEntity)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ResteasyUriInfo (org.jboss.resteasy.spi.ResteasyUriInfo)2 DateTime (org.joda.time.DateTime)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Inject (com.google.inject.Inject)1 ResourceInstanceDTO (com.peterphi.servicemanager.service.rest.resource.type.ResourceInstanceDTO)1 AuthConstraint (com.peterphi.std.guice.common.auth.annotations.AuthConstraint)1 HibernateDao (com.peterphi.std.guice.hibernate.dao.HibernateDao)1 QEntityFactory (com.peterphi.std.guice.hibernate.webquery.impl.QEntityFactory)1 JPASearchExecutor (com.peterphi.std.guice.hibernate.webquery.impl.jpa.JPASearchExecutor)1 JPASearchStrategy (com.peterphi.std.guice.hibernate.webquery.impl.jpa.JPASearchStrategy)1 GuiceUnit (com.peterphi.std.guice.testing.GuiceUnit)1