use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.
the class PyramusSchoolDataEntityFactory method createEntity.
public WorkspaceAssessment createEntity(CourseAssessment courseAssessment) {
if (courseAssessment == null) {
logger.severe("Attempted to translate null course assessment into school data entity");
return null;
}
SchoolDataIdentifier gradeIdentifier = identifierMapper.getGradeIdentifier(courseAssessment.getGradeId());
SchoolDataIdentifier gradingScaleIdentifier = identifierMapper.getGradingScaleIdentifier(courseAssessment.getGradingScaleId());
Date courseAssessmentDate = null;
if (courseAssessment.getDate() != null) {
courseAssessmentDate = Date.from(courseAssessment.getDate().toInstant());
}
return new PyramusWorkspaceAssessment(courseAssessment.getId().toString(), identifierMapper.getWorkspaceStudentIdentifier(courseAssessment.getCourseStudentId()), identifierMapper.getStaffIdentifier(courseAssessment.getAssessorId()), gradeIdentifier == null ? null : gradeIdentifier.getIdentifier(), gradingScaleIdentifier == null ? null : gradingScaleIdentifier.getIdentifier(), courseAssessment.getVerbalAssessment(), courseAssessmentDate, courseAssessment.getPassing());
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.
the class PyramusSchoolDataEntityFactory method createEntity.
public WorkspaceUser createEntity(CourseStaffMember staffMember) {
if (staffMember == null) {
return null;
}
SchoolDataIdentifier identifier = toIdentifier(identifierMapper.getWorkspaceStaffIdentifier(staffMember.getId()));
SchoolDataIdentifier userIdentifier = toIdentifier(identifierMapper.getStaffIdentifier(staffMember.getStaffMemberId()));
SchoolDataIdentifier workspaceIdentifier = toIdentifier(identifierMapper.getWorkspaceIdentifier(staffMember.getCourseId()));
SchoolDataIdentifier roleIdentifier = toIdentifier(identifierMapper.getWorkspaceStaffRoleIdentifier(staffMember.getRoleId()));
return new PyramusWorkspaceUser(identifier, userIdentifier, workspaceIdentifier, roleIdentifier, null);
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.
the class WorkspaceRESTService method getFeeInfo.
@GET
@Path("/workspaces/{ID}/feeInfo")
@RESTPermit(value = MuikkuPermissions.VIEW_WORKSPACE_FEE, requireLoggedIn = true)
public Response getFeeInfo(@PathParam("ID") Long workspaceEntityId) {
SchoolDataIdentifier userIdentifier = sessionController.getLoggedUser();
if (userIdentifier == null) {
return Response.status(Status.UNAUTHORIZED).build();
}
User user = userController.findUserByIdentifier(userIdentifier);
if (user == null) {
return Response.status(Status.FORBIDDEN).build();
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
if (workspace == null) {
return Response.status(Status.NOT_FOUND).build();
}
// #3069: If the user has evaluation fees and a school set, all workspaces have an
// evaluation fee. Otherwise it depends on the applicability of the workspace itself.
boolean evaluationFees = user.hasEvaluationFees() && (StringUtils.isNotEmpty(user.getSchool()) || workspace.isEvaluationFeeApplicable());
return Response.ok(new WorkspaceFeeInfo(evaluationFees)).build();
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.
the class WorkspaceRESTService method listJournalEntries.
@GET
@Path("/workspaces/{WORKSPACEID}/journal")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listJournalEntries(@PathParam("WORKSPACEID") Long workspaceEntityId, @QueryParam("userEntityId") Long userEntityId, @QueryParam("workspaceStudentId") String workspaceStudentId, @QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("25") Integer maxResults) {
List<WorkspaceJournalEntry> entries = new ArrayList<>();
List<WorkspaceJournalEntryRESTModel> result = new ArrayList<>();
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
UserEntity userEntity = sessionController.getLoggedUserEntity();
boolean canListAllEntries = sessionController.hasWorkspacePermission(MuikkuPermissions.LIST_ALL_JOURNAL_ENTRIES, workspaceEntity);
if (workspaceStudentId == null && userEntityId == null && canListAllEntries) {
List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityController.listActiveWorkspaceStudents(workspaceEntity);
Set<UserEntity> userEntities = new HashSet<>();
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
userEntities.add(workspaceUserEntity.getUserSchoolDataIdentifier().getUserEntity());
}
entries = workspaceJournalController.listEntriesForStudents(workspaceEntity, userEntities, firstResult, maxResults);
} else {
if (userEntityId != null) {
// List by user entity (Muikku)
if (!userEntityId.equals(userEntity.getId())) {
if (canListAllEntries) {
userEntity = userEntityController.findUserEntityById(userEntityId);
if (userEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
} else {
return Response.status(Status.FORBIDDEN).build();
}
}
} else if (workspaceStudentId != null) {
// List by workspace student (school data)
SchoolDataIdentifier workspaceUserIdentifier = SchoolDataIdentifier.fromId(workspaceStudentId);
if (workspaceUserIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid workspaceStudentId").build();
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
if (workspaceUserEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
UserEntity userEntityFromWorkspaceUser = workspaceUserEntity.getUserSchoolDataIdentifier().getUserEntity();
if (userEntityFromWorkspaceUser == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (!canListAllEntries) {
if (!userEntity.getId().equals(userEntityFromWorkspaceUser.getId())) {
return Response.status(Status.FORBIDDEN).build();
}
} else {
userEntity = userEntityFromWorkspaceUser;
}
}
entries = workspaceJournalController.listEntriesByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity, firstResult, maxResults);
}
for (WorkspaceJournalEntry entry : entries) {
UserEntity entryUserEntity = userEntityController.findUserEntityById(entry.getUserEntityId());
if (entryUserEntity != null) {
User user = userController.findUserByUserEntityDefaults(entryUserEntity);
if (user != null) {
result.add(new WorkspaceJournalEntryRESTModel(entry.getId(), entry.getWorkspaceEntityId(), entry.getUserEntityId(), user.getFirstName(), user.getLastName(), entry.getHtml(), entry.getTitle(), entry.getCreated()));
}
}
}
return Response.ok(result).build();
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.
the class WorkspaceRESTService method updateWorkspaceStudent.
@PUT
@Path("/workspaces/{WORKSPACEENTITYID}/students/{ID}")
@RESTPermit(handling = Handling.INLINE)
public Response updateWorkspaceStudent(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("ID") String workspaceStudentId, WorkspaceStudent workspaceStudent) {
// Workspace
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).build();
}
// Access check
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).entity("Not logged in").build();
}
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_MEMBERS, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
// Workspace student and school data user
SchoolDataIdentifier workspaceUserIdentifier = SchoolDataIdentifier.fromId(workspaceStudentId);
if (workspaceUserIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid workspace user id").build();
}
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser bridgeUser = workspaceController.findWorkspaceUser(workspaceIdentifier, workspaceUserIdentifier);
if (bridgeUser == null) {
return Response.status(Status.NOT_FOUND).entity("School data user not found").build();
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
// Reindex user when switching between active and inactive
if (workspaceStudent.getActive() != null && !workspaceStudent.getActive().equals(workspaceUserEntity.getActive())) {
workspaceController.updateWorkspaceStudentActivity(bridgeUser, workspaceStudent.getActive());
workspaceUserEntityController.updateActive(workspaceUserEntity, workspaceStudent.getActive());
UserSchoolDataIdentifier userSchoolDataIdentifier = workspaceUserEntity.getUserSchoolDataIdentifier();
userIndexer.indexUser(userSchoolDataIdentifier.getDataSource().getIdentifier(), userSchoolDataIdentifier.getIdentifier());
}
return Response.ok(workspaceStudent).build();
}
Aggregations