public User create(User user, Role initialRole) throws EntityAlreadyExistsException, InvalidEntityException
{
if (this.dao.findBySlug(user.getSlug(), getTenant()) != null) {
throw new EntityAlreadyExistsException();
}
this.dao.begin();
UUID entityId = UUID.randomUUID();
user.setId(entityId);
if (getTenant() == null && user.isGlobal()) {
this.dao.createEntity(user, USER_ENTITY_TYPE);
} else {
this.dao.createEntity(user, USER_ENTITY_TYPE, getTenant());
}
this.dao.create(user);
this.dao.addRoleToUser(entityId, initialRole.toString());
this.dao.commit();
return user;
}