Пример #1
0
  public static Date getLastCalendarModifiedDate(long calendarId)
      throws PortalException, SystemException {

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

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

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

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

    dynamicQuery.setLimit(0, 1);

    dynamicQuery.addOrder(OrderFactoryUtil.desc("modifiedDate"));

    List<Object> lastModifiedDate = CalendarBookingLocalServiceUtil.dynamicQuery(dynamicQuery);

    if ((lastModifiedDate != null) && !lastModifiedDate.isEmpty()) {
      Timestamp ts = (Timestamp) lastModifiedDate.get(0);
      return new Date(ts.getTime());
    }

    return new Date();
  }
  public int populateMessages(
      List<Message> messages,
      long folderId,
      String keywords,
      int pageNumber,
      int messagesPerPage,
      String orderByField,
      String orderByType)
      throws SystemException {

    DynamicQuery countDynamicQuery =
        DynamicQueryFactoryUtil.forClass(Message.class, getClassLoader());

    countDynamicQuery.add(RestrictionsFactoryUtil.eq("folderId", folderId));

    DynamicQuery messageDynamicQuery =
        DynamicQueryFactoryUtil.forClass(Message.class, getClassLoader());

    messageDynamicQuery.add(RestrictionsFactoryUtil.eq("folderId", folderId));

    if (Validator.isNotNull(keywords)) {
      String value = "%" + keywords + "%";

      Disjunction disjunction = RestrictionsFactoryUtil.disjunction();

      disjunction.add(RestrictionsFactoryUtil.ilike("subject", value));
      disjunction.add(RestrictionsFactoryUtil.ilike("body", value));

      countDynamicQuery.add(disjunction);

      messageDynamicQuery.add(disjunction);
    }

    if (orderByType.equals("desc")) {
      messageDynamicQuery.addOrder(OrderFactoryUtil.desc(orderByField));
    } else {
      messageDynamicQuery.addOrder(OrderFactoryUtil.asc(orderByField));
    }

    int start = messagesPerPage * (pageNumber - 1);
    int end = messagesPerPage * pageNumber;

    messages.addAll(messagePersistence.findWithDynamicQuery(messageDynamicQuery, start, end));

    return (int) dynamicQueryCount(countDynamicQuery);
  }
Пример #3
0
  @Test
  public void testNegativeLowerBound() {
    DynamicQuery dynamicQuery = ClassNameLocalServiceUtil.dynamicQuery();

    dynamicQuery.addOrder(OrderFactoryUtil.asc("classNameId"));
    dynamicQuery.setLimit(-50, _allClassNames.size());

    Assert.assertEquals(
        _allClassNames, ClassNameLocalServiceUtil.<ClassName>dynamicQuery(dynamicQuery));
  }
Пример #4
0
  @Test
  public void testUpperBound() {
    DynamicQuery dynamicQuery = ClassNameLocalServiceUtil.dynamicQuery();

    dynamicQuery.addOrder(OrderFactoryUtil.asc("classNameId"));
    dynamicQuery.setLimit(QueryUtil.ALL_POS, 10);

    Assert.assertEquals(
        _allClassNames.subList(0, 10),
        ClassNameLocalServiceUtil.<ClassName>dynamicQuery(dynamicQuery));
  }
Пример #5
0
  @Test
  public void testSingleResult() {
    DynamicQuery dynamicQuery = ClassNameLocalServiceUtil.dynamicQuery();

    dynamicQuery.addOrder(OrderFactoryUtil.asc("classNameId"));
    dynamicQuery.setLimit(10, 11);

    List<ClassName> dynamicQueryClassNames = ClassNameLocalServiceUtil.dynamicQuery(dynamicQuery);

    Assert.assertEquals(1, dynamicQueryClassNames.size());
    Assert.assertEquals(_allClassNames.get(10), dynamicQueryClassNames.get(0));
  }
  public Message getRemoteMessage(long folderId, boolean oldest)
      throws PortalException, SystemException {

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

    dynamicQuery.add(RestrictionsFactoryUtil.eq("folderId", folderId));
    dynamicQuery.add(RestrictionsFactoryUtil.gt("remoteMessageId", new Long(0)));

    if (oldest) {
      dynamicQuery.addOrder(OrderFactoryUtil.asc("remoteMessageId"));
    } else {
      dynamicQuery.addOrder(OrderFactoryUtil.desc("remoteMessageId"));
    }

    List<Message> messages = messagePersistence.findWithDynamicQuery(dynamicQuery, 0, 1);

    if (messages.isEmpty()) {
      throw new NoSuchMessageException();
    }

    return messages.get(0);
  }
  @Override
  public List<StagedAssetLink> fetchStagedModelsByUuidAndCompanyId(String uuid, long companyId) {

    DynamicQuery dynamicQuery =
        getAssetLinkDynamicQuery(
            companyId, 0, parseAssetEntry1Uuid(uuid), parseAssetEntry2Uuid(uuid));

    dynamicQuery.addOrder(OrderFactoryUtil.desc("linkId"));

    List<AssetLink> assetLinks = _assetLinkLocalService.dynamicQuery(dynamicQuery);

    return ModelAdapterUtil.adapt(assetLinks, AssetLink.class, StagedAssetLink.class);
  }
