brandizzi icon

An example of a very complicated code

brandizzi | PRO | 11/25/18 07:19:15 PM UTC | 0 ⭐ | 801 👁️ | Never ⏰ | []
Java |

4.25 KB

|

None

|

0 👍

/

0 👎

protected void addChildCalendarBookings(
        CalendarBooking calendarBooking, long[] childCalendarIds,
        ServiceContext serviceContext)
    throws PortalException {
 
    if (!calendarBooking.isMasterBooking()) {
        return;
    }
 
    long recurringCalendarBookingId =
        CalendarBookingConstants.RECURRING_CALENDAR_BOOKING_ID_DEFAULT;
 
    Map<Long, CalendarBooking> childCalendarBookingMap = new HashMap<>();
 
    List<CalendarBooking> childCalendarBookings =
        calendarBookingPersistence.findByParentCalendarBookingId(
            calendarBooking.getCalendarBookingId());
 
    for (CalendarBooking childCalendarBooking : childCalendarBookings) {
        if (childCalendarBooking.isMasterBooking() ||
            (childCalendarBooking.isDenied() &&
             ArrayUtil.contains(
                 childCalendarIds, childCalendarBooking.getCalendarId()))) {
 
            continue;
        }
 
        deleteCalendarBooking(childCalendarBooking.getCalendarBookingId());
 
        childCalendarBookingMap.put(
            childCalendarBooking.getCalendarId(), childCalendarBooking);
    }
 
    for (long calendarId : childCalendarIds) {
        try {
            calendarId = getNotLiveCalendarId(calendarId);
        }
        catch (NoSuchCalendarException nsce) {
            continue;
        }
 
        int count = calendarBookingPersistence.countByC_P(
            calendarId, calendarBooking.getCalendarBookingId());
 
        if (count > 0) {
            continue;
        }
 
        long firstReminder = calendarBooking.getFirstReminder();
        String firstReminderType = calendarBooking.getFirstReminderType();
        long secondReminder = calendarBooking.getSecondReminder();
        String secondReminderType = calendarBooking.getSecondReminderType();
 
        if (childCalendarBookingMap.containsKey(calendarId)) {
            CalendarBooking oldChildCalendarBooking =
                childCalendarBookingMap.get(calendarId);
 
            firstReminder = oldChildCalendarBooking.getFirstReminder();
            firstReminderType =
                oldChildCalendarBooking.getFirstReminderType();
            secondReminder = oldChildCalendarBooking.getSecondReminder();
            secondReminderType =
                oldChildCalendarBooking.getSecondReminderType();
        }
 
        if (!calendarBooking.isMasterRecurringBooking()) {
            CalendarBooking childMasterRecurringBooking =
                calendarBookingPersistence.fetchByC_P(
                    calendarId,
                    calendarBooking.getRecurringCalendarBookingId());
 
            if (childMasterRecurringBooking == null) {
                childMasterRecurringBooking = childCalendarBookingMap.get(
                    calendarId);
            }
 
            if (childMasterRecurringBooking != null) {
                recurringCalendarBookingId =
                    childMasterRecurringBooking.getCalendarBookingId();
            }
        }
 
        serviceContext.setAttribute("sendNotification", Boolean.FALSE);
 
        CalendarBooking childCalendarBooking = addCalendarBooking(
            calendarBooking.getUserId(), calendarId, new long[0],
            calendarBooking.getCalendarBookingId(),
            recurringCalendarBookingId, calendarBooking.getTitleMap(),
            calendarBooking.getDescriptionMap(),
            calendarBooking.getLocation(), calendarBooking.getStartTime(),
            calendarBooking.getEndTime(), calendarBooking.isAllDay(),
            calendarBooking.getRecurrence(), firstReminder,
            firstReminderType, secondReminder, secondReminderType,
            serviceContext);
 
        serviceContext.setAttribute("sendNotification", Boolean.TRUE);
 
        if (childCalendarBookingMap.containsKey(calendarId)) {
            CalendarBooking oldChildCalendarBooking =
                childCalendarBookingMap.get(calendarId);
            int workflowAction = GetterUtil.getInteger(
                serviceContext.getAttribute("workflowAction"));
 
            if ((calendarBooking.getStartTime() ==
                    oldChildCalendarBooking.getStartTime()) &&
                (calendarBooking.getEndTime() ==
                    oldChildCalendarBooking.getEndTime()) &&
                (workflowAction != WorkflowConstants.ACTION_SAVE_DRAFT)) {
 
                updateStatus(
                    childCalendarBooking.getUserId(), childCalendarBooking,
                    oldChildCalendarBooking.getStatus(), serviceContext);
            }
        }
 
        NotificationTemplateType notificationTemplateType =
            NotificationTemplateType.INVITE;
 
        if (childCalendarBooking.isDenied()) {
            notificationTemplateType = NotificationTemplateType.DECLINE;
        }
        else if (childCalendarBookingMap.containsKey(
                    childCalendarBooking.getCalendarId())) {
 
            notificationTemplateType = NotificationTemplateType.UPDATE;
        }
 
        sendNotification(
            childCalendarBooking, notificationTemplateType, serviceContext);
    }
}

Comments