Search in sources :

Example 21 with WebQuery

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

the class LargeTableQueryTest method testSearchWorks.

/**
 * Test that searching works with a simple primary key
 */
@Test
@Transactional
public void testSearchWorks() {
    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(2, dao.countWithAInName());
    // Now try a web query
    assertEquals(2, dao.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 22 with WebQuery

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

the class RoleUIServiceImpl method get.

@Override
@Transactional(readOnly = true)
public String get(final String id) {
    TemplateCall call = templater.template("role");
    final RoleEntity entity = dao.getById(id);
    if (entity == null)
        throw new IllegalArgumentException("No such Role: " + id);
    call.set("entity", entity);
    call.set("allUsers", userDao.getAll());
    call.set("users", userDao.findByUriQuery(new WebQuery().eq("roles.id", id)).getList());
    call.set("nonce", nonceStore.getValue(NONCE_USE));
    return call.process();
}
Also used : RoleEntity(com.peterphi.usermanager.db.entity.RoleEntity) WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 23 with WebQuery

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

the class ServiceUIServiceImpl method getList.

@Override
@Transactional(readOnly = true)
public String getList(final UriInfo query) {
    final ConstrainedResultSet<OAuthServiceEntity> resultset = dao.findByUriQuery(new WebQuery().decode(query.getQueryParameters()));
    final TemplateCall call = templater.template("services");
    call.set("nonce", nonceStore.getValue(NONCE_USE));
    call.set("resultset", resultset);
    call.set("entities", resultset.getList());
    return call.process();
}
Also used : OAuthServiceEntity(com.peterphi.usermanager.db.entity.OAuthServiceEntity) WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 24 with WebQuery

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

the class UserUIServiceImpl method getUsers.

@Override
@Transactional(readOnly = true)
@AuthConstraint(role = UserLogin.ROLE_ADMIN)
public String getUsers(UriInfo query) {
    ConstrainedResultSet<UserEntity> resultset = accountDao.findByUriQuery(new WebQuery().orderAsc("id").decode(query));
    TemplateCall call = templater.template("users");
    call.set("resultset", resultset);
    call.set("users", resultset.getList());
    call.set("nonce", nonceStore.getValue(NONCE_USE));
    return call.process();
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) UserEntity(com.peterphi.usermanager.db.entity.UserEntity) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall) AuthConstraint(com.peterphi.std.guice.common.auth.annotations.AuthConstraint) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

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