@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;
  }
  protected void doExportStagedModel(
      PortletDataContext portletDataContext, CalendarResource calendarResource) throws Exception {

    Element calendarResourceElement = portletDataContext.getExportDataElement(calendarResource);

    for (Calendar calendar : calendarResource.getCalendars()) {
      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext, calendarResource, calendar, PortletDataContext.REFERENCE_TYPE_STRONG);
    }

    if (calendarResource.getClassNameId() == PortalUtil.getClassNameId(User.class)) {

      User user = UserLocalServiceUtil.getUser(calendarResource.getClassPK());

      portletDataContext.addReferenceElement(
          calendarResource,
          calendarResourceElement,
          user,
          User.class,
          PortletDataContext.REFERENCE_TYPE_DEPENDENCY_DISPOSABLE,
          true);
    }

    portletDataContext.addClassedModel(
        calendarResourceElement,
        ExportImportPathUtil.getModelPath(calendarResource),
        calendarResource);
  }
예제 #3
1
  public static List<Calendar> getUserGroupCalendars(PermissionChecker permissionChecker)
      throws PortalException, SystemException {

    List<Calendar> calendars = new ArrayList<Calendar>();

    long classNameId = PortalUtil.getClassNameId(Group.class.getName());

    List<CalendarResource> calendarResources =
        CalendarResourceServiceUtil.search(
            permissionChecker.getCompanyId(),
            new long[] {},
            new long[] {classNameId},
            null,
            true,
            true,
            QueryUtil.ALL_POS,
            QueryUtil.ALL_POS,
            null);

    for (CalendarResource calendarResource : calendarResources) {
      for (Calendar calendar : calendarResource.getCalendars()) {
        if (CalendarPermission.contains(permissionChecker, calendar, ActionKeys.VIEW)) {

          calendars.add(calendar);
        }
      }
    }

    return calendars;
  }
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    CalendarResource newCalendarResource = addCalendarResource();

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

    Assert.assertEquals(existingCalendarResource, newCalendarResource);
  }
예제 #5
1
  public static List<Calendar> getUserCalendars(long userId)
      throws PortalException, SystemException {

    long classNameId = PortalUtil.getClassNameId(User.class.getName());

    CalendarResource calendarResource =
        CalendarResourceServiceUtil.fetchCalendarResource(classNameId, userId);

    return calendarResource.getCalendars();
  }
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    CalendarResource calendarResource = _persistence.create(pk);

    Assert.assertNotNull(calendarResource);

    Assert.assertEquals(calendarResource.getPrimaryKey(), pk);
  }
  @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]));
  }
  @Test
  public void testRemove() throws Exception {
    CalendarResource newCalendarResource = addCalendarResource();

    _persistence.remove(newCalendarResource);

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

    Assert.assertNull(existingCalendarResource);
  }
예제 #9
0
  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));
  }
예제 #10
0
  protected static boolean isCurrentUserCalendar(long userId, Calendar calendar)
      throws PortalException, SystemException {

    CalendarResource calendarResource = calendar.getCalendarResource();

    if (calendarResource.getClassName().equals(User.class.getName())
        && (calendarResource.getClassPK() == userId)) {

      return true;
    } else {
      return false;
    }
  }
  protected long getClassPK(
      PortletDataContext portletDataContext, CalendarResource calendarResource, long userId) {

    long classPK = 0;

    if (calendarResource.getClassNameId() == PortalUtil.getClassNameId(Group.class)) {

      classPK = portletDataContext.getScopeGroupId();
    } else if (calendarResource.getClassNameId() == PortalUtil.getClassNameId(User.class)) {

      classPK = userId;
    }

    return classPK;
  }
  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    CalendarResource newCalendarResource = addCalendarResource();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newCalendarResource.getPrimaryKey());

    Map<Serializable, CalendarResource> calendarResources =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, calendarResources.size());
    Assert.assertEquals(
        newCalendarResource, calendarResources.get(newCalendarResource.getPrimaryKey()));
  }
  /**
   * Adds the calendar resource to the database. Also notifies the appropriate model listeners.
   *
   * @param calendarResource the calendar resource
   * @return the calendar resource that was added
   */
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public CalendarResource addCalendarResource(CalendarResource calendarResource) {
    calendarResource.setNew(true);

    return calendarResourcePersistence.update(calendarResource);
  }
  protected void updateCalendars(
      PortletDataContext portletDataContext,
      CalendarResource calendarResource,
      CalendarResource importedCalendarResource)
      throws SystemException {

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

    List<Element> referenceElements =
        portletDataContext.getReferenceElements(calendarResource, Calendar.class);

    for (Element referenceElement : referenceElements) {
      long calendarId = GetterUtil.getLong(referenceElement.attributeValue("class-pk"));

      Calendar calendar =
          CalendarLocalServiceUtil.fetchCalendar(MapUtil.getLong(calendarIds, calendarId));

      if (calendar != null) {
        calendar.setCalendarResourceId(importedCalendarResource.getCalendarResourceId());

        CalendarLocalServiceUtil.updateCalendar(calendar);
      }
    }
  }
  protected void prepareLanguagesForImport(CalendarResource calendarResource)
      throws PortalException {

    Locale defaultLocale = LocaleUtil.fromLanguageId(calendarResource.getDefaultLanguageId());

    Locale[] availableLocales =
        LocaleUtil.fromLanguageIds(calendarResource.getAvailableLanguageIds());

    Locale defaultImportLocale =
        LocalizationUtil.getDefaultImportLocale(
            CalendarResource.class.getName(),
            calendarResource.getPrimaryKey(),
            defaultLocale,
            availableLocales);

    calendarResource.prepareLocalizedFieldsForImport(defaultImportLocale);
  }
  @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);
  }
  @Override
  public void onAfterUpdate(Group group) throws ModelListenerException {
    try {
      long classNameId = PortalUtil.getClassNameId(Group.class);

      CalendarResource calendarResource =
          CalendarResourceLocalServiceUtil.fetchCalendarResource(classNameId, group.getGroupId());

      if (calendarResource == null) {
        return;
      }

      calendarResource.setNameMap(group.getNameMap());

      CalendarResourceLocalServiceUtil.updateCalendarResource(calendarResource);
    } catch (Exception e) {
      throw new ModelListenerException(e);
    }
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    CalendarResource newCalendarResource = addCalendarResource();

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

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq(
            "calendarResourceId", newCalendarResource.getCalendarResourceId()));

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

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

    CalendarResource existingCalendarResource = result.get(0);

    Assert.assertEquals(existingCalendarResource, newCalendarResource);
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    CalendarResource newCalendarResource = addCalendarResource();

    long pk = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newCalendarResource.getPrimaryKey());
    primaryKeys.add(pk);

    Map<Serializable, CalendarResource> calendarResources =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, calendarResources.size());
    Assert.assertEquals(
        newCalendarResource, calendarResources.get(newCalendarResource.getPrimaryKey()));
  }
  protected boolean countStagedModel(
      PortletDataContext portletDataContext, CalendarResource calendarResource) {

    if (calendarResource.getClassNameId() == PortalUtil.getClassNameId(CalendarResource.class)) {

      return true;
    }

    return false;
  }
  public int compareTo(CalendarResource calendarResource) {
    int value = 0;

    value = getName().toLowerCase().compareTo(calendarResource.getName().toLowerCase());

    if (value != 0) {
      return value;
    }

    return 0;
  }
  @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);
  }
  protected Map<Locale, String> getCalendarResourceNameMap(
      PortletDataContext portletDataContext, CalendarResource calendarResource) throws Exception {

    String calendarResourceName = calendarResource.getName(LocaleUtil.getDefault());

    Group sourceGroup = GroupLocalServiceUtil.fetchGroup(portletDataContext.getSourceGroupId());

    if ((sourceGroup == null) || !calendarResourceName.equals(sourceGroup.getDescriptiveName())) {

      return calendarResource.getNameMap();
    }

    Map<Locale, String> calendarResourceNameMap = new HashMap<Locale, String>();

    Group scopeGroup = GroupLocalServiceUtil.getGroup(portletDataContext.getScopeGroupId());

    calendarResourceNameMap.put(LocaleUtil.getDefault(), scopeGroup.getName());

    return calendarResourceNameMap;
  }
