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.util.PortalUtil;
035    
036    import com.liferay.portlet.wiki.model.WikiPage;
037    
038    /**
039     * @author Brian Wing Shun Chan
040     * @generated
041     */
042    public class WikiPageExportActionableDynamicQuery
043            extends WikiPageActionableDynamicQuery {
044            public WikiPageExportActionableDynamicQuery(
045                    PortletDataContext portletDataContext) throws SystemException {
046                    _portletDataContext = portletDataContext;
047    
048                    setCompanyId(_portletDataContext.getCompanyId());
049    
050                    setGroupId(_portletDataContext.getScopeGroupId());
051            }
052    
053            @Override
054            public long performCount() throws PortalException, SystemException {
055                    ManifestSummary manifestSummary = _portletDataContext.getManifestSummary();
056    
057                    StagedModelType stagedModelType = getStagedModelType();
058    
059                    long modelAdditionCount = super.performCount();
060    
061                    manifestSummary.addModelAdditionCount(stagedModelType.toString(),
062                            modelAdditionCount);
063    
064                    long modelDeletionCount = ExportImportHelperUtil.getModelDeletionCount(_portletDataContext,
065                                    stagedModelType);
066    
067                    manifestSummary.addModelDeletionCount(stagedModelType.toString(),
068                            modelDeletionCount);
069    
070                    return modelAdditionCount;
071            }
072    
073            @Override
074            protected void addCriteria(DynamicQuery dynamicQuery) {
075                    Criterion modifiedDateCriterion = _portletDataContext.getDateRangeCriteria(
076                                    "modifiedDate");
077                    Criterion statusDateCriterion = _portletDataContext.getDateRangeCriteria(
078                                    "statusDate");
079    
080                    if ((modifiedDateCriterion != null) && (statusDateCriterion != null)) {
081                            Disjunction disjunction = RestrictionsFactoryUtil.disjunction();
082    
083                            disjunction.add(modifiedDateCriterion);
084                            disjunction.add(statusDateCriterion);
085    
086                            dynamicQuery.add(disjunction);
087                    }
088    
089                    StagedModelDataHandler<?> stagedModelDataHandler = StagedModelDataHandlerRegistryUtil.getStagedModelDataHandler(WikiPage.class.getName());
090    
091                    Property workflowStatusProperty = PropertyFactoryUtil.forName("status");
092    
093                    dynamicQuery.add(workflowStatusProperty.in(
094                                    stagedModelDataHandler.getExportableStatuses()));
095            }
096    
097            @Override
098            protected Projection getCountProjection() {
099                    return ProjectionFactoryUtil.countDistinct("resourcePrimKey");
100            }
101    
102            protected StagedModelType getStagedModelType() {
103                    return new StagedModelType(PortalUtil.getClassNameId(
104                                    WikiPage.class.getName()));
105            }
106    
107            @Override
108            @SuppressWarnings("unused")
109            protected void performAction(Object object)
110                    throws PortalException, SystemException {
111                    WikiPage stagedModel = (WikiPage)object;
112    
113                    StagedModelDataHandlerUtil.exportStagedModel(_portletDataContext,
114                            stagedModel);
115            }
116    
117            private PortletDataContext _portletDataContext;
118    }