001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.journal.service.persistence;
016    
017    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
018    import com.liferay.portal.kernel.dao.orm.Projection;
019    import com.liferay.portal.kernel.dao.orm.ProjectionFactoryUtil;
020    import com.liferay.portal.kernel.dao.orm.Property;
021    import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
022    import com.liferay.portal.kernel.exception.PortalException;
023    import com.liferay.portal.kernel.exception.SystemException;
024    import com.liferay.portal.kernel.lar.ExportImportHelperUtil;
025    import com.liferay.portal.kernel.lar.ManifestSummary;
026    import com.liferay.portal.kernel.lar.PortletDataContext;
027    import com.liferay.portal.kernel.lar.StagedModelDataHandler;
028    import com.liferay.portal.kernel.lar.StagedModelDataHandlerRegistryUtil;
029    import com.liferay.portal.kernel.lar.StagedModelDataHandlerUtil;
030    import com.liferay.portal.kernel.lar.StagedModelType;
031    import com.liferay.portal.util.PortalUtil;
032    
033    import com.liferay.portlet.journal.model.JournalArticle;
034    
035    /**
036     * @author Brian Wing Shun Chan
037     * @generated
038     */
039    public class JournalArticleExportActionableDynamicQuery
040            extends JournalArticleActionableDynamicQuery {
041            public JournalArticleExportActionableDynamicQuery(
042                    PortletDataContext portletDataContext) throws SystemException {
043                    _portletDataContext = portletDataContext;
044    
045                    setCompanyId(_portletDataContext.getCompanyId());
046    
047                    setGroupId(_portletDataContext.getScopeGroupId());
048            }
049    
050            @Override
051            public long performCount() throws PortalException, SystemException {
052                    ManifestSummary manifestSummary = _portletDataContext.getManifestSummary();
053    
054                    StagedModelType stagedModelType = getStagedModelType();
055    
056                    long modelAdditionCount = super.performCount();
057    
058                    manifestSummary.addModelAdditionCount(stagedModelType.toString(),
059                            modelAdditionCount);
060    
061                    long modelDeletionCount = ExportImportHelperUtil.getModelDeletionCount(_portletDataContext,
062                                    stagedModelType);
063    
064                    manifestSummary.addModelDeletionCount(stagedModelType.toString(),
065                            modelDeletionCount);
066    
067                    return modelAdditionCount;
068            }
069    
070            @Override
071            protected void addCriteria(DynamicQuery dynamicQuery) {
072                    _portletDataContext.addDateRangeCriteria(dynamicQuery, "modifiedDate");
073    
074                    if (getStagedModelType().getReferrerClassNameId() >= 0) {
075                            Property classNameIdProperty = PropertyFactoryUtil.forName(
076                                            "classNameId");
077    
078                            dynamicQuery.add(classNameIdProperty.eq(getStagedModelType()
079                                                                                                                    .getReferrerClassNameId()));
080                    }
081    
082                    StagedModelDataHandler<?> stagedModelDataHandler = StagedModelDataHandlerRegistryUtil.getStagedModelDataHandler(JournalArticle.class.getName());
083    
084                    Property workflowStatusProperty = PropertyFactoryUtil.forName("status");
085    
086                    dynamicQuery.add(workflowStatusProperty.in(
087                                    stagedModelDataHandler.getExportableStatuses()));
088            }
089    
090            @Override
091            protected Projection getCountProjection() {
092                    return ProjectionFactoryUtil.countDistinct("resourcePrimKey");
093            }
094    
095            protected StagedModelType getStagedModelType() {
096                    return new StagedModelType(PortalUtil.getClassNameId(
097                                    JournalArticle.class.getName()));
098            }
099    
100            @Override
101            @SuppressWarnings("unused")
102            protected void performAction(Object object)
103                    throws PortalException, SystemException {
104                    JournalArticle stagedModel = (JournalArticle)object;
105    
106                    StagedModelDataHandlerUtil.exportStagedModel(_portletDataContext,
107                            stagedModel);
108            }
109    
110            private PortletDataContext _portletDataContext;
111    }