001    /**
002     * Copyright (c) 2000-present 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.documentlibrary.lar;
016    
017    import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
018    import com.liferay.portal.kernel.dao.orm.Conjunction;
019    import com.liferay.portal.kernel.dao.orm.Criterion;
020    import com.liferay.portal.kernel.dao.orm.Disjunction;
021    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
022    import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
023    import com.liferay.portal.kernel.dao.orm.ExportActionableDynamicQuery;
024    import com.liferay.portal.kernel.dao.orm.ProjectionFactoryUtil;
025    import com.liferay.portal.kernel.dao.orm.Property;
026    import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
027    import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil;
028    import com.liferay.portal.kernel.exception.PortalException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.repository.model.FileEntry;
032    import com.liferay.portal.kernel.repository.model.FileShortcut;
033    import com.liferay.portal.kernel.repository.model.Folder;
034    import com.liferay.portal.kernel.util.GetterUtil;
035    import com.liferay.portal.kernel.util.MapUtil;
036    import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
037    import com.liferay.portal.kernel.util.StringPool;
038    import com.liferay.portal.kernel.xml.Element;
039    import com.liferay.portal.model.Repository;
040    import com.liferay.portal.model.impl.RepositoryEntryImpl;
041    import com.liferay.portal.model.impl.RepositoryImpl;
042    import com.liferay.portal.repository.liferayrepository.LiferayRepositoryDefiner;
043    import com.liferay.portal.repository.temporaryrepository.TemporaryFileEntryRepositoryDefiner;
044    import com.liferay.portal.service.RepositoryLocalServiceUtil;
045    import com.liferay.portal.util.PortalUtil;
046    import com.liferay.portal.util.PropsValues;
047    import com.liferay.portlet.documentlibrary.lar.xstream.FileEntryConverter;
048    import com.liferay.portlet.documentlibrary.lar.xstream.FileVersionConverter;
049    import com.liferay.portlet.documentlibrary.lar.xstream.FolderConverter;
050    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
051    import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
052    import com.liferay.portlet.documentlibrary.model.DLFileEntryType;
053    import com.liferay.portlet.documentlibrary.model.DLFileRank;
054    import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
055    import com.liferay.portlet.documentlibrary.model.DLFileShortcutConstants;
056    import com.liferay.portlet.documentlibrary.model.DLFileVersion;
057    import com.liferay.portlet.documentlibrary.model.DLFolder;
058    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
059    import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl;
060    import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeImpl;
061    import com.liferay.portlet.documentlibrary.model.impl.DLFileShortcutImpl;
062    import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
063    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
064    import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
065    import com.liferay.portlet.documentlibrary.service.DLFileEntryTypeLocalServiceUtil;
066    import com.liferay.portlet.documentlibrary.service.DLFileShortcutLocalServiceUtil;
067    import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
068    import com.liferay.portlet.documentlibrary.service.permission.DLPermission;
069    import com.liferay.portlet.documentlibrary.util.DLConstants;
070    import com.liferay.portlet.exportimport.lar.BasePortletDataHandler;
071    import com.liferay.portlet.exportimport.lar.PortletDataContext;
072    import com.liferay.portlet.exportimport.lar.PortletDataHandlerBoolean;
073    import com.liferay.portlet.exportimport.lar.PortletDataHandlerControl;
074    import com.liferay.portlet.exportimport.lar.StagedModelDataHandler;
075    import com.liferay.portlet.exportimport.lar.StagedModelDataHandlerRegistryUtil;
076    import com.liferay.portlet.exportimport.lar.StagedModelDataHandlerUtil;
077    import com.liferay.portlet.exportimport.lar.StagedModelType;
078    import com.liferay.portlet.exportimport.xstream.XStreamAliasRegistryUtil;
079    import com.liferay.portlet.exportimport.xstream.XStreamConverterRegistryUtil;
080    
081    import java.util.List;
082    import java.util.Map;
083    
084    import javax.portlet.PortletPreferences;
085    
086    /**
087     * @author Bruno Farache
088     * @author Raymond Aug??
089     * @author Sampsa Sohlman
090     * @author Mate Thurzo
091     * @author Zsolt Berentey
092     */
093    public class DLPortletDataHandler extends BasePortletDataHandler {
094    
095            public static final String NAMESPACE = "document_library";
096    
097            public DLPortletDataHandler() {
098                    setDataLocalized(true);
099                    setDataPortletPreferences("rootFolderId");
100                    setDeletionSystemEventStagedModelTypes(
101                            new StagedModelType(DLFileEntryType.class),
102                            new StagedModelType(DLFileRank.class),
103                            new StagedModelType(DLFileShortcut.class),
104                            new StagedModelType(DLFileEntryConstants.getClassName()),
105                            new StagedModelType(DLFolderConstants.getClassName()),
106                            new StagedModelType(Repository.class));
107                    setExportControls(
108                            new PortletDataHandlerBoolean(
109                                    NAMESPACE, "repositories", true, false, null,
110                                    Repository.class.getName()),
111                            new PortletDataHandlerBoolean(
112                                    NAMESPACE, "folders", true, false, null,
113                                    DLFolderConstants.getClassName()),
114                            new PortletDataHandlerBoolean(
115                                    NAMESPACE, "documents", true, false,
116                                    new PortletDataHandlerControl[] {
117                                            new PortletDataHandlerBoolean(
118                                                    NAMESPACE, "previews-and-thumbnails")
119                                    },
120                                    DLFileEntryConstants.getClassName()),
121                            new PortletDataHandlerBoolean(
122                                    NAMESPACE, "document-types", true, false, null,
123                                    DLFileEntryType.class.getName()),
124                            new PortletDataHandlerBoolean(
125                                    NAMESPACE, "shortcuts", true, false, null,
126                                    DLFileShortcutConstants.getClassName()));
127                    setPublishToLiveByDefault(PropsValues.DL_PUBLISH_TO_LIVE_BY_DEFAULT);
128    
129                    XStreamAliasRegistryUtil.register(DLFileEntryImpl.class, "DLFileEntry");
130                    XStreamAliasRegistryUtil.register(
131                            DLFileEntryTypeImpl.class, "DLFileEntryType");
132                    XStreamAliasRegistryUtil.register(
133                            DLFileShortcutImpl.class, "DLFileShortcut");
134                    XStreamAliasRegistryUtil.register(DLFolderImpl.class, "DLFolder");
135                    XStreamAliasRegistryUtil.register(RepositoryImpl.class, "Repository");
136                    XStreamAliasRegistryUtil.register(
137                            RepositoryEntryImpl.class, "RepositoryEntry");
138    
139                    XStreamConverterRegistryUtil.register(new FileEntryConverter());
140                    XStreamConverterRegistryUtil.register(new FileVersionConverter());
141                    XStreamConverterRegistryUtil.register(new FolderConverter());
142            }
143    
144            @Override
145            public String getServiceName() {
146                    return DLConstants.SERVICE_NAME;
147            }
148    
149            @Override
150            protected PortletPreferences doDeleteData(
151                            PortletDataContext portletDataContext, String portletId,
152                            PortletPreferences portletPreferences)
153                    throws Exception {
154    
155                    if (portletDataContext.addPrimaryKey(
156                                    DLPortletDataHandler.class, "deleteData")) {
157    
158                            return portletPreferences;
159                    }
160    
161                    DLAppLocalServiceUtil.deleteAll(portletDataContext.getScopeGroupId());
162    
163                    return portletPreferences;
164            }
165    
166            @Override
167            protected String doExportData(
168                            final PortletDataContext portletDataContext, String portletId,
169                            PortletPreferences portletPreferences)
170                    throws Exception {
171    
172                    portletDataContext.addPortletPermissions(DLPermission.RESOURCE_NAME);
173    
174                    Element rootElement = addExportDataRootElement(portletDataContext);
175    
176                    rootElement.addAttribute(
177                            "group-id", String.valueOf(portletDataContext.getScopeGroupId()));
178    
179                    if (portletDataContext.getBooleanParameter(NAMESPACE, "folders")) {
180                            ActionableDynamicQuery folderActionableDynamicQuery =
181                                    getFolderActionableDynamicQuery(portletDataContext);
182    
183                            folderActionableDynamicQuery.performActions();
184                    }
185    
186                    if (portletDataContext.getBooleanParameter(NAMESPACE, "documents")) {
187                            ActionableDynamicQuery fileEntryActionableDynamicQuery =
188                                    getFileEntryActionableDynamicQuery(portletDataContext);
189    
190                            fileEntryActionableDynamicQuery.performActions();
191                    }
192    
193                    if (portletDataContext.getBooleanParameter(
194                                    NAMESPACE, "document-types")) {
195    
196                            ActionableDynamicQuery fileEntryTypeActionableDynamicQuery =
197                                    getDLFileEntryTypeActionableDynamicQuery(portletDataContext);
198    
199                            fileEntryTypeActionableDynamicQuery.performActions();
200                    }
201    
202                    if (portletDataContext.getBooleanParameter(NAMESPACE, "repositories")) {
203                            ActionableDynamicQuery repositoryActionableDynamicQuery =
204                                    getRepositoryActionableDynamicQuery(portletDataContext);
205    
206                            repositoryActionableDynamicQuery.performActions();
207                    }
208    
209                    if (portletDataContext.getBooleanParameter(NAMESPACE, "shortcuts")) {
210                            ActionableDynamicQuery fileShortcutActionableDynamicQuery =
211                                    getDLFileShortcutActionableDynamicQuery(portletDataContext);
212    
213                            fileShortcutActionableDynamicQuery.performActions();
214                    }
215    
216                    return getExportDataRootElementString(rootElement);
217            }
218    
219            @Override
220            protected PortletPreferences doImportData(
221                            PortletDataContext portletDataContext, String portletId,
222                            PortletPreferences portletPreferences, String data)
223                    throws Exception {
224    
225                    portletDataContext.importPortletPermissions(DLPermission.RESOURCE_NAME);
226    
227                    if (portletDataContext.getBooleanParameter(NAMESPACE, "folders")) {
228                            Element foldersElement =
229                                    portletDataContext.getImportDataGroupElement(DLFolder.class);
230    
231                            List<Element> folderElements = foldersElement.elements();
232    
233                            for (Element folderElement : folderElements) {
234                                    StagedModelDataHandlerUtil.importStagedModel(
235                                            portletDataContext, folderElement);
236                            }
237                    }
238    
239                    if (portletDataContext.getBooleanParameter(NAMESPACE, "documents")) {
240                            Element fileEntriesElement =
241                                    portletDataContext.getImportDataGroupElement(DLFileEntry.class);
242    
243                            List<Element> fileEntryElements = fileEntriesElement.elements();
244    
245                            for (Element fileEntryElement : fileEntryElements) {
246                                    StagedModelDataHandlerUtil.importStagedModel(
247                                            portletDataContext, fileEntryElement);
248                            }
249                    }
250    
251                    if (portletDataContext.getBooleanParameter(
252                                    NAMESPACE, "document-types")) {
253    
254                            Element fileEntryTypesElement =
255                                    portletDataContext.getImportDataGroupElement(
256                                            DLFileEntryType.class);
257    
258                            List<Element> fileEntryTypeElements =
259                                    fileEntryTypesElement.elements();
260    
261                            for (Element fileEntryTypeElement : fileEntryTypeElements) {
262                                    StagedModelDataHandlerUtil.importStagedModel(
263                                            portletDataContext, fileEntryTypeElement);
264                            }
265                    }
266    
267                    if (portletDataContext.getBooleanParameter(NAMESPACE, "repositories")) {
268                            Element repositoriesElement =
269                                    portletDataContext.getImportDataGroupElement(Repository.class);
270    
271                            List<Element> repositoryElements = repositoriesElement.elements();
272    
273                            for (Element repositoryElement : repositoryElements) {
274                                    StagedModelDataHandlerUtil.importStagedModel(
275                                            portletDataContext, repositoryElement);
276                            }
277                    }
278    
279                    if (portletDataContext.getBooleanParameter(NAMESPACE, "shortcuts")) {
280                            Element fileShortcutsElement =
281                                    portletDataContext.getImportDataGroupElement(
282                                            DLFileShortcut.class);
283    
284                            List<Element> fileShortcutElements =
285                                    fileShortcutsElement.elements();
286    
287                            for (Element fileShortcutElement : fileShortcutElements) {
288                                    StagedModelDataHandlerUtil.importStagedModel(
289                                            portletDataContext, fileShortcutElement);
290                            }
291                    }
292    
293                    return portletPreferences;
294            }
295    
296            @Override
297            protected void doPrepareManifestSummary(
298                            final PortletDataContext portletDataContext,
299                            PortletPreferences portletPreferences)
300                    throws Exception {
301    
302                    ActionableDynamicQuery dlFileShortcutActionableDynamicQuery =
303                            getDLFileShortcutActionableDynamicQuery(portletDataContext);
304    
305                    dlFileShortcutActionableDynamicQuery.performCount();
306    
307                    ActionableDynamicQuery fileEntryActionableDynamicQuery =
308                            getFileEntryActionableDynamicQuery(portletDataContext);
309    
310                    fileEntryActionableDynamicQuery.performCount();
311    
312                    ActionableDynamicQuery fileEntryTypeActionableDynamicQuery =
313                            getDLFileEntryTypeActionableDynamicQuery(portletDataContext);
314    
315                    fileEntryTypeActionableDynamicQuery.performCount();
316    
317                    ActionableDynamicQuery folderActionableDynamicQuery =
318                            getFolderActionableDynamicQuery(portletDataContext);
319    
320                    folderActionableDynamicQuery.performCount();
321    
322                    ActionableDynamicQuery repositoryActionableDynamicQuery =
323                            getRepositoryActionableDynamicQuery(portletDataContext);
324    
325                    repositoryActionableDynamicQuery.performCount();
326            }
327    
328            @Override
329            protected PortletPreferences doProcessExportPortletPreferences(
330                            PortletDataContext portletDataContext, String portletId,
331                            PortletPreferences portletPreferences)
332                    throws Exception {
333    
334                    long rootFolderId = GetterUtil.getLong(
335                            portletPreferences.getValue("rootFolderId", null));
336    
337                    if (rootFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
338                            Folder folder = null;
339    
340                            try {
341                                    folder = DLAppLocalServiceUtil.getFolder(rootFolderId);
342                            }
343                            catch (PortalException e) {
344                                    if (_log.isErrorEnabled()) {
345                                            _log.error(
346                                                    "Portlet " + portletId +
347                                                            " refers to an invalid root folder ID " +
348                                                                    rootFolderId);
349                                    }
350    
351                                    throw e;
352                            }
353    
354                            StagedModelDataHandlerUtil.exportReferenceStagedModel(
355                                    portletDataContext, portletId, folder);
356                    }
357    
358                    return portletPreferences;
359            }
360    
361            @Override
362            protected PortletPreferences doProcessImportPortletPreferences(
363                            PortletDataContext portletDataContext, String portletId,
364                            PortletPreferences portletPreferences)
365                    throws Exception {
366    
367                    long rootFolderId = GetterUtil.getLong(
368                            portletPreferences.getValue("rootFolderId", null));
369    
370                    if (rootFolderId > 0) {
371                            Element foldersElement =
372                                    portletDataContext.getImportDataGroupElement(DLFolder.class);
373    
374                            List<Element> folderElements = foldersElement.elements();
375    
376                            if (!folderElements.isEmpty()) {
377                                    StagedModelDataHandlerUtil.importStagedModel(
378                                            portletDataContext, folderElements.get(0));
379    
380                                    Map<Long, Long> folderIds =
381                                            (Map<Long, Long>)portletDataContext.getNewPrimaryKeysMap(
382                                                    Folder.class + ".folderIdsAndRepositoryEntryIds");
383    
384                                    rootFolderId = MapUtil.getLong(
385                                            folderIds, rootFolderId, rootFolderId);
386    
387                                    portletPreferences.setValue(
388                                            "rootFolderId", String.valueOf(rootFolderId));
389                            }
390                    }
391    
392                    return portletPreferences;
393            }
394    
395            protected ActionableDynamicQuery getDLFileEntryTypeActionableDynamicQuery(
396                            final PortletDataContext portletDataContext)
397                    throws Exception {
398    
399                    ActionableDynamicQuery actionableDynamicQuery =
400                            DLFileEntryTypeLocalServiceUtil.getExportActionableDynamicQuery(
401                                    portletDataContext);
402    
403                    final ActionableDynamicQuery.AddCriteriaMethod addCriteriaMethod =
404                            actionableDynamicQuery.getAddCriteriaMethod();
405    
406                    actionableDynamicQuery.setAddCriteriaMethod(
407                            new ActionableDynamicQuery.AddCriteriaMethod() {
408    
409                                    @Override
410                                    public void addCriteria(DynamicQuery dynamicQuery) {
411                                            addCriteriaMethod.addCriteria(dynamicQuery);
412    
413                                            Property property = PropertyFactoryUtil.forName("groupId");
414    
415                                            dynamicQuery.add(
416                                                    property.in(
417                                                            new Long[] {portletDataContext.getScopeGroupId()}));
418                                    }
419    
420                            });
421                    actionableDynamicQuery.setPerformActionMethod(
422                            new ActionableDynamicQuery.PerformActionMethod() {
423    
424                                    @Override
425                                    public void performAction(Object object)
426                                            throws PortalException {
427    
428                                            DLFileEntryType dlFileEntryType = (DLFileEntryType)object;
429    
430                                            if (dlFileEntryType.isExportable()) {
431                                                    StagedModelDataHandlerUtil.exportStagedModel(
432                                                            portletDataContext, dlFileEntryType);
433                                            }
434                                    }
435    
436                            });
437    
438                    return actionableDynamicQuery;
439            }
440    
441            protected ActionableDynamicQuery getDLFileShortcutActionableDynamicQuery(
442                            final PortletDataContext portletDataContext)
443                    throws Exception {
444    
445                    final ExportActionableDynamicQuery exportActionableDynamicQuery =
446                            DLFileShortcutLocalServiceUtil.getExportActionableDynamicQuery(
447                                    portletDataContext);
448    
449                    final ActionableDynamicQuery.AddCriteriaMethod addCriteriaMethod =
450                            exportActionableDynamicQuery.getAddCriteriaMethod();
451    
452                    exportActionableDynamicQuery.setAddCriteriaMethod(
453                            new ActionableDynamicQuery.AddCriteriaMethod() {
454    
455                                    @Override
456                                    public void addCriteria(DynamicQuery dynamicQuery) {
457                                            addCriteriaMethod.addCriteria(dynamicQuery);
458    
459                                            Property property = PropertyFactoryUtil.forName("active");
460    
461                                            dynamicQuery.add(property.eq(Boolean.TRUE));
462                                    }
463    
464                            });
465                    exportActionableDynamicQuery.setPerformActionMethod(
466                            new ActionableDynamicQuery.PerformActionMethod() {
467                                    @Override
468                                    public void performAction(Object object)
469                                            throws PortalException {
470    
471                                            DLFileShortcut dlFileShortcut = (DLFileShortcut)object;
472    
473                                            FileShortcut fileShortcut =
474                                                    DLAppLocalServiceUtil.getFileShortcut(
475                                                            dlFileShortcut.getFileShortcutId());
476    
477                                            StagedModelDataHandlerUtil.exportStagedModel(
478                                                    portletDataContext, fileShortcut);
479                                    }
480                            });
481                    exportActionableDynamicQuery.setStagedModelType(
482                            new StagedModelType(DLFileShortcutConstants.getClassName()));
483    
484                    return exportActionableDynamicQuery;
485            }
486    
487            protected ActionableDynamicQuery getFileEntryActionableDynamicQuery(
488                            final PortletDataContext portletDataContext)
489                    throws Exception {
490    
491                    final ExportActionableDynamicQuery exportActionableDynamicQuery =
492                            DLFileEntryLocalServiceUtil.getExportActionableDynamicQuery(
493                                    portletDataContext);
494    
495                    exportActionableDynamicQuery.setAddCriteriaMethod(
496                            new ActionableDynamicQuery.AddCriteriaMethod() {
497    
498                                    @Override
499                                    public void addCriteria(DynamicQuery dynamicQuery) {
500                                            DynamicQuery fileVersionDynamicQuery =
501                                                    DynamicQueryFactoryUtil.forClass(
502                                                            DLFileVersion.class, "dlFileVersion",
503                                                            PortalClassLoaderUtil.getClassLoader());
504    
505                                            fileVersionDynamicQuery.setProjection(
506                                                    ProjectionFactoryUtil.property("fileEntryId"));
507    
508                                            fileVersionDynamicQuery.add(
509                                                    RestrictionsFactoryUtil.eqProperty(
510                                                            "dlFileVersion.fileEntryId", "fileEntryId"));
511                                            fileVersionDynamicQuery.add(
512                                                    RestrictionsFactoryUtil.eqProperty(
513                                                            "dlFileVersion.version", "version"));
514    
515                                            Property statusProperty = PropertyFactoryUtil.forName(
516                                                    "status");
517    
518                                            StagedModelDataHandler<?> stagedModelDataHandler =
519                                                    StagedModelDataHandlerRegistryUtil.
520                                                            getStagedModelDataHandler(
521                                                                    DLFileEntry.class.getName());
522    
523                                            fileVersionDynamicQuery.add(
524                                                    statusProperty.in(
525                                                            stagedModelDataHandler.getExportableStatuses()));
526    
527                                            Criterion modifiedDateCriterion =
528                                                    portletDataContext.getDateRangeCriteria("modifiedDate");
529                                            Criterion statusDateCriterion =
530                                                    portletDataContext.getDateRangeCriteria("statusDate");
531    
532                                            if ((modifiedDateCriterion != null) &&
533                                                    (statusDateCriterion != null)) {
534    
535                                                    Disjunction disjunction =
536                                                            RestrictionsFactoryUtil.disjunction();
537    
538                                                    disjunction.add(modifiedDateCriterion);
539                                                    disjunction.add(statusDateCriterion);
540    
541                                                    fileVersionDynamicQuery.add(disjunction);
542                                            }
543    
544                                            Property fileEntryIdProperty = PropertyFactoryUtil.forName(
545                                                    "fileEntryId");
546    
547                                            dynamicQuery.add(
548                                                    fileEntryIdProperty.in(fileVersionDynamicQuery));
549    
550                                            Property repositoryIdProperty = PropertyFactoryUtil.forName(
551                                                    "repositoryId");
552    
553                                            dynamicQuery.add(
554                                                    repositoryIdProperty.eq(
555                                                            portletDataContext.getScopeGroupId()));
556                                    }
557    
558                            });
559                    exportActionableDynamicQuery.setPerformActionMethod(
560                            new ActionableDynamicQuery.PerformActionMethod() {
561    
562                                    @Override
563                                    public void performAction(Object object)
564                                            throws PortalException {
565    
566                                            DLFileEntry dlFileEntry = (DLFileEntry)object;
567    
568                                            FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(
569                                                    dlFileEntry.getFileEntryId());
570    
571                                            StagedModelDataHandlerUtil.exportStagedModel(
572                                                    portletDataContext, fileEntry);
573                                    }
574                            });
575                    exportActionableDynamicQuery.setStagedModelType(
576                            new StagedModelType(DLFileEntryConstants.getClassName()));
577    
578                    return exportActionableDynamicQuery;
579            }
580    
581            protected ActionableDynamicQuery getFolderActionableDynamicQuery(
582                            final PortletDataContext portletDataContext)
583                    throws Exception {
584    
585                    ExportActionableDynamicQuery exportActionableDynamicQuery =
586                            DLFolderLocalServiceUtil.getExportActionableDynamicQuery(
587                                    portletDataContext);
588    
589                    final ActionableDynamicQuery.AddCriteriaMethod addCriteriaMethod =
590                            exportActionableDynamicQuery.getAddCriteriaMethod();
591    
592                    exportActionableDynamicQuery.setAddCriteriaMethod(
593                            new ActionableDynamicQuery.AddCriteriaMethod() {
594    
595                                    @Override
596                                    public void addCriteria(DynamicQuery dynamicQuery) {
597                                            addCriteriaMethod.addCriteria(dynamicQuery);
598    
599                                            Property property = PropertyFactoryUtil.forName(
600                                                    "repositoryId");
601    
602                                            dynamicQuery.add(
603                                                    property.eq(portletDataContext.getScopeGroupId()));
604                                    }
605    
606                            });
607                    exportActionableDynamicQuery.setPerformActionMethod(
608                            new ActionableDynamicQuery.PerformActionMethod() {
609    
610                                    @Override
611                                    public void performAction(Object object)
612                                            throws PortalException {
613    
614                                            DLFolder dlFolder = (DLFolder)object;
615    
616                                            if (dlFolder.isInTrash()) {
617                                                    return;
618                                            }
619    
620                                            Folder folder = DLAppLocalServiceUtil.getFolder(
621                                                    dlFolder.getFolderId());
622    
623                                            StagedModelDataHandlerUtil.exportStagedModel(
624                                                    portletDataContext, folder);
625                                    }
626    
627                            });
628                    exportActionableDynamicQuery.setStagedModelType(
629                            new StagedModelType(DLFolderConstants.getClassName()));
630    
631                    return exportActionableDynamicQuery;
632            }
633    
634            protected ActionableDynamicQuery getRepositoryActionableDynamicQuery(
635                            final PortletDataContext portletDataContext)
636                    throws Exception {
637    
638                    ExportActionableDynamicQuery exportActionableDynamicQuery =
639                            RepositoryLocalServiceUtil.getExportActionableDynamicQuery(
640                                    portletDataContext);
641    
642                    final ActionableDynamicQuery.AddCriteriaMethod addCriteriaMethod =
643                            exportActionableDynamicQuery.getAddCriteriaMethod();
644    
645                    exportActionableDynamicQuery.setAddCriteriaMethod(
646                            new ActionableDynamicQuery.AddCriteriaMethod() {
647    
648                                    @Override
649                                    public void addCriteria(DynamicQuery dynamicQuery) {
650                                            addCriteriaMethod.addCriteria(dynamicQuery);
651    
652                                            Conjunction conjunction =
653                                                    RestrictionsFactoryUtil.conjunction();
654    
655                                            Property classNameIdProperty = PropertyFactoryUtil.forName(
656                                                    "classNameId");
657    
658                                            long liferayRepositoryClassNameId =
659                                                    PortalUtil.getClassNameId(
660                                                            LiferayRepositoryDefiner.CLASS_NAME);
661    
662                                            conjunction.add(
663                                                    classNameIdProperty.ne(liferayRepositoryClassNameId));
664    
665                                            long tempFileRepositoryClassNameId =
666                                                    PortalUtil.getClassNameId(
667                                                            TemporaryFileEntryRepositoryDefiner.CLASS_NAME);
668    
669                                            conjunction.add(
670                                                    classNameIdProperty.ne(tempFileRepositoryClassNameId));
671    
672                                            dynamicQuery.add(conjunction);
673    
674                                            Disjunction disjunction =
675                                                    RestrictionsFactoryUtil.disjunction();
676    
677                                            Property portletIdProperty = PropertyFactoryUtil.forName(
678                                                    "portletId");
679    
680                                            disjunction.add(portletIdProperty.isNull());
681                                            disjunction.add(portletIdProperty.eq(StringPool.BLANK));
682    
683                                            dynamicQuery.add(disjunction);
684                                    }
685    
686                            });
687                    exportActionableDynamicQuery.setStagedModelType(
688                            new StagedModelType(
689                                    PortalUtil.getClassNameId(Repository.class.getName()),
690                                    StagedModelType.REFERRER_CLASS_NAME_ID_ALL));
691    
692                    return exportActionableDynamicQuery;
693            }
694    
695            private static final Log _log = LogFactoryUtil.getLog(
696                    DLPortletDataHandler.class);
697    
698    }