protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay)
      throws Exception {

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (!CalEventPermission.contains(permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {

      return null;
    }

    String groupName = StringPool.BLANK;

    if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
      groupName = getGroupName(activity.getGroupId(), themeDisplay);
    }

    String creatorUserName = getUserName(activity.getUserId(), themeDisplay);

    int activityType = activity.getType();

    // Link

    CalEvent event = CalEventLocalServiceUtil.getEvent(activity.getClassPK());

    String link =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathMain()
            + "/calendar/find_event?redirect="
            + themeDisplay.getURLCurrent()
            + "&eventId="
            + activity.getClassPK();

    // Title

    String titlePattern = null;

    if (activityType == CalendarActivityKeys.ADD_EVENT) {
      titlePattern = "activity-calendar-add-event";
    } else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
      titlePattern = "activity-calendar-update-event";
    }

    if (Validator.isNotNull(groupName)) {
      titlePattern += "-in";
    }

    String eventTitle = wrapLink(link, HtmlUtil.escape(cleanContent(event.getTitle())));

    Object[] titleArguments = new Object[] {groupName, creatorUserName, eventTitle};

    String title = themeDisplay.translate(titlePattern, titleArguments);

    // Body

    String body = StringPool.BLANK;

    return new SocialActivityFeedEntry(link, title, body);
  }
  protected void initActionableDynamicQuery(ActionableDynamicQuery actionableDynamicQuery) {
    actionableDynamicQuery.setBaseLocalService(
        com.liferay.portlet.calendar.service.CalEventLocalServiceUtil.getService());
    actionableDynamicQuery.setClass(CalEvent.class);
    actionableDynamicQuery.setClassLoader(getClassLoader());

    actionableDynamicQuery.setPrimaryKeyPropertyName("eventId");
  }
示例#3
0
 public static int getEventsCount(long groupId, String type) {
   try {
     return CalEventLocalServiceUtil.getEventsCount(groupId, type);
   } catch (SystemException e) {
     // TODO Auto-generated catch block
     _log.error(e);
     return -1;
   }
 }
示例#4
0
  public static List<CalEvent> getEvents(
      TimeZone timeZone, Locale locale, long groupId, String type) {
    Calendar curCal = CalendarFactoryUtil.getCalendar(timeZone, locale);

    try {
      return CalEventLocalServiceUtil.getEvents(groupId, curCal, type);
    } catch (SystemException e) {
      // TODO Auto-generated catch block
      _log.error(e);
      return null;
    }
  }
  @Override
  public ActionableDynamicQuery getActionableDynamicQuery() {
    ActionableDynamicQuery actionableDynamicQuery = new DefaultActionableDynamicQuery();

    actionableDynamicQuery.setBaseLocalService(
        com.liferay.portlet.calendar.service.CalEventLocalServiceUtil.getService());
    actionableDynamicQuery.setClass(CalEvent.class);
    actionableDynamicQuery.setClassLoader(getClassLoader());

    actionableDynamicQuery.setPrimaryKeyPropertyName("eventId");

    return actionableDynamicQuery;
  }
  protected void verifyNoAssets() throws Exception {
    List<CalEvent> events = CalEventLocalServiceUtil.getNoAssetEvents();

    if (_log.isDebugEnabled()) {
      _log.debug("Processing " + events.size() + " events with no asset");
    }

    for (CalEvent event : events) {
      try {
        CalEventLocalServiceUtil.updateAsset(event.getUserId(), event, null, null, null);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(
              "Unable to update asset for event " + event.getEventId() + ": " + e.getMessage());
        }
      }
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Assets verified for events");
    }
  }
  @Override
  protected PortletPreferences doDeleteData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

    if (!portletDataContext.addPrimaryKey(CalendarPortletDataHandlerImpl.class, "deleteData")) {

      CalEventLocalServiceUtil.deleteEvents(portletDataContext.getScopeGroupId());
    }

    return null;
  }
示例#8
0
  public static List<CalEvent> getEventFromDateRange(
      ThemeDisplay themeDisplay, Date startDate, Date endDate) {
    List<CalEvent> lstEvents = null;
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(CalEvent.class);
    dynamicQuery.add(PropertyFactoryUtil.forName("groupId").eq(themeDisplay.getScopeGroupId()));

    Criterion criterion = null;

    criterion = RestrictionsFactoryUtil.between("startDate", startDate, endDate);
    Order defaultOrder = OrderFactoryUtil.asc("startDate");

    dynamicQuery.add(criterion);
    dynamicQuery.addOrder(defaultOrder);
    try {
      lstEvents = CalEventLocalServiceUtil.dynamicQuery(dynamicQuery);
    } catch (SystemException e) {

      _log.error(e);
    }

    return lstEvents;
  }
  @Test
  public void testActionableDynamicQuery() throws Exception {
    final IntegerWrapper count = new IntegerWrapper();

    ActionableDynamicQuery actionableDynamicQuery =
        CalEventLocalServiceUtil.getActionableDynamicQuery();

    actionableDynamicQuery.setPerformActionMethod(
        new ActionableDynamicQuery.PerformActionMethod() {
          @Override
          public void performAction(Object object) {
            CalEvent calEvent = (CalEvent) object;

            Assert.assertNotNull(calEvent);

            count.increment();
          }
        });

    actionableDynamicQuery.performActions();

    Assert.assertEquals(count.getValue(), _persistence.countAll());
  }
