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