@Override
  public PortletURL getURLAdd(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      long classTypeId)
      throws PortalException {

    ThemeDisplay themeDisplay =
        (ThemeDisplay) liferayPortletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    CalendarResource calendarResource =
        CalendarResourceUtil.getScopeGroupCalendarResource(
            liferayPortletRequest, themeDisplay.getScopeGroupId());

    if (calendarResource == null) {
      return null;
    }

    PortletURL portletURL =
        PortalUtil.getControlPanelPortletURL(
            liferayPortletRequest, CalendarPortletKeys.CALENDAR, PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcPath", "/edit_calendar_booking.jsp");

    Calendar calendar = calendarResource.getDefaultCalendar();

    portletURL.setParameter("calendarId", String.valueOf(calendar.getCalendarId()));

    return portletURL;
  }
예제 #2
0
  public static List<CalendarBooking> getCalendarBookings(
      PermissionChecker permissionChecker, Calendar calendar, Date startDate, Date endDate)
      throws PortalException, SystemException {

    ClassLoader classLoader = ClassLoaderPool.getClassLoader("calendar-portlet");

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(CalendarBooking.class, classLoader);

    dynamicQuery.add(RestrictionsFactoryUtil.eq("calendarId", calendar.getCalendarId()));

    List<Integer> calendarStatus = new ArrayList<Integer>();
    calendarStatus.add(WorkflowConstants.STATUS_APPROVED);
    calendarStatus.add(WorkflowConstants.STATUS_PENDING);
    calendarStatus.add(WorkflowConstants.STATUS_DRAFT_FROM_APPROVED);

    dynamicQuery.add(RestrictionsFactoryUtil.in("status", calendarStatus));

    if (startDate != null) {
      dynamicQuery.add(RestrictionsFactoryUtil.ge("startTime", new Long(startDate.getTime())));
    }

    if (endDate != null) {
      dynamicQuery.add(RestrictionsFactoryUtil.le("endTime", new Long(endDate.getTime())));
    }

    List<CalendarBooking> allCalendarBookings =
        CalendarBookingLocalServiceUtil.dynamicQuery(dynamicQuery);

    return filterCalendarBookings(allCalendarBookings, permissionChecker, ActionKeys.VIEW);
  }
  @Override
  protected void doImportMissingReference(
      PortletDataContext portletDataContext, String uuid, long groupId, long calendarId)
      throws Exception {

    Calendar existingCalendar = fetchMissingReference(uuid, groupId);

    if (existingCalendar == null) {
      return;
    }

    Map<Long, Long> calendarIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Calendar.class);

    calendarIds.put(calendarId, existingCalendar.getCalendarId());
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    Calendar newCalendar = addCalendar();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Calendar.class, _dynamicQueryClassLoader);

    dynamicQuery.add(RestrictionsFactoryUtil.eq("calendarId", newCalendar.getCalendarId()));

    List<Calendar> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Calendar existingCalendar = result.get(0);

    Assert.assertEquals(existingCalendar, newCalendar);
  }
  @Override
  protected Document doGetDocument(Calendar calendar) throws Exception {
    Document document = getBaseModelDocument(CLASS_NAME, calendar);

    document.addLocalizedText(Field.DESCRIPTION, calendar.getDescriptionMap());
    document.addLocalizedText(Field.NAME, calendar.getNameMap());
    document.addKeyword("calendarId", calendar.getCalendarId());

    Locale defaultLocale = LocaleUtil.getSiteDefault();

    String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

    document.addText("defaultLanguageId", defaultLanguageId);

    CalendarResource calendarResource = calendar.getCalendarResource();

    document.addLocalizedText("resourceName", calendarResource.getNameMap());

    return document;
  }
  @Override
  public boolean hasAddPermission(
      PermissionChecker permissionChecker, long groupId, long classTypeId) throws Exception {

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setCompanyId(permissionChecker.getCompanyId());

    CalendarResource calendarResource =
        CalendarResourceUtil.getScopeGroupCalendarResource(groupId, serviceContext);

    if (calendarResource == null) {
      return false;
    }

    Calendar calendar = calendarResource.getDefaultCalendar();

    return CalendarPermission.contains(
        permissionChecker, calendar.getCalendarId(), CalendarActionKeys.MANAGE_BOOKINGS);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    Calendar newCalendar = addCalendar();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Calendar.class, _dynamicQueryClassLoader);

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("calendarId"));

    Object newCalendarId = newCalendar.getCalendarId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("calendarId", new Object[] {newCalendarId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingCalendarId = result.get(0);

    Assert.assertEquals(existingCalendarId, newCalendarId);
  }
  @Override
  @SystemEvent(action = SystemEventConstants.ACTION_SKIP, type = SystemEventConstants.TYPE_DELETE)
  public CalendarResource deleteCalendarResource(CalendarResource calendarResource)
      throws PortalException {

    // Calendar resource

    calendarResourcePersistence.remove(calendarResource);

    // Resources

    resourceLocalService.deleteResource(calendarResource, ResourceConstants.SCOPE_INDIVIDUAL);

    // Calendars

    List<Calendar> calendars =
        calendarPersistence.findByG_C(
            calendarResource.getGroupId(), calendarResource.getCalendarResourceId());

    for (Calendar calendar : calendars) {
      calendarPersistence.remove(calendar);

      resourceLocalService.deleteResource(calendar, ResourceConstants.SCOPE_INDIVIDUAL);

      calendarNotificationTemplateLocalService.deleteCalendarNotificationTemplates(
          calendar.getCalendarId());
    }

    // Calendar bookings

    List<CalendarBooking> calendarBookings =
        calendarBookingPersistence.findByCalendarResourceId(
            calendarResource.getCalendarResourceId());

    for (CalendarBooking calendarBooking : calendarBookings) {
      calendarBookingLocalService.deleteCalendarBooking(calendarBooking);
    }

    return calendarResource;
  }
  @Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, Calendar calendar)
      throws Exception {

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

    Map<Long, Long> calendarResourceIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(CalendarResource.class);

    long calendarResourceId =
        MapUtil.getLong(
            calendarResourceIds,
            calendar.getCalendarResourceId(),
            calendar.getCalendarResourceId());

    Map<Locale, String> calendarNameMap = getCalendarNameMap(portletDataContext, calendar);

    ServiceContext serviceContext = portletDataContext.createServiceContext(calendar);

    Calendar importedCalendar = null;

    if (portletDataContext.isDataStrategyMirror()) {
      Calendar existingCalendar =
          fetchStagedModelByUuidAndGroupId(
              calendar.getUuid(), portletDataContext.getScopeGroupId());

      if (existingCalendar == null) {
        serviceContext.setUuid(calendar.getUuid());

        importedCalendar =
            CalendarLocalServiceUtil.addCalendar(
                userId,
                portletDataContext.getScopeGroupId(),
                calendarResourceId,
                calendarNameMap,
                calendar.getDescriptionMap(),
                calendar.getTimeZoneId(),
                calendar.getColor(),
                calendar.isDefaultCalendar(),
                calendar.isEnableComments(),
                calendar.isEnableRatings(),
                serviceContext);
      } else {
        importedCalendar =
            CalendarLocalServiceUtil.updateCalendar(
                existingCalendar.getCalendarId(),
                calendar.getNameMap(),
                calendar.getDescriptionMap(),
                calendar.getTimeZoneId(),
                calendar.getColor(),
                calendar.isDefaultCalendar(),
                calendar.isEnableComments(),
                calendar.isEnableRatings(),
                serviceContext);
      }
    } else {
      importedCalendar =
          CalendarLocalServiceUtil.addCalendar(
              userId,
              portletDataContext.getScopeGroupId(),
              calendarResourceId,
              calendarNameMap,
              calendar.getDescriptionMap(),
              calendar.getTimeZoneId(),
              calendar.getColor(),
              calendar.isDefaultCalendar(),
              calendar.isEnableComments(),
              calendar.isEnableRatings(),
              serviceContext);
    }

    portletDataContext.importClassedModel(calendar, importedCalendar);
  }
