@Test
  public void testResetOriginalValues() throws Exception {
    CalendarResource newCalendarResource = addCalendarResource();

    _persistence.clearCache();

    CalendarResource existingCalendarResource =
        _persistence.findByPrimaryKey(newCalendarResource.getPrimaryKey());

    Assert.assertTrue(
        Validator.equals(
            existingCalendarResource.getUuid(),
            ReflectionTestUtil.invoke(
                existingCalendarResource, "getOriginalUuid", new Class<?>[0])));
    Assert.assertEquals(
        Long.valueOf(existingCalendarResource.getGroupId()),
        ReflectionTestUtil.<Long>invoke(
            existingCalendarResource, "getOriginalGroupId", new Class<?>[0]));

    Assert.assertEquals(
        Long.valueOf(existingCalendarResource.getClassNameId()),
        ReflectionTestUtil.<Long>invoke(
            existingCalendarResource, "getOriginalClassNameId", new Class<?>[0]));
    Assert.assertEquals(
        Long.valueOf(existingCalendarResource.getClassPK()),
        ReflectionTestUtil.<Long>invoke(
            existingCalendarResource, "getOriginalClassPK", new Class<?>[0]));
  }
  @Override
  public void updateAsset(
      long userId,
      CalendarResource calendarResource,
      long[] assetCategoryIds,
      String[] assetTagNames)
      throws PortalException {

    assetEntryLocalService.updateEntry(
        userId,
        calendarResource.getGroupId(),
        calendarResource.getCreateDate(),
        calendarResource.getModifiedDate(),
        CalendarResource.class.getName(),
        calendarResource.getCalendarResourceId(),
        calendarResource.getUuid(),
        0,
        assetCategoryIds,
        assetTagNames,
        true,
        null,
        null,
        null,
        ContentTypes.TEXT,
        calendarResource.getName(),
        calendarResource.getDescription(),
        null,
        null,
        null,
        0,
        0,
        null,
        false);
  }
コード例 #3
0
ファイル: CalendarUtil.java プロジェクト: smclab/caldav-sync
  public static List<Calendar> getCalendarResourceCalendars(CalendarResource calendarResource)
      throws PortalException, SystemException {

    return CalendarServiceUtil.search(
        calendarResource.getCompanyId(),
        new long[] {calendarResource.getGroupId()},
        new long[] {calendarResource.getCalendarResourceId()},
        null,
        false,
        QueryUtil.ALL_POS,
        QueryUtil.ALL_POS,
        new CalendarNameComparator(true));
  }
  @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;
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    CalendarResource newCalendarResource = _persistence.create(pk);

    newCalendarResource.setUuid(RandomTestUtil.randomString());

    newCalendarResource.setGroupId(RandomTestUtil.nextLong());

    newCalendarResource.setCompanyId(RandomTestUtil.nextLong());

    newCalendarResource.setUserId(RandomTestUtil.nextLong());

    newCalendarResource.setUserName(RandomTestUtil.randomString());

    newCalendarResource.setCreateDate(RandomTestUtil.nextDate());

    newCalendarResource.setModifiedDate(RandomTestUtil.nextDate());

    newCalendarResource.setResourceBlockId(RandomTestUtil.nextLong());

    newCalendarResource.setClassNameId(RandomTestUtil.nextLong());

    newCalendarResource.setClassPK(RandomTestUtil.nextLong());

    newCalendarResource.setClassUuid(RandomTestUtil.randomString());

    newCalendarResource.setCode(RandomTestUtil.randomString());

    newCalendarResource.setName(RandomTestUtil.randomString());

    newCalendarResource.setDescription(RandomTestUtil.randomString());

    newCalendarResource.setActive(RandomTestUtil.randomBoolean());

    newCalendarResource.setLastPublishDate(RandomTestUtil.nextDate());

    _calendarResources.add(_persistence.update(newCalendarResource));

    CalendarResource existingCalendarResource =
        _persistence.findByPrimaryKey(newCalendarResource.getPrimaryKey());

    Assert.assertEquals(existingCalendarResource.getUuid(), newCalendarResource.getUuid());
    Assert.assertEquals(
        existingCalendarResource.getCalendarResourceId(),
        newCalendarResource.getCalendarResourceId());
    Assert.assertEquals(existingCalendarResource.getGroupId(), newCalendarResource.getGroupId());
    Assert.assertEquals(
        existingCalendarResource.getCompanyId(), newCalendarResource.getCompanyId());
    Assert.assertEquals(existingCalendarResource.getUserId(), newCalendarResource.getUserId());
    Assert.assertEquals(existingCalendarResource.getUserName(), newCalendarResource.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingCalendarResource.getCreateDate()),
        Time.getShortTimestamp(newCalendarResource.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingCalendarResource.getModifiedDate()),
        Time.getShortTimestamp(newCalendarResource.getModifiedDate()));
    Assert.assertEquals(
        existingCalendarResource.getResourceBlockId(), newCalendarResource.getResourceBlockId());
    Assert.assertEquals(
        existingCalendarResource.getClassNameId(), newCalendarResource.getClassNameId());
    Assert.assertEquals(existingCalendarResource.getClassPK(), newCalendarResource.getClassPK());
    Assert.assertEquals(
        existingCalendarResource.getClassUuid(), newCalendarResource.getClassUuid());
    Assert.assertEquals(existingCalendarResource.getCode(), newCalendarResource.getCode());
    Assert.assertEquals(existingCalendarResource.getName(), newCalendarResource.getName());
    Assert.assertEquals(
        existingCalendarResource.getDescription(), newCalendarResource.getDescription());
    Assert.assertEquals(existingCalendarResource.getActive(), newCalendarResource.getActive());
    Assert.assertEquals(
        Time.getShortTimestamp(existingCalendarResource.getLastPublishDate()),
        Time.getShortTimestamp(newCalendarResource.getLastPublishDate()));
  }
  @Override
  public CalendarResource addCalendarResource(
      long userId,
      long groupId,
      long classNameId,
      long classPK,
      String classUuid,
      String code,
      Map<Locale, String> nameMap,
      Map<Locale, String> descriptionMap,
      boolean active,
      ServiceContext serviceContext)
      throws PortalException {

    // Calendar resource

    User user = userPersistence.findByPrimaryKey(userId);

    long calendarResourceId = counterLocalService.increment();

    if (classNameId == classNameLocalService.getClassNameId(CalendarResource.class)) {

      classPK = calendarResourceId;
    }

    if (PortletPropsValues.CALENDAR_RESOURCE_FORCE_AUTOGENERATE_CODE || Validator.isNull(code)) {

      code = String.valueOf(calendarResourceId);
    } else {
      code = code.trim();
      code = StringUtil.toUpperCase(code);
    }

    Date now = new Date();

    validate(groupId, classNameId, classPK, code, nameMap);

    CalendarResource calendarResource = calendarResourcePersistence.create(calendarResourceId);

    calendarResource.setUuid(serviceContext.getUuid());
    calendarResource.setGroupId(groupId);
    calendarResource.setCompanyId(user.getCompanyId());
    calendarResource.setUserId(user.getUserId());
    calendarResource.setUserName(user.getFullName());
    calendarResource.setCreateDate(serviceContext.getCreateDate(now));
    calendarResource.setModifiedDate(serviceContext.getModifiedDate(now));
    calendarResource.setClassNameId(classNameId);
    calendarResource.setClassPK(classPK);
    calendarResource.setClassUuid(classUuid);
    calendarResource.setCode(code);
    calendarResource.setNameMap(nameMap);
    calendarResource.setDescriptionMap(descriptionMap);
    calendarResource.setActive(active);

    calendarResourcePersistence.update(calendarResource);

    // Resources

    resourceLocalService.addModelResources(calendarResource, serviceContext);

    // Calendar

    if (!ExportImportThreadLocal.isImportInProcess()) {
      serviceContext.setAddGroupPermissions(true);
      serviceContext.setAddGuestPermissions(true);

      calendarLocalService.addCalendar(
          userId,
          calendarResource.getGroupId(),
          calendarResourceId,
          nameMap,
          descriptionMap,
          calendarResource.getTimeZoneId(),
          PortletPropsValues.CALENDAR_COLOR_DEFAULT,
          true,
          false,
          false,
          serviceContext);
    }

    // Asset

    updateAsset(
        calendarResource.getUserId(),
        calendarResource,
        serviceContext.getAssetCategoryIds(),
        serviceContext.getAssetTagNames());

    return calendarResource;
  }
