Example #1
0
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    ExportImportConfiguration newExportImportConfiguration = addExportImportConfiguration();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            ExportImportConfiguration.class, ExportImportConfiguration.class.getClassLoader());

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

    Object newExportImportConfigurationId =
        newExportImportConfiguration.getExportImportConfigurationId();

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

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

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

    Object existingExportImportConfigurationId = result.get(0);

    Assert.assertEquals(existingExportImportConfigurationId, newExportImportConfigurationId);
  }
Example #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);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    KaleoNotificationRecipient newKaleoNotificationRecipient = addKaleoNotificationRecipient();

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

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

    Object newKaleoNotificationRecipientId =
        newKaleoNotificationRecipient.getKaleoNotificationRecipientId();

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

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

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

    Object existingKaleoNotificationRecipientId = result.get(0);

    Assert.assertEquals(existingKaleoNotificationRecipientId, newKaleoNotificationRecipientId);
  }
  public void testDynamicQueryByProjectionMissing() throws Exception {
    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Counter.class, Counter.class.getClassLoader());

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

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

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

    assertEquals(0, result.size());
  }
  @Test
  public void testDynamicQueryByProjectionMissing() throws Exception {
    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(MBBan.class, MBBan.class.getClassLoader());

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

    dynamicQuery.add(RestrictionsFactoryUtil.in("banId", new Object[] {RandomTestUtil.nextLong()}));

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

    Assert.assertEquals(0, result.size());
  }
  public void testDynamicQueryByProjectionMissing() throws Exception {
    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            WikiPageResource.class, WikiPageResource.class.getClassLoader());

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

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

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

    assertEquals(0, result.size());
  }
  @Test
  public void testDynamicQueryByProjectionMissing() throws Exception {
    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            SocialActivityAchievement.class, SocialActivityAchievement.class.getClassLoader());

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

    dynamicQuery.add(
        RestrictionsFactoryUtil.in(
            "activityAchievementId", new Object[] {ServiceTestUtil.nextLong()}));

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

    Assert.assertEquals(0, result.size());
  }
  public void testDynamicQueryByProjectionExisting() throws Exception {
    User newUser = addUser();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(User.class, User.class.getClassLoader());

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

    Object newUserId = newUser.getUserId();

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

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

    assertEquals(1, result.size());

    Object existingUserId = result.get(0);

    assertEquals(existingUserId, newUserId);
  }
  public void testDynamicQueryByProjectionExisting() throws Exception {
    Counter newCounter = addCounter();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Counter.class, Counter.class.getClassLoader());

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

    Object newName = newCounter.getName();

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

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

    assertEquals(1, result.size());

    Object existingName = result.get(0);

    assertEquals(existingName, newName);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    OrgLabor newOrgLabor = addOrgLabor();

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

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

    Object newOrgLaborId = newOrgLabor.getOrgLaborId();

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

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

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

    Object existingOrgLaborId = result.get(0);

    Assert.assertEquals(existingOrgLaborId, newOrgLaborId);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    VirtualHost newVirtualHost = addVirtualHost();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(VirtualHost.class, VirtualHost.class.getClassLoader());

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

    Object newVirtualHostId = newVirtualHost.getVirtualHostId();

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

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

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

    Object existingVirtualHostId = result.get(0);

    Assert.assertEquals(existingVirtualHostId, newVirtualHostId);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    MBMessage newMBMessage = addMBMessage();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(MBMessage.class, MBMessage.class.getClassLoader());

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

    Object newMessageId = newMBMessage.getMessageId();

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

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

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

    Object existingMessageId = result.get(0);

    Assert.assertEquals(existingMessageId, newMessageId);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    Layout newLayout = addLayout();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Layout.class, Layout.class.getClassLoader());

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

    Object newPlid = newLayout.getPlid();

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

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

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

    Object existingPlid = result.get(0);

    Assert.assertEquals(existingPlid, newPlid);
  }
  public void testDynamicQueryByProjectionExisting() throws Exception {
    SocialEquityLog newSocialEquityLog = addSocialEquityLog();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            SocialEquityLog.class, SocialEquityLog.class.getClassLoader());

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

    Object newEquityLogId = newSocialEquityLog.getEquityLogId();

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

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

    assertEquals(1, result.size());

    Object existingEquityLogId = result.get(0);

    assertEquals(existingEquityLogId, newEquityLogId);
  }
  public void testDynamicQueryByProjectionExisting() throws Exception {
    JournalArticle newJournalArticle = addJournalArticle();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            JournalArticle.class, JournalArticle.class.getClassLoader());

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

    Object newId = newJournalArticle.getId();

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

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

    assertEquals(1, result.size());

    Object existingId = result.get(0);

    assertEquals(existingId, newId);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    MBDiscussion newMBDiscussion = addMBDiscussion();

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

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

    Object newDiscussionId = newMBDiscussion.getDiscussionId();

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

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

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

    Object existingDiscussionId = result.get(0);

    Assert.assertEquals(existingDiscussionId, newDiscussionId);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    ResourceBlock newResourceBlock = addResourceBlock();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(ResourceBlock.class, ResourceBlock.class.getClassLoader());

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

    Object newResourceBlockId = newResourceBlock.getResourceBlockId();

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

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

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

    Object existingResourceBlockId = result.get(0);

    Assert.assertEquals(existingResourceBlockId, newResourceBlockId);
  }
  public void testDynamicQueryByProjectionExisting() throws Exception {
    DDMStructureLink newDDMStructureLink = addDDMStructureLink();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            DDMStructureLink.class, DDMStructureLink.class.getClassLoader());

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

    Object newStructureLinkId = newDDMStructureLink.getStructureLinkId();

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

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

    assertEquals(1, result.size());

    Object existingStructureLinkId = result.get(0);

    assertEquals(existingStructureLinkId, newStructureLinkId);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    AnnouncementsDelivery newAnnouncementsDelivery = addAnnouncementsDelivery();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            AnnouncementsDelivery.class, AnnouncementsDelivery.class.getClassLoader());

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

    Object newDeliveryId = newAnnouncementsDelivery.getDeliveryId();

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

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

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

    Object existingDeliveryId = result.get(0);

    Assert.assertEquals(existingDeliveryId, newDeliveryId);
  }
  public void testDynamicQueryByProjectionExisting() throws Exception {
    WikiPageResource newWikiPageResource = addWikiPageResource();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            WikiPageResource.class, WikiPageResource.class.getClassLoader());

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

    Object newResourcePrimKey = newWikiPageResource.getResourcePrimKey();

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

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

    assertEquals(1, result.size());

    Object existingResourcePrimKey = result.get(0);

    assertEquals(existingResourcePrimKey, newResourcePrimKey);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    JournalContentSearch newJournalContentSearch = addJournalContentSearch();

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

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

    Object newContentSearchId = newJournalContentSearch.getContentSearchId();

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

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

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

    Object existingContentSearchId = result.get(0);

    Assert.assertEquals(existingContentSearchId, newContentSearchId);
  }
  @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);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    PasswordPolicy newPasswordPolicy = addPasswordPolicy();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            PasswordPolicy.class, PasswordPolicy.class.getClassLoader());

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

    Object newPasswordPolicyId = newPasswordPolicy.getPasswordPolicyId();

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

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

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

    Object existingPasswordPolicyId = result.get(0);

    Assert.assertEquals(existingPasswordPolicyId, newPasswordPolicyId);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    DLFileEntryMetadata newDLFileEntryMetadata = addDLFileEntryMetadata();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            DLFileEntryMetadata.class, DLFileEntryMetadata.class.getClassLoader());

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

    Object newFileEntryMetadataId = newDLFileEntryMetadata.getFileEntryMetadataId();

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

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

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

    Object existingFileEntryMetadataId = result.get(0);

    Assert.assertEquals(existingFileEntryMetadataId, newFileEntryMetadataId);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    SocialActivityAchievement newSocialActivityAchievement = addSocialActivityAchievement();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            SocialActivityAchievement.class, SocialActivityAchievement.class.getClassLoader());

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

    Object newActivityAchievementId = newSocialActivityAchievement.getActivityAchievementId();

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

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

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

    Object existingActivityAchievementId = result.get(0);

    Assert.assertEquals(existingActivityAchievementId, newActivityAchievementId);
  }