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.wiki.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.wiki.model.WikiPage;
038    
039    /**
040     * @author Brian Wing Shun Chan
041     * @generated
042     */
043    public class WikiPageExportActionableDynamicQuery
044            extends WikiPageActionableDynamicQuery {
045            public WikiPageExportActionableDynamicQuery(
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                    Property workflowStatusProperty = PropertyFactoryUtil.forName("status");
091    
092                    if (_portletDataContext.isInitialPublication()) {
093                            dynamicQuery.add(workflowStatusProperty.ne(
094                                            WorkflowConstants.STATUS_IN_TRASH));
095                    }
096                    else {
097                            StagedModelDataHandler<?> stagedModelDataHandler = StagedModelDataHandlerRegistryUtil.getStagedModelDataHandler(WikiPage.class.getName());
098    
099                            dynamicQuery.add(workflowStatusProperty.in(
100                                            stagedModelDataHandler.getExportableStatuses()));
101                    }
102            }
103    
104            @Override
105            protected Projection getCountProjection() {
106                    return ProjectionFactoryUtil.countDistinct("resourcePrimKey");
107            }
108    
109            protected StagedModelType getStagedModelType() {
110                    return new StagedModelType(PortalUtil.getClassNameId(
111                                    WikiPage.class.getName()));
112            }
113    
114            @Override
115            @SuppressWarnings("unused")
116            protected void performAction(Object object)
117                    throws PortalException, SystemException {
118                    WikiPage stagedModel = (WikiPage)object;
119    
120                    StagedModelDataHandlerUtil.exportStagedModel(_portletDataContext,
121                            stagedModel);
122            }
123    
124            private PortletDataContext _portletDataContext;
125    }