use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceEntityDAO method create.
public WorkspaceEntity create(SchoolDataSource dataSource, String identifier, String urlName, WorkspaceAccess access, Boolean published, Boolean archived) {
WorkspaceEntity workspaceEntity = new WorkspaceEntity();
workspaceEntity.setDataSource(dataSource);
workspaceEntity.setIdentifier(identifier);
workspaceEntity.setUrlName(urlName);
workspaceEntity.setAccess(access);
workspaceEntity.setArchived(archived);
workspaceEntity.setPublished(published);
return persist(workspaceEntity);
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceEntityDAO method findByUrlName.
public WorkspaceEntity findByUrlName(String urlName) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceEntity> criteria = criteriaBuilder.createQuery(WorkspaceEntity.class);
Root<WorkspaceEntity> root = criteria.from(WorkspaceEntity.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(WorkspaceEntity_.urlName), urlName));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceEntityDAO method listIdentifiersByDataSourceAndArchived.
public List<String> listIdentifiersByDataSourceAndArchived(SchoolDataSource dataSource, Boolean archived) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<String> criteria = criteriaBuilder.createQuery(String.class);
Root<WorkspaceEntity> root = criteria.from(WorkspaceEntity.class);
criteria.select(root.get(WorkspaceEntity_.identifier));
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceEntity_.archived), archived), criteriaBuilder.equal(root.get(WorkspaceEntity_.dataSource), dataSource)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceEntityDAO method findByUrlNameAndArchived.
public WorkspaceEntity findByUrlNameAndArchived(String urlName, Boolean archived) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceEntity> criteria = criteriaBuilder.createQuery(WorkspaceEntity.class);
Root<WorkspaceEntity> root = criteria.from(WorkspaceEntity.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceEntity_.urlName), urlName), criteriaBuilder.equal(root.get(WorkspaceEntity_.archived), archived)));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class ForumPermissionResolver method hasPermission.
@Override
public boolean hasPermission(String permission, ContextReference contextReference, User user) {
ForumArea forumArea = getForumArea(contextReference);
Permission perm = permissionDAO.findByName(permission);
UserEntity userEntity = getUserEntity(user);
if (forumArea == null) {
return false;
}
RoleEntity userRole;
// TODO: typecasts
if (forumArea instanceof WorkspaceForumArea) {
WorkspaceForumArea workspaceForum = (WorkspaceForumArea) forumArea;
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceForum.getWorkspace());
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity);
if (workspaceUserEntity != null) {
userRole = workspaceUserEntity.getWorkspaceUserRole();
if (resourceUserRolePermissionDAO.hasResourcePermissionAccess(resourceRightsController.findResourceRightsById(forumArea.getRights()), userRole, perm) || hasEveryonePermission(permission, forumArea) || userEntity.getId().equals(forumArea.getOwner()))
return true;
}
}
EnvironmentUser environmentUser = environmentUserDAO.findByUserAndArchived(userEntity, Boolean.FALSE);
userRole = environmentUser.getRole();
boolean isOwner = userEntity != null ? userEntity.getId().equals(forumArea.getOwner()) : false;
return resourceUserRolePermissionDAO.hasResourcePermissionAccess(resourceRightsController.findResourceRightsById(forumArea.getRights()), userRole, perm) || hasEveryonePermission(permission, forumArea) || isOwner;
}
Aggregations