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