Search in sources :

Example 11 with EducationType

use of fi.otavanopisto.pyramus.domainmodel.base.EducationType in project pyramus by otavanopisto.

the class OrganizationRESTService method createOrganization.

@Path("/")
@POST
@RESTPermit(OrganizationPermissions.CREATE_ORGANIZATION)
public Response createOrganization(fi.otavanopisto.pyramus.rest.model.Organization entity) {
    if ((entity == null) || StringUtils.isBlank(entity.getName())) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    EducationType educationType = null;
    if ((entity.getEducationType() != null) && (entity.getEducationType().getId() != null)) {
        educationType = educationTypeDAO.findById(entity.getEducationType().getId());
    }
    Organization organization = organizationDAO.create(entity.getName(), educationType);
    if (entity.getBillingDetails() != null) {
        BillingDetails billingDetails = billingDetailsDAO.create(entity.getBillingDetails().getPersonName(), entity.getBillingDetails().getCompanyName(), entity.getBillingDetails().getStreetAddress1(), entity.getBillingDetails().getStreetAddress2(), entity.getBillingDetails().getPostalCode(), entity.getBillingDetails().getCity(), entity.getBillingDetails().getRegion(), entity.getBillingDetails().getCountry(), entity.getBillingDetails().getPhoneNumber(), entity.getBillingDetails().getEmailAddress(), entity.getBillingDetails().getElectronicBillingAddress(), entity.getBillingDetails().getElectronicBillingOperator(), entity.getBillingDetails().getCompanyIdentifier(), entity.getBillingDetails().getReferenceNumber(), entity.getBillingDetails().getNotes());
        organization = organizationDAO.updateBillingDetails(organization, billingDetails);
    }
    // Contract Periods
    List<fi.otavanopisto.pyramus.rest.model.OrganizationContractPeriod> updatedContractPeriods = CollectionUtils.isNotEmpty(entity.getContractPeriods()) ? entity.getContractPeriods() : Collections.emptyList();
    for (fi.otavanopisto.pyramus.rest.model.OrganizationContractPeriod updatedContractPeriod : updatedContractPeriods) {
        Date begin = updatedContractPeriod.getBegin() != null ? java.sql.Date.valueOf(updatedContractPeriod.getBegin()) : null;
        Date end = updatedContractPeriod.getEnd() != null ? java.sql.Date.valueOf(updatedContractPeriod.getEnd()) : null;
        organizationContractPeriodDAO.create(organization, begin, end);
    }
    // Contact Persons
    List<fi.otavanopisto.pyramus.rest.model.OrganizationContactPerson> contactPersons = CollectionUtils.isNotEmpty(entity.getContactPersons()) ? entity.getContactPersons() : Collections.emptyList();
    for (fi.otavanopisto.pyramus.rest.model.OrganizationContactPerson contactPerson : contactPersons) {
        fi.otavanopisto.pyramus.rest.model.OrganizationContactPersonType contactPersonType = contactPerson.getType();
        OrganizationContactPersonType type = contactPersonType != null ? OrganizationContactPersonType.valueOf(contactPersonType.name()) : null;
        organizationContactPersonDAO.create(organization, type, contactPerson.getName(), contactPerson.getEmail(), contactPerson.getPhone(), contactPerson.getTitle());
    }
    return Response.ok(objectFactory.createModel(organization)).build();
}
Also used : Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) OrganizationContactPerson(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContactPerson) BillingDetails(fi.otavanopisto.pyramus.domainmodel.base.BillingDetails) Date(java.util.Date) OrganizationContractPeriod(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContractPeriod) OrganizationContactPersonType(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContactPersonType) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) POST(javax.ws.rs.POST)

Example 12 with EducationType

use of fi.otavanopisto.pyramus.domainmodel.base.EducationType in project pyramus by otavanopisto.

the class OrganizationRESTService method updateOrganization.

