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;
}
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);
}
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();
}
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();
}
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();
}
Aggregations