コード例 #7
0
  @Override
  public void importCalEvent(CalEvent calEvent) throws PortalException, SystemException {

    // Calendar event

    if (isImported(calEvent)) {
      return;
    }

    long calendarBookingId = counterLocalService.increment();

    CalendarResource calendarResource =
        getCalendarResource(calEvent.getCompanyId(), calEvent.getGroupId());

    Date startDate = calEvent.getStartDate();

    long startTime = startDate.getTime();

    long endTime =
        startTime
            + calEvent.getDurationHour() * Time.HOUR
            + calEvent.getDurationMinute() * Time.MINUTE;

    if (calEvent.isAllDay()) {
      endTime = endTime - 1;
    }

    String recurrence = getRecurrence(calEvent.getRecurrenceObj());

    addCalendarBooking(
        calEvent.getUuid(),
        calendarBookingId,
        calEvent.getCompanyId(),
        calendarResource.getGroupId(),
        calEvent.getUserId(),
        calEvent.getUserName(),
        calEvent.getCreateDate(),
        calEvent.getModifiedDate(),
        calendarResource.getDefaultCalendarId(),
        calendarResource.getCalendarResourceId(),
        calEvent.getTitle(),
        calEvent.getDescription(),
        calEvent.getLocation(),
        startTime,
        endTime,
        calEvent.getAllDay(),
        recurrence,
        calEvent.getFirstReminder(),
        NotificationType.EMAIL,
        calEvent.getSecondReminder(),
        NotificationType.EMAIL);

    // Resources

    importCalendarBookingResourcePermissions(calEvent, calendarBookingId);

    // Subscriptions

    importSubscriptions(calEvent, calendarBookingId);

    // Asset

    importAssets(calEvent, calendarBookingId);

    // Message boards

    importMBDiscussion(calEvent, calendarBookingId);

    // Social

    importSocialActivities(calEvent, calendarBookingId);

    // Ratings

    importRatings(
        classNameLocalService.getClassNameId(CalEvent.class.getName()),
        calEvent.getEventId(),
        classNameLocalService.getClassNameId(CalendarBooking.class.getName()),
        calendarBookingId);
  }