@Path("/{ID:[0-9]*}")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@RESTPermit(OrganizationPermissions.UPDATE_ORGANIZATION)
public Response updateOrganization(@PathParam("ID") Long id, fi.otavanopisto.pyramus.rest.model.Organization entity) {
    if (entity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    String name = entity.getName();
    if (StringUtils.isBlank(name) || entity.getBillingDetails() == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Organization organization = organizationDAO.findById(id);
    if (organization == null || organization.getArchived() || !UserUtils.canAccessOrganization(sessionController.getUser(), organization)) {
        return Response.status(Status.NOT_FOUND).build();
    }
    EducationType educationType = organization.getEducationType();
    if ((entity.getEducationType() != null) && (entity.getEducationType().getId() != null)) {
        educationType = educationTypeDAO.findById(entity.getEducationType().getId());
    }
    if (organization.getBillingDetails() == null) {
        BillingDetails billingDetails = billingDetailsDAO.create(entity.getBillingDetails().getPersonName(), entity.getBillingDetails().getCompanyName(), entity.getBillingDetails().getStreetAddress1(), entity.getBillingDetails().getStreetAddress2(), entity.getBillingDetails().getPostalCode(), entity.getBillingDetails().getCity(), entity.getBillingDetails().getRegion(), entity.getBillingDetails().getCountry(), entity.getBillingDetails().getPhoneNumber(), entity.getBillingDetails().getEmailAddress(), entity.getBillingDetails().getElectronicBillingAddress(), entity.getBillingDetails().getElectronicBillingOperator(), entity.getBillingDetails().getCompanyIdentifier(), entity.getBillingDetails().getReferenceNumber(), entity.getBillingDetails().getNotes());
        organization = organizationDAO.updateBillingDetails(organization, billingDetails);
    } else {
        BillingDetails billingDetails = organization.getBillingDetails();
        billingDetails.setPersonName(entity.getBillingDetails().getPersonName());
        billingDetails.setCompanyName(entity.getBillingDetails().getCompanyName());
        billingDetails.setStreetAddress1(entity.getBillingDetails().getStreetAddress1());
        billingDetails.setStreetAddress2(entity.getBillingDetails().getStreetAddress2());
        billingDetails.setPostalCode(entity.getBillingDetails().getPostalCode());
        billingDetails.setCity(entity.getBillingDetails().getCity());
        billingDetails.setRegion(entity.getBillingDetails().getRegion());
        billingDetails.setCountry(entity.getBillingDetails().getCountry());
        billingDetails.setPhoneNumber(entity.getBillingDetails().getPhoneNumber());
        billingDetails.setEmailAddress(entity.getBillingDetails().getEmailAddress());
        billingDetails.setElectronicBillingAddress(entity.getBillingDetails().getElectronicBillingAddress());
        billingDetails.setElectronicBillingOperator(entity.getBillingDetails().getElectronicBillingOperator());
        billingDetails.setCompanyIdentifier(entity.getBillingDetails().getCompanyIdentifier());
        billingDetails.setReferenceNumber(entity.getBillingDetails().getReferenceNumber());
        billingDetails.setNotes(entity.getBillingDetails().getNotes());
    }
    organization = organizationDAO.update(organization, name, educationType);
    // Update Contract Periods
    List<OrganizationContractPeriod> existingContractPeriods = organizationContractPeriodDAO.listBy(organization);
    List<fi.otavanopisto.pyramus.rest.model.OrganizationContractPeriod> updatedContractPeriods = CollectionUtils.isNotEmpty(entity.getContractPeriods()) ? entity.getContractPeriods() : Collections.emptyList();
    for (fi.otavanopisto.pyramus.rest.model.OrganizationContractPeriod updatedContractPeriod : updatedContractPeriods) {
        Date begin = updatedContractPeriod.getBegin() != null ? java.sql.Date.valueOf(updatedContractPeriod.getBegin()) : null;
        Date end = updatedContractPeriod.getEnd() != null ? java.sql.Date.valueOf(updatedContractPeriod.getEnd()) : null;
        if ((updatedContractPeriod.getId() == null) || NumberUtils.LONG_MINUS_ONE.equals(updatedContractPeriod.getId())) {
            organizationContractPeriodDAO.create(organization, begin, end);
        } else {
            OrganizationContractPeriod contractPeriod = organizationContractPeriodDAO.findById(updatedContractPeriod.getId());
            organizationContractPeriodDAO.update(contractPeriod, begin, end);
        }
    }
    Set<Long> remainingContractPeriodIds = updatedContractPeriods.stream().map(contractPeriod -> contractPeriod.getId()).collect(Collectors.toSet());
    existingContractPeriods.forEach(contractPeriod -> {
        if (!remainingContractPeriodIds.contains(contractPeriod.getId())) {
            organizationContractPeriodDAO.delete(contractPeriod);
        }
    });
    // Update Contact Persons
    List<OrganizationContactPerson> existingContactPersons = organizationContactPersonDAO.listBy(organization);
    List<fi.otavanopisto.pyramus.rest.model.OrganizationContactPerson> updatedContactPersons = CollectionUtils.isNotEmpty(entity.getContactPersons()) ? entity.getContactPersons() : Collections.emptyList();
    for (fi.otavanopisto.pyramus.rest.model.OrganizationContactPerson updatedContactPerson : updatedContactPersons) {
        fi.otavanopisto.pyramus.rest.model.OrganizationContactPersonType contactPersonType = updatedContactPerson.getType();
        OrganizationContactPersonType type = contactPersonType != null ? OrganizationContactPersonType.valueOf(contactPersonType.name()) : null;
        if ((updatedContactPerson.getId() == null) || NumberUtils.LONG_MINUS_ONE.equals(updatedContactPerson.getId())) {
            organizationContactPersonDAO.create(organization, type, updatedContactPerson.getName(), updatedContactPerson.getEmail(), updatedContactPerson.getPhone(), updatedContactPerson.getTitle());
        } else {
            OrganizationContactPerson contactPerson = organizationContactPersonDAO.findById(updatedContactPerson.getId());
            organizationContactPersonDAO.update(contactPerson, type, updatedContactPerson.getName(), updatedContactPerson.getEmail(), updatedContactPerson.getPhone(), updatedContactPerson.getTitle());
        }
    }
    Set<Long> remainingIds = updatedContactPersons.stream().map(contactPerson -> contactPerson.getId()).collect(Collectors.toSet());
    existingContactPersons.forEach(contactPerson -> {
        if (!remainingIds.contains(contactPerson.getId())) {
            organizationContactPersonDAO.delete(contactPerson);
        }
    });
    return Response.ok(objectFactory.createModel(organization)).build();
}
Also used : Arrays(java.util.Arrays) PathParam(javax.ws.rs.PathParam) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) UserUtils(fi.otavanopisto.pyramus.framework.UserUtils) Date(java.util.Date) OrganizationContractPeriod(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContractPeriod) Path(javax.ws.rs.Path) OrganizationContactPersonDAO(fi.otavanopisto.pyramus.dao.base.OrganizationContactPersonDAO) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) User(fi.otavanopisto.pyramus.domainmodel.users.User) CollectionUtils(org.apache.commons.collections.CollectionUtils) OrganizationContactPerson(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContactPerson) DefaultValue(javax.ws.rs.DefaultValue) OrganizationContractPeriodDAO(fi.otavanopisto.pyramus.dao.base.OrganizationContractPeriodDAO) Status(javax.ws.rs.core.Response.Status) DELETE(javax.ws.rs.DELETE) OrganizationContactPersonType(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContactPersonType) POST(javax.ws.rs.POST) Set(java.util.Set) SessionController(fi.otavanopisto.pyramus.security.impl.SessionController) Collectors(java.util.stream.Collectors) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) Stateful(javax.ejb.Stateful) List(java.util.List) Response(javax.ws.rs.core.Response) RequestScoped(javax.enterprise.context.RequestScoped) NumberUtils(org.apache.commons.lang3.math.NumberUtils) BillingDetails(fi.otavanopisto.pyramus.domainmodel.base.BillingDetails) OrganizationPermissions(fi.otavanopisto.pyramus.security.impl.permissions.OrganizationPermissions) PUT(javax.ws.rs.PUT) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) Collections(java.util.Collections) BillingDetailsDAO(fi.otavanopisto.pyramus.dao.base.BillingDetailsDAO) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) OrganizationContactPerson(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContactPerson) BillingDetails(fi.otavanopisto.pyramus.domainmodel.base.BillingDetails) Date(java.util.Date) OrganizationContractPeriod(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContractPeriod) OrganizationContactPersonType(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContactPersonType) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 13 with EducationType

