@SuppressWarnings("unchecked") public List<AuditEntry> findByclassName_classPK_filterByActions( String className, long classPK, List<String> actions) throws SystemException { DynamicQuery dq = auditEntryLocalService.dynamicQuery(); Criterion criterion = PropertyFactoryUtil.forName("classname").eq(className); if (classPK > 0) { criterion = RestrictionsFactoryUtil.and( criterion, PropertyFactoryUtil.forName("classPK").eq(classPK)); } Criterion criterionAux = criterion; for (int i = 0; i < actions.size(); i++) { if (i == 0) { criterion = RestrictionsFactoryUtil.and( criterion, PropertyFactoryUtil.forName("action").eq(actions.get(i))); } else { Criterion criterionAnd = RestrictionsFactoryUtil.and( criterionAux, PropertyFactoryUtil.forName("action").eq(actions.get(i))); criterion = RestrictionsFactoryUtil.or(criterion, criterionAnd); } } dq.add(criterion); return auditEntryLocalService.dynamicQuery(dq); }
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); }
public int getFolderUnreadMessagesCount(long folderId) throws SystemException { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Message.class, getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("folderId", folderId)); dynamicQuery.add( RestrictionsFactoryUtil.not( RestrictionsFactoryUtil.like("flags", "%" + MailConstants.FLAG_SEEN + ",%"))); return (int) dynamicQueryCount(dynamicQuery); }
@Test public void testDynamicQueryByPrimaryKeyMissing() throws Exception { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(OrgGroupRole.class, OrgGroupRole.class.getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("id.organizationId", ServiceTestUtil.nextLong())); dynamicQuery.add(RestrictionsFactoryUtil.eq("id.groupId", ServiceTestUtil.nextLong())); dynamicQuery.add(RestrictionsFactoryUtil.eq("id.roleId", ServiceTestUtil.nextLong())); List<OrgGroupRole> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(0, result.size()); }
@Override public Date getLastPostDateByUserId(long groupId, long userId) { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass( MBThread.class, MBStatsUserImpl.TABLE_NAME, ClassLoaderUtil.getPortalClassLoader()); Projection projection = ProjectionFactoryUtil.max("lastPostDate"); dynamicQuery.setProjection(projection); Property property = PropertyFactoryUtil.forName("threadId"); Disjunction disjunction = RestrictionsFactoryUtil.disjunction(); QueryDefinition queryDefinition = new QueryDefinition(WorkflowConstants.STATUS_IN_TRASH); List<MBThread> threads = mbThreadLocalService.getGroupThreads(groupId, queryDefinition); for (MBThread thread : threads) { disjunction.add(property.ne(thread.getThreadId())); } dynamicQuery.add(disjunction); List<Date> results = mbStatsUserLocalService.dynamicQuery(dynamicQuery); return results.get(0); }
private void update() { if (!IConstants.CFG_NOTIFY_OLD_USERS) return; DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(User.class, PortalClassLoaderUtil.getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("jobTitle", "mail-not-sent")); try { @SuppressWarnings("unchecked") List<User> users = UserLocalServiceUtil.dynamicQuery(dynamicQuery); int cnt = 0; for (User user : users) { // notifyUser thru email and SMS user.setJobTitle(StringPool.BLANK); user.setLastName(StringPool.BLANK); user = UserLocalServiceUtil.updateUser(user); cnt++; if (cnt == 200) break; } } catch (SystemException e) { e.printStackTrace(); } }
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(); }
@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); }
protected List<ResourceTypePermission> getResourceTypePermissions( PortletDataContext portletDataContext, Role importedRole) throws SystemException { DynamicQuery dynamicQuery = ResourceTypePermissionLocalServiceUtil.dynamicQuery(); Property companyIdProperty = PropertyFactoryUtil.forName("companyId"); dynamicQuery.add(companyIdProperty.eq(portletDataContext.getCompanyId())); Junction junction = RestrictionsFactoryUtil.disjunction(); long[] permissibleGroupIds = { GroupConstants.DEFAULT_PARENT_GROUP_ID, portletDataContext.getCompanyId(), portletDataContext.getCompanyGroupId(), portletDataContext.getUserPersonalSiteGroupId() }; for (long permissibleGroupId : permissibleGroupIds) { Property property = PropertyFactoryUtil.forName("groupId"); junction.add(property.eq(permissibleGroupId)); } dynamicQuery.add(junction); Property roleIdProperty = PropertyFactoryUtil.forName("roleId"); dynamicQuery.add(roleIdProperty.eq(importedRole.getRoleId())); return ResourceTypePermissionLocalServiceUtil.dynamicQuery(dynamicQuery); }
@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); }
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; }
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); }
/** * This method inserts new TerminationReason record into the database table * * @param actionRequest * @param actionResponse * @throws IOException * @throws PortletException * @throws SystemException */ public void saveTerminationReasons(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException, SystemException { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); try { TerminationReasons terminationReasons = TerminationReasonsLocalServiceUtil.createTerminationReasons( CounterLocalServiceUtil.increment()); String id = ParamUtil.getString(actionRequest, "terminationreasonsId"); String name = ParamUtil.getString(actionRequest, "terminationreasonsName"); String terminationReason = name.trim(); if (terminationReason.equals("") || terminationReason == null) { System.out.println("Empty value in TerminationReason..."); SessionMessages.add(actionRequest.getPortletSession(), "termination-form-error"); actionResponse.setRenderParameter("mvcPath", "/html/terminationreasons/add.jsp"); } else { System.out.println("id == " + id + "Name = " + name); if (id == "" || id == null) { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass( TerminationReasons.class, PortalClassLoaderUtil.getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("terminationreasonsName", name)); List<TerminationReasons> list = TerminationReasonsLocalServiceUtil.dynamicQuery(dynamicQuery); if (list.size() > 0) { TerminationReasons terminationReasons2 = list.get(0); if (terminationReasons2 != null) { SessionMessages.add( actionRequest.getPortletSession(), "termination-form-duplicate-error"); actionResponse.setRenderParameter("mvcPath", "/html/terminationreasons/add.jsp"); } } else { terminationReasons.setTerminationreasonsName( ParamUtil.getString(actionRequest, "terminationreasonsName")); terminationReasons.setCreateDate(date); terminationReasons.setModifiedDate(date); terminationReasons.setCompanyId(themeDisplay.getCompanyId()); terminationReasons.setGroupId(themeDisplay.getCompanyGroupId()); terminationReasons.setUserId(themeDisplay.getUserId()); terminationReasons = TerminationReasonsLocalServiceUtil.addTerminationReasons(terminationReasons); } } } } catch (SystemException e) { e.printStackTrace(); } }
public void testDynamicQueryByPrimaryKeyMissing() throws Exception { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(ClusterGroup.class, ClusterGroup.class.getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("clusterGroupId", nextLong())); List<ClusterGroup> result = _persistence.findWithDynamicQuery(dynamicQuery); assertEquals(0, result.size()); }
@Override protected void doReindex(String[] arg0) throws Exception { long companyId = Long.valueOf(arg0[0]); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(FAQEntry.class); dynamicQuery.add(RestrictionsFactoryUtil.eq("companyId", companyId)); List<FAQEntry> faqs = FAQEntryLocalServiceUtil.dynamicQuery(dynamicQuery); for (FAQEntry faq : faqs) { if (faq.getGroupId() > 01) reindex(faq); } }
public void testDynamicQueryByPrimaryKeyMissing() throws Exception { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Counter.class, Counter.class.getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("name", randomString())); List<Counter> result = _persistence.findWithDynamicQuery(dynamicQuery); assertEquals(0, result.size()); }
@Test public void testDynamicQueryByPrimaryKeyMissing() throws Exception { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(VirtualHost.class, VirtualHost.class.getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("virtualHostId", ServiceTestUtil.nextLong())); List<VirtualHost> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(0, result.size()); }
public void testDynamicQueryByPrimaryKeyMissing() throws Exception { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass( DDMStructureLink.class, DDMStructureLink.class.getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("structureLinkId", nextLong())); List<DDMStructureLink> result = _persistence.findWithDynamicQuery(dynamicQuery); assertEquals(0, result.size()); }
public void testDynamicQueryByPrimaryKeyMissing() throws Exception { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass( WikiPageResource.class, WikiPageResource.class.getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("resourcePrimKey", nextLong())); List<WikiPageResource> result = _persistence.findWithDynamicQuery(dynamicQuery); assertEquals(0, result.size()); }
@Test public void testDynamicQueryByPrimaryKeyExisting() throws Exception { OrgGroupRole newOrgGroupRole = addOrgGroupRole(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(OrgGroupRole.class, OrgGroupRole.class.getClassLoader()); dynamicQuery.add( RestrictionsFactoryUtil.eq("id.organizationId", newOrgGroupRole.getOrganizationId())); dynamicQuery.add(RestrictionsFactoryUtil.eq("id.groupId", newOrgGroupRole.getGroupId())); dynamicQuery.add(RestrictionsFactoryUtil.eq("id.roleId", newOrgGroupRole.getRoleId())); List<OrgGroupRole> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(1, result.size()); OrgGroupRole existingOrgGroupRole = result.get(0); Assert.assertEquals(existingOrgGroupRole, newOrgGroupRole); }
@Test public void testDynamicQueryByPrimaryKeyMissing() throws Exception { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(CalendarResource.class, _dynamicQueryClassLoader); dynamicQuery.add(RestrictionsFactoryUtil.eq("calendarResourceId", RandomTestUtil.nextLong())); List<CalendarResource> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(0, result.size()); }
protected Criterion getAssetClassPKs(Long[] assetClassPKs) { Disjunction disjunction = RestrictionsFactoryUtil.disjunction(); for (Long assetClassPK : assetClassPKs) { Property classPKProperty = PropertyFactoryUtil.forName("classPK"); disjunction.add(classPKProperty.eq(assetClassPK)); } return disjunction; }
public void testDynamicQueryByPrimaryKeyMissing() throws Exception { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass( SCFrameworkVersion.class, SCFrameworkVersion.class.getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("frameworkVersionId", nextLong())); List<SCFrameworkVersion> result = _persistence.findWithDynamicQuery(dynamicQuery); assertEquals(0, result.size()); }
protected Criterion getAssetClassNames(String[] assetClassNames) { Disjunction disjunction = RestrictionsFactoryUtil.disjunction(); for (String assetClassName : assetClassNames) { Property classNameProperty = PropertyFactoryUtil.forName("className"); disjunction.add(classNameProperty.like(assetClassName)); } return disjunction; }
@Test public void testDynamicQueryByPrimaryKeyMissing() throws Exception { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(MBBan.class, MBBan.class.getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("banId", RandomTestUtil.nextLong())); List<MBBan> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(0, result.size()); }
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()); }
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); }
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(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()); }
@Test public void testDynamicQueryByPrimaryKeyMissing() throws Exception { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass( ExportImportConfiguration.class, ExportImportConfiguration.class.getClassLoader()); dynamicQuery.add( RestrictionsFactoryUtil.eq("exportImportConfigurationId", ServiceTestUtil.nextLong())); List<ExportImportConfiguration> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(0, result.size()); }