Example usage for com.liferay.portal.kernel.dao.orm ProjectionFactoryUtil distinct

List of usage examples for com.liferay.portal.kernel.dao.orm ProjectionFactoryUtil distinct

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.dao.orm ProjectionFactoryUtil distinct.

Prototype

public static Projection distinct(Projection projection) 

Source Link

Usage

From source file:com.bemis.portal.order.service.impl.OrderLocalServiceImpl.java

License:Open Source License

protected DynamicQuery getDistinctDynamicQuery(String propertyName) {
    DynamicQuery dynamicQuery = orderLocalService.dynamicQuery();

    Projection projection = PropertyFactoryUtil.forName(propertyName);

    ProjectionList projectionList = ProjectionFactoryUtil.projectionList();

    projectionList.add(ProjectionFactoryUtil.distinct(projection));

    dynamicQuery = dynamicQuery.setProjection(projectionList);

    return dynamicQuery;
}

From source file:com.ext.portlet.halcon.service.impl.ProductoComplementarioLocalServiceImpl.java

License:Open Source License

public List<ProductoComplementario> obtenerProductosCOmplementarioDistinct() throws BusinessException {
    ClassLoader classLoader = (ClassLoader) PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(),
            "portletClassLoader");
    DynamicQuery consultaProductoComplementario = DynamicQueryFactoryUtil.forClass(ProductoComplementario.class,
            classLoader);// w  ww  .j av a  2 s.  co  m
    DynamicQuery consultaProductoComplementarioDict = consultaProductoComplementario.setProjection(
            ProjectionFactoryUtil.distinct(PropertyFactoryUtil.forName("idProductoComplementario")));
    try {

        //         List<ProductoComplementario > l =ProductoComplementarioLocalServiceUtil.dynamicQuery(consultaProductoComplementarioDict);
        List<ProductoComplementario> l = solicitudProductoFinder.obtenerLstProductosComplementariosDistinc();
        //List<ProductoComplementario > l = consultaProductoComplementario.list(); 
        if (l != null) {
            return l;
        }
    } catch (Exception e) {
        //_log.error("Error e:"+e.getLocalizedMessage() + " e: "+e.getMessage()  );
        //         throw new BusinessException(nameClase+" - obtenerProductosCOmplementarioDistinct",e.toString());
        //e.printStackTrace();
        _log.error(Propiedades.getResourceBundleMetodo(
                "capa.halcon.producto.complementario.obtenerproductoscomplementariodistinct") + e.toString());
        throw new BusinessException(
                Propiedades.getResourceBundle("capa.halcon.producto.complementario",
                        "capa.halcon.producto.complementario.obtenerproductoscomplementariodistinct"),
                e.toString());
    }
    //      List<ProductoComplementario > l1 = new ArrayList<ProductoComplementario>();
    //      ProductoComplementario pc1 = newInstance();
    //      pc1.setIdProductoComplementario(1);
    //      pc1.setIdSolicitudProducto(1);
    //      pc1.setIdProducto("1");
    //      pc1.setProducto("pro1");
    //      l1.add(pc1);
    //      
    //      ProductoComplementario pc2 = newInstance();
    //      pc2.setIdProductoComplementario(2);
    //      pc2.setIdSolicitudProducto(2);
    //      pc2.setIdProducto("2");
    //      pc2.setProducto("pro2");
    //      l1.add(pc2);
    //
    //      ProductoComplementario pc3 = newInstance();
    //      pc3.setIdProductoComplementario(3);
    //      pc3.setIdSolicitudProducto(3);
    //      pc3.setIdProducto("3");
    //      pc3.setProducto("pro3");
    //      l1.add(pc3);
    //      
    //      return l1;      
    return null;
}

From source file:com.idetronic.portlet.service.impl.FAQEntryLocalServiceImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<String> getCategory() {
    List<String> catList = new ArrayList<String>();

    DynamicQuery query = DynamicQueryFactoryUtil.forClass(FAQEntry.class);

    query.setProjection(ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.property("category")));
    //query.addOrder(OrderFactoryUtil.asc("displayOrder"));

    try {//from ww  w  . j av  a 2 s.  c  o  m
        catList = dynamicQuery(query);

    } catch (SystemException ex) {
        ex.printStackTrace();
    }

    return catList;
}