예제 #10
0
 @Override
 protected void doDelete(Calendar calendar) throws Exception {
   deleteDocument(calendar.getCompanyId(), calendar.getCalendarId());
 }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Calendar newCalendar = _persistence.create(pk);

    newCalendar.setUuid(RandomTestUtil.randomString());

    newCalendar.setGroupId(RandomTestUtil.nextLong());

    newCalendar.setCompanyId(RandomTestUtil.nextLong());

    newCalendar.setUserId(RandomTestUtil.nextLong());

    newCalendar.setUserName(RandomTestUtil.randomString());

    newCalendar.setCreateDate(RandomTestUtil.nextDate());

    newCalendar.setModifiedDate(RandomTestUtil.nextDate());

    newCalendar.setResourceBlockId(RandomTestUtil.nextLong());

    newCalendar.setCalendarResourceId(RandomTestUtil.nextLong());

    newCalendar.setName(RandomTestUtil.randomString());

    newCalendar.setDescription(RandomTestUtil.randomString());

    newCalendar.setTimeZoneId(RandomTestUtil.randomString());

    newCalendar.setColor(RandomTestUtil.nextInt());

    newCalendar.setDefaultCalendar(RandomTestUtil.randomBoolean());

    newCalendar.setEnableComments(RandomTestUtil.randomBoolean());

    newCalendar.setEnableRatings(RandomTestUtil.randomBoolean());

    newCalendar.setLastPublishDate(RandomTestUtil.nextDate());

    _calendars.add(_persistence.update(newCalendar));

    Calendar existingCalendar = _persistence.findByPrimaryKey(newCalendar.getPrimaryKey());

    Assert.assertEquals(existingCalendar.getUuid(), newCalendar.getUuid());
    Assert.assertEquals(existingCalendar.getCalendarId(), newCalendar.getCalendarId());
    Assert.assertEquals(existingCalendar.getGroupId(), newCalendar.getGroupId());
    Assert.assertEquals(existingCalendar.getCompanyId(), newCalendar.getCompanyId());
    Assert.assertEquals(existingCalendar.getUserId(), newCalendar.getUserId());
    Assert.assertEquals(existingCalendar.getUserName(), newCalendar.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingCalendar.getCreateDate()),
        Time.getShortTimestamp(newCalendar.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingCalendar.getModifiedDate()),
        Time.getShortTimestamp(newCalendar.getModifiedDate()));
    Assert.assertEquals(existingCalendar.getResourceBlockId(), newCalendar.getResourceBlockId());
    Assert.assertEquals(
        existingCalendar.getCalendarResourceId(), newCalendar.getCalendarResourceId());
    Assert.assertEquals(existingCalendar.getName(), newCalendar.getName());
    Assert.assertEquals(existingCalendar.getDescription(), newCalendar.getDescription());
    Assert.assertEquals(existingCalendar.getTimeZoneId(), newCalendar.getTimeZoneId());
    Assert.assertEquals(existingCalendar.getColor(), newCalendar.getColor());
    Assert.assertEquals(existingCalendar.getDefaultCalendar(), newCalendar.getDefaultCalendar());
    Assert.assertEquals(existingCalendar.getEnableComments(), newCalendar.getEnableComments());
    Assert.assertEquals(existingCalendar.getEnableRatings(), newCalendar.getEnableRatings());
    Assert.assertEquals(
        Time.getShortTimestamp(existingCalendar.getLastPublishDate()),
        Time.getShortTimestamp(newCalendar.getLastPublishDate()));
  }
  @Override
  protected void doDelete(Object object) throws Exception {
    Calendar calendar = (Calendar) object;

    deleteDocument(calendar.getCompanyId(), calendar.getCalendarId());
  }