Search in sources :

Example 6 with CourseStaffMember

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember in project pyramus by otavanopisto.

the class ObjectFactory method init.

@PostConstruct
public void init() {
    mappers = new HashMap<>();
    addMappers(new Mapper<fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm>() {

        @Override
        public Object map(fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm entity) {
            return new AcademicTerm(entity.getId(), entity.getName(), toOffsetDateTime(entity.getStartDate()), toOffsetDateTime(entity.getEndDate()), entity.getArchived());
        }
    }, new Mapper<CourseParticipationType>() {

        @Override
        public Object map(CourseParticipationType entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseParticipationType(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<CourseEnrolmentType>() {

        @Override
        public Object map(CourseEnrolmentType entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseEnrolmentType(entity.getId(), entity.getName());
        }
    }, new Mapper<CourseState>() {

        @Override
        public Object map(CourseState entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseState(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<CourseType>() {

        @Override
        public Object map(CourseType entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseType(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<CourseEducationType>() {

        @Override
        public Object map(CourseEducationType entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseEducationType(entity.getId(), entity.getEducationType().getId(), false);
        }
    }, new Mapper<CourseEducationSubtype>() {

        @Override
        public Object map(CourseEducationSubtype entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseEducationSubtype(entity.getId(), entity.getEducationSubtype().getId(), false);
        }
    }, new Mapper<Course>() {

        @Override
        public Object map(Course entity) {
            Long subjectId = null;
            Subject courseSubject = entity.getSubject();
            if (courseSubject != null) {
                subjectId = courseSubject.getId();
            }
            List<String> tags = new ArrayList<>();
            Set<Tag> courseTags = entity.getTags();
            if (courseTags != null) {
                for (Tag courseTag : courseTags) {
                    tags.add(courseTag.getText());
                }
            }
            Double length = entity.getCourseLength() != null ? entity.getCourseLength().getUnits() : null;
            Long lengthUnitId = entity.getCourseLength() != null && entity.getCourseLength().getUnit() != null ? entity.getCourseLength().getUnit().getId() : null;
            OffsetDateTime created = toOffsetDateTime(entity.getCreated());
            OffsetDateTime lastModified = toOffsetDateTime(entity.getLastModified());
            OffsetDateTime beginDate = fromDateToOffsetDateTime(entity.getBeginDate());
            OffsetDateTime endDate = fromDateToOffsetDateTime(entity.getEndDate());
            OffsetDateTime enrolmentTimeEnd = toOffsetDateTime(entity.getEnrolmentTimeEnd());
            Long creatorId = entity.getCreator() != null ? entity.getCreator().getId() : null;
            Long lastModifierId = entity.getLastModifier() != null ? entity.getLastModifier().getId() : null;
            Long moduleId = entity.getModule() != null ? entity.getModule().getId() : null;
            Long stateId = entity.getState() != null ? entity.getState().getId() : null;
            Long typeId = entity.getType() != null ? entity.getType().getId() : null;
            Set<Long> curriculumIds = new HashSet<Long>();
            for (fi.otavanopisto.pyramus.domainmodel.base.Curriculum curriculum : entity.getCurriculums()) curriculumIds.add(curriculum.getId());
            List<CourseBaseVariable> entityVariables = courseController.listCourseVariablesByCourse(entity);
            Map<String, String> variables = new HashMap<>();
            for (CourseBaseVariable entityVariable : entityVariables) {
                variables.put(entityVariable.getKey().getVariableKey(), entityVariable.getValue());
            }
            ;
            // #1257: Course's primary education type and subtype
            // If the course has subject defined, primary education type is that of the subject.
            // If no subject is defined, and course has only one education type, that is primary.
            // Primary subtype exists, if the course has only one subtype belonging to the primary education type.
            EducationType educationType = null;
            EducationSubtype educationSubtype = null;
            if (entity.getSubject() != null && entity.getSubject().getEducationType() != null) {
                educationType = entity.getSubject().getEducationType();
            } else if (entity.getCourseEducationTypes().size() == 1) {
                educationType = entity.getCourseEducationTypes().get(0).getEducationType();
            }
            if (educationType != null && !entity.getCourseEducationTypes().isEmpty()) {
                for (CourseEducationType cet : entity.getCourseEducationTypes()) {
                    if (cet.getEducationType().getId().equals(educationType.getId())) {
                        if (cet.getCourseEducationSubtypes().size() == 1) {
                            educationSubtype = cet.getCourseEducationSubtypes().get(0).getEducationSubtype();
                        }
                        break;
                    }
                }
            }
            return new fi.otavanopisto.pyramus.rest.model.Course(entity.getId(), entity.getName(), created, lastModified, entity.getDescription(), entity.getArchived(), entity.getCourseNumber(), entity.getMaxParticipantCount(), beginDate, endDate, entity.getNameExtension(), entity.getLocalTeachingDays(), entity.getTeachingHours(), entity.getDistanceTeachingHours(), entity.getDistanceTeachingDays(), entity.getAssessingHours(), entity.getPlanningHours(), enrolmentTimeEnd, creatorId, lastModifierId, subjectId, curriculumIds, length, lengthUnitId, moduleId, stateId, typeId, variables, tags, entity.getOrganization() == null ? null : entity.getOrganization().getId(), entity.isCourseTemplate(), educationType == null ? null : educationType.getId(), educationSubtype == null ? null : educationSubtype.getId());
        }
    }, new Mapper<CourseComponent>() {

        @Override
        public Object map(CourseComponent entity) {
            Long lengthUnitId = entity.getLength() != null ? entity.getLength().getUnit().getId() : null;
            Double length = entity.getLength() != null ? entity.getLength().getUnits() : null;
            return new fi.otavanopisto.pyramus.rest.model.CourseComponent(entity.getId(), entity.getName(), entity.getDescription(), length, lengthUnitId, entity.getArchived());
        }
    }, new Mapper<CourseDescription>() {

        @Override
        public Object map(CourseDescription entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseDescription(entity.getId(), entity.getCourseBase().getId(), entity.getCategory().getId(), entity.getDescription());
        }
    }, new Mapper<CourseDescriptionCategory>() {

        @Override
        public Object map(CourseDescriptionCategory entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseDescriptionCategory(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<CourseAssessment>() {

        @Override
        public Object map(CourseAssessment entity) {
            Long courseStudentId = entity.getCourseStudent() != null ? entity.getCourseStudent().getId() : null;
            Long gradeId = entity.getGrade() != null ? entity.getGrade().getId() : null;
            Long gradingScaleId = entity.getGrade() != null && entity.getGrade().getGradingScale() != null ? entity.getGrade().getGradingScale().getId() : null;
            Long assessorId = entity.getAssessor() != null ? entity.getAssessor().getId() : null;
            Boolean passing = entity.getGrade() != null ? entity.getGrade().getPassingGrade() : null;
            return new fi.otavanopisto.pyramus.rest.model.CourseAssessment(entity.getId(), courseStudentId, gradeId, gradingScaleId, assessorId, toOffsetDateTime(entity.getDate()), entity.getVerbalAssessment(), passing);
        }
    }, new Mapper<TransferCredit>() {

        @Override
        public Object map(TransferCredit entity) {
            Long studentId = entity.getStudent() != null ? entity.getStudent().getId() : null;
            OffsetDateTime date = toOffsetDateTime(entity.getDate());
            Long gradeId = entity.getGrade() != null ? entity.getGrade().getId() : null;
            Long gradigScaleId = entity.getGrade() != null ? entity.getGrade().getGradingScale().getId() : null;
            Long assessorId = entity.getAssessor() != null ? entity.getAssessor().getId() : null;
            Double length = entity.getCourseLength() != null ? entity.getCourseLength().getUnits() : null;
            Long lengthUnitId = entity.getCourseLength() != null ? entity.getCourseLength().getUnit().getId() : null;
            Long schoolId = entity.getSchool() != null ? entity.getSchool().getId() : null;
            Long subjectId = entity.getSubject() != null ? entity.getSubject().getId() : null;
            CourseOptionality optionality = entity.getOptionality() != null ? CourseOptionality.valueOf(entity.getOptionality().name()) : null;
            Long curriculumId = entity.getCurriculum() != null ? entity.getCurriculum().getId() : null;
            Boolean offCurriculum = entity.getOffCurriculum() != null ? entity.getOffCurriculum() : Boolean.FALSE;
            return new fi.otavanopisto.pyramus.rest.model.TransferCredit(entity.getId(), studentId, date, gradeId, gradigScaleId, entity.getVerbalAssessment(), assessorId, entity.getArchived(), entity.getCourseName(), entity.getCourseNumber(), length, lengthUnitId, schoolId, subjectId, optionality, curriculumId, offCurriculum);
        }
    }, new Mapper<CreditLink>() {

        @Override
        public Object map(CreditLink entity) {
            Long studentId = entity.getStudent() != null ? entity.getStudent().getId() : null;
            if (entity.getCredit() != null) {
                switch(entity.getCredit().getCreditType()) {
                    case CourseAssessment:
                        fi.otavanopisto.pyramus.rest.model.CourseAssessment credit = (fi.otavanopisto.pyramus.rest.model.CourseAssessment) createModel(entity.getCredit());
                        return new fi.otavanopisto.pyramus.rest.model.CreditLinkCourseAssessment(entity.getId(), studentId, credit);
                    case TransferCredit:
                        fi.otavanopisto.pyramus.rest.model.TransferCredit tc = (fi.otavanopisto.pyramus.rest.model.TransferCredit) createModel(entity.getCredit());
                        return new fi.otavanopisto.pyramus.rest.model.CreditLinkTransferCredit(entity.getId(), studentId, tc);
                    default:
                        return null;
                }
            }
            return null;
        }
    }, new Mapper<CourseAssessmentRequest>() {

        @Override
        public Object map(CourseAssessmentRequest entity) {
            OffsetDateTime created = toOffsetDateTime(entity.getCreated());
            return new fi.otavanopisto.pyramus.rest.model.CourseAssessmentRequest(entity.getId(), entity.getCourseStudent().getId(), created, entity.getRequestText(), entity.getArchived(), entity.getHandled());
        }
    }, new Mapper<EducationType>() {

        @Override
        public Object map(EducationType entity) {
            return new fi.otavanopisto.pyramus.rest.model.EducationType(entity.getId(), entity.getName(), entity.getCode(), entity.getArchived());
        }
    }, new Mapper<EducationSubtype>() {

        @Override
        public Object map(EducationSubtype entity) {
            Long educationTypeId = entity.getEducationType() != null ? entity.getEducationType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.EducationSubtype(entity.getId(), entity.getName(), entity.getCode(), educationTypeId, entity.getArchived());
        }
    }, new Mapper<Subject>() {

        @Override
        public Object map(Subject entity) {
            Long educationTypeId = entity.getEducationType() != null ? entity.getEducationType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.Subject(entity.getId(), entity.getCode(), entity.getName(), educationTypeId, entity.getArchived());
        }
    }, new Mapper<GradingScale>() {

        @Override
        public Object map(GradingScale entity) {
            return new fi.otavanopisto.pyramus.rest.model.GradingScale(entity.getId(), entity.getName(), entity.getDescription(), entity.getArchived());
        }
    }, new Mapper<Grade>() {

        @Override
        public Object map(Grade entity) {
            Long gradingScaleId = entity.getGradingScale() != null ? entity.getGradingScale().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.Grade(entity.getId(), entity.getName(), entity.getDescription(), gradingScaleId, entity.getPassingGrade(), entity.getQualification(), entity.getGPA(), entity.getArchived());
        }
    }, new Mapper<EducationalTimeUnit>() {

        @Override
        public Object map(EducationalTimeUnit entity) {
            return new fi.otavanopisto.pyramus.rest.model.EducationalTimeUnit(entity.getId(), entity.getName(), entity.getSymbol(), entity.getBaseUnits(), entity.getArchived());
        }
    }, new Mapper<Module>() {

        @Override
        public Object map(Module entity) {
            Long creatorId = entity.getCreator().getId();
            Long lastModifierId = entity.getLastModifier() != null ? entity.getLastModifier().getId() : null;
            Long subjectId = entity.getSubject() != null ? entity.getSubject().getId() : null;
            Double length = entity.getCourseLength() != null ? entity.getCourseLength().getUnits() : null;
            Long lenghtUnitId = entity.getCourseLength() != null && entity.getCourseLength().getUnit() != null ? entity.getCourseLength().getUnit().getId() : null;
            List<String> tags = new ArrayList<>();
            Set<Tag> moduleTags = entity.getTags();
            if (moduleTags != null) {
                for (Tag courseTag : moduleTags) {
                    tags.add(courseTag.getText());
                }
            }
            Set<Long> curriculumIds = new HashSet<Long>();
            for (fi.otavanopisto.pyramus.domainmodel.base.Curriculum curriculum : entity.getCurriculums()) curriculumIds.add(curriculum.getId());
            return new fi.otavanopisto.pyramus.rest.model.Module(entity.getId(), entity.getName(), toOffsetDateTime(entity.getCreated()), toOffsetDateTime(entity.getLastModified()), entity.getDescription(), entity.getArchived(), entity.getCourseNumber(), entity.getMaxParticipantCount(), creatorId, lastModifierId, subjectId, curriculumIds, length, lenghtUnitId, tags);
        }
    }, new Mapper<ModuleComponent>() {

        @Override
        public Object map(ModuleComponent entity) {
            Long lengthUnitId = entity.getLength() != null && entity.getLength().getUnit() != null ? entity.getLength().getUnit().getId() : null;
            Double length = entity.getLength() != null ? entity.getLength().getUnits() : null;
            return new fi.otavanopisto.pyramus.rest.model.ModuleComponent(entity.getId(), entity.getName(), entity.getDescription(), length, lengthUnitId, entity.getArchived());
        }
    }, new Mapper<Project>() {

        @Override
        public Object map(Project entity) {
            Double optionalStudiesLength = entity.getOptionalStudiesLength() != null ? entity.getOptionalStudiesLength().getUnits() : null;
            Long optionalStudiesLengthUnitId = entity.getOptionalStudiesLength() != null && entity.getOptionalStudiesLength().getUnit() != null ? entity.getOptionalStudiesLength().getUnit().getId() : null;
            Long creatorId = entity.getCreator().getId();
            Long lastModifierId = entity.getLastModifier() != null ? entity.getLastModifier().getId() : null;
            List<String> tags = new ArrayList<>();
            Set<Tag> entityTags = entity.getTags();
            if (entityTags != null) {
                for (Tag entityTag : entityTags) {
                    tags.add(entityTag.getText());
                }
            }
            return new fi.otavanopisto.pyramus.rest.model.Project(entity.getId(), entity.getName(), entity.getDescription(), optionalStudiesLength, optionalStudiesLengthUnitId, toOffsetDateTime(entity.getCreated()), creatorId, toOffsetDateTime(entity.getLastModified()), lastModifierId, tags, entity.getArchived());
        }
    }, new Mapper<ProjectModule>() {

        @Override
        public Object map(ProjectModule entity) {
            ProjectModuleOptionality optionality = null;
            switch(entity.getOptionality()) {
                case MANDATORY:
                    optionality = ProjectModuleOptionality.MANDATORY;
                    break;
                case OPTIONAL:
                    optionality = ProjectModuleOptionality.OPTIONAL;
                    break;
            }
            Long moduleId = entity.getModule() != null ? entity.getModule().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.ProjectModule(entity.getId(), moduleId, optionality);
        }
    }, new Mapper<School>() {

        @Override
        public Object map(School entity) {
            Long fieldId = entity.getField() != null ? entity.getField().getId() : null;
            List<String> tags = new ArrayList<>();
            Set<Tag> entityTags = entity.getTags();
            if (entityTags != null) {
                for (Tag entityTag : entityTags) {
                    tags.add(entityTag.getText());
                }
            }
            List<SchoolVariable> entityVariables = schoolController.listSchoolVariablesBySchool(entity);
            Map<String, String> variables = new HashMap<>();
            for (SchoolVariable entityVariable : entityVariables) {
                variables.put(entityVariable.getKey().getVariableKey(), entityVariable.getValue());
            }
            String additionalInfo = entity.getContactInfo() != null ? entity.getContactInfo().getAdditionalInfo() : null;
            return new fi.otavanopisto.pyramus.rest.model.School(entity.getId(), entity.getCode(), entity.getName(), tags, fieldId, additionalInfo, entity.getArchived(), variables);
        }
    }, new Mapper<SchoolField>() {

        @Override
        public Object map(SchoolField entity) {
            return new fi.otavanopisto.pyramus.rest.model.SchoolField(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<SchoolVariableKey>() {

        @Override
        public Object map(SchoolVariableKey entity) {
            return new fi.otavanopisto.pyramus.rest.model.VariableKey(entity.getVariableKey(), entity.getVariableName(), entity.getUserEditable(), toVariableType(entity.getVariableType()));
        }
    }, new Mapper<CourseBaseVariableKey>() {

        @Override
        public Object map(CourseBaseVariableKey entity) {
            return new fi.otavanopisto.pyramus.rest.model.VariableKey(entity.getVariableKey(), entity.getVariableName(), entity.getUserEditable(), toVariableType(entity.getVariableType()));
        }
    }, new Mapper<Language>() {

        @Override
        public Object map(Language entity) {
            return new fi.otavanopisto.pyramus.rest.model.Language(entity.getId(), entity.getCode(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<Municipality>() {

        @Override
        public Object map(Municipality entity) {
            return new fi.otavanopisto.pyramus.rest.model.Municipality(entity.getId(), entity.getCode(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<Nationality>() {

        @Override
        public Object map(Nationality entity) {
            return new fi.otavanopisto.pyramus.rest.model.Nationality(entity.getId(), entity.getCode(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<StudentActivityType>() {

        @Override
        public Object map(StudentActivityType entity) {
            return new fi.otavanopisto.pyramus.rest.model.StudentActivityType(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<StudentEducationalLevel>() {

        @Override
        public Object map(StudentEducationalLevel entity) {
            return new fi.otavanopisto.pyramus.rest.model.StudentEducationalLevel(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<StudentExaminationType>() {

        @Override
        public Object map(StudentExaminationType entity) {
            return new fi.otavanopisto.pyramus.rest.model.StudentExaminationType(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<StudyProgrammeCategory>() {

        @Override
        public Object map(StudyProgrammeCategory entity) {
            Long educationTypeId = entity.getEducationType() != null ? entity.getEducationType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.StudyProgrammeCategory(entity.getId(), entity.getName(), educationTypeId, entity.getArchived());
        }
    }, new Mapper<StudyProgramme>() {

        @Override
        public Object map(StudyProgramme entity) {
            Long categoryId = entity.getCategory() != null ? entity.getCategory().getId() : null;
            Long organizationId = entity.getOrganization() != null ? entity.getOrganization().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.StudyProgramme(entity.getId(), organizationId, entity.getCode(), entity.getName(), categoryId, entity.getHasEvaluationFees(), entity.getArchived());
        }
    }, new Mapper<StudentGroup>() {

        public Object map(StudentGroup entity) {
            Long creatorId = entity.getCreator().getId();
            Long lastModifierId = entity.getLastModifier() != null ? entity.getLastModifier().getId() : null;
            Long organizationId = entity.getOrganization() != null ? entity.getOrganization().getId() : null;
            List<String> tags = new ArrayList<>();
            Set<Tag> entityTags = entity.getTags();
            if (entityTags != null) {
                for (Tag entityTag : entityTags) {
                    tags.add(entityTag.getText());
                }
            }
            return new fi.otavanopisto.pyramus.rest.model.StudentGroup(entity.getId(), entity.getName(), entity.getDescription(), toOffsetDateTime(entity.getBeginDate()), creatorId, toOffsetDateTime(entity.getCreated()), lastModifierId, toOffsetDateTime(entity.getLastModified()), tags, entity.getGuidanceGroup(), organizationId, entity.getArchived());
        }
    }, new Mapper<Person>() {

        public Object map(Person entity) {
            Sex sex = null;
            if (entity.getSex() != null) {
                switch(entity.getSex()) {
                    case FEMALE:
                        sex = Sex.FEMALE;
                        break;
                    case MALE:
                        sex = Sex.MALE;
                        break;
                    case OTHER:
                        sex = Sex.OTHER;
                        break;
                }
            }
            Long defaultUserId = entity.getDefaultUser() != null ? entity.getDefaultUser().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.Person(entity.getId(), toOffsetDateTime(entity.getBirthday()), entity.getSocialSecurityNumber(), sex, entity.getSecureInfo(), entity.getBasicInfo(), defaultUserId);
        }
    }, new Mapper<Student>() {

        public Object map(Student entity) {
            Long personId = entity.getPerson() != null ? entity.getPerson().getId() : null;
            Long nationalityId = entity.getNationality() != null ? entity.getNationality().getId() : null;
            Long languageId = entity.getLanguage() != null ? entity.getLanguage().getId() : null;
            Long municipalityId = entity.getMunicipality() != null ? entity.getMunicipality().getId() : null;
            Long schoolId = entity.getSchool() != null ? entity.getSchool().getId() : null;
            Long activityTypeId = entity.getActivityType() != null ? entity.getActivityType().getId() : null;
            Long examinationTypeId = entity.getExaminationType() != null ? entity.getExaminationType().getId() : null;
            Long educationalLevelId = entity.getEducationalLevel() != null ? entity.getEducationalLevel().getId() : null;
            Long studyProgrammeId = entity.getStudyProgramme() != null ? entity.getStudyProgramme().getId() : null;
            Long studyEndReasonId = entity.getStudyEndReason() != null ? entity.getStudyEndReason().getId() : null;
            Long curriculumId = entity.getCurriculum() != null ? entity.getCurriculum().getId() : null;
            List<String> tags = new ArrayList<>();
            Set<Tag> entityTags = entity.getTags();
            if (entityTags != null) {
                for (Tag entityTag : entityTags) {
                    tags.add(entityTag.getText());
                }
            }
            List<UserVariable> entityVariables = userController.listUserVariablesByUser(entity);
            Map<String, String> variables = new HashMap<>();
            for (UserVariable entityVariable : entityVariables) {
                variables.put(entityVariable.getKey().getVariableKey(), entityVariable.getValue());
            }
            ;
            String additionalContectInfo = entity.getContactInfo() != null ? entity.getContactInfo().getAdditionalInfo() : null;
            // TODO Remove this from the rest model
            boolean lodging = false;
            return new fi.otavanopisto.pyramus.rest.model.Student(entity.getId(), personId, entity.getFirstName(), entity.getLastName(), entity.getNickname(), entity.getAdditionalInfo(), additionalContectInfo, nationalityId, languageId, municipalityId, schoolId, activityTypeId, examinationTypeId, educationalLevelId, toOffsetDateTime(entity.getStudyTimeEnd()), studyProgrammeId, curriculumId, entity.getPreviousStudies(), entity.getEducation(), lodging, toOffsetDateTime(entity.getStudyStartDate()), toOffsetDateTime(entity.getStudyEndDate()), studyEndReasonId, entity.getStudyEndText(), variables, tags, entity.getArchived());
        }
    }, new Mapper<StudentStudyEndReason>() {

        @Override
        public Object map(StudentStudyEndReason entity) {
            Long parentReasonId = entity.getParentReason() != null ? entity.getParentReason().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.StudentStudyEndReason(entity.getId(), entity.getName(), parentReasonId);
        }
    }, new Mapper<StudentContactLogEntry>() {

        @Override
        public Object map(StudentContactLogEntry entity) {
            StudentContactLogEntryType type = StudentContactLogEntryType.valueOf(entity.getType().name());
            return new fi.otavanopisto.pyramus.rest.model.StudentContactLogEntry(entity.getId(), entity.getText(), entity.getCreatorName(), toOffsetDateTime(entity.getEntryDate()), type, entity.getArchived());
        }
    }, new Mapper<StudentGroupStudent>() {

        @Override
        public Object map(StudentGroupStudent entity) {
            Long studentId = entity.getStudent() != null ? entity.getStudent().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.StudentGroupStudent(entity.getId(), studentId);
        }
    }, new Mapper<StudentGroupUser>() {

        @Override
        public Object map(StudentGroupUser entity) {
            Long staffMemberId = entity.getStaffMember() != null ? entity.getStaffMember().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.StudentGroupUser(entity.getId(), staffMemberId);
        }
    }, new Mapper<Email>() {

        @Override
        public Object map(Email entity) {
            Long contactTypeId = entity.getContactType() != null ? entity.getContactType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.Email(entity.getId(), contactTypeId, entity.getDefaultAddress(), entity.getAddress());
        }
    }, new Mapper<PhoneNumber>() {

        @Override
        public Object map(PhoneNumber entity) {
            Long contactTypeId = entity.getContactType() != null ? entity.getContactType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.PhoneNumber(entity.getId(), contactTypeId, entity.getDefaultNumber(), entity.getNumber());
        }
    }, new Mapper<ContactURL>() {

        @Override
        public Object map(ContactURL entity) {
            Long contactURLTypeId = entity.getContactURLType() != null ? entity.getContactURLType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.ContactURL(entity.getId(), contactURLTypeId, entity.getURL());
        }
    }, new Mapper<Address>() {

        @Override
        public Object map(Address entity) {
            Long contactTypeId = entity.getContactType() != null ? entity.getContactType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.Address(entity.getId(), contactTypeId, entity.getDefaultAddress(), entity.getName(), entity.getStreetAddress(), entity.getPostalCode(), entity.getCity(), entity.getCountry());
        }
    }, new Mapper<ContactType>() {

        @Override
        public Object map(ContactType entity) {
            return new fi.otavanopisto.pyramus.rest.model.ContactType(entity.getId(), entity.getName(), entity.getArchived(), entity.getNonUnique());
        }
    }, new Mapper<ContactURLType>() {

        @Override
        public Object map(ContactURLType entity) {
            return new fi.otavanopisto.pyramus.rest.model.ContactURLType(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<UserVariableKey>() {

        @Override
        public Object map(UserVariableKey entity) {
            return new fi.otavanopisto.pyramus.rest.model.VariableKey(entity.getVariableKey(), entity.getVariableName(), entity.getUserEditable(), toVariableType(entity.getVariableType()));
        }
    }, new Mapper<CourseStaffMemberRole>() {

        @Override
        public Object map(CourseStaffMemberRole entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseStaffMemberRole(entity.getId(), entity.getName());
        }
    }, new Mapper<CourseStaffMember>() {

        @Override
        public Object map(CourseStaffMember entity) {
            Long courseId = entity.getCourse() != null ? entity.getCourse().getId() : null;
            Long userId = entity.getStaffMember() != null ? entity.getStaffMember().getId() : null;
            Long roleId = entity.getRole() != null ? entity.getRole().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.CourseStaffMember(entity.getId(), courseId, userId, roleId);
        }
    }, new Mapper<CourseStudent>() {

        @Override
        public Object map(CourseStudent entity) {
            Long courseId = entity.getCourse() != null ? entity.getCourse().getId() : null;
            Long studentId = entity.getStudent() != null ? entity.getStudent().getId() : null;
            Long participantTypeId = entity.getParticipationType() != null ? entity.getParticipationType().getId() : null;
            Long courseEnrolmentTypeId = entity.getCourseEnrolmentType() != null ? entity.getCourseEnrolmentType().getId() : null;
            CourseOptionality optionality = entity.getOptionality() != null ? CourseOptionality.valueOf(entity.getOptionality().name()) : null;
            Long billingDetailsId = entity.getBillingDetails() != null ? entity.getBillingDetails().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.CourseStudent(entity.getId(), courseId, studentId, toOffsetDateTime(entity.getEnrolmentTime()), entity.getArchived(), participantTypeId, courseEnrolmentTypeId, entity.getLodging(), optionality, billingDetailsId);
        }
    }, new Mapper<StaffMember>() {

        public Object map(StaffMember entity) {
            List<String> tags = new ArrayList<>();
            Set<Tag> entityTags = entity.getTags();
            if (entityTags != null) {
                for (Tag entityTag : entityTags) {
                    tags.add(entityTag.getText());
                }
            }
            List<UserVariable> entityVariables = userController.listUserVariablesByUser(entity);
            Map<String, String> variables = new HashMap<>();
            for (UserVariable entityVariable : entityVariables) {
                variables.put(entityVariable.getKey().getVariableKey(), entityVariable.getValue());
            }
            ;
            UserRole role = UserRole.valueOf(entity.getRole().name());
            String additionalContactInfo = entity.getContactInfo() != null ? entity.getContactInfo().getAdditionalInfo() : null;
            Long personId = entity.getPerson() != null ? entity.getPerson().getId() : null;
            Long organizationId = entity.getOrganization() != null ? entity.getOrganization().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.StaffMember(entity.getId(), personId, organizationId, additionalContactInfo, entity.getFirstName(), entity.getLastName(), entity.getTitle(), role, tags, variables);
        }
    }, new Mapper<fi.otavanopisto.pyramus.domainmodel.base.Curriculum>() {

        @Override
        public Object map(fi.otavanopisto.pyramus.domainmodel.base.Curriculum entity) {
            return new Curriculum(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<fi.otavanopisto.pyramus.domainmodel.base.Organization>() {

        @Override
        public Object map(Organization entity) {
            BillingDetails billingDetails = entity.getBillingDetails();
            fi.otavanopisto.pyramus.rest.model.BillingDetails billingDetailsRestModel = null;
            if (billingDetails != null) {
                billingDetailsRestModel = new fi.otavanopisto.pyramus.rest.model.BillingDetails(billingDetails.getId(), billingDetails.getPersonName(), billingDetails.getCompanyName(), billingDetails.getStreetAddress1(), billingDetails.getStreetAddress2(), billingDetails.getPostalCode(), billingDetails.getCity(), billingDetails.getRegion(), billingDetails.getCountry(), billingDetails.getPhoneNumber(), billingDetails.getEmailAddress(), billingDetails.getCompanyIdentifier(), billingDetails.getReferenceNumber(), billingDetails.getElectronicBillingAddress(), billingDetails.getElectronicBillingOperator(), billingDetails.getNotes());
            }
            List<OrganizationContractPeriod> contractPeriods = organizationContractPeriodDAO.listBy(entity);
            List<fi.otavanopisto.pyramus.rest.model.OrganizationContractPeriod> contractPeriodsModel = contractPeriods.stream().map(contractPeriod -> {
                Long id = contractPeriod.getId();
                LocalDate begin = contractPeriod.getBegin() != null ? new java.sql.Date(contractPeriod.getBegin().getTime()).toLocalDate() : null;
                LocalDate end = contractPeriod.getEnd() != null ? new java.sql.Date(contractPeriod.getEnd().getTime()).toLocalDate() : null;
                return new fi.otavanopisto.pyramus.rest.model.OrganizationContractPeriod(id, begin, end);
            }).collect(Collectors.toList());
            List<OrganizationContactPerson> contactPersons = organizationContactPersonDAO.listBy(entity);
            List<fi.otavanopisto.pyramus.rest.model.OrganizationContactPerson> contactPersonsModel = contactPersons.stream().map(contactPerson -> {
                Long id = contactPerson.getId();
                OrganizationContactPersonType type = contactPerson.getType() != null ? OrganizationContactPersonType.valueOf(contactPerson.getType().name()) : null;
                String name = contactPerson.getName();
                String email = contactPerson.getEmail();
                String phone = contactPerson.getPhone();
                String title = contactPerson.getTitle();
                return new fi.otavanopisto.pyramus.rest.model.OrganizationContactPerson(id, type, name, email, phone, title);
            }).collect(Collectors.toList());
            fi.otavanopisto.pyramus.rest.model.Organization organizationModel = new fi.otavanopisto.pyramus.rest.model.Organization(entity.getId(), entity.getName(), billingDetailsRestModel, entity.getArchived());
            organizationModel.setContactPersons(contactPersonsModel);
            organizationModel.setContractPeriods(contractPeriodsModel);
            return organizationModel;
        }
    }, new Mapper<fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriod>() {

        @Override
        public Object map(StudentStudyPeriod entity) {
            Long studentId = entity.getStudent() != null ? entity.getStudent().getId() : null;
            StudentStudyPeriodType type = entity.getPeriodType() != null ? StudentStudyPeriodType.valueOf(entity.getPeriodType().toString()) : null;
            LocalDate begin = entity.getBegin() != null ? Instant.ofEpochMilli(entity.getBegin().getTime()).atZone(ZoneId.systemDefault()).toLocalDate() : null;
            LocalDate end = entity.getEnd() != null ? Instant.ofEpochMilli(entity.getEnd().getTime()).atZone(ZoneId.systemDefault()).toLocalDate() : null;
            return new fi.otavanopisto.pyramus.rest.model.students.StudentStudyPeriod(entity.getId(), studentId, type, begin, end);
        }
    }, new Mapper<fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudentGroup>() {

        @Override
        public Object map(CourseSignupStudentGroup entity) {
            Long courseId = entity.getCourse() != null ? entity.getCourse().getId() : null;
            Long studentGroupId = entity.getStudentGroup() != null ? entity.getStudentGroup().getId() : null;
            String studentGroupName = entity.getStudentGroup() != null ? entity.getStudentGroup().getName() : null;
            Organization studentGroupOrganization = entity.getStudentGroup() != null ? entity.getStudentGroup().getOrganization() : null;
            fi.otavanopisto.pyramus.rest.model.OrganizationBasicInfo organization = studentGroupOrganization != null ? new fi.otavanopisto.pyramus.rest.model.OrganizationBasicInfo(studentGroupOrganization.getId(), studentGroupOrganization.getName(), studentGroupOrganization.getArchived()) : null;
            return new fi.otavanopisto.pyramus.rest.model.course.CourseSignupStudentGroup(entity.getId(), courseId, studentGroupId, studentGroupName, organization);
        }
    }, new Mapper<fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudyProgramme>() {

        @Override
        public Object map(CourseSignupStudyProgramme entity) {
            Long courseId = entity.getCourse() != null ? entity.getCourse().getId() : null;
            Long studyProgrammeId = entity.getStudyProgramme() != null ? entity.getStudyProgramme().getId() : null;
            String studyProgrammeName = entity.getStudyProgramme() != null ? entity.getStudyProgramme().getName() : null;
            Organization studyProgrammeOrganization = entity.getStudyProgramme() != null ? entity.getStudyProgramme().getOrganization() : null;
            fi.otavanopisto.pyramus.rest.model.OrganizationBasicInfo organization = studyProgrammeOrganization != null ? new fi.otavanopisto.pyramus.rest.model.OrganizationBasicInfo(studyProgrammeOrganization.getId(), studyProgrammeOrganization.getName(), studyProgrammeOrganization.getArchived()) : null;
            return new fi.otavanopisto.pyramus.rest.model.course.CourseSignupStudyProgramme(entity.getId(), courseId, studyProgrammeId, studyProgrammeName, organization);
        }
    });
}
Also used : UserVariable(fi.otavanopisto.pyramus.domainmodel.users.UserVariable) LocalDate(java.time.LocalDate) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) OrganizationContactPersonType(fi.otavanopisto.pyramus.rest.model.OrganizationContactPersonType) Set(java.util.Set) HashSet(java.util.HashSet) Sex(fi.otavanopisto.pyramus.rest.model.Sex) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) ContactURL(fi.otavanopisto.pyramus.domainmodel.base.ContactURL) CourseEnrolmentType(fi.otavanopisto.pyramus.domainmodel.courses.CourseEnrolmentType) CourseBaseVariableKey(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) Curriculum(fi.otavanopisto.pyramus.rest.model.Curriculum) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) CourseSignupStudentGroup(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudentGroup) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) OrganizationContactPerson(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContactPerson) StudentEducationalLevel(fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) CourseSignupStudyProgramme(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudyProgramme) ArrayList(java.util.ArrayList) List(java.util.List) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) OffsetDateTime(java.time.OffsetDateTime) StudentActivityType(fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType) CourseOptionality(fi.otavanopisto.pyramus.rest.model.CourseOptionality) SchoolVariable(fi.otavanopisto.pyramus.domainmodel.base.SchoolVariable) School(fi.otavanopisto.pyramus.domainmodel.base.School) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) CourseSignupStudentGroup(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudentGroup) SchoolField(fi.otavanopisto.pyramus.domainmodel.base.SchoolField) BillingDetails(fi.otavanopisto.pyramus.domainmodel.base.BillingDetails) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) ProjectModuleOptionality(fi.otavanopisto.pyramus.rest.model.ProjectModuleOptionality) UserRole(fi.otavanopisto.pyramus.rest.model.UserRole) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) OrganizationContractPeriod(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContractPeriod) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) UserVariableKey(fi.otavanopisto.pyramus.domainmodel.users.UserVariableKey) StudentStudyEndReason(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason) CourseBaseVariable(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) StudyProgrammeCategory(fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) ModuleComponent(fi.otavanopisto.pyramus.domainmodel.modules.ModuleComponent) StudentStudyPeriodType(fi.otavanopisto.pyramus.rest.model.students.StudentStudyPeriodType) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) Map(java.util.Map) HashMap(java.util.HashMap) OrganizationContactPerson(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContactPerson) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) CourseSignupStudyProgramme(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudyProgramme) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) CourseType(fi.otavanopisto.pyramus.domainmodel.courses.CourseType) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentStudyPeriod(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriod) GradingScale(fi.otavanopisto.pyramus.domainmodel.grading.GradingScale) CourseStaffMemberRole(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMemberRole) StudentContactLogEntry(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntry) CourseDescription(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescription) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) StudentExaminationType(fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) SchoolVariableKey(fi.otavanopisto.pyramus.domainmodel.base.SchoolVariableKey) StudentContactLogEntryType(fi.otavanopisto.pyramus.rest.model.StudentContactLogEntryType) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) CourseDescriptionCategory(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescriptionCategory) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType) Date(java.util.Date) LocalDate(java.time.LocalDate) AcademicTerm(fi.otavanopisto.pyramus.rest.model.AcademicTerm) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) StudentGroupUser(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupUser) PostConstruct(javax.annotation.PostConstruct)

Example 7 with CourseStaffMember

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember in project pyramus by otavanopisto.

the class CourseUserEntityFactory method buildFromDomainObject.

public CourseUserEntity buildFromDomainObject(Object domainObject) {
    if (domainObject == null) {
        return null;
    }
    CourseStaffMember courseUser = (CourseStaffMember) domainObject;
    CourseEntity course = EntityFactoryVault.buildFromDomainObject(courseUser.getCourse());
    UserEntity user = EntityFactoryVault.buildFromDomainObject(courseUser.getStaffMember());
    CourseUserRoleEntity role = EntityFactoryVault.buildFromDomainObject(courseUser.getRole());
    return new CourseUserEntity(courseUser.getId(), course, user, role);
}
Also used : CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) UserEntity(fi.pyramus.services.entities.users.UserEntity)

Example 8 with CourseStaffMember

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember in project pyramus by otavanopisto.

the class EditCourseJSONRequestController method process.

/**
 * Processes the request to edit a course.
 * The request should contain the following parameters:
 * <dl>
 *   <dt><code>name</code></dt>
 *   <dd>The name of the course.</dd>
 *   <dt><code>nameExtension</code></dt>
 *   <dd>The name extension of the course.</dd>
 *   <dt><code>state</code></dt>
 *   <dd>The ID of the initial course state.</dd>
 *   <dt><code>description</code></dt>
 *   <dd>The description of the course, in HTML.</dd>
 *   <dt><code>module</code></dt>
 *   <dd>The ID of the module the course is associated with.</dd>
 *   <dt><code>subject</code></dt>
 *   <dd>The ID of the subject of the course.</dd>
 *   <dt><code>courseNumber</code></dt>
 *   <dd>The course number of the course.</dd>
 *   <dt><code>beginDate</code></dt>
 *   <dd>The beginning date of the course, as a timestamp in ms.</dd>
 *   <dt><code>endDate</code></dt>
 *   <dd>The end date of the course, as a timestamp in ms.</dd>
 *   <dt><code>enrolmentTimeEnd</code></dt>
 *   <dd>The time when enrollment for the course ends, as a timestamp in ms.</dd>
 *   <dt><code>courseLength</code></dt>
 *   <dd>The length of the course, in units specified in <code>courseLengthTimeUnit</code>.</dd>
 *   <dt><code>courseLengthTimeUnit</code></dt>
 *   <dd>The ID of the time unit for the courses.</dd>
 *   <dt><code>maxParticipantCount</code></dt>
 *   <dd>The maximum number of participants for this course.</dd>
 *   <dt><code>distanceTeachingDays</code></dt>
 *   <dd>The number of days of distance teaching.</dd>
 *   <dt><code>localTeachingDays</code></dt>
 *   <dd>The number of days of local teaching.</dd>
 *   <dt><code>teachingHours</code></dt>
 *   <dd>The total number of teaching hours.</dd>
 *   <dt><code>planningHours</code></dt>
 *   <dd>The total number of hours used for planning.
 *   <dt><code>assessingHours</code></dt>
 *   <dd>The total number of hours used for assessing.
 *   <dt><code>tags</code></dt>
 *   <dd>The tags associated with the course, separated by spaces.</dd>
 * </dl>
 * The following are not single but multiple parameters, arranged
 * as collections of objects. Each parameter is defined by the
 * following scheme (zero indexed):<br/>
 * <code>
 * <i>collection name</i>.<i>property name</i>
 * </code>
 * or<br/>
 * <code>
 * <i>collection name</i>.<i>object index</i>.<i>property name</i>
 * </code>
 * <dl>
 *   <dt><code>courseDescription.*.catId</code></dt>
 *   <dd>The course description category ID to add the description to.
 *   <dt><code>courseDescription.*.text</code></dt>
 *   <dd>The description of the course.</dd>
 *   <dt><code>personnelTable.rowCount</code></dt>
 *   <dd>The number of personnel in the course.</dd>
 *   <dt><code>personnelTable.*.userId</code></dt>
 *   <dd>The ID of the user in the personnel table.</dd>
 *   <dt><code>personnelTable.*.roleId</code></dt>
 *   <dd>The role ID of the user in the personnel table.</dd>
 *   <dt><code>components.componentCount</code></dt>
 *   <dd>The number of course components in this course.</dd>
 *   <dt><code>components.*.0.name</code></dt>
 *   <dd>The name of the course component.</dd>
 *   <dt><code>components.*.0.length</code></dt>
 *   <dd>The length of the course component, in default time units.</dd>
 *   <dt><code>components.*.0.description</code></dt>
 *   <dd>The description of the course component.</dd>
 *   <dt><code>components.*.resourceCategoryCount</code></dt>
 *   <dd>The number of resource categories in the course component.</dd>
 *   <dt><code>components.*.*.resources.rowCount</code></dt>
 *   <dd>The number of resources in the resource category.</dd>
 *   <dt><code>components.*.*.resources.*.resourceId</code></dt>
 *   <dd>The ID of the resource.</dd>
 *   <dt><code>components.*.*.resources.*.quantity</code></dt>
 *   <dd>The quantity of the resource.</dd>
 *   <dt><code>components.*.*.resources.*.usage</code></dt>
 *   <dd>The usage of the resource.</dd>
 *   <dt><code>educationType.*.*</code></dt>
 *   <dd>The education types and subtypes (as numerical IDs) of the course.</dd>
 *   <dt><code>basicResourcesTable.rowCount</code></dt>
 *   <dd>The number of basic resources associated with the course.</dd>
 *   <dt><code>basicResourcesTable.*.hours</code></dt>
 *   <dd>The number of hours the resource is used.</dd>
 *   <dt><code>basicResourcesTable.*.hourlyCost</code></dt>
 *   <dd>The hourly cost of the resource.</dd>
 *   <dt><code>basicResourcesTable.*.units</code></dt>
 *   <dd>The number of units of the resource used.</dd>
 *   <dt><code>basicResourcesTable.*.unitCost</code></dt>
 *   <dd>The cost of a single unit of the resource.</dd>
 *   <dt><code>basicResourcesTable.*.resourceId</code></dt>
 *   <dd>The ID of the resource.</dd>
 *   <dt><code>studentResourcesTable.rowCount</code></dt>
 *   <dd>The number of student resources associated with the course.</dd>
 *   <dt><code>studentResourcesTable.*.hours</code></dt>
 *   <dd>The number of hours the resource is used.</dd>
 *   <dt><code>studentResourcesTable.*.hourlyCost</code></dt>
 *   <dd>The hourly cost of the resource.</dd>
 *   <dt><code>studentResourcesTable.*.unitCost</code></dt>
 *   <dd>The cost of a single unit of the resource.</dd>
 *   <dt><code>studentResourcesTable.*.resourceId</code></dt>
 *   <dd>The ID of the resource.</dd>
 *   <dt><code>gradeResourcesTable.rowCount</code></dt>
 *   <dd>The number of grade resources associated with the course.</dd>
 *   <dt><code>gradeResourcesTable.*.hours</code></dt>
 *   <dd>The number of hours the resource is used.</dd>
 *   <dt><code>gradeResourcesTable.*.hourlyCost</code></dt>
 *   <dd>The hourly cost of the resource.</dd>
 *   <dt><code>gradeResourcesTable.*.unitCost</code></dt>
 *   <dd>The cost of a single unit of the resource.</dd>
 *   <dt><code>gradeResourcesTable.*.resourceId</code></dt>
 *   <dd>The ID of the resource.</dd>
 *   <dt><code>otherCostsTable.rowCount</code></dt>
 *   <dd>The number of other costs associated with this course.</dd>
 *   <dt><code>otherCostsTable.*.name</code></dt>
 *   <dd>The name of the cost.</dd>
 *   <dt><code>otherCostsTable.*.count</code></dt>
 *   <dd>The amount of the cost.</dd>
 *   <dt><code>studentsTable.rowCount</code></dt>
 *   <dd>The number of students attending this course.</dd>
 *   <dt><code>studentsTable.*.studentId</code></dt>
 *   <dd>The ID of the student.</dd>
 *   <dt><code>studentsTable.*.enrolmentDate</code></dt>
 *   <dd>The enrollment date of the student, as a timestamp in ms.</dd>
 *   <dt><code>studentsTable.*.enrolmentType</code></dt>
 *   <dd>The ID of the enrollment type of the student.</dd>
 *   <dt><code>studentsTable.*.participationType</code></dt>
 *   <dd>The ID of the participation type of the student.</dd>
 *   <dt><code>studentsTable.*.lodging</code></dt>
 *   <dd><code>true</code> if the student is lodging on campus.</dd>
 *   <dt><code>studentsTable.*.optionality</code></dt>
 *   <dd>The optionality of the course for the student:
 *   <code>MANDATORY</code> or <code>OPTIONAL</code></dd>
 * </dl>
 *
 * @param requestContext The JSON request context
 */
public void process(JSONRequestContext requestContext) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    ResourceDAO resourceDAO = DAOFactory.getInstance().getResourceDAO();
    CourseDescriptionDAO courseDescriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
    CourseParticipationTypeDAO participationTypeDAO = DAOFactory.getInstance().getCourseParticipationTypeDAO();
    CourseComponentResourceDAO componentResourceDAO = DAOFactory.getInstance().getCourseComponentResourceDAO();
    CourseEnrolmentTypeDAO enrolmentTypeDAO = DAOFactory.getInstance().getCourseEnrolmentTypeDAO();
    CourseComponentDAO componentDAO = DAOFactory.getInstance().getCourseComponentDAO();
    CourseStaffMemberDAO courseStaffMemberDAO = DAOFactory.getInstance().getCourseStaffMemberDAO();
    CourseStaffMemberRoleDAO courseStaffMemberRoleDAO = DAOFactory.getInstance().getCourseStaffMemberRoleDAO();
    CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
    CourseDescriptionCategoryDAO descriptionCategoryDAO = DAOFactory.getInstance().getCourseDescriptionCategoryDAO();
    OtherCostDAO otherCostDAO = DAOFactory.getInstance().getOtherCostDAO();
    BasicCourseResourceDAO basicCourseResourceDAO = DAOFactory.getInstance().getBasicCourseResourceDAO();
    StudentCourseResourceDAO studentCourseResourceDAO = DAOFactory.getInstance().getStudentCourseResourceDAO();
    GradeCourseResourceDAO gradeCourseResourceDAO = DAOFactory.getInstance().getGradeCourseResourceDAO();
    CourseEducationTypeDAO courseEducationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
    CourseEducationSubtypeDAO courseEducationSubtypeDAO = DAOFactory.getInstance().getCourseEducationSubtypeDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    CourseTypeDAO courseTypeDAO = DAOFactory.getInstance().getCourseTypeDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    Locale locale = requestContext.getRequest().getLocale();
    StaffMember loggedUser = staffMemberDAO.findById(requestContext.getLoggedUserId());
    Organization organization = organizationDAO.findById(requestContext.getLong("organizationId"));
    if (!UserUtils.canAccessOrganization(loggedUser, organization)) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid organization.");
    }
    // Course basic information
    Long courseId = requestContext.getLong("course");
    Course course = courseDAO.findById(courseId);
    String name = requestContext.getString("name");
    String nameExtension = requestContext.getString("nameExtension");
    Long courseStateId = requestContext.getLong("state");
    Long courseTypeId = requestContext.getLong("type");
    Long maxParticipantCount = requestContext.getLong("maxParticipantCount");
    Date enrolmentTimeEnd = requestContext.getDate("enrolmentTimeEnd");
    CourseState courseState = courseStateId == null ? course.getState() : courseStateDAO.findById(courseStateId);
    CourseType courseType = courseTypeId != null ? courseTypeDAO.findById(courseTypeId) : null;
    String description = requestContext.getString("description");
    Subject subject = subjectDAO.findById(requestContext.getLong("subject"));
    Integer courseNumber = requestContext.getInteger("courseNumber");
    Date beginDate = requestContext.getDate("beginDate");
    Date endDate = requestContext.getDate("endDate");
    Double courseLength = requestContext.getDouble("courseLength");
    EducationalTimeUnit courseLengthTimeUnit = educationalTimeUnitDAO.findById(requestContext.getLong("courseLengthTimeUnit"));
    Double distanceTeachingDays = requestContext.getDouble("distanceTeachingDays");
    Double localTeachingDays = requestContext.getDouble("localTeachingDays");
    Double teachingHours = requestContext.getDouble("teachingHours");
    Double distanceTeachingHours = requestContext.getDouble("distanceTeachingHours");
    Double planningHours = requestContext.getDouble("planningHours");
    Double assessingHours = requestContext.getDouble("assessingHours");
    String tagsText = requestContext.getString("tags");
    BigDecimal courseFee = requestContext.getBigDecimal("courseFee");
    Currency courseFeeCurrency = requestContext.getCurrency("courseFeeCurrency");
    Long version = requestContext.getLong("version");
    if (!course.getVersion().equals(version))
        throw new StaleObjectStateException(Course.class.getName(), course.getId());
    List<Curriculum> allCurriculums = curriculumDAO.listUnarchived();
    Set<Curriculum> curriculums = new HashSet<>();
    for (Curriculum curriculum : allCurriculums) {
        if ("1".equals(requestContext.getString("curriculum." + curriculum.getId()))) {
            curriculums.add(curriculum);
        }
    }
    Set<Tag> tagEntities = new HashSet<>();
    if (!StringUtils.isBlank(tagsText)) {
        List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
        for (String tag : tags) {
            if (!StringUtils.isBlank(tag)) {
                Tag tagEntity = tagDAO.findByText(tag.trim());
                if (tagEntity == null)
                    tagEntity = tagDAO.create(tag);
                tagEntities.add(tagEntity);
            }
        }
    }
    StaffMember staffMember = userDAO.findById(requestContext.getLoggedUserId());
    courseDAO.update(course, organization, name, nameExtension, courseState, courseType, subject, courseNumber, beginDate, endDate, courseLength, courseLengthTimeUnit, distanceTeachingDays, localTeachingDays, teachingHours, distanceTeachingHours, planningHours, assessingHours, description, maxParticipantCount, enrolmentTimeEnd, staffMember);
    courseDAO.updateCurriculums(course, curriculums);
    if (Role.ADMINISTRATOR.equals(loggedUser.getRole())) {
        Boolean isCourseTemplate = requestContext.getBoolean("isCourseTemplate");
        courseDAO.updateCourseTemplate(course, Boolean.TRUE.equals(isCourseTemplate));
    }
    Long moduleId = requestContext.getLong("moduleId");
    Long currentModuleId = course.getModule() != null ? course.getModule().getId() : null;
    if ((moduleId != null) && (!moduleId.equals(currentModuleId))) {
        Module module = moduleDAO.findById(moduleId);
        courseDAO.updateModule(course, module);
    }
    courseDAO.updateCourseFee(course, courseFee, courseFeeCurrency, staffMember);
    // Tags
    courseDAO.setCourseTags(course, tagEntities);
    // Education types and subtypes submitted from the web page
    Map<Long, Vector<Long>> chosenEducationTypes = new HashMap<>();
    Enumeration<String> parameterNames = requestContext.getRequest().getParameterNames();
    while (parameterNames.hasMoreElements()) {
        name = (String) parameterNames.nextElement();
        if (name.startsWith("educationType.")) {
            String[] nameElements = name.split("\\.");
            Long educationTypeId = new Long(nameElements[1]);
            Long educationSubtypeId = new Long(nameElements[2]);
            Vector<Long> v = chosenEducationTypes.containsKey(educationTypeId) ? chosenEducationTypes.get(educationTypeId) : new Vector<Long>();
            v.add(educationSubtypeId);
            if (!chosenEducationTypes.containsKey(educationTypeId)) {
                chosenEducationTypes.put(educationTypeId, v);
            }
        }
    }
    // Remove education types and subtypes
    List<CourseEducationType> courseEducationTypes = course.getCourseEducationTypes();
    for (int i = courseEducationTypes.size() - 1; i >= 0; i--) {
        CourseEducationType courseEducationType = courseEducationTypes.get(i);
        if (!chosenEducationTypes.containsKey(courseEducationType.getEducationType().getId())) {
            courseEducationTypeDAO.delete(courseEducationType);
        } else {
            Vector<Long> v = chosenEducationTypes.get(courseEducationType.getEducationType().getId());
            List<CourseEducationSubtype> courseEducationSubtypes = courseEducationType.getCourseEducationSubtypes();
            for (int j = courseEducationSubtypes.size() - 1; j >= 0; j--) {
                CourseEducationSubtype courseEducationSubtype = courseEducationSubtypes.get(j);
                if (!v.contains(courseEducationSubtype.getEducationSubtype().getId())) {
                    courseEducationType.removeSubtype(courseEducationSubtype);
                }
            }
        }
    }
    for (Map.Entry<Long, Vector<Long>> entry : chosenEducationTypes.entrySet()) {
        EducationType educationType = educationTypeDAO.findById(entry.getKey());
        CourseEducationType courseEducationType;
        if (!course.contains(educationType)) {
            courseEducationType = courseEducationTypeDAO.create(course, educationType);
        } else {
            courseEducationType = course.getCourseEducationTypeByEducationTypeId(entry.getKey());
        }
        for (Long educationSubtypeId : entry.getValue()) {
            EducationSubtype educationSubtype = educationSubtypeDAO.findById(educationSubtypeId);
            if (!courseEducationType.contains(educationSubtype)) {
                courseEducationSubtypeDAO.create(courseEducationType, educationSubtype);
            }
        }
    }
    // Course Descriptions
    List<CourseDescriptionCategory> descriptionCategories = descriptionCategoryDAO.listUnarchived();
    Set<CourseDescription> nonExistingDescriptions = new HashSet<>();
    for (CourseDescriptionCategory cat : descriptionCategories) {
        String varName = "courseDescription." + cat.getId().toString();
        Long descriptionCatId = requestContext.getLong(varName + ".catId");
        String descriptionText = requestContext.getString(varName + ".text");
        CourseDescription oldDesc = descriptionDAO.findByCourseAndCategory(course, cat);
        if (descriptionCatId != null && descriptionCatId.intValue() != -1) {
            // Description has been submitted from form
            if (oldDesc != null)
                descriptionDAO.update(oldDesc, course, cat, descriptionText);
            else
                descriptionDAO.create(course, cat, descriptionText);
        } else {
            // Description wasn't submitted from form, if it exists, it's marked for deletion
            if (oldDesc != null)
                nonExistingDescriptions.add(oldDesc);
        }
    }
    // Delete non existing descriptions
    for (CourseDescription desc : nonExistingDescriptions) {
        courseDescriptionDAO.delete(desc);
    }
    // Personnel
    Set<Long> existingIds = new HashSet<>();
    int rowCount = requestContext.getInteger("personnelTable.rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "personnelTable." + i;
        Long courseUserId = requestContext.getLong(colPrefix + ".courseUserId");
        Long userId = requestContext.getLong(colPrefix + ".userId");
        Long roleId = requestContext.getLong(colPrefix + ".roleId");
        staffMember = userDAO.findById(userId);
        CourseStaffMemberRole role = courseStaffMemberRoleDAO.findById(roleId);
        if (courseUserId == -1) {
            courseUserId = courseStaffMemberDAO.create(course, staffMember, role).getId();
        } else {
            courseStaffMemberDAO.updateRole(courseStaffMemberDAO.findById(courseUserId), role);
        }
        existingIds.add(courseUserId);
    }
    List<CourseStaffMember> courseUsers = courseStaffMemberDAO.listByCourse(courseDAO.findById(courseId));
    for (CourseStaffMember courseUser : courseUsers) {
        if (!existingIds.contains(courseUser.getId())) {
            courseStaffMemberDAO.delete(courseUser);
        }
    }
    // Course components
    rowCount = requestContext.getInteger("components.componentCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "components.component." + i;
        Long componentId = requestContext.getLong(colPrefix + ".0.componentId");
        String componentName = requestContext.getString(colPrefix + ".0.name");
        Double componentLength = requestContext.getDouble(colPrefix + ".0.length");
        String componentDescription = requestContext.getString(colPrefix + ".0.description");
        // TODO Component length; should be just hours but it currently depends on the default time unit - ok?
        EducationalTimeUnit componentTimeUnit = defaultsDAO.getDefaults().getBaseTimeUnit();
        CourseComponent courseComponent;
        if (componentId == -1) {
            courseComponent = componentDAO.create(course, componentLength, componentTimeUnit, componentName, componentDescription);
        } else {
            courseComponent = componentDAO.update(componentDAO.findById(componentId), componentLength, componentTimeUnit, componentName, componentDescription);
        }
        Long resourceCategoryCount = requestContext.getLong(colPrefix + ".resourceCategoryCount");
        for (int categoryIndex = 0; categoryIndex < resourceCategoryCount; categoryIndex++) {
            String resourcesPrefix = colPrefix + "." + categoryIndex + ".resources";
            Long resourcesCount = requestContext.getLong(resourcesPrefix + ".rowCount");
            for (int j = 0; j < resourcesCount; j++) {
                String resourcePrefix = resourcesPrefix + "." + j;
                Long id = requestContext.getLong(resourcePrefix + ".id");
                Long resourceId = requestContext.getLong(resourcePrefix + ".resourceId");
                Resource resource = resourceDAO.findById(resourceId);
                Double usagePercent;
                if (resource.getResourceType() == ResourceType.MATERIAL_RESOURCE) {
                    usagePercent = requestContext.getDouble(resourcePrefix + ".quantity") * 100;
                } else {
                    usagePercent = requestContext.getDouble(resourcePrefix + ".usage");
                }
                if (id == -1) {
                    componentResourceDAO.create(courseComponent, resource, usagePercent);
                } else {
                    CourseComponentResource courseComponentResource = componentResourceDAO.findById(id);
                    componentResourceDAO.updateUsagePercent(courseComponentResource, usagePercent);
                }
            }
        }
    }
    // Basic course resources
    existingIds = new HashSet<>();
    rowCount = requestContext.getInteger("basicResourcesTable.rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "basicResourcesTable." + i;
        Double hours = requestContext.getDouble(colPrefix + ".hours");
        if (hours == null) {
            hours = 0.0;
        }
        MonetaryAmount hourlyCost = new MonetaryAmount();
        hourlyCost.setAmount(requestContext.getDouble(colPrefix + ".hourlyCost"));
        Integer units = requestContext.getInteger(colPrefix + ".units");
        MonetaryAmount unitCost = new MonetaryAmount();
        unitCost.setAmount(requestContext.getDouble(colPrefix + ".unitCost"));
        Long resourceId = requestContext.getLong(colPrefix + ".resourceId");
        Resource resource = resourceDAO.findById(resourceId);
        Long basicResourceId = requestContext.getLong(colPrefix + ".basicResourceId");
        if (basicResourceId == -1) {
            basicResourceId = basicCourseResourceDAO.create(course, resource, hours, hourlyCost, units, unitCost).getId();
        } else {
            basicCourseResourceDAO.update(basicCourseResourceDAO.findById(basicResourceId), hours, hourlyCost, units, unitCost);
        }
        existingIds.add(basicResourceId);
    }
    List<BasicCourseResource> basicCourseResources = basicCourseResourceDAO.listByCourse(course);
    for (BasicCourseResource basicCourseResource : basicCourseResources) {
        if (!existingIds.contains(basicCourseResource.getId())) {
            basicCourseResourceDAO.delete(basicCourseResource);
        }
    }
    // Student course resources
    existingIds = new HashSet<>();
    rowCount = requestContext.getInteger("studentResourcesTable.rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "studentResourcesTable." + i;
        Double hours = requestContext.getDouble(colPrefix + ".hours");
        if (hours == null) {
            hours = 0.0;
        }
        MonetaryAmount hourlyCost = new MonetaryAmount();
        hourlyCost.setAmount(requestContext.getDouble(colPrefix + ".hourlyCost"));
        MonetaryAmount unitCost = new MonetaryAmount();
        hourlyCost.setAmount(requestContext.getDouble(colPrefix + ".unitCost"));
        Long resourceId = requestContext.getLong(colPrefix + ".resourceId");
        Resource resource = resourceDAO.findById(resourceId);
        Long studentResourceId = requestContext.getLong(colPrefix + ".studentResourceId");
        if (studentResourceId == -1) {
            studentResourceId = studentCourseResourceDAO.create(course, resource, hours, hourlyCost, unitCost).getId();
        } else {
            studentCourseResourceDAO.update(studentCourseResourceDAO.findById(studentResourceId), hours, hourlyCost, unitCost);
        }
        existingIds.add(studentResourceId);
    }
    List<StudentCourseResource> studentCourseResources = studentCourseResourceDAO.listByCourse(course);
    for (StudentCourseResource studentCourseResource : studentCourseResources) {
        if (!existingIds.contains(studentCourseResource.getId())) {
            studentCourseResourceDAO.delete(studentCourseResource);
        }
    }
    // Grade course resources
    existingIds = new HashSet<>();
    rowCount = requestContext.getInteger("gradeResourcesTable.rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "gradeResourcesTable." + i;
        Double hours = requestContext.getDouble(colPrefix + ".hours");
        if (hours == null) {
            hours = 0.0;
        }
        MonetaryAmount hourlyCost = new MonetaryAmount();
        hourlyCost.setAmount(requestContext.getDouble(colPrefix + ".hourlyCost"));
        MonetaryAmount unitCost = new MonetaryAmount();
        unitCost.setAmount(requestContext.getDouble(colPrefix + ".unitCost"));
        Long resourceId = requestContext.getLong(colPrefix + ".resourceId");
        Resource resource = resourceDAO.findById(resourceId);
        Long gradeResourceId = requestContext.getLong(colPrefix + ".gradeResourceId");
        if (gradeResourceId == -1) {
            gradeResourceId = gradeCourseResourceDAO.create(course, resource, hours, hourlyCost, unitCost).getId();
        } else {
            gradeCourseResourceDAO.update(gradeCourseResourceDAO.findById(gradeResourceId), hours, hourlyCost, unitCost);
        }
        existingIds.add(gradeResourceId);
    }
    List<GradeCourseResource> gradeCourseResources = gradeCourseResourceDAO.listByCourse(course);
    for (GradeCourseResource gradeCourseResource : gradeCourseResources) {
        if (!existingIds.contains(gradeCourseResource.getId())) {
            gradeCourseResourceDAO.delete(gradeCourseResource);
        }
    }
    // Other costs
    existingIds = new HashSet<>();
    rowCount = requestContext.getInteger("otherCostsTable.rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "otherCostsTable." + i;
        name = requestContext.getString(colPrefix + ".name");
        MonetaryAmount cost = new MonetaryAmount();
        cost.setAmount(requestContext.getDouble(colPrefix + ".cost"));
        Long otherCostId = requestContext.getLong(colPrefix + ".otherCostId");
        if (otherCostId == -1) {
            otherCostId = otherCostDAO.create(course, name, cost).getId();
        } else {
            otherCostDAO.update(otherCostDAO.findById(otherCostId), name, cost);
        }
        existingIds.add(otherCostId);
    }
    List<OtherCost> otherCosts = otherCostDAO.listByCourse(course);
    for (OtherCost otherCost : otherCosts) {
        if (!existingIds.contains(otherCost.getId())) {
            otherCostDAO.delete(otherCost);
        }
    }
    // Students
    existingIds = new HashSet<>();
    rowCount = requestContext.getInteger("studentsTable.rowCount");
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "studentsTable." + i;
        Long studentId = requestContext.getLong(colPrefix + ".studentId");
        Long courseStudentId = requestContext.getLong(colPrefix + ".courseStudentId");
        Date enrolmentDate = requestContext.getDate(colPrefix + ".enrolmentDate");
        Long enrolmentTypeId = requestContext.getLong(colPrefix + ".enrolmentType");
        Long participationTypeId = requestContext.getLong(colPrefix + ".participationType");
        Boolean lodging = requestContext.getBoolean(colPrefix + ".lodging");
        CourseEnrolmentType enrolmentType = enrolmentTypeId != null ? enrolmentTypeDAO.findById(enrolmentTypeId) : null;
        CourseParticipationType participationType = participationTypeId != null ? participationTypeDAO.findById(participationTypeId) : null;
        CourseStudent courseStudent;
        CourseOptionality optionality = (CourseOptionality) requestContext.getEnum(colPrefix + ".optionality", CourseOptionality.class);
        if (courseStudentId == -1) {
            /* New student */
            Student student = studentDAO.findById(studentId);
            String organizationName = null;
            String additionalInfo = null;
            Room room = null;
            BigDecimal lodgingFee = null;
            Currency lodgingFeeCurrency = null;
            BigDecimal reservationFee = null;
            Currency reservationFeeCurrency = null;
            if (course.isCourseTemplate()) {
                throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, Messages.getInstance().getText(locale, "generic.errors.cannotAddStudentsToCourseTemplate"));
            }
            try {
                courseStudent = courseStudentDAO.create(course, student, enrolmentType, participationType, enrolmentDate, lodging, optionality, null, organizationName, additionalInfo, room, lodgingFee, lodgingFeeCurrency, reservationFee, reservationFeeCurrency, Boolean.FALSE);
            } catch (DuplicateCourseStudentException dcse) {
                throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, Messages.getInstance().getText(locale, "generic.errors.duplicateCourseStudent", new Object[] { student.getFullName() }));
            }
        } else {
            boolean modified = new Integer(1).equals(requestContext.getInteger(colPrefix + ".modified"));
            if (modified) {
                /* Existing student */
                Student student = studentDAO.findById(studentId);
                courseStudent = courseStudentDAO.findById(courseStudentId);
                try {
                    courseStudentDAO.update(courseStudent, student, enrolmentType, participationType, enrolmentDate, lodging, optionality);
                } catch (DuplicateCourseStudentException dcse) {
                    throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, Messages.getInstance().getText(locale, "generic.errors.duplicateCourseStudent", new Object[] { student.getFullName() }));
                }
            }
        }
    }
    processSignupStudyProgrammes(requestContext, course, loggedUser);
    processSignupStudentGroups(requestContext, course, loggedUser);
    requestContext.setRedirectURL(requestContext.getReferer(true));
}
Also used : BasicCourseResourceDAO(fi.otavanopisto.pyramus.dao.courses.BasicCourseResourceDAO) StudentCourseResource(fi.otavanopisto.pyramus.domainmodel.courses.StudentCourseResource) Currency(java.util.Currency) StudentCourseResourceDAO(fi.otavanopisto.pyramus.dao.courses.StudentCourseResourceDAO) Vector(java.util.Vector) MonetaryAmount(fi.otavanopisto.pyramus.persistence.usertypes.MonetaryAmount) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseEducationTypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStaffMemberRoleDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberRoleDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) CourseEnrolmentTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseEnrolmentTypeDAO) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) Map(java.util.Map) HashMap(java.util.HashMap) CourseTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseTypeDAO) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) DuplicateCourseStudentException(fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) CourseDescriptionCategoryDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionCategoryDAO) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) CourseType(fi.otavanopisto.pyramus.domainmodel.courses.CourseType) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) GradeCourseResource(fi.otavanopisto.pyramus.domainmodel.courses.GradeCourseResource) CourseEnrolmentType(fi.otavanopisto.pyramus.domainmodel.courses.CourseEnrolmentType) CourseEducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO) EducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO) CourseEducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO) BasicCourseResource(fi.otavanopisto.pyramus.domainmodel.courses.BasicCourseResource) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) CourseComponentResourceDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentResourceDAO) GradeCourseResourceDAO(fi.otavanopisto.pyramus.dao.courses.GradeCourseResourceDAO) StudentCourseResourceDAO(fi.otavanopisto.pyramus.dao.courses.StudentCourseResourceDAO) BasicCourseResourceDAO(fi.otavanopisto.pyramus.dao.courses.BasicCourseResourceDAO) ResourceDAO(fi.otavanopisto.pyramus.dao.resources.ResourceDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) Locale(java.util.Locale) CourseStaffMemberRole(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMemberRole) HashMap(java.util.HashMap) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) CourseDescription(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescription) CourseComponentResource(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponentResource) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) HashSet(java.util.HashSet) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) CourseParticipationTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseParticipationTypeDAO) CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) BasicCourseResource(fi.otavanopisto.pyramus.domainmodel.courses.BasicCourseResource) GradeCourseResource(fi.otavanopisto.pyramus.domainmodel.courses.GradeCourseResource) Resource(fi.otavanopisto.pyramus.domainmodel.resources.Resource) StudentCourseResource(fi.otavanopisto.pyramus.domainmodel.courses.StudentCourseResource) CourseComponentResource(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponentResource) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) OtherCostDAO(fi.otavanopisto.pyramus.dao.courses.OtherCostDAO) OtherCost(fi.otavanopisto.pyramus.domainmodel.courses.OtherCost) CourseEducationTypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) StaleObjectStateException(org.hibernate.StaleObjectStateException) GradeCourseResourceDAO(fi.otavanopisto.pyramus.dao.courses.GradeCourseResourceDAO) CourseComponentResourceDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentResourceDAO) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) CourseStateDAO(fi.otavanopisto.pyramus.dao.courses.CourseStateDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) CourseDescriptionCategory(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescriptionCategory) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType) Room(fi.otavanopisto.pyramus.domainmodel.accommodation.Room) Date(java.util.Date) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) BigDecimal(java.math.BigDecimal) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember)

