Search in sources :

Example 36 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class OAuthSessionContextDaoImpl method create.

/**
 * Create a context (or reuse an existing active context)
 *
 * @param user
 * 		the user
 * @param service
 * 		the service
 * @param scope
 * 		the access scope the service is granted
 *
 * @return
 */
@Transactional
public OAuthSessionContextEntity create(final UserEntity user, final OAuthServiceEntity service, final String scope) {
    // Create a new context
    OAuthSessionContextEntity entity = get(user.getId(), service.getId(), scope);
    // No active context exists, we must create one
    if (entity == null) {
        entity = new OAuthSessionContextEntity();
        entity.setUser(user);
        entity.setScope(StringUtils.trimToEmpty(scope));
        entity.setService(service);
        entity.setActive(true);
        entity.setId(save(entity));
    }
    return entity;
}
Also used : OAuthSessionContextEntity(com.peterphi.usermanager.db.entity.OAuthSessionContextEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 37 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class ResourceInstanceDaoImpl method getByProviderAndState.

@Transactional(readOnly = true)
public List<Integer> getByProviderAndState(final String provider, ResourceInstanceState... states) {
    final Criteria criteria = createCriteria();
    criteria.add(Restrictions.eq("provider", provider));
    criteria.add(Restrictions.in("state", states));
    criteria.addOrder(Order.asc("updated"));
    criteria.setProjection(Projections.id());
    return getIdList(criteria);
}
Also used : Criteria(org.hibernate.Criteria) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 38 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional 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 39 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class RoleUIServiceImpl method changeCaption.

@Override
@Transactional
public Response changeCaption(final String id, final String nonce, final String caption) {
    nonceStore.validate(NONCE_USE, nonce);
    final RoleEntity entity = dao.getById(id);
    if (entity == null)
        throw new IllegalArgumentException("No such Role: " + id);
    entity.setCaption(caption);
    dao.update(entity);
    return Response.seeOther(URI.create("/role/" + id)).build();
}
Also used : RoleEntity(com.peterphi.usermanager.db.entity.RoleEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 40 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class RoleUIServiceImpl method create.

@Override
@Transactional
public Response create(final String id, final String nonce, final String caption) {
    nonceStore.validate(NONCE_USE, nonce);
    if (dao.getById(id) != null)
        throw new IllegalArgumentException("Role with name already exists: " + id);
    RoleEntity entity = new RoleEntity();
    entity.setId(id);
    entity.setCaption(caption);
    dao.save(entity);
    return Response.seeOther(URI.create("/role/" + id)).build();
}
Also used : RoleEntity(com.peterphi.usermanager.db.entity.RoleEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Aggregations

Transactional (com.peterphi.std.guice.database.annotation.Transactional)46 UserEntity (com.peterphi.usermanager.db.entity.UserEntity)13 WebQuery (com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery)11 TemplateCall (com.peterphi.std.guice.web.rest.templating.TemplateCall)9 RoleEntity (com.peterphi.usermanager.db.entity.RoleEntity)9 AuthConstraint (com.peterphi.std.guice.common.auth.annotations.AuthConstraint)8 OAuthServiceEntity (com.peterphi.usermanager.db.entity.OAuthServiceEntity)5 AuthenticationFailureException (com.peterphi.usermanager.guice.authentication.AuthenticationFailureException)5 OAuthSessionEntity (com.peterphi.usermanager.db.entity.OAuthSessionEntity)4 Test (org.junit.Test)4 ResourceInstanceEntity (com.peterphi.servicemanager.service.db.entity.ResourceInstanceEntity)3 ResourceTemplateEntity (com.peterphi.servicemanager.service.db.entity.ResourceTemplateEntity)3 Criteria (org.hibernate.Criteria)3 List (java.util.List)2 DateTime (org.joda.time.DateTime)2 Timer (com.codahale.metrics.Timer)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 ServiceInstanceEntity (com.peterphi.servicemanager.service.db.entity.ServiceInstanceEntity)1 ResourceNetworkConfig (com.peterphi.servicemanager.service.guice.ResourceNetworkConfig)1