示例#10
0
  protected void importEvent(
      PortletDataContext portletDataContext, Element eventElement, CalEvent event)
      throws Exception {

    long userId = portletDataContext.getUserId(event.getUserUuid());

    Date startDate = event.getStartDate();

    int startDateMonth = 0;
    int startDateDay = 0;
    int startDateYear = 0;
    int startDateHour = 0;
    int startDateMinute = 0;

    if (startDate != null) {
      Locale locale = null;
      TimeZone timeZone = null;

      if (event.getTimeZoneSensitive()) {
        User user = UserLocalServiceUtil.getUser(userId);

        locale = user.getLocale();
        timeZone = user.getTimeZone();
      } else {
        locale = LocaleUtil.getDefault();
        timeZone = TimeZoneUtil.getTimeZone(StringPool.UTC);
      }

      Calendar startCal = CalendarFactoryUtil.getCalendar(timeZone, locale);

      startCal.setTime(startDate);

      startDateMonth = startCal.get(Calendar.MONTH);
      startDateDay = startCal.get(Calendar.DATE);
      startDateYear = startCal.get(Calendar.YEAR);
      startDateHour = startCal.get(Calendar.HOUR);
      startDateMinute = startCal.get(Calendar.MINUTE);

      if (startCal.get(Calendar.AM_PM) == Calendar.PM) {
        startDateHour += 12;
      }
    }

    ServiceContext serviceContext =
        portletDataContext.createServiceContext(eventElement, event, NAMESPACE);

    CalEvent importedEvent = null;

    if (portletDataContext.isDataStrategyMirror()) {
      CalEvent existingEvent =
          CalEventUtil.fetchByUUID_G(event.getUuid(), portletDataContext.getScopeGroupId());

      if (existingEvent == null) {
        serviceContext.setUuid(event.getUuid());

        importedEvent =
            CalEventLocalServiceUtil.addEvent(
                userId,
                event.getTitle(),
                event.getDescription(),
                event.getLocation(),
                startDateMonth,
                startDateDay,
                startDateYear,
                startDateHour,
                startDateMinute,
                event.getDurationHour(),
                event.getDurationMinute(),
                event.isAllDay(),
                event.isTimeZoneSensitive(),
                event.getType(),
                event.getRepeating(),
                event.getRecurrenceObj(),
                event.getRemindBy(),
                event.getFirstReminder(),
                event.getSecondReminder(),
                serviceContext);
      } else {
        importedEvent =
            CalEventLocalServiceUtil.updateEvent(
                userId,
                existingEvent.getEventId(),
                event.getTitle(),
                event.getDescription(),
                event.getLocation(),
                startDateMonth,
                startDateDay,
                startDateYear,
                startDateHour,
                startDateMinute,
                event.getDurationHour(),
                event.getDurationMinute(),
                event.isAllDay(),
                event.isTimeZoneSensitive(),
                event.getType(),
                event.getRepeating(),
                event.getRecurrenceObj(),
                event.getRemindBy(),
                event.getFirstReminder(),
                event.getSecondReminder(),
                serviceContext);
      }
    } else {
      importedEvent =
          CalEventLocalServiceUtil.addEvent(
              userId,
              event.getTitle(),
              event.getDescription(),
              event.getLocation(),
              startDateMonth,
              startDateDay,
              startDateYear,
              startDateHour,
              startDateMinute,
              event.getDurationHour(),
              event.getDurationMinute(),
              event.isAllDay(),
              event.isTimeZoneSensitive(),
              event.getType(),
              event.getRepeating(),
              event.getRecurrenceObj(),
              event.getRemindBy(),
              event.getFirstReminder(),
              event.getSecondReminder(),
              serviceContext);
    }

    portletDataContext.importClassedModel(event, importedEvent, NAMESPACE);
  }
  private CalEvent createEvent4Patient(
      String name,
      User creatorUser,
      long patientId,
      Date startDate,
      Date endDate,
      ServiceContext serviceContext)
      throws SystemException, PortalException {

    debug("Adding event for patient: " + patientId);
    debug("dates:" + startDate + " to " + endDate);

    Patient patient = PatientLocalServiceUtil.getPatient(patientId);

    Locale locale =
        (serviceContext.getLocale() != null ? serviceContext.getLocale() : Locale.getDefault());

    String title = LanguageUtil.format(locale, "wizard-044-event-title", new Object[] {name});
    String description =
        LanguageUtil.format(
            locale,
            "wizard-043-event-description",
            new Object[] {
              PatientLocalServiceUtil.getPatientFullName(patient), creatorUser.getFullName(), name
            });
    String location = StringPool.BLANK;

    Calendar startCal = Calendar.getInstance();
    startCal.setTime(startDate);

    Calendar endCal = Calendar.getInstance();
    endCal.setTime(endDate);

    boolean allDay = true;
    boolean timeZoneSensitive = false;
    String type = StringPool.BLANK;
    boolean repeating = false;
    TZSRecurrence recurrence = null;
    int remindBy = 0;
    int firstReminder = 0;
    int secondReminder = 0;
    CalEvent event =
        CalEventLocalServiceUtil.addEvent(
            creatorUser.getUserId(),
            title,
            description,
            location,
            startCal.get(Calendar.MONTH),
            startCal.get(Calendar.DAY_OF_MONTH),
            startCal.get(Calendar.YEAR),
            0,
            0,
            endCal.get(Calendar.MONTH),
            endCal.get(Calendar.DAY_OF_MONTH),
            endCal.get(Calendar.YEAR),
            24,
            0,
            allDay,
            timeZoneSensitive,
            type,
            repeating,
            recurrence,
            remindBy,
            firstReminder,
            secondReminder,
            serviceContext);
    debug("CalEvent succesfully created: " + event);

    PrimumUtilLocalServiceUtil.setExpandoValue(
        creatorUser.getCompanyId(),
        CalEvent.class.getName(),
        "patientId",
        event.getPrimaryKey(),
        String.valueOf(patientId));
    return event;
  }