Example 9 with CourseStaffMember

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember in project pyramus by otavanopisto.

the class EditCourseViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    CourseDescriptionCategoryDAO descriptionCategoryDAO = DAOFactory.getInstance().getCourseDescriptionCategoryDAO();
    CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
    CourseParticipationTypeDAO participationTypeDAO = DAOFactory.getInstance().getCourseParticipationTypeDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
    CourseTypeDAO courseTypeDAO = DAOFactory.getInstance().getCourseTypeDAO();
    CourseStaffMemberDAO courseStaffMemberDAO = DAOFactory.getInstance().getCourseStaffMemberDAO();
    CourseStaffMemberRoleDAO courseStaffMemberRoleDAO = DAOFactory.getInstance().getCourseStaffMemberRoleDAO();
    CourseComponentDAO courseComponentDAO = DAOFactory.getInstance().getCourseComponentDAO();
    CourseEnrolmentTypeDAO enrolmentTypeDAO = DAOFactory.getInstance().getCourseEnrolmentTypeDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    // The course to be edited
    Course course = courseDAO.findById(NumberUtils.createLong(pageRequestContext.getRequest().getParameter("course")));
    pageRequestContext.getRequest().setAttribute("course", course);
    // Create a hashmap of the education types and education subtypes selected in the course
    List<EducationType> educationTypes = educationTypeDAO.listUnarchived();
    Collections.sort(educationTypes, new StringAttributeComparator("getName"));
    pageRequestContext.getRequest().setAttribute("educationTypes", educationTypes);
    Map<String, Boolean> enabledEducationTypes = new HashMap<>();
    for (CourseEducationType courseEducationType : course.getCourseEducationTypes()) {
        for (CourseEducationSubtype courseEducationSubtype : courseEducationType.getCourseEducationSubtypes()) {
            enabledEducationTypes.put(courseEducationType.getEducationType().getId() + "." + courseEducationSubtype.getEducationSubtype().getId(), Boolean.TRUE);
        }
    }
    pageRequestContext.getRequest().setAttribute("enabledEducationTypes", enabledEducationTypes);
    // Various lists of base entities from module, course, and resource DAOs
    List<CourseStudent> courseStudents = courseStudentDAO.listByCourse(course);
    Collections.sort(courseStudents, new Comparator<CourseStudent>() {

        @Override
        public int compare(CourseStudent o1, CourseStudent o2) {
            int cmp = o1.getStudent().getLastName().compareToIgnoreCase(o2.getStudent().getLastName());
            if (cmp == 0)
                cmp = o1.getStudent().getFirstName().compareToIgnoreCase(o2.getStudent().getFirstName());
            return cmp;
        }
    });
    List<CourseStaffMember> courseUsers = courseStaffMemberDAO.listByCourse(course);
    Collections.sort(courseUsers, new Comparator<CourseStaffMember>() {

        @Override
        public int compare(CourseStaffMember o1, CourseStaffMember o2) {
            int cmp = o1.getStaffMember().getLastName().compareToIgnoreCase(o2.getStaffMember().getLastName());
            if (cmp == 0)
                cmp = o1.getStaffMember().getFirstName().compareToIgnoreCase(o2.getStaffMember().getFirstName());
            return cmp;
        }
    });
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = course.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    List<CourseComponent> courseComponents = courseComponentDAO.listByCourse(course);
    // course students students
    Map<Long, List<Student>> courseStudentsStudents = new HashMap<>();
    for (CourseStudent courseStudent : courseStudents) {
        courseStudentsStudents.put(courseStudent.getId(), studentDAO.listByPerson(courseStudent.getStudent().getPerson()));
    }
    // Subjects
    Map<Long, List<Subject>> subjectsByEducationType = new HashMap<>();
    List<Subject> subjectsByNoEducationType = subjectDAO.listByEducationType(null);
    Collections.sort(subjectsByNoEducationType, new StringAttributeComparator("getName"));
    for (EducationType educationType : educationTypes) {
        List<Subject> subjectsOfType = subjectDAO.listByEducationType(educationType);
        if (subjectsOfType != null && !subjectsOfType.isEmpty()) {
            Collections.sort(subjectsOfType, new StringAttributeComparator("getName"));
            subjectsByEducationType.put(educationType.getId(), subjectsOfType);
        }
    }
    List<EducationalTimeUnit> educationalTimeUnits = educationalTimeUnitDAO.listUnarchived();
    Collections.sort(educationalTimeUnits, new StringAttributeComparator("getName"));
    List<CourseParticipationType> courseParticipationTypes = participationTypeDAO.listUnarchived();
    Collections.sort(courseParticipationTypes, new Comparator<CourseParticipationType>() {

        public int compare(CourseParticipationType o1, CourseParticipationType o2) {
            return o1.getIndexColumn() == null ? -1 : o2.getIndexColumn() == null ? 1 : o1.getIndexColumn().compareTo(o2.getIndexColumn());
        }
    });
    Map<Long, List<EducationSubtype>> educationSubtypes = new HashMap<>();
    for (EducationType educationType : educationTypes) {
        List<EducationSubtype> subtypes = educationSubtypeDAO.listByEducationType(educationType);
        Collections.sort(subtypes, new StringAttributeComparator("getName"));
        educationSubtypes.put(educationType.getId(), subtypes);
    }
    // TODO: Support other currencies
    List<Currency> currencies = Arrays.asList(Currency.getInstance("EUR"));
    List<Curriculum> curriculums = curriculumDAO.listUnarchived();
    Collections.sort(curriculums, new StringAttributeComparator("getName"));
    // Organizations
    Long loggedUserId = pageRequestContext.getLoggedUserId();
    StaffMember user = staffMemberDAO.findById(loggedUserId);
    List<Organization> organizations;
    if (UserUtils.canAccessAllOrganizations(user)) {
        organizations = organizationDAO.listUnarchived();
    } else {
        organizations = Arrays.asList(user.getOrganization());
    }
    Collections.sort(organizations, new StringAttributeComparator("getName"));
    pageRequestContext.getRequest().setAttribute("organizations", organizations);
    pageRequestContext.getRequest().setAttribute("educationSubtypes", educationSubtypes);
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    pageRequestContext.getRequest().setAttribute("states", courseStateDAO.listUnarchived());
    pageRequestContext.getRequest().setAttribute("types", courseTypeDAO.listUnarchived());
    pageRequestContext.getRequest().setAttribute("roles", courseStaffMemberRoleDAO.listAll());
    pageRequestContext.getRequest().setAttribute("subjectsByNoEducationType", subjectsByNoEducationType);
    pageRequestContext.getRequest().setAttribute("subjectsByEducationType", subjectsByEducationType);
    pageRequestContext.getRequest().setAttribute("courseParticipationTypes", courseParticipationTypes);
    pageRequestContext.getRequest().setAttribute("courseEnrolmentTypes", enrolmentTypeDAO.listAll());
    pageRequestContext.getRequest().setAttribute("courseStudents", courseStudents);
    pageRequestContext.getRequest().setAttribute("courseUsers", courseUsers);
    pageRequestContext.getRequest().setAttribute("courseLengthTimeUnits", educationalTimeUnits);
    pageRequestContext.getRequest().setAttribute("courseComponents", courseComponents);
    pageRequestContext.getRequest().setAttribute("courseStudentsStudents", courseStudentsStudents);
    pageRequestContext.getRequest().setAttribute("courseDescriptions", descriptionDAO.listByCourseBase(course));
    pageRequestContext.getRequest().setAttribute("courseDescriptionCategories", descriptionCategoryDAO.listUnarchived());
    pageRequestContext.getRequest().setAttribute("currencies", currencies);
    pageRequestContext.getRequest().setAttribute("curriculums", curriculums);
    pageRequestContext.setIncludeJSP("/templates/courses/editcourse.jsp");
}
Also used : HashMap(java.util.HashMap) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Currency(java.util.Currency) List(java.util.List) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) CourseParticipationTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseParticipationTypeDAO) CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseStaffMemberRoleDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberRoleDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) CourseEnrolmentTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseEnrolmentTypeDAO) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) CourseTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseTypeDAO) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) CourseDescriptionCategoryDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionCategoryDAO) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) CourseStateDAO(fi.otavanopisto.pyramus.dao.courses.CourseStateDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) EducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag)

Example 10 with CourseStaffMember

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember in project pyramus by otavanopisto.

the class CourseDAO method listByStaffMember.

public List<Course> listByStaffMember(StaffMember staffMember) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Course> criteria = criteriaBuilder.createQuery(Course.class);
    Root<CourseStaffMember> root = criteria.from(CourseStaffMember.class);
    criteria.select(root.get(CourseStaffMember_.course));
    criteria.where(criteriaBuilder.equal(root.get(CourseStaffMember_.staffMember), staffMember));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) FullTextEntityManager(org.hibernate.search.jpa.FullTextEntityManager) EntityManager(javax.persistence.EntityManager) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Aggregations

CourseStaffMember (fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember)11 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)6 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)6 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)5 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)4 CourseStaffMemberDAO (fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO)4 HashMap (java.util.HashMap)4 CourseComponentDAO (fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO)3 CourseDescriptionDAO (fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO)3 CourseStaffMemberRoleDAO (fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberRoleDAO)3 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)3 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)3 CourseEducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype)3 CourseEducationType (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType)3 EducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype)3 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)3 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)3 Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)3 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)3 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)3