use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.
the class RoleUIServiceImpl method delete.
@Override
@Transactional
public Response delete(final String id, final String nonce) {
nonceStore.validate(NONCE_USE, nonce);
if (StringUtils.equalsIgnoreCase(id, UserLogin.ROLE_ADMIN))
throw new IllegalArgumentException("Cannot delete the user manager admin role!");
final RoleEntity entity = dao.getById(id);
if (entity == null)
throw new IllegalArgumentException("No such Role: " + id);
dao.delete(entity);
return Response.seeOther(URI.create("/roles")).build();
}
use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.
the class RoleUIServiceImpl method changeMembers.
@Override
@Transactional
public Response changeMembers(final String id, final String nonce, final List<Integer> members) {
nonceStore.validate(NONCE_USE, nonce);
final RoleEntity entity = dao.getById(id);
if (entity == null)
throw new IllegalArgumentException("No such Role: " + id);
final List<UserEntity> users = userDao.getListById(members);
if (users.size() != members.size())
throw new IllegalArgumentException("One or more members provided did not exist! " + members);
{
final List<Integer> existing = entity.getMembers().stream().map(UserEntity::getId).collect(Collectors.toList());
final List<Integer> added = members.stream().filter(i -> !existing.contains(i)).collect(Collectors.toList());
final List<Integer> removed = members.stream().filter(i -> existing.contains(i)).collect(Collectors.toList());
}
entity.getMembers().clear();
;
entity.getMembers().addAll(users);
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 getRoles.
@Override
@Transactional(readOnly = true)
public String getRoles(UriInfo query) {
ConstrainedResultSet<RoleEntity> resultset = dao.findByUriQuery(new WebQuery().orderAsc("id").decode(query));
TemplateCall call = templater.template("roles");
call.set("resultset", resultset);
call.set("roles", resultset.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 ServiceUIServiceImpl method disable.
@Override
@Transactional
public Response disable(final String id, final String nonce) {
nonceStore.validate(NONCE_USE, nonce);
final OAuthServiceEntity entity = dao.getById(id);
if (entity == null)
throw new IllegalArgumentException("No such service with client_id: " + id);
else if (!entity.isEnabled())
throw new IllegalArgumentException("Cannot disable an already-disabled service: " + id);
else if (entity.getOwner().getId() != userProvider.get().getId() && !userProvider.get().isAdmin())
throw new IllegalArgumentException("Only the owner or an admin can change a service!");
entity.setEnabled(false);
dao.update(entity);
return Response.seeOther(URI.create("/service/" + id)).build();
}
use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.
the class ServiceUIServiceImpl method create.
@Override
@Transactional
public Response create(final String nonce, final String name, final String endpoints) {
nonceStore.validate(NONCE_USE, nonce);
final int userId = userProvider.get().getId();
final UserEntity user = userDao.getById(userId);
OAuthServiceEntity entity = new OAuthServiceEntity();
entity.setOwner(user);
entity.setName(name);
entity.setEndpoints(StringUtils.trimToNull(endpoints));
entity.setEnabled(true);
dao.save(entity);
return Response.seeOther(URI.create("/service/" + entity.getId())).build();
}
Aggregations