use of fi.otavanopisto.muikku.schooldata.entity.Subject in project muikku by otavanopisto.
the class WorkspaceIndexer method indexWorkspace.
private void indexWorkspace(Workspace workspace, WorkspaceEntity workspaceEntity) {
try {
Map<String, Object> extra = new HashMap<>();
extra.put("published", workspaceEntity.getPublished());
extra.put("access", workspaceEntity.getAccess());
if (workspace.getSubjectIdentifier() != null) {
Subject subject = courseMetaController.findSubject(workspace.getSchoolDataSource(), workspace.getSubjectIdentifier());
extra.put("subject", subject.getName());
}
List<WorkspaceUser> staffMembers = workspaceController.listWorkspaceStaffMembers(workspaceEntity);
Set<IndexedWorkspaceUser> indexedWorkspaceStaffMembers = new HashSet<IndexedWorkspaceUser>();
for (WorkspaceUser staffMember : staffMembers) {
// TODO: more efficient name fetching
User staffMemberUser = userController.findUserByIdentifier(staffMember.getUserIdentifier());
if (staffMemberUser != null) {
indexedWorkspaceStaffMembers.add(new IndexedWorkspaceUser(staffMember.getUserIdentifier(), staffMemberUser.getFirstName(), staffMemberUser.getLastName()));
} else {
String userId = staffMember.getUserIdentifier() != null ? staffMember.getUserIdentifier().toId() : "NULL";
logger.warning(String.format("Couldn't find staffmember #%s in workspace %s", userId, workspace.getIdentifier(), workspace.getSchoolDataSource()));
}
}
extra.put("staffMembers", indexedWorkspaceStaffMembers);
indexer.index(Workspace.class.getSimpleName(), workspace, extra);
} catch (Exception e) {
logger.warning(String.format("could not index workspace #%s/%s", workspace.getIdentifier(), workspace.getSchoolDataSource()));
}
}
use of fi.otavanopisto.muikku.schooldata.entity.Subject 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.schooldata.entity.Subject in project muikku by otavanopisto.
the class TranscriptofRecordsRESTService method getVops.
@GET
@Path("/vops/{IDENTIFIER}")
@RESTPermit(handling = Handling.INLINE)
public Response getVops(@PathParam("IDENTIFIER") String studentIdentifierString) {
String educationTypeMappingString = pluginSettingsController.getPluginSetting("transcriptofrecords", "educationTypeMapping");
EducationTypeMapping educationTypeMapping = new EducationTypeMapping();
if (educationTypeMappingString != null) {
try {
educationTypeMapping = new ObjectMapper().readValue(educationTypeMappingString, EducationTypeMapping.class);
} catch (IOException e) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity("Education type mapping not set").build();
}
}
if (!sessionController.isLoggedIn()) {
return Response.status(Status.FORBIDDEN).entity("Must be logged in").build();
}
SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(studentIdentifierString);
if (studentIdentifier == null) {
return Response.status(Status.NOT_FOUND).entity("Student identifier not found").build();
}
if (!sessionController.hasEnvironmentPermission(TranscriptofRecordsPermissions.TRANSCRIPT_OF_RECORDS_VIEW_ANY_STUDENT_STUDIES) && !Objects.equals(sessionController.getLoggedUser(), studentIdentifier)) {
return Response.status(Status.FORBIDDEN).entity("Can only look at own information").build();
}
User student = userController.findUserByIdentifier(studentIdentifier);
if (!vopsController.shouldShowStudies(student)) {
VopsRESTModel result = new VopsRESTModel(null, 0, 0, false);
return Response.ok(result).build();
}
List<TransferCredit> transferCredits = new ArrayList<>(gradingController.listStudentTransferCredits(studentIdentifier));
List<Subject> subjects = courseMetaController.listSubjects();
Map<SchoolDataIdentifier, WorkspaceAssessment> studentAssessments = vopsController.listStudentAssessments(studentIdentifier);
String curriculum = pluginSettingsController.getPluginSetting("transcriptofrecords", "curriculum");
SchoolDataIdentifier curriculumIdentifier = null;
if (curriculum != null) {
curriculumIdentifier = SchoolDataIdentifier.fromId(curriculum);
}
final List<String> subjectList = new ArrayList<String>();
String commaSeparatedSubjectsOrder = pluginSettingsController.getPluginSetting("transcriptofrecords", "subjectsOrder");
if (!StringUtils.isBlank(commaSeparatedSubjectsOrder)) {
subjectList.addAll(Arrays.asList(commaSeparatedSubjectsOrder.split(",")));
}
subjects.sort(new Comparator<Subject>() {
public int compare(Subject o1, Subject o2) {
int i1 = subjectList.indexOf(o1.getCode());
int i2 = subjectList.indexOf(o2.getCode());
i1 = i1 == -1 ? Integer.MAX_VALUE : i1;
i2 = i2 == -1 ? Integer.MAX_VALUE : i2;
return i1 < i2 ? -1 : i1 == i2 ? 0 : 1;
}
});
VopsLister lister = new VopsLister(subjects, vopsController, student, transferCredits, curriculumIdentifier, workspaceController, workspaceUserEntityController, studentIdentifier, studentAssessments, userGroupEntityController, permissionController, studiesViewCourseChoiceController, studentIdentifierString, gradingController, educationTypeMapping);
lister.performListing();
VopsRESTModel result = new VopsRESTModel(lister.getRows(), lister.getNumCourses(), lister.getNumMandatoryCourses(), lister.isOptedIn());
return Response.ok(result).build();
}
use of fi.otavanopisto.muikku.schooldata.entity.Subject in project muikku by otavanopisto.
the class VopsLister method performListing.
public void performListing() {
for (Subject subject : subjects) {
boolean subjectHasCourses = false;
if (vopsController.subjectAppliesToStudent(student, subject)) {
List<VopsRESTModel.VopsEntry> entries = new ArrayList<>();
for (int courseNumber = 1; courseNumber <= MAX_COURSE_NUMBER; courseNumber++) {
VopsRESTModel.VopsEntry entry = processCourse(subject, courseNumber);
entries.add(entry);
if (!(entry instanceof VopsRESTModel.VopsPlaceholder)) {
subjectHasCourses = true;
}
}
if (subjectHasCourses) {
rows.add(new VopsRESTModel.VopsRow(subject.getCode(), new SchoolDataIdentifier(subject.getIdentifier(), subject.getSchoolDataSource()).toId(), entries));
}
}
}
}
use of fi.otavanopisto.muikku.schooldata.entity.Subject in project muikku by otavanopisto.
the class PyramusCourseMetaSchoolDataBridge method listCourseIdentifiers.
@Override
public List<CourseIdentifier> listCourseIdentifiers() {
List<CourseIdentifier> result = new ArrayList<>();
fi.otavanopisto.pyramus.rest.model.Subject[] subjects = pyramusClient.get("/common/subjects/", fi.otavanopisto.pyramus.rest.model.Subject[].class);
if (subjects != null) {
for (fi.otavanopisto.pyramus.rest.model.Subject subject : subjects) {
List<String> courseNumbers = new ArrayList<String>();
String identifier = subject.getId().toString();
Course[] courses = pyramusClient.get("/common/subjects/" + identifier + "/courses", fi.otavanopisto.pyramus.rest.model.Course[].class);
if (courses != null) {
for (Course course : courses) {
String courseNumber = course.getCourseNumber() != null ? course.getCourseNumber().toString() : "null";
if (!courseNumbers.contains(courseNumber))
courseNumbers.add(courseNumber);
}
for (String cn : courseNumbers) {
result.add(new PyramusCourseIdentifier(subject.getId().toString() + "/" + cn, subject.getCode(), subject.getId().toString()));
}
}
}
}
return result;
}
Aggregations