From source file:com.liferay.adaptive.media.document.library.web.internal.optimizer.DLAMImageOptimizer.java

License:Open Source License

private void _optimize(long companyId, String configurationEntryUuid, int total, AtomicInteger atomicCounter) {

    ActionableDynamicQuery actionableDynamicQuery = _dlFileEntryLocalService.getActionableDynamicQuery();

    actionableDynamicQuery.setAddCriteriaMethod(new ActionableDynamicQuery.AddCriteriaMethod() {

        @Override//from   ww  w  .java 2 s .c  om
        public void addCriteria(DynamicQuery dynamicQuery) {
            Property companyIdProperty = PropertyFactoryUtil.forName("companyId");

            dynamicQuery.add(companyIdProperty.eq(companyId));

            Property groupIdProperty = PropertyFactoryUtil.forName("groupId");
            Property repositoryIdProperty = PropertyFactoryUtil.forName("repositoryId");

            dynamicQuery.add(groupIdProperty.eqProperty(repositoryIdProperty));

            Property mimeTypeProperty = PropertyFactoryUtil.forName("mimeType");

            dynamicQuery.add(mimeTypeProperty.in(_amImageMimeTypeProvider.getSupportedMimeTypes()));

            DynamicQuery dlFileVersionDynamicQuery = _dlFileVersionLocalService.dynamicQuery();

            dlFileVersionDynamicQuery.setProjection(
                    ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.property("fileEntryId")));

            dlFileVersionDynamicQuery.add(companyIdProperty.eq(companyId));

            dlFileVersionDynamicQuery.add(groupIdProperty.eqProperty(repositoryIdProperty));

            dlFileVersionDynamicQuery
                    .add(mimeTypeProperty.in(_amImageMimeTypeProvider.getSupportedMimeTypes()));

            Property statusProperty = PropertyFactoryUtil.forName("status");

            dlFileVersionDynamicQuery.add(statusProperty.eq(WorkflowConstants.STATUS_IN_TRASH));

            Property fileEntryIdProperty = PropertyFactoryUtil.forName("fileEntryId");

            dynamicQuery.add(fileEntryIdProperty.notIn(dlFileVersionDynamicQuery));
        }

    });
    actionableDynamicQuery
            .setPerformActionMethod(new ActionableDynamicQuery.PerformActionMethod<DLFileEntry>() {

                @Override
                public void performAction(DLFileEntry dlFileEntry) throws PortalException {

                    FileEntry fileEntry = new LiferayFileEntry(dlFileEntry);

                    try {
                        _amImageProcessor.process(fileEntry.getFileVersion(), configurationEntryUuid);

                        _sendStatusMessage(atomicCounter.incrementAndGet(), total);
                    } catch (PortalException pe) {
                        _log.error("Unable to process file entry " + fileEntry.getFileEntryId(), pe);
                    }
                }

            });

    try {
        actionableDynamicQuery.performActions();
    } catch (PortalException pe) {
        _log.error(pe, pe);
    }
}

From source file:com.liferay.events.global.mobile.service.impl.EventPollQuestionLocalServiceImpl.java

License:Open Source License

public List<String> getAllEvents() throws SystemException {

    DynamicQuery q = DynamicQueryFactoryUtil.forClass(EventPollQuestion.class,
            EventPollQuestion.class.getClassLoader());

    q.setProjection(ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.property("eventId")));

    return (List<String>) dynamicQuery(q);
}

From source file:com.liferay.lms.service.impl.CourseLocalServiceImpl.java

License:Open Source License

public List<Course> getPublicCoursesByCompanyId(Long companyId) {

    Long classNameId = ClassNameLocalServiceUtil.getClassNameId(Course.class.getName());

    if (classNameId != null) {
        try {/*from w w w .  jav  a  2  s  .co  m*/
            DynamicQuery dq = DynamicQueryFactoryUtil.forClass(AssetEntry.class);
            dq.add(PropertyFactoryUtil.forName("companyId").eq(companyId));
            dq.add(PropertyFactoryUtil.forName("classNameId").eq(classNameId));
            dq.add(PropertyFactoryUtil.forName("visible").eq(true));
            dq.setProjection(ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.property("classPK")));
            List<Long> results = (List<Long>) assetEntryLocalService.dynamicQuery(dq);

            List<Course> courses = new ArrayList<Course>();
            for (Long courseId : results) {
                Course course = coursePersistence.fetchByPrimaryKey(courseId);
                if (course != null)
                    courses.add(course);
            }

            return courses;

        } catch (SystemException e) {
            if (log.isDebugEnabled())
                e.printStackTrace();
        }
    }

    return null;
}