예제 #24
0
  @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 CalendarResource updateCalendarResource(
      long calendarResourceId,
      Map<Locale, String> nameMap,
      Map<Locale, String> descriptionMap,
      boolean active,
      ServiceContext serviceContext)
      throws PortalException {

    // Calendar resource

    validate(nameMap);

    CalendarResource calendarResource =
        calendarResourcePersistence.findByPrimaryKey(calendarResourceId);

    calendarResource.setModifiedDate(serviceContext.getModifiedDate(null));
    calendarResource.setNameMap(nameMap);
    calendarResource.setDescriptionMap(descriptionMap);
    calendarResource.setActive(active);

    calendarResourcePersistence.update(calendarResource);

    // Asset

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

    return calendarResource;
  }
  @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 testDynamicQueryByProjectionExisting() throws Exception {
    CalendarResource newCalendarResource = addCalendarResource();

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

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

    Object newCalendarResourceId = newCalendarResource.getCalendarResourceId();

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

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

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

    Object existingCalendarResourceId = result.get(0);

    Assert.assertEquals(existingCalendarResourceId, newCalendarResourceId);
  }
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }

    CalendarResource calendarResource = null;

    try {
      calendarResource = (CalendarResource) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long primaryKey = calendarResource.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    CalendarResource newCalendarResource1 = addCalendarResource();
    CalendarResource newCalendarResource2 = addCalendarResource();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newCalendarResource1.getPrimaryKey());
    primaryKeys.add(newCalendarResource2.getPrimaryKey());

    Map<Serializable, CalendarResource> calendarResources =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, calendarResources.size());
    Assert.assertEquals(
        newCalendarResource1, calendarResources.get(newCalendarResource1.getPrimaryKey()));
    Assert.assertEquals(
        newCalendarResource2, calendarResources.get(newCalendarResource2.getPrimaryKey()));
  }
  protected CalendarResource addCalendarResource() throws Exception {
    long pk = RandomTestUtil.nextLong();

    CalendarResource calendarResource = _persistence.create(pk);

    calendarResource.setUuid(RandomTestUtil.randomString());

    calendarResource.setGroupId(RandomTestUtil.nextLong());

    calendarResource.setCompanyId(RandomTestUtil.nextLong());

    calendarResource.setUserId(RandomTestUtil.nextLong());

    calendarResource.setUserName(RandomTestUtil.randomString());

    calendarResource.setCreateDate(RandomTestUtil.nextDate());

    calendarResource.setModifiedDate(RandomTestUtil.nextDate());

    calendarResource.setResourceBlockId(RandomTestUtil.nextLong());

    calendarResource.setClassNameId(RandomTestUtil.nextLong());

    calendarResource.setClassPK(RandomTestUtil.nextLong());

    calendarResource.setClassUuid(RandomTestUtil.randomString());

    calendarResource.setCode(RandomTestUtil.randomString());

    calendarResource.setName(RandomTestUtil.randomString());

    calendarResource.setDescription(RandomTestUtil.randomString());

    calendarResource.setActive(RandomTestUtil.randomBoolean());

    calendarResource.setLastPublishDate(RandomTestUtil.nextDate());

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

    return calendarResource;
  }