use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class UserIndexer method indexUser.
public void indexUser(String dataSource, String identifier) {
schoolDataBridgeSessionController.startSystemSession();
try {
User user = userController.findUserByDataSourceAndIdentifier(dataSource, identifier);
if (user != null) {
EnvironmentRoleArchetype archetype = null;
UserEntity userEntity = userEntityController.findUserEntityByDataSourceAndIdentifier(user.getSchoolDataSource(), user.getIdentifier());
if (userEntity != null) {
EnvironmentUser eu = environmentUserController.findEnvironmentUserByUserEntity(userEntity);
if ((eu != null) && (eu.getRole() != null))
archetype = eu.getRole().getArchetype();
}
if ((archetype != null) && (userEntity != null)) {
SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(user.getIdentifier(), user.getSchoolDataSource());
boolean isDefaultIdentifier = (userEntity.getDefaultIdentifier() != null && userEntity.getDefaultSchoolDataSource() != null) ? userEntity.getDefaultIdentifier().equals(user.getIdentifier()) && userEntity.getDefaultSchoolDataSource().getIdentifier().equals(user.getSchoolDataSource()) : false;
Map<String, Object> extra = new HashMap<>();
extra.put("archetype", archetype);
extra.put("userEntityId", userEntity.getId());
extra.put("isDefaultIdentifier", isDefaultIdentifier);
Set<Long> workspaceEntityIds = new HashSet<Long>();
Set<Long> userGroupIds = new HashSet<Long>();
// List workspaces in which the student is active (TODO Should we have a separate variable for all workspaces?)
List<WorkspaceEntity> workspaces = workspaceUserEntityController.listActiveWorkspaceEntitiesByUserIdentifier(userIdentifier);
for (WorkspaceEntity workspace : workspaces) {
workspaceEntityIds.add(workspace.getId());
}
extra.put("workspaces", workspaceEntityIds);
List<UserGroupEntity> userGroups = userGroupEntityController.listUserGroupsByUserIdentifier(userIdentifier);
for (UserGroupEntity userGroup : userGroups) {
userGroupIds.add(userGroup.getId());
}
extra.put("groups", userGroupIds);
if (EnvironmentRoleArchetype.TEACHER.equals(archetype) || EnvironmentRoleArchetype.STUDY_GUIDER.equals(archetype) || EnvironmentRoleArchetype.STUDY_PROGRAMME_LEADER.equals(archetype) || EnvironmentRoleArchetype.MANAGER.equals(archetype) || EnvironmentRoleArchetype.ADMINISTRATOR.equals(archetype)) {
String userDefaultEmailAddress = userEmailEntityController.getUserDefaultEmailAddress(userEntity, false);
extra.put("email", userDefaultEmailAddress);
}
indexer.index(User.class.getSimpleName(), user, extra);
} else
indexer.index(User.class.getSimpleName(), user);
} else {
logger.info(String.format("Removing user %s/%s from index", identifier, dataSource));
removeUser(dataSource, identifier);
}
} catch (Exception ex) {
logger.log(Level.SEVERE, "Indexing of user identifier " + identifier + " failed.", ex);
} finally {
schoolDataBridgeSessionController.endSystemSession();
}
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceMaterialsManagementBackingBean method init.
@RequestAction
public String init() {
String urlName = getWorkspaceUrlName();
if (StringUtils.isBlank(urlName)) {
return NavigationRules.NOT_FOUND;
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
if (workspaceEntity == null) {
return NavigationRules.NOT_FOUND;
}
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_MATERIALS, workspaceEntity)) {
return NavigationRules.ACCESS_DENIED;
}
rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
workspaceEntityId = workspaceEntity.getId();
workspaceBackingBean.setWorkspaceUrlName(urlName);
workspaceName = workspaceBackingBean.getWorkspaceName();
try {
contentNodes = workspaceMaterialController.listWorkspaceMaterialsAsContentNodes(workspaceEntity, true);
} catch (WorkspaceMaterialException e) {
logger.log(Level.SEVERE, "Error loading materials", e);
return NavigationRules.INTERNAL_ERROR;
}
materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
return null;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceIndexBackingBean method init.
@RequestAction
public String init() {
String urlName = getWorkspaceUrlName();
if (StringUtils.isBlank(urlName)) {
return NavigationRules.NOT_FOUND;
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
if (workspaceEntity == null) {
return NavigationRules.NOT_FOUND;
}
canPublish = sessionController.hasWorkspacePermission(MuikkuPermissions.PUBLISH_WORKSPACE, workspaceEntity);
workspaceEntityId = workspaceEntity.getId();
published = workspaceEntity.getPublished();
if (!published) {
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_UNPUBLISHED_WORKSPACE, workspaceEntity)) {
return NavigationRules.NOT_FOUND;
}
}
try {
WorkspaceMaterial frontPage = workspaceMaterialController.ensureWorkspaceFrontPageExists(workspaceEntity);
contentNodes = Arrays.asList(workspaceMaterialController.createContentNode(frontPage));
} catch (WorkspaceMaterialException e) {
logger.log(Level.SEVERE, "Error loading materials", e);
return NavigationRules.INTERNAL_ERROR;
}
workspaceBackingBean.setWorkspaceUrlName(urlName);
schoolDataBridgeSessionController.startSystemSession();
try {
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
if (workspace == null) {
logger.warning(String.format("Could not find workspace for workspaceEntity #%d", workspaceEntity.getId()));
return NavigationRules.NOT_FOUND;
}
WorkspaceType workspaceType = workspaceController.findWorkspaceType(workspace.getWorkspaceTypeId());
EducationType educationTypeObject = workspace.getEducationTypeIdentifier() == null ? null : courseMetaController.findEducationType(workspace.getEducationTypeIdentifier());
Subject subjectObject = courseMetaController.findSubject(workspace.getSchoolDataSource(), workspace.getSubjectIdentifier());
CourseLengthUnit lengthUnit = null;
if ((workspace.getLength() != null) && (workspace.getLengthUnitIdentifier() != null)) {
lengthUnit = courseMetaController.findCourseLengthUnit(workspace.getSchoolDataSource(), workspace.getLengthUnitIdentifier());
}
workspaceId = workspaceEntity.getId();
workspaceName = workspace.getName();
workspaceNameExtension = workspace.getNameExtension();
subject = subjectObject != null ? subjectObject.getName() : null;
educationType = educationTypeObject != null ? educationTypeObject.getName() : null;
if (lengthUnit != null) {
courseLength = workspace.getLength();
courseLengthSymbol = lengthUnit.getSymbol();
}
beginDate = workspace.getBeginDate() != null ? Date.from(workspace.getBeginDate().toInstant()) : null;
endDate = workspace.getEndDate() != null ? Date.from(workspace.getEndDate().toInstant()) : null;
if (workspaceType != null) {
this.workspaceType = workspaceType.getName();
}
} finally {
schoolDataBridgeSessionController.endSystemSession();
}
WorkspaceEntityFile customFrontImage = workspaceEntityFileController.findWorkspaceEntityFile(workspaceEntity, "workspace-frontpage-image-cropped");
hasCustomFrontPageImage = customFrontImage != null;
customFrontPageImageUrl = hasCustomFrontPageImage ? String.format("/rest/workspace/workspaces/%d/workspacefile/workspace-frontpage-image-cropped", workspaceEntity.getId()) : null;
materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
announcementsBaseUrl = String.format("/workspace/%s/announcements", workspaceUrlName);
workspaceVisitController.visit(workspaceEntity);
return null;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceJournalEntryDAO method listByWorkspaceEntityAndUserEntities.
public List<WorkspaceJournalEntry> listByWorkspaceEntityAndUserEntities(WorkspaceEntity workspaceEntity, Collection<UserEntity> userEntities, int firstResult, int maxResults) {
EntityManager entityManager = getEntityManager();
Set<Long> userEntityIds = userEntities.stream().map(userEntity -> userEntity.getId()).collect(Collectors.toSet());
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceJournalEntry> criteria = criteriaBuilder.createQuery(WorkspaceJournalEntry.class);
Root<WorkspaceJournalEntry> root = criteria.from(WorkspaceJournalEntry.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceJournalEntry_.workspaceEntityId), workspaceEntity.getId()), root.get(WorkspaceJournalEntry_.userEntityId).in(userEntityIds), criteriaBuilder.equal(root.get(WorkspaceJournalEntry_.archived), Boolean.FALSE)));
criteria.orderBy(criteriaBuilder.desc(root.get(WorkspaceJournalEntry_.created)));
TypedQuery<WorkspaceJournalEntry> query = entityManager.createQuery(criteria);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
return query.getResultList();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class Evaluation2RESTService method listAssessmentRequests.
@GET
@Path("/compositeAssessmentRequests")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listAssessmentRequests(@QueryParam("workspaceEntityId") Long workspaceEntityId) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
return Response.status(Status.FORBIDDEN).build();
}
List<RestAssessmentRequest> restAssessmentRequests = new ArrayList<RestAssessmentRequest>();
if (workspaceEntityId == null) {
// List assessment requests by staff member
SchoolDataIdentifier loggedUser = sessionController.getLoggedUser();
List<CompositeAssessmentRequest> assessmentRequests = gradingController.listAssessmentRequestsByStaffMember(loggedUser);
for (CompositeAssessmentRequest assessmentRequest : assessmentRequests) {
restAssessmentRequests.add(toRestAssessmentRequest(assessmentRequest));
}
} else {
// List assessment requests by workspace
List<String> workspaceStudentIdentifiers = new ArrayList<String>();
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityController.listActiveWorkspaceStudents(workspaceEntity);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
workspaceStudentIdentifiers.add(workspaceUserEntity.getIdentifier());
}
List<CompositeAssessmentRequest> assessmentRequests = gradingController.listAssessmentRequestsByWorkspace(workspaceIdentifier, workspaceStudentIdentifiers);
for (CompositeAssessmentRequest assessmentRequest : assessmentRequests) {
restAssessmentRequests.add(toRestAssessmentRequest(assessmentRequest));
}
}
return Response.ok(restAssessmentRequests).build();
}
Aggregations