Search in sources :

Example 1 with CleaningBeanSer

use of com.github.drbookings.model.ser.CleaningBeanSer in project drbookings by DrBookings.

the class DataStore method transform.

public static CleaningBeanSer transform(final CleaningEntry c) {
    final CleaningBeanSer b = new CleaningBeanSer();
    b.date = c.getDate();
    b.name = c.getElement().getName();
    b.room = c.getRoom().getName();
    b.calendarIds = c.getCalendarIds();
    b.cleaningCosts = c.getCleaningCosts();
    if (c.getBooking() != null) {
        b.bookingId = c.getBooking().getId();
    }
    return b;
}
Also used : CleaningBeanSer(com.github.drbookings.model.ser.CleaningBeanSer)

Example 2 with CleaningBeanSer

use of com.github.drbookings.model.ser.CleaningBeanSer in project drbookings by DrBookings.

the class DataStore method load.

public void load(final MainManager manager) {
    final List<BookingBean> bookingsToAdd = new ArrayList<>();
    for (final BookingBeanSer bb : (Iterable<BookingBeanSer>) () -> getBookingsSer().stream().sorted((b1, b2) -> b1.checkInDate.compareTo(b2.checkInDate)).iterator()) {
        try {
            final BookingBean b = manager.createBooking(bb.bookingId, bb.checkInDate, bb.checkOutDate, bb.guestName, bb.roomName, bb.source);
            // b.setGrossEarnings(bb.grossEarnings);
            b.setGrossEarningsExpression(bb.grossEarningsExpression);
            b.setWelcomeMailSend(bb.welcomeMailSend);
            b.setCheckInNote(bb.checkInNote);
            b.setPaymentDone(bb.paymentDone);
            b.setSpecialRequestNote(bb.specialRequestNote);
            b.setCheckOutNote(bb.checkOutNote);
            b.setExternalId(bb.externalId);
            b.setCalendarIds(bb.calendarIds);
            b.setCleaningFees(bb.cleaningFees);
            b.setServiceFeesPercent(bb.serviceFeePercent);
            b.setDateOfPayment(bb.dateOfPayment);
            b.setSplitBooking(bb.splitBooking);
            b.setPayments(Payment.transform(bb.paymentsSoFar));
            bookingsToAdd.add(b);
        } catch (final Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error(e.getLocalizedMessage(), e);
            }
        }
    }
    bookingsToAdd.forEach(b -> {
        try {
            manager.addBooking(b);
        } catch (final OverbookingException e) {
            if (logger.isWarnEnabled()) {
                logger.warn(e.getLocalizedMessage());
            }
        }
    });
    if (logger.isDebugEnabled()) {
        logger.debug(bookingsToAdd.size() + " added");
    }
    for (final CleaningBeanSer cb : getCleaningsSer()) {
        final Optional<BookingBean> b = manager.getBooking(cb.bookingId);
        if (b.isPresent()) {
            manager.addCleaning(cb.date, cb.name, b.get()).setCalendarIds(cb.calendarIds).setCleaningCosts(cb.cleaningCosts);
        } else {
            if (logger.isWarnEnabled()) {
                logger.warn("Failed to add cleaning " + cb + ", failed to find booking for ID " + cb.bookingId);
            }
        }
    }
}
Also used : CleaningBeanSer(com.github.drbookings.model.ser.CleaningBeanSer) ArrayList(java.util.ArrayList) BookingBeanSer(com.github.drbookings.model.ser.BookingBeanSer) OverbookingException(com.github.drbookings.OverbookingException) BookingBean(com.github.drbookings.model.data.BookingBean) OverbookingException(com.github.drbookings.OverbookingException)

Example 3 with CleaningBeanSer

use of com.github.drbookings.model.ser.CleaningBeanSer in project drbookings by DrBookings.

the class CleaningCostsAdder method main.

public static void main(final String[] args) throws Exception {
    final File file = new File("/home/alex/bookings.xml");
    final float cleaningCosts = 30;
    final DataStore ds = new XMLStorage().load(file);
    for (final CleaningBeanSer bs : ds.getCleaningsSer()) {
        if (bs.name.equalsIgnoreCase("Natalia")) {
            bs.cleaningCosts = cleaningCosts;
        }
    }
    new XMLStorage().save(ds, file);
}
Also used : XMLStorage(com.github.drbookings.ser.XMLStorage) CleaningBeanSer(com.github.drbookings.model.ser.CleaningBeanSer) DataStore(com.github.drbookings.ser.DataStore) File(java.io.File)

Example 4 with CleaningBeanSer

use of com.github.drbookings.model.ser.CleaningBeanSer in project drbookings by DrBookings.

the class Anonymiser method main.

public static void main(final String[] args) throws Exception {
    final File file = new File("/home/alex/bookings-anonym.xml");
    new BackupCreator().makeBackup(file);
    final DataStore ds = new XMLStorage().load(file);
    for (final Iterator<BookingBeanSer> it = ds.getBookingsSer().iterator(); it.hasNext(); ) {
        final BookingBeanSer bs = it.next();
        bs.guestName = new RandomString().ofLength(bs.guestName.length()).toString();
    }
    for (final Iterator<CleaningBeanSer> it = ds.getCleaningsSer().iterator(); it.hasNext(); ) {
        final CleaningBeanSer bs = it.next();
        bs.name = new RandomString().ofLength(bs.name.length()).toString();
    }
    new XMLStorage().save(ds, file);
}
Also used : XMLStorage(com.github.drbookings.ser.XMLStorage) CleaningBeanSer(com.github.drbookings.model.ser.CleaningBeanSer) BackupCreator(com.github.ktools1000.io.BackupCreator) DataStore(com.github.drbookings.ser.DataStore) RandomString(com.github.ktools1000.RandomString) File(java.io.File) BookingBeanSer(com.github.drbookings.model.ser.BookingBeanSer)

Aggregations

CleaningBeanSer (com.github.drbookings.model.ser.CleaningBeanSer)4 BookingBeanSer (com.github.drbookings.model.ser.BookingBeanSer)2 DataStore (com.github.drbookings.ser.DataStore)2 XMLStorage (com.github.drbookings.ser.XMLStorage)2 File (java.io.File)2 OverbookingException (com.github.drbookings.OverbookingException)1 BookingBean (com.github.drbookings.model.data.BookingBean)1 RandomString (com.github.ktools1000.RandomString)1 BackupCreator (com.github.ktools1000.io.BackupCreator)1 ArrayList (java.util.ArrayList)1