001
014
015 package com.liferay.portlet.bookmarks.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.bookmarks.model.BookmarksEntry;
036
037
041 public class BookmarksEntryExportActionableDynamicQuery
042 extends BookmarksEntryActionableDynamicQuery {
043 public BookmarksEntryExportActionableDynamicQuery(
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(BookmarksEntry.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 BookmarksEntry.class.getName()));
105 }
106
107 @Override
108 @SuppressWarnings("unused")
109 protected void performAction(Object object)
110 throws PortalException, SystemException {
111 BookmarksEntry stagedModel = (BookmarksEntry)object;
112
113 StagedModelDataHandlerUtil.exportStagedModel(_portletDataContext,
114 stagedModel);
115 }
116
117 private PortletDataContext _portletDataContext;
118 }