Пример #8
0
  @Test
  public void testNoLimit() {
    DynamicQuery dynamicQuery = ClassNameLocalServiceUtil.dynamicQuery();

    dynamicQuery.addOrder(OrderFactoryUtil.asc("classNameId"));

    List<ClassName> classNames = ClassNameLocalServiceUtil.dynamicQuery(dynamicQuery);

    for (ClassName className : _allClassNames) {
      if (!classNames.contains(className)) {
        Assert.fail("Class names do not contain " + className);
      }
    }
  }
  public List<SocialActivity> getActivities(Long userId, int start, int count)
      throws SystemException {
    List<ActivitySubscription> subscriptions = null;
    // for now no activity selection is made, TODO
    subscriptions = activitySubscriptionPersistence.findByreceiverId(userId);

    if (subscriptions.size() == 0) {
      return new ArrayList<SocialActivity>();
    }

    DynamicQuery query = DynamicQueryFactoryUtil.forClass(SocialActivity.class);
    Criterion crit = null;

    for (ActivitySubscription sub : subscriptions) {
      Map<String, Number> criterion = new HashMap<String, Number>();
      criterion.put("classNameId", sub.getClassNameId());
      criterion.put("classPK", sub.getClassPK());

      if (sub.getType() != null) {
        criterion.put("type", sub.getType());
      }
      Criterion subCriterion = RestrictionsFactoryUtil.allEq(criterion);

      if (sub.getExtraData() != null && sub.getExtraData().length() > 0) {
        subCriterion =
            RestrictionsFactoryUtil.and(
                subCriterion, RestrictionsFactoryUtil.ilike("extraData", sub.getExtraData() + "%"));
      }

      if (crit == null) {
        crit = subCriterion;
      } else {
        crit = RestrictionsFactoryUtil.or(crit, subCriterion);
      }
    }
    query.add(crit).addOrder(OrderFactoryUtil.desc("createDate"));

    List<SocialActivity> activities = new ArrayList<SocialActivity>();
    List<Object> queryResults =
        SocialActivityLocalServiceUtil.dynamicQuery(query, start, start + count - 1);

    for (Object activity : queryResults) {
      activities.add((SocialActivity) activity);
    }

    return activities;
  }
Пример #10
0
  @Test
  public void testOrderBy() {
    DynamicQuery dynamicQuery = ClassNameLocalServiceUtil.dynamicQuery();

    Property classNameIdProperty = PropertyFactoryUtil.forName("classNameId");

    ClassName lastClassName = _allClassNames.get(_allClassNames.size() - 1);

    dynamicQuery.add(classNameIdProperty.le(lastClassName.getClassNameId()));

    dynamicQuery.addOrder(OrderFactoryUtil.desc("classNameId"));

    _allClassNames = new ArrayList<>(_allClassNames);

    Collections.reverse(_allClassNames);

    Assert.assertEquals(
        _allClassNames, ClassNameLocalServiceUtil.<ClassName>dynamicQuery(dynamicQuery));
  }
Пример #11
0
  @SuppressWarnings("unchecked")
  public List<Asset> getAssets(String pattern, boolean ticker) {
    List<Asset> results = new ArrayList<Asset>();
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(AssetImpl.class);

    dynamicQuery.add(
        RestrictionsFactoryUtil.like(
            ticker ? "security_ticker" : "id_isin",
            StringPool.PERCENT + pattern + StringPool.PERCENT));
    dynamicQuery.addOrder(OrderFactoryUtil.asc(ticker ? "security_ticker" : "id_isin"));

    try {
      results = assetLocalService.dynamicQuery(dynamicQuery);
    } catch (SystemException e) {
      e.printStackTrace();
    }

    return results;
  }
 public List<AuditEntry> search(
     long companyId,
     long groupId,
     String className,
     long classPK,
     long userId,
     Date startDate,
     Date endDate,
     int start,
     int end)
     throws SystemException {
   DynamicQuery dq = auditEntryLocalService.dynamicQuery();
   Criterion criterion = PropertyFactoryUtil.forName("companyId").eq(companyId);
   dq.add(criterion);
   if (groupId > 0) {
     criterion = PropertyFactoryUtil.forName("groupId").eq(groupId);
     dq.add(criterion);
   }
   if (userId > 0) {
     criterion = PropertyFactoryUtil.forName("userId").eq(userId);
     dq.add(criterion);
   }
   if (startDate != null) {
     criterion = PropertyFactoryUtil.forName("auditDate").ge(startDate);
     dq.add(criterion);
   }
   if (endDate != null) {
     criterion = PropertyFactoryUtil.forName("auditDate").le(endDate);
     dq.add(criterion);
   }
   if (className != null) {
     criterion = PropertyFactoryUtil.forName("classname").eq(className);
     dq.add(criterion);
     if (classPK > 0) {
       criterion = PropertyFactoryUtil.forName("classPK").eq(classPK);
       dq.add(criterion);
     }
   }
   dq.addOrder(OrderFactoryUtil.desc("auditDate"));
   return ((List<AuditEntry>) auditEntryLocalService.dynamicQuery(dq, start, end));
 }
Пример #13
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;
  }