use of fi.otavanopisto.pyramus.domainmodel.base.EducationType in project pyramus by otavanopisto.

the class StudentRESTService method createStudyProgrammeCategory.

@Path("/studyProgrammeCategories")
@POST
@RESTPermit(StudyProgrammeCategoryPermissions.CREATE_STUDYPROGRAMMECATEGORY)
public Response createStudyProgrammeCategory(fi.otavanopisto.pyramus.rest.model.StudyProgrammeCategory entity) {
    String name = entity.getName();
    if (StringUtils.isBlank(name)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (entity.getEducationTypeId() == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    EducationType educationType = commonController.findEducationTypeById(entity.getEducationTypeId());
    if (educationType == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    return Response.ok(objectFactory.createModel(studyProgrammeCategoryController.createStudyProgrammeCategory(name, educationType))).build();
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) POST(javax.ws.rs.POST)

Example 14 with EducationType

use of fi.otavanopisto.pyramus.domainmodel.base.EducationType in project pyramus by otavanopisto.

the class StudentRESTService method updateStudyProgrammeCategory.

@Path("/studyProgrammeCategories/{ID:[0-9]*}")
@PUT
@RESTPermit(StudyProgrammeCategoryPermissions.UPDATE_STUDYPROGRAMMECATEGORY)
public Response updateStudyProgrammeCategory(@PathParam("ID") Long id, fi.otavanopisto.pyramus.rest.model.StudyProgrammeCategory entity) {
    StudyProgrammeCategory studyProgrammeCategory = studyProgrammeCategoryController.findStudyProgrammeCategoryById(id);
    if (studyProgrammeCategory == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (studyProgrammeCategory.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    String name = entity.getName();
    if (StringUtils.isBlank(name)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (entity.getEducationTypeId() == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    EducationType educationType = commonController.findEducationTypeById(entity.getEducationTypeId());
    if (educationType == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    return Response.ok().entity(objectFactory.createModel(studyProgrammeCategoryController.updateStudyProgrammeCategory(studyProgrammeCategory, name, educationType))).build();
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) StudyProgrammeCategory(fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) PUT(javax.ws.rs.PUT)

Example 15 with EducationType

use of fi.otavanopisto.pyramus.domainmodel.base.EducationType in project pyramus by otavanopisto.

the class MatriculationEligibilityController method getStudentMatriculationEligible.

/**
 * Resolves matriculation eligibility into given subject for a student
 *
 * @param student student
 * @param subjectCode subject code
 * @return matriculation eligibility into given subject for a student
 */
public StudentMatriculationEligibilityResult getStudentMatriculationEligible(Student student, String subjectCode) {
    Curriculum curriculum = student.getCurriculum();
    if (curriculum == null) {
        if (logger.isLoggable(Level.SEVERE)) {
            logger.log(Level.SEVERE, String.format("Failed to resolve matriculation eligibility, student %d is missing curriculum", student.getId()));
        }
        return null;
    }
    Subject subject = commonController.findSubjectByCode(subjectCode);
    if (subject == null) {
        if (logger.isLoggable(Level.SEVERE)) {
            logger.log(Level.SEVERE, String.format("Failed to resolve matriculation eligibility, subject %s is missing", subjectCode));
        }
        return null;
    }
    MatriculationEligibilitySubjectMapping mapping = getMatriculationMapping(curriculum.getName(), subject);
    if (mapping == null) {
        mapping = getMatriculationMapping(ANY_CURRICULUM, subject);
    }
    if (mapping == null) {
        if (logger.isLoggable(Level.SEVERE)) {
            logger.log(Level.SEVERE, String.format("Failed to resolve matriculation eligibility, no mapping for curriculum %s, subjectCode %s", curriculum == null ? "NULL" : curriculum.getName(), subjectCode));
        }
        return null;
    }
    String educationTypeCode = mapping.getEducationType();
    String educationSubtypeCode = mapping.getEducationSubtype();
    Integer requirePassingGrades = mapping.getPassingGrades();
    EducationType educationType = null;
    EducationSubtype educationSubtype = null;
    if (StringUtils.isNotBlank(educationTypeCode)) {
        educationType = commonController.findEducationTypeByCode(educationTypeCode);
        if (educationType == null) {
            if (logger.isLoggable(Level.SEVERE)) {
                logger.log(Level.SEVERE, String.format("Failed to resolve matriculation eligibility, could not find educationType %s", educationTypeCode));
            }
            return null;
        }
    }
    if (StringUtils.isNotBlank(educationSubtypeCode)) {
        educationSubtype = commonController.findEducationSubtypeByCode(educationType, educationSubtypeCode);
        if (educationSubtype == null) {
            if (logger.isLoggable(Level.SEVERE)) {
                logger.log(Level.SEVERE, String.format("Failed to resolve matriculation eligibility, could not find educationSubtype %s", educationSubtypeCode));
            }
            return null;
        }
    }
    int acceptedCourseCount = assessmentController.getAcceptedCourseCount(student, subject, educationType, educationSubtype, curriculum);
    int acceptedTransferCreditCount = assessmentController.getAcceptedTransferCreditCount(student, subject, mapping.getTransferCreditOnlyMandatory(), curriculum);
    if (CollectionUtils.isNotEmpty(mapping.getIncludedSubjects())) {
        for (String includedSubjectCode : mapping.getIncludedSubjects()) {
            Subject includedSubject = commonController.findSubjectByCode(includedSubjectCode);
            if (includedSubject != null) {
                acceptedCourseCount += assessmentController.getAcceptedCourseCount(student, includedSubject, educationType, educationSubtype, curriculum);
                acceptedTransferCreditCount += assessmentController.getAcceptedTransferCreditCount(student, includedSubject, mapping.getTransferCreditOnlyMandatory(), curriculum);
            } else {
                logger.log(Level.SEVERE, String.format("Failed to resolve includedSubject %s for subject %s", includedSubjectCode, subjectCode));
            }
        }
    }
    return new StudentMatriculationEligibilityResult(requirePassingGrades, acceptedCourseCount, acceptedTransferCreditCount, acceptedCourseCount + acceptedTransferCreditCount >= requirePassingGrades);
}
Also used : MatriculationEligibilitySubjectMapping(fi.otavanopisto.pyramus.rest.matriculation.MatriculationEligibilitySubjectMapping) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject)

Aggregations

EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)66 EducationTypeDAO (fi.otavanopisto.pyramus.dao.base.EducationTypeDAO)42 EducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype)24 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)23 SubjectDAO (fi.otavanopisto.pyramus.dao.base.SubjectDAO)20 EducationSubtypeDAO (fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO)17 HashMap (java.util.HashMap)17 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)16 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)13 Date (java.util.Date)13 Path (javax.ws.rs.Path)13 List (java.util.List)12 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)11 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)10 CourseEducationType (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType)10 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)10 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)9 Map (java.util.Map)9 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)8 CourseDescriptionCategoryDAO (fi.otavanopisto.pyramus.dao.courses.CourseDescriptionCategoryDAO)8