Search in sources :

Example 1 with RoomDAO

use of fi.otavanopisto.pyramus.dao.accommodation.RoomDAO in project pyramus by otavanopisto.

the class CourseStudentDetailsDialogViewController method process.

public void process(PageRequestContext pageRequestContext) {
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    RoomTypeDAO roomTypeDAO = DAOFactory.getInstance().getRoomTypeDAO();
    RoomDAO roomDAO = DAOFactory.getInstance().getRoomDAO();
    Long courseStudentId = pageRequestContext.getLong("courseStudentId");
    if (courseStudentId == null) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, "Missing courseStudentId parameter");
    }
    CourseStudent courseStudent = courseStudentDAO.findById(courseStudentId);
    if (courseStudent == null) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, "Invalid courseStudentId parameter");
    }
    Map<RoomType, List<Room>> rooms = new TreeMap<>(new Comparator<RoomType>() {

        @Override
        public int compare(RoomType o1, RoomType o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    List<RoomType> roomTypes = roomTypeDAO.listAll();
    for (RoomType roomType : roomTypes) {
        List<Room> typeRooms = roomDAO.listByType(roomType);
        rooms.put(roomType, typeRooms);
    }
    // Support other currencies
    List<Currency> currencies = Arrays.asList(Currency.getInstance("EUR"));
    List<BillingDetails> existingBillingDetails = getExistingBillingDetails(courseStudent);
    pageRequestContext.getRequest().setAttribute("courseStudent", courseStudent);
    pageRequestContext.getRequest().setAttribute("rooms", rooms);
    pageRequestContext.getRequest().setAttribute("currencies", currencies);
    pageRequestContext.getRequest().setAttribute("existingBillingDetails", existingBillingDetails);
    pageRequestContext.setIncludeJSP("/templates/courses/studentdetailsdialog.jsp");
}
Also used : RoomDAO(fi.otavanopisto.pyramus.dao.accommodation.RoomDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) TreeMap(java.util.TreeMap) BillingDetails(fi.otavanopisto.pyramus.domainmodel.base.BillingDetails) RoomType(fi.otavanopisto.pyramus.domainmodel.accommodation.RoomType) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Currency(java.util.Currency) RoomTypeDAO(fi.otavanopisto.pyramus.dao.accommodation.RoomTypeDAO) ArrayList(java.util.ArrayList) List(java.util.List) Room(fi.otavanopisto.pyramus.domainmodel.accommodation.Room)

Example 2 with RoomDAO

use of fi.otavanopisto.pyramus.dao.accommodation.RoomDAO in project pyramus by otavanopisto.

the class SaveStudentDetailsJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    RoomDAO roomDAO = DAOFactory.getInstance().getRoomDAO();
    BillingDetailsDAO billingDetailsDAO = DAOFactory.getInstance().getBillingDetailsDAO();
    Long courseStudentId = requestContext.getLong("courseStudentId");
    String organization = requestContext.getString("organization");
    String additionalInfo = requestContext.getString("additionalInfo");
    Long roomId = requestContext.getLong("roomId");
    String roomAdditionalInfo = requestContext.getString("roomAdditionalInfo");
    BigDecimal lodgingFee = requestContext.getBigDecimal("lodgingFee");
    Currency lodgingFeeCurrency = requestContext.getCurrency("lodgingFeeCurrency");
    BigDecimal reservationFee = requestContext.getBigDecimal("reservationFee");
    Currency reservationFeeCurrency = requestContext.getCurrency("reservationFeeCurrency");
    String billingDetailsPersonName = requestContext.getString("billingDetailsPersonName");
    String billingDetailsCompanyName = requestContext.getString("billingDetailsCompanyName");
    String billingDetailsStreetAddress1 = requestContext.getString("billingDetailsStreetAddress1");
    String billingDetailsStreetAddress2 = requestContext.getString("billingDetailsStreetAddress2");
    String billingDetailsPostalCode = requestContext.getString("billingDetailsPostalCode");
    String billingDetailsCity = requestContext.getString("billingDetailsCity");
    String billingDetailsRegion = requestContext.getString("billingDetailsRegion");
    String billingDetailsCountry = requestContext.getString("billingDetailsCountry");
    String billingDetailsPhoneNumber = requestContext.getString("billingDetailsPhoneNumber");
    String billingDetailsEmailAddress = requestContext.getString("billingDetailsEmailAddress");
    String billingDetailsCompanyIdentifier = requestContext.getString("billingDetailsCompanyIdentifier");
    String billingDetailsReferenceNumber = requestContext.getString("billingDetailsReferenceNumber");
    String billingDetailsElectronicBillingAddress = requestContext.getString("billingDetailsElectronicBillingAddress");
    String billingDetailsElectronicBillingOperator = requestContext.getString("billingDetailsElectronicBillingOperator");
    String billingDetailsNotes = requestContext.getString("billingDetailsNotes");
    Long billingDetailsId = requestContext.getLong("billingDetailsId");
    if (billingDetailsId != null) {
        BillingDetails billingDetails = billingDetailsDAO.findById(billingDetailsId);
        if (billingDetails != null) {
            billingDetailsPersonName = billingDetails.getPersonName();
            billingDetailsCompanyName = billingDetails.getCompanyName();
            billingDetailsStreetAddress1 = billingDetails.getStreetAddress1();
            billingDetailsStreetAddress2 = billingDetails.getStreetAddress2();
            billingDetailsPostalCode = billingDetails.getPostalCode();
            billingDetailsCity = billingDetails.getCity();
            billingDetailsRegion = billingDetails.getRegion();
            billingDetailsCountry = billingDetails.getCountry();
            billingDetailsPhoneNumber = billingDetails.getPhoneNumber();
            billingDetailsEmailAddress = billingDetails.getEmailAddress();
            billingDetailsCompanyIdentifier = billingDetails.getCompanyIdentifier();
            billingDetailsReferenceNumber = billingDetails.getReferenceNumber();
            billingDetailsElectronicBillingAddress = billingDetails.getElectronicBillingAddress();
            billingDetailsElectronicBillingOperator = billingDetails.getElectronicBillingOperator();
            billingDetailsNotes = billingDetails.getNotes();
        }
    }
    boolean billingDetailsSet = !allNull(billingDetailsPersonName, billingDetailsCompanyName, billingDetailsStreetAddress1, billingDetailsStreetAddress2, billingDetailsPostalCode, billingDetailsCity, billingDetailsRegion, billingDetailsCountry, billingDetailsPhoneNumber, billingDetailsEmailAddress, billingDetailsCompanyIdentifier, billingDetailsReferenceNumber, billingDetailsElectronicBillingAddress, billingDetailsElectronicBillingOperator, billingDetailsNotes);
    if (courseStudentId == null) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, "Missing courseStudentId parameter");
    }
    CourseStudent courseStudent = courseStudentDAO.findById(courseStudentId);
    if (courseStudent == null) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, "Invalid courseStudentId parameter");
    }
    Room room = null;
    if (roomId != null) {
        room = roomDAO.findById(roomId);
        if (room == null) {
            throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, "Invalid roomId");
        }
    }
    BillingDetails billingDetails = courseStudent.getBillingDetails();
    if (billingDetailsSet) {
        if (billingDetails != null) {
            billingDetailsDAO.updatePersonName(billingDetails, billingDetailsPersonName);
            billingDetailsDAO.updateCompanyName(billingDetails, billingDetailsCompanyName);
            billingDetailsDAO.updateStreetAddress1(billingDetails, billingDetailsStreetAddress1);
            billingDetailsDAO.updateStreetAddress2(billingDetails, billingDetailsStreetAddress2);
            billingDetailsDAO.updatePostalCode(billingDetails, billingDetailsPostalCode);
            billingDetailsDAO.updateCity(billingDetails, billingDetailsCity);
            billingDetailsDAO.updateRegion(billingDetails, billingDetailsRegion);
            billingDetailsDAO.updateCountry(billingDetails, billingDetailsCountry);
            billingDetailsDAO.updatePhoneNumber(billingDetails, billingDetailsPhoneNumber);
            billingDetailsDAO.updateEmailAddress(billingDetails, billingDetailsEmailAddress);
            billingDetailsDAO.updateCompanyIdentifier(billingDetails, billingDetailsCompanyIdentifier);
            billingDetailsDAO.updateReferenceNumber(billingDetails, billingDetailsReferenceNumber);
            billingDetailsDAO.updateNotes(billingDetails, billingDetailsNotes);
            billingDetailsDAO.updateElectronicBillingAddress(billingDetails, billingDetailsElectronicBillingAddress);
            billingDetailsDAO.updateElectronicBillingOperator(billingDetails, billingDetailsElectronicBillingOperator);
        } else {
            courseStudentDAO.updateBillingDetails(courseStudent, billingDetailsDAO.create(billingDetailsPersonName, billingDetailsCompanyName, billingDetailsStreetAddress1, billingDetailsStreetAddress2, billingDetailsPostalCode, billingDetailsCity, billingDetailsRegion, billingDetailsCountry, billingDetailsPhoneNumber, billingDetailsEmailAddress, billingDetailsElectronicBillingAddress, billingDetailsElectronicBillingOperator, billingDetailsCompanyIdentifier, billingDetailsReferenceNumber, billingDetailsNotes));
        }
    } else {
        if (billingDetails != null) {
            courseStudentDAO.updateBillingDetails(courseStudent, null);
            billingDetailsDAO.delete(billingDetails);
        }
    }
    courseStudentDAO.updateOrganization(courseStudent, organization);
    courseStudentDAO.updateAdditionalInfo(courseStudent, additionalInfo);
    courseStudentDAO.updateRoom(courseStudent, room);
    courseStudentDAO.updateRoomAdditionalInfo(courseStudent, roomAdditionalInfo);
    courseStudentDAO.updateLodgingFee(courseStudent, lodgingFee, lodgingFeeCurrency);
    courseStudentDAO.updateReservationFee(courseStudent, reservationFee, reservationFeeCurrency);
}
Also used : RoomDAO(fi.otavanopisto.pyramus.dao.accommodation.RoomDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) Currency(java.util.Currency) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) BillingDetailsDAO(fi.otavanopisto.pyramus.dao.base.BillingDetailsDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) BillingDetails(fi.otavanopisto.pyramus.domainmodel.base.BillingDetails) Room(fi.otavanopisto.pyramus.domainmodel.accommodation.Room) BigDecimal(java.math.BigDecimal)

Aggregations

SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)2 RoomDAO (fi.otavanopisto.pyramus.dao.accommodation.RoomDAO)2 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)2 Room (fi.otavanopisto.pyramus.domainmodel.accommodation.Room)2 BillingDetails (fi.otavanopisto.pyramus.domainmodel.base.BillingDetails)2 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)2 Currency (java.util.Currency)2 RoomTypeDAO (fi.otavanopisto.pyramus.dao.accommodation.RoomTypeDAO)1 BillingDetailsDAO (fi.otavanopisto.pyramus.dao.base.BillingDetailsDAO)1 RoomType (fi.otavanopisto.pyramus.domainmodel.accommodation.RoomType)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1