Search in sources :

Example 6 with WebQuery

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

the class LargeTableQueryTest method testSearchComplexPK.

/**
 * Test that searching works even with a complex primary key
 */
@Test
@Transactional
public void testSearchComplexPK() {
    complexPKdao.save(new LargeTableComplexPKEntity("Alice"));
    complexPKdao.save(new LargeTableComplexPKEntity("Bob"));
    complexPKdao.save(new LargeTableComplexPKEntity("Carol"));
    complexPKdao.save(new LargeTableComplexPKEntity("Dave"));
    complexPKdao.save(new LargeTableComplexPKEntity("Eve"));
    assertEquals(2, complexPKdao.findByUriQuery(new WebQuery().contains("name", "a")).getList().size());
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Test(org.junit.Test) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 7 with WebQuery

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

the class LargeTableQueryTest method testSearchComplexPKIDs.

/**
 * Test that searching for IDs works even with a complex primary key
 */
@Test
@Transactional
public void testSearchComplexPKIDs() {
    complexPKdao.save(new LargeTableComplexPKEntity("Alice"));
    complexPKdao.save(new LargeTableComplexPKEntity("Bob"));
    complexPKdao.save(new LargeTableComplexPKEntity("Carol"));
    complexPKdao.save(new LargeTableComplexPKEntity("Dave"));
    complexPKdao.save(new LargeTableComplexPKEntity("Eve"));
    final List<SomePrimaryKey> results = complexPKdao.findIdsByUriQuery(new WebQuery().contains("name", "a")).getList();
    assertEquals("expect 2 results", 2, results.size());
    assertEquals("expect results to be of id type", SomePrimaryKey.class, results.get(0).getClass());
    assertEquals("expect results to be of id type", SomePrimaryKey.class, results.get(1).getClass());
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Test(org.junit.Test) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 8 with WebQuery

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

the class LargeTableQueryTest method testSearchForPrimaryKeyWorks.

/**
 * Test that searching works with a simple primary key
 */
@Test
@Transactional
public void testSearchForPrimaryKeyWorks() {
    dao.save(new LargeTableSimplePKEntity("Alice"));
    dao.save(new LargeTableSimplePKEntity("Bob"));
    dao.save(new LargeTableSimplePKEntity("Carol"));
    dao.save(new LargeTableSimplePKEntity("Dave"));
    dao.save(new LargeTableSimplePKEntity("Eve"));
    // Try a regular query
    assertEquals("custom-coded count should return 2", 2, dao.countWithAInName());
    // Now try a web query
    final ConstrainedResultSet<Long> result = dao.findIdsByUriQuery(new WebQuery().computeSize(true).contains("name", "a"));
    assertEquals("total results for generic query should be 2", Long.valueOf(2), result.getTotal());
    assertEquals("generic get IDs should return 2 results", new ArrayList<>(Arrays.asList(3L, 4L)), new ArrayList<>(result.getList()));
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Test(org.junit.Test) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 9 with WebQuery

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

the class WebQueryTest method testParseQueryStringToWebQuery.

@Test
public void testParseQueryStringToWebQuery() {
    WebQuery expected = new WebQuery().logSQL(true).eq("id", "123").offset(0).limit(200);
    WebQuery actual = new WebQuery().decode(new ResteasyUriInfo(URI.create("http://example.com?_log_sql=true&id=123")));
    assertEquals(expected.encode().toString(), actual.encode().toString());
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) Test(org.junit.Test)

Example 10 with WebQuery

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

the class ResourceInstanceHelper method activeInstances.

/**
 * Returns the number of active instances of the given template name
 *
 * @param service
 * @param templateName
 *
 * @return
 */
public List<ResourceInstanceDTO> activeInstances(ServiceManagerResourceRestService service, String templateName) {
    WebQuery wq = new WebQuery();
    wq.eq("template.id", templateName);
    wq.eq("state", ResourceInstanceState.TO_PROVISION, ResourceInstanceState.PROVISIONING, ResourceInstanceState.NOT_IN_SERVICE, ResourceInstanceState.IN_SERVICE);
    List<ResourceInstanceDTO> instances = service.searchInstances(wq);
    return instances;
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) ResourceInstanceDTO(com.peterphi.servicemanager.service.rest.resource.type.ResourceInstanceDTO)

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