use of com.github.drbookings.core.datamodel.impl.BookingBean in project drbookings by DrBookings.
the class RunnableImportGoogleCalendar method process.
@Override
protected List<Booking> process(final IProgressMonitor monitor) throws Exception {
try {
if (logger.isInfoEnabled()) {
logger.info("Adding from " + url);
}
// initialize the transport
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
// initialize the data store factory
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
// authorization
final Credential credential = authorize();
// set up global Calendar instance
final Calendar client = new com.google.api.services.calendar.Calendar.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName("drbookings").build();
final CalendarList list = client.calendarList().list().execute();
String id = null;
for (final CalendarListEntry item : list.getItems()) {
if (item.getSummary().contains("airbnb")) {
id = item.getId();
}
}
final Events feed = client.events().list(id).execute();
final List<Booking> result = new ArrayList<>();
for (final Event item : feed.getItems()) {
System.out.println(item);
result.add(new BookingBean(item.getSummary(), LocalDate.parse(item.getStart().getDate().toString()), LocalDate.parse(item.getEnd().getDate().toString())));
}
return result;
} finally {
monitor.done();
}
}
use of com.github.drbookings.core.datamodel.impl.BookingBean in project drbookings by DrBookings.
the class RunnableImportCSVBooking method process.
@Override
protected List<BookingBean> process(final IProgressMonitor monitor) throws Exception {
try {
if (logger.isInfoEnabled()) {
logger.info("Reading " + file);
}
final FileInputStream stream = new FileInputStream(file);
final HSSFWorkbook workbook = new HSSFWorkbook(stream);
final HSSFSheet sheet = workbook.getSheetAt(0);
if (logger.isInfoEnabled()) {
logger.info("Processing sheet " + sheet.getSheetName());
}
final int indexBookingNumber = getColumnIndexBookingNumber(sheet.getRow(0));
final int indexClientName = getColumnIndexClientName(sheet.getRow(0));
final int indexBookingCheckIn = getColumnIndexCheckIn(sheet.getRow(0));
final int indexBookingCheckOut = getColumnIndexCheckOut(sheet.getRow(0));
final int indexStatus = getColumnIndexStatus(sheet.getRow(0));
final List<Integer> bookingNumbers = new ArrayList<>();
final List<String> guestNames = new ArrayList<>();
final List<String> stati = new ArrayList<>();
final List<LocalDate> bookingCheckIn = new ArrayList<>();
final List<LocalDate> bookingCheckOut = new ArrayList<>();
for (final Row r : sheet) {
// skip first row
if (r.getRowNum() == 0) {
continue;
}
bookingNumbers.add(getBookingNumber(r.getCell(indexBookingNumber)));
guestNames.add(getString(r.getCell(indexClientName)));
bookingCheckIn.add(getDate(r.getCell(indexBookingCheckIn)));
bookingCheckOut.add(getDate(r.getCell(indexBookingCheckOut)));
stati.add(getString(r.getCell(indexStatus)));
}
if (logger.isDebugEnabled()) {
logger.debug("Booking numbers: " + bookingNumbers);
logger.debug("Guest names: " + guestNames);
logger.debug("Check-in dates: " + bookingCheckIn);
logger.debug("Check-out dates: " + bookingCheckOut);
}
if (logger.isInfoEnabled()) {
logger.info("Building bookings.. ");
}
final List<BookingBean> bookings = new ArrayList<>();
for (int i = 0; i < bookingNumbers.size(); i++) {
final int number = bookingNumbers.get(i);
final LocalDate checkIn = bookingCheckIn.get(i);
final LocalDate checkOut = bookingCheckOut.get(i);
final String names = guestNames.get(i);
final String status = stati.get(i);
bookings.add(new BookingBean(Integer.toString(number), checkIn, checkOut, Arrays.asList(names.split(","))).setStatus(status));
}
return bookings;
} finally {
monitor.done();
}
}
Aggregations