From source file:com.liferay.lms.service.impl.ModuleLocalServiceImpl.java

License:Open Source License

public long usersStarted(long moduleId) throws SystemException {
    ClassLoader classLoader = (ClassLoader) PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(),
            "portletClassLoader");
    DynamicQuery dq = DynamicQueryFactoryUtil.forClass(LearningActivityTry.class, classLoader);
    java.util.List<Long> actIds = LearningActivityLocalServiceUtil.getLearningActivityIdsOfModule(moduleId);
    long result = 0;
    Criterion crit;/*from  w w  w  . j a  va2  s  .com*/
    crit = PropertyFactoryUtil.forName("actId").in(actIds.toArray());
    dq.add(crit);
    dq.setProjection(ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.property("userId")));
    result = LearningActivityTryLocalServiceUtil.dynamicQueryCount(dq);
    return result;
}

From source file:com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.java

License:Open Source License

@Override
public AssetEntry updateEntry(long userId, long groupId, Date createDate, Date modifiedDate, String className,
        long classPK, String classUuid, long classTypeId, long[] categoryIds, String[] tagNames,
        boolean visible, Date startDate, Date endDate, Date expirationDate, String mimeType, String title,
        String description, String summary, String url, String layoutUuid, int height, int width,
        Integer priority, boolean sync) throws PortalException, SystemException {
    // Entry//from   ww w.j a  va2  s  . co m

    User user = userPersistence.findByPrimaryKey(userId);
    long classNameId = PortalUtil.getClassNameId(className);
    List<String> newTagsList = new ArrayList<String>();
    if (!Validator.isNull(tagNames) && className.equalsIgnoreCase(JournalArticle.class.getName())) {
        for (String tag : tagNames) {
            if (PropsUtil.get("stoxx-contentmanagement-all-region").equalsIgnoreCase(tag)) {
                ClassLoader classLoader = (ClassLoader) PortletBeanLocatorUtil
                        .locate(ClpSerializer.getServletContextName(), "portletClassLoader");
                DynamicQuery query = DynamicQueryFactoryUtil.forClass(IndexDB.class, classLoader);
                query.setProjection(
                        ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.property("superRegion")));
                query.addOrder(OrderFactoryUtil.asc("superRegion"));
                query.add(RestrictionsFactoryUtil.eq("data1", "1"));
                newTagsList.addAll(new ArrayList<String>(IndexDBLocalServiceUtil.dynamicQuery(query)));
            } else if (PropsUtil.get("stoxx-contentmanagement-all-type").equalsIgnoreCase(tag)) {
                ClassLoader classLoader = (ClassLoader) PortletBeanLocatorUtil
                        .locate(ClpSerializer.getServletContextName(), "portletClassLoader");
                DynamicQuery query = DynamicQueryFactoryUtil.forClass(IndexDB.class, classLoader);
                query.setProjection(
                        ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.property("superType")));
                query.addOrder(OrderFactoryUtil.asc("superType"));
                query.add(RestrictionsFactoryUtil.eq("data1", "1"));
                newTagsList.addAll(new ArrayList<String>(IndexDBLocalServiceUtil.dynamicQuery(query)));
            } else {
                List<String> regionSuperTypeList = getRegionandTypeList(tag);
                if (regionSuperTypeList.size() > 0) {
                    newTagsList.addAll(regionSuperTypeList);
                }
            }
        }
    }

    if (newTagsList.size() > 0) {
        int arraySize = newTagsList.size() + tagNames.length;
        String[] newTagNames = new String[arraySize];
        int count = 0;
        for (String tag : newTagsList) {
            tag = tag.replace(StringPool.SLASH, StringPool.BLANK);
            tag = tag.replace(StringPool.AMPERSAND, StringPool.BLANK);
            tag = tag.replace(StringPool.PERCENT, StringPool.BLANK);
            newTagNames[count] = tag;
            count++;
        }

        for (String tag : tagNames) {
            if (!PropsUtil.get("stoxx-contentmanagement-all-type").equalsIgnoreCase(tag)
                    && !PropsUtil.get("stoxx-contentmanagement-all-region").equalsIgnoreCase(tag)) {
                newTagNames[count] = tag;
                count++;
            }
        }

        List<String> tagList = new ArrayList<String>(Arrays.asList(newTagNames));
        tagList.removeAll(Collections.singleton(null));

        tagNames = tagList.toArray(new String[tagList.size()]);
    }

    validate(groupId, className, categoryIds, tagNames);

    AssetEntry entry = assetEntryPersistence.fetchByC_C(classNameId, classPK);

    boolean oldVisible = false;

    if (entry != null) {
        oldVisible = entry.isVisible();
    }

    if (modifiedDate == null) {
        modifiedDate = new Date();
    }

    if (entry == null) {
        long entryId = counterLocalService.increment();

        entry = assetEntryPersistence.create(entryId);

        entry.setCompanyId(user.getCompanyId());
        entry.setUserId(user.getUserId());
        entry.setUserName(user.getFullName());

        if (createDate == null) {
            createDate = new Date();
        }

        entry.setCreateDate(createDate);

        entry.setModifiedDate(modifiedDate);
        entry.setClassNameId(classNameId);
        entry.setClassPK(classPK);
        entry.setClassUuid(classUuid);
        entry.setVisible(visible);
        entry.setExpirationDate(expirationDate);

        if (priority == null) {
            entry.setPriority(0);
        }

        entry.setViewCount(0);
    }

    entry.setGroupId(groupId);
    entry.setModifiedDate(modifiedDate);
    entry.setClassTypeId(classTypeId);
    entry.setVisible(visible);
    entry.setStartDate(startDate);
    entry.setEndDate(endDate);
    entry.setExpirationDate(expirationDate);
    entry.setMimeType(mimeType);
    entry.setTitle(title);
    entry.setDescription(description);
    entry.setSummary(summary);
    entry.setUrl(url);
    entry.setLayoutUuid(layoutUuid);
    entry.setHeight(height);
    entry.setWidth(width);

    if (priority != null) {
        entry.setPriority(priority.intValue());
    }

    // Categories

    if (categoryIds != null) {
        assetEntryPersistence.setAssetCategories(entry.getEntryId(), categoryIds);
    }

    // Tags

    if (tagNames != null) {
        long siteGroupId = PortalUtil.getSiteGroupId(groupId);

        Group siteGroup = groupLocalService.getGroup(siteGroupId);

        List<AssetTag> tags = assetTagLocalService.checkTags(userId, siteGroup, tagNames);

        List<AssetTag> oldTags = assetEntryPersistence.getAssetTags(entry.getEntryId());

        assetEntryPersistence.setAssetTags(entry.getEntryId(), tags);

        if (entry.isVisible()) {
            boolean isNew = entry.isNew();

            assetEntryPersistence.updateImpl(entry);

            if (isNew) {
                for (AssetTag tag : tags) {
                    assetTagLocalService.incrementAssetCount(tag.getTagId(), classNameId);
                }
            } else {
                for (AssetTag oldTag : oldTags) {
                    if (!tags.contains(oldTag)) {
                        assetTagLocalService.decrementAssetCount(oldTag.getTagId(), classNameId);
                    }
                }

                for (AssetTag tag : tags) {
                    if (!oldTags.contains(tag)) {
                        assetTagLocalService.incrementAssetCount(tag.getTagId(), classNameId);
                    }
                }
            }
        } else if (oldVisible) {
            for (AssetTag oldTag : oldTags) {
                assetTagLocalService.decrementAssetCount(oldTag.getTagId(), classNameId);
            }
        }
    }

    // Update entry after tags so that entry listeners have access to the
    // saved categories and tags
    log.info("AssetEntryLocalServiceImpl.updateEntry() inside updateEntry");
    if (entry.getClassName().equals(JournalArticle.class.getName())) {
        List<AssetCategory> assetCategory = entry.getCategories();
        for (AssetCategory ae : assetCategory) {
            log.info("AssetEntryLocalServiceImpl.updateEntry() the asset category is " + ae.getName());
            if (STOXXConstants.CATEGORY_STOXX_NEWS_PRESS_RELEASE.equalsIgnoreCase(ae.getName())
                    || STOXXConstants.CATEGORY_STOXX_NEWS_MARKET_NEWS.equalsIgnoreCase(ae.getName())
                    || STOXXConstants.CATEGORY_STOXX_RESEARCH_MARKET_TRENDS.equalsIgnoreCase(ae.getName())
                    || STOXXConstants.CATEGORY_STOXX_RESEARCH_WEBINARS.equalsIgnoreCase(ae.getName())
                    || STOXXConstants.CATEGORY_STOXX_RESEARCH_EXPERT_SPEAK.equalsIgnoreCase(ae.getName())
                    || STOXXConstants.CATEGORY_STOXX_RESEARCH_EVENTS.equalsIgnoreCase(ae.getName())
                    || STOXXConstants.CATEGORY_STOXX_RESEARCH_PULSE.equalsIgnoreCase(ae.getName())) {
                JournalArticle journalArticle = null;
                try {
                    journalArticle = JournalArticleLocalServiceUtil.getLatestArticle(entry.getClassPK());
                } catch (Exception e) {
                    log.info("The exception in getting journalArticle " + e.getMessage());
                    break;
                }
                String strDate = getXmlDocument(journalArticle, "Date");
                log.info("AssetEntryLocalServiceImpl.updateEntry() Date is strDate" + strDate);
                if (!Validator.isBlank(strDate)) {
                    log.info("AssetEntryLocalServiceImpl.updateEntry() date is not null");
                    Date date = new Date(Long.parseLong(strDate));
                    entry.setModifiedDate(date);
                    break;
                }
            }
        }
    }
    log.info("AssetEntryLocalServiceImpl.updateEntry() processing finished");
    assetEntryPersistence.update(entry);

    // Synchronize

    if (!sync) {
        return entry;
    }

    if (className.equals(BlogsEntry.class.getName())) {
        BlogsEntry blogsEntry = blogsEntryPersistence.findByPrimaryKey(classPK);

        blogsEntry.setTitle(title);

        blogsEntryPersistence.update(blogsEntry);
    } else if (className.equals(BookmarksEntry.class.getName())) {
        BookmarksEntry bookmarksEntry = bookmarksEntryPersistence.findByPrimaryKey(classPK);

        bookmarksEntry.setName(title);
        bookmarksEntry.setDescription(description);
        bookmarksEntry.setUrl(url);

        bookmarksEntryPersistence.update(bookmarksEntry);
    } else if (className.equals(DLFileEntry.class.getName())) {
        DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(classPK);

        dlFileEntry.setTitle(title);
        dlFileEntry.setDescription(description);

        dlFileEntryPersistence.update(dlFileEntry);
    } else if (className.equals(JournalArticle.class.getName())) {
        JournalArticle journalArticle = journalArticlePersistence.findByPrimaryKey(classPK);

        journalArticle.setTitle(title);
        journalArticle.setDescription(description);

        journalArticlePersistence.update(journalArticle);
    } else if (className.equals(MBMessage.class.getName())) {
        MBMessage mbMessage = mbMessagePersistence.findByPrimaryKey(classPK);

        mbMessage.setSubject(title);

        mbMessagePersistence.update(mbMessage);
    } else if (className.equals(WikiPage.class.getName())) {
        WikiPage wikiPage = wikiPagePersistence.findByPrimaryKey(classPK);

        wikiPage.setTitle(title);

        wikiPagePersistence.update(wikiPage);
    }

    return entry;
}

From source file:com.liferay.so.activities.hook.social.SOSocialActivityInterpreter.java

License:Open Source License

protected List<Long> getActivitySetUserIds(long activitySetId) {
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(SocialActivity.class);

    dynamicQuery.add(RestrictionsFactoryUtil.eq("activitySetId", activitySetId));
    dynamicQuery.setProjection(ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.property("userId")));

    return SocialActivityLocalServiceUtil.dynamicQuery(dynamicQuery);
}

From source file:com.liferay.training.service.builder.service.impl.SearchResultLocalServiceImpl.java

License:Open Source License

private static DynamicQuery _getUserIdsFromZipQuery(Integer zipCode) {

    String zeroPaddedZip = String.format("%05d", zipCode);

    return DynamicQueryFactoryUtil.forClass(Address.class)
            .add(PropertyFactoryUtil.forName("zip").eq(zeroPaddedZip))
            .setProjection(ProjectionFactoryUtil.distinct(PropertyFactoryUtil.forName("userId")));

}