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.Criterion;
018    import com.liferay.portal.kernel.dao.orm.Disjunction;
019    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
020    import com.liferay.portal.kernel.dao.orm.Projection;
021    import com.liferay.portal.kernel.dao.orm.ProjectionFactoryUtil;
022    import com.liferay.portal.kernel.dao.orm.Property;
023    import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
024    import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil;
025    import com.liferay.portal.kernel.exception.PortalException;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.lar.ExportImportHelperUtil;
028    import com.liferay.portal.kernel.lar.ManifestSummary;
029    import com.liferay.portal.kernel.lar.PortletDataContext;
030    import com.liferay.portal.kernel.lar.StagedModelDataHandler;
031    import com.liferay.portal.kernel.lar.StagedModelDataHandlerRegistryUtil;
032    import com.liferay.portal.kernel.lar.StagedModelDataHandlerUtil;
033    import com.liferay.portal.kernel.lar.StagedModelType;
034    import com.liferay.portal.kernel.workflow.WorkflowConstants;
035    import com.liferay.portal.util.PortalUtil;
036    
037    import com.liferay.portlet.journal.model.JournalArticle;
038    
039    /**
040     * @author Brian Wing Shun Chan
041     * @generated
042     */
043    public class JournalArticleExportActionableDynamicQuery
044            extends JournalArticleActionableDynamicQuery {
045            public JournalArticleExportActionableDynamicQuery(
046                    PortletDataContext portletDataContext) throws SystemException {
047                    _portletDataContext = portletDataContext;
048    
049                    setCompanyId(_portletDataContext.getCompanyId());
050    
051                    setGroupId(_portletDataContext.getScopeGroupId());
052            }
053    
054            @Override
055            public long performCount() throws PortalException, SystemException {
056                    ManifestSummary manifestSummary = _portletDataContext.getManifestSummary();
057    
058                    StagedModelType stagedModelType = getStagedModelType();
059    
060                    long modelAdditionCount = super.performCount();
061    
062                    manifestSummary.addModelAdditionCount(stagedModelType.toString(),
063                            modelAdditionCount);
064    
065                    long modelDeletionCount = ExportImportHelperUtil.getModelDeletionCount(_portletDataContext,
066                                    stagedModelType);
067    
068                    manifestSummary.addModelDeletionCount(stagedModelType.toString(),
069                            modelDeletionCount);
070    
071                    return modelAdditionCount;
072            }
073    
074            @Override
075            protected void addCriteria(DynamicQuery dynamicQuery) {
076                    Criterion modifiedDateCriterion = _portletDataContext.getDateRangeCriteria(
077                                    "modifiedDate");
078                    Criterion statusDateCriterion = _portletDataContext.getDateRangeCriteria(
079                                    "statusDate");
080    
081                    if ((modifiedDateCriterion != null) && (statusDateCriterion != null)) {
082                            Disjunction disjunction = RestrictionsFactoryUtil.disjunction();
083    
084                            disjunction.add(modifiedDateCriterion);
085                            disjunction.add(statusDateCriterion);
086    
087                            dynamicQuery.add(disjunction);
088                    }
089    
090                    if (getStagedModelType().getReferrerClassNameId() >= 0) {
091                            Property classNameIdProperty = PropertyFactoryUtil.forName(
092                                            "classNameId");
093    
094                            dynamicQuery.add(classNameIdProperty.eq(getStagedModelType()
095                                                                                                                    .getReferrerClassNameId()));
096                    }
097    
098                    Property workflowStatusProperty = PropertyFactoryUtil.forName("status");
099    
100                    if (_portletDataContext.isInitialPublication()) {
101                            dynamicQuery.add(workflowStatusProperty.ne(
102                                            WorkflowConstants.STATUS_IN_TRASH));
103                    }
104                    else {
105                            StagedModelDataHandler<?> stagedModelDataHandler = StagedModelDataHandlerRegistryUtil.getStagedModelDataHandler(JournalArticle.class.getName());
106    
107                            dynamicQuery.add(workflowStatusProperty.in(
108                                            stagedModelDataHandler.getExportableStatuses()));
109                    }
110            }
111    
112            @Override
113            protected Projection getCountProjection() {
114                    return ProjectionFactoryUtil.countDistinct("resourcePrimKey");
115            }
116    
117            protected StagedModelType getStagedModelType() {
118                    return new StagedModelType(PortalUtil.getClassNameId(
119                                    JournalArticle.class.getName()));
120            }
121    
122            @Override
123            @SuppressWarnings("unused")
124            protected void performAction(Object object)
125                    throws PortalException, SystemException {
126                    JournalArticle stagedModel = (JournalArticle)object;
127    
128                    StagedModelDataHandlerUtil.exportStagedModel(_portletDataContext,
129                            stagedModel);
130            }
131    
132            private PortletDataContext _portletDataContext;
133    }