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();
}
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();
}
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();
}
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();
}
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);
}
Aggregations