SimpleDateFormat icalFormatter = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
SimpleDateFormat logFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm Z");
Company company = DatastoreProxy.getCompanyByLogin(attendee);
if (company != null) {
log.info("Found company: " + company.getLastname());
Slot slot = new Slot();
slot.setOwnerId(company.getId());
log.info("DTSTART :" + startDate);
Date parsedStartDate = icalFormatter.parse(startDate);
log.info("Parsed start date :" + logFormatter.format(parsedStartDate));
log.info("DTEND :" + endDate);
Date parsedEndDate = icalFormatter.parse(endDate);
log.info("Parsed end date :" + logFormatter.format(parsedEndDate));
slot.setStartDate(parsedStartDate);
slot.setEndDate(parsedEndDate);
slot.setStatus(SlotStatus.Ordered);
long slotInterval = parsedEndDate.getTime() - parsedStartDate.getTime();
log.info("Interval in miliseconds: " + slotInterval);
long slotDurationInMilisecondes = (long) duration * 60 * 1000;
log.info("Default slot duration in miliseconds: " + slotDurationInMilisecondes);
long nbSlots = slotInterval / slotDurationInMilisecondes;
log.info("Number of slots (Long): " + nbSlots);
slot.setNbSlots((int) nbSlots);
slot.setPrice(price);
Slot entity = DatastoreProxy.createSlot(slot);
log.info("Created new slot for company:" + company.getLastname());
log.info(entity.toString());
} else {
log.warning("Did not find a company with attendee: " + attendee);
log.info("Trying to a find a publisher with attendee: " + attendee);
Publisher publisher = DatastoreProxy.getPublisherByLogin(attendee);
if (publisher != null) {
log.info("Found publisher with attendee: " + publisher.getFirstname() + " " + publisher.getLastname());
Slot slot = new Slot();
slot.setOwnerId(publisher.getId());
log.info("DTSTART :" + startDate);
Date parsedStartDate = icalFormatter.parse(startDate);
log.info("Parsed start date :" + logFormatter.format(parsedStartDate));
log.info("DTEND :" + endDate);
Date parsedEndDate = icalFormatter.parse(endDate);
log.info("Parsed end date :" + logFormatter.format(parsedEndDate));
slot.setStartDate(parsedStartDate);
slot.setEndDate(parsedEndDate);
slot.setStatus(SlotStatus.Ordered);
long slotInterval = parsedEndDate.getTime() - parsedStartDate.getTime();
log.info("Interval in miliseconds: " + slotInterval);
long slotDurationInMilisecondes = (long) duration * 60 * 1000;
log.info("Default slot duration in miliseconds: " + slotDurationInMilisecondes);
long nbSlots = slotInterval / slotDurationInMilisecondes;
log.info("Number of slots (Long): " + nbSlots);
slot.setNbSlots((int) nbSlots);
slot.setPrice(price);
Slot entity = DatastoreProxy.createSlot(slot);
log.info("Created new slot for publisher:" + publisher.getFirstname() + " " + publisher.getLastname());
log.info(entity.toString());
} else {
log.warning("Could not find publisher: " + attendee);
}
response.getWriter().println(logFormatter.format(new Date()) + " : Finshed! See the server logs for debug.");
}