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.documentlibrary.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.json.JSONFactoryUtil;
020    import com.liferay.portal.kernel.json.JSONObject;
021    import com.liferay.portal.kernel.repository.model.FileEntry;
022    import com.liferay.portal.kernel.repository.model.FileVersion;
023    import com.liferay.portal.kernel.repository.model.Folder;
024    import com.liferay.portal.kernel.transaction.TransactionCommitCallbackRegistryUtil;
025    import com.liferay.portal.kernel.util.ListUtil;
026    import com.liferay.portal.kernel.util.StringUtil;
027    import com.liferay.portal.kernel.util.Validator;
028    import com.liferay.portal.kernel.workflow.WorkflowConstants;
029    import com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil;
030    import com.liferay.portal.model.Group;
031    import com.liferay.portal.repository.liferayrepository.model.LiferayFileEntry;
032    import com.liferay.portal.repository.liferayrepository.model.LiferayFileVersion;
033    import com.liferay.portal.service.ServiceContext;
034    import com.liferay.portal.util.PropsValues;
035    import com.liferay.portlet.asset.NoSuchEntryException;
036    import com.liferay.portlet.asset.model.AssetEntry;
037    import com.liferay.portlet.asset.model.AssetLink;
038    import com.liferay.portlet.asset.model.AssetLinkConstants;
039    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
040    import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
041    import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
042    import com.liferay.portlet.documentlibrary.model.DLFileVersion;
043    import com.liferay.portlet.documentlibrary.model.DLSyncConstants;
044    import com.liferay.portlet.documentlibrary.service.base.DLAppHelperLocalServiceBaseImpl;
045    import com.liferay.portlet.documentlibrary.social.DLActivityKeys;
046    import com.liferay.portlet.documentlibrary.util.DLProcessorRegistryUtil;
047    
048    import java.io.Serializable;
049    
050    import java.util.HashMap;
051    import java.util.List;
052    import java.util.Map;
053    import java.util.concurrent.Callable;
054    
055    /**
056     * @author Alexander Chow
057     */
058    public class DLAppHelperLocalServiceImpl
059            extends DLAppHelperLocalServiceBaseImpl {
060    
061            @Override
062            public void addFileEntry(
063                            long userId, FileEntry fileEntry, FileVersion fileVersion,
064                            ServiceContext serviceContext)
065                    throws PortalException, SystemException {
066    
067                    updateAsset(
068                            userId, fileEntry, fileVersion,
069                            serviceContext.getAssetCategoryIds(),
070                            serviceContext.getAssetTagNames(),
071                            serviceContext.getAssetLinkEntryIds());
072    
073                    if (PropsValues.DL_FILE_ENTRY_COMMENTS_ENABLED) {
074                            mbMessageLocalService.addDiscussionMessage(
075                                    fileEntry.getUserId(), fileEntry.getUserName(),
076                                    fileEntry.getGroupId(), DLFileEntryConstants.getClassName(),
077                                    fileEntry.getFileEntryId(), WorkflowConstants.ACTION_PUBLISH);
078                    }
079    
080                    if (fileVersion instanceof LiferayFileVersion) {
081                            DLFileVersion dlFileVersion = (DLFileVersion)fileVersion.getModel();
082    
083                            Map<String, Serializable> workflowContext =
084                                    new HashMap<String, Serializable>();
085    
086                            workflowContext.put("event", DLSyncConstants.EVENT_ADD);
087    
088                            WorkflowHandlerRegistryUtil.startWorkflowInstance(
089                                    dlFileVersion.getCompanyId(), dlFileVersion.getGroupId(),
090                                    userId, DLFileEntryConstants.getClassName(),
091                                    dlFileVersion.getFileVersionId(), dlFileVersion, serviceContext,
092                                    workflowContext);
093                    }
094    
095                    registerDLProcessorCallback(fileEntry);
096            }
097    
098            @Override
099            public void addFolder(Folder folder, ServiceContext serviceContext)
100                    throws PortalException, SystemException {
101    
102                    if (!isStagingGroup(folder.getGroupId())) {
103                            dlSyncLocalService.addSync(
104                                    folder.getFolderId(), folder.getUuid(), folder.getCompanyId(),
105                                    folder.getRepositoryId(), folder.getParentFolderId(),
106                                    folder.getName(), folder.getDescription(),
107                                    DLSyncConstants.TYPE_FOLDER, "-1");
108                    }
109            }
110    
111            @Override
112            public void cancelCheckOut(
113                            long userId, FileEntry fileEntry,
114                            FileVersion destinationFileVersion, FileVersion draftFileVersion,
115                            ServiceContext serviceContext)
116                    throws PortalException, SystemException {
117    
118                    updateFileEntry(
119                            userId, fileEntry, destinationFileVersion, serviceContext);
120    
121                    if (draftFileVersion == null) {
122                            return;
123                    }
124    
125                    AssetEntry draftAssetEntry = null;
126    
127                    try {
128                            draftAssetEntry = assetEntryLocalService.getEntry(
129                                    DLFileEntryConstants.getClassName(),
130                                    draftFileVersion.getPrimaryKey());
131    
132                            assetEntryLocalService.deleteEntry(draftAssetEntry.getEntryId());
133                    }
134                    catch (NoSuchEntryException nsee) {
135                    }
136            }
137    
138            @Override
139            public void checkAssetEntry(
140                            long userId, FileEntry fileEntry, FileVersion fileVersion)
141                    throws PortalException, SystemException {
142    
143                    AssetEntry fileEntryAssetEntry = assetEntryLocalService.fetchEntry(
144                            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());
145    
146                    long[] assetCategoryIds = new long[0];
147                    String[] assetTagNames = new String[0];
148    
149                    long fileEntryTypeId = getFileEntryTypeId(fileEntry);
150    
151                    if (fileEntryAssetEntry == null) {
152                            fileEntryAssetEntry = assetEntryLocalService.updateEntry(
153                                    userId, fileEntry.getGroupId(), fileEntry.getCreateDate(),
154                                    fileEntry.getModifiedDate(),
155                                    DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId(),
156                                    fileEntry.getUuid(), fileEntryTypeId, assetCategoryIds,
157                                    assetTagNames, false, null, null, null, null,
158                                    fileEntry.getMimeType(), fileEntry.getTitle(),
159                                    fileEntry.getDescription(), null, null, null, 0, 0, null,
160                                    false);
161                    }
162    
163                    AssetEntry fileVersionAssetEntry = assetEntryLocalService.fetchEntry(
164                            DLFileEntryConstants.getClassName(),
165                            fileVersion.getFileVersionId());
166    
167                    if ((fileVersionAssetEntry == null) && !fileVersion.isApproved() &&
168                            !fileVersion.getVersion().equals(
169                                    DLFileEntryConstants.VERSION_DEFAULT)) {
170    
171                            assetCategoryIds = assetCategoryLocalService.getCategoryIds(
172                                    DLFileEntryConstants.getClassName(),
173                                    fileEntry.getFileEntryId());
174                            assetTagNames = assetTagLocalService.getTagNames(
175                                    DLFileEntryConstants.getClassName(),
176                                    fileEntry.getFileEntryId());
177    
178                            fileVersionAssetEntry = assetEntryLocalService.updateEntry(
179                                    userId, fileEntry.getGroupId(), fileEntry.getCreateDate(),
180                                    fileEntry.getModifiedDate(),
181                                    DLFileEntryConstants.getClassName(),
182                                    fileVersion.getFileVersionId(), fileEntry.getUuid(),
183                                    fileEntryTypeId, assetCategoryIds, assetTagNames, false, null,
184                                    null, null, null, fileEntry.getMimeType(), fileEntry.getTitle(),
185                                    fileEntry.getDescription(), null, null, null, 0, 0, null,
186                                    false);
187    
188                            List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(
189                                    fileEntryAssetEntry.getEntryId());
190    
191                            long[] assetLinkIds = StringUtil.split(
192                                    ListUtil.toString(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR),
193                                    0L);
194    
195                            assetLinkLocalService.updateLinks(
196                                    userId, fileVersionAssetEntry.getEntryId(), assetLinkIds,
197                                    AssetLinkConstants.TYPE_RELATED);
198                    }
199            }
200    
201            @Override
202            public void deleteFileEntry(FileEntry fileEntry)
203                    throws PortalException, SystemException {
204    
205                    // Subscriptions
206    
207                    subscriptionLocalService.deleteSubscriptions(
208                            fileEntry.getCompanyId(), DLFileEntryConstants.getClassName(),
209                            fileEntry.getFileEntryId());
210    
211                    // File previews
212    
213                    DLProcessorRegistryUtil.cleanUp(fileEntry);
214    
215                    // File ranks
216    
217                    dlFileRankLocalService.deleteFileRanksByFileEntryId(
218                            fileEntry.getFileEntryId());
219    
220                    // File shortcuts
221    
222                    dlFileShortcutLocalService.deleteFileShortcuts(
223                            fileEntry.getFileEntryId());
224    
225                    // Sync
226    
227                    if (isUpdateSync(fileEntry)) {
228                            dlSyncLocalService.updateSync(
229                                    fileEntry.getFileEntryId(), fileEntry.getFolderId(),
230                                    fileEntry.getTitle(), fileEntry.getDescription(),
231                                    DLSyncConstants.EVENT_DELETE, fileEntry.getVersion());
232                    }
233    
234                    // Asset
235    
236                    assetEntryLocalService.deleteEntry(
237                            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());
238    
239                    // Message boards
240    
241                    mbMessageLocalService.deleteDiscussionMessages(
242                            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());
243    
244                    // Ratings
245    
246                    ratingsStatsLocalService.deleteStats(
247                            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());
248            }
249    
250            @Override
251            public void deleteFolder(Folder folder)
252                    throws PortalException, SystemException {
253    
254                    if (!isStagingGroup(folder.getGroupId())) {
255                            dlSyncLocalService.updateSync(
256                                    folder.getFolderId(), folder.getParentFolderId(),
257                                    folder.getName(), folder.getDescription(),
258                                    DLSyncConstants.EVENT_DELETE, "-1");
259                    }
260            }
261    
262            @Override
263            public void getFileAsStream(
264                            long userId, FileEntry fileEntry, boolean incrementCounter)
265                    throws SystemException {
266    
267                    if (!incrementCounter) {
268                            return;
269                    }
270    
271                    // File rank
272    
273                    if (userId > 0) {
274                            dlFileRankLocalService.updateFileRank(
275                                    fileEntry.getGroupId(), fileEntry.getCompanyId(), userId,
276                                    fileEntry.getFileEntryId(), new ServiceContext());
277                    }
278    
279                    // File read count
280    
281                    assetEntryLocalService.incrementViewCounter(
282                            userId, DLFileEntryConstants.getClassName(),
283                            fileEntry.getFileEntryId(), 1);
284    
285                    List<DLFileShortcut> fileShortcuts =
286                            dlFileShortcutPersistence.findByToFileEntryId(
287                                    fileEntry.getFileEntryId());
288    
289                    for (DLFileShortcut fileShortcut : fileShortcuts) {
290                            assetEntryLocalService.incrementViewCounter(
291                                    userId, DLFileShortcut.class.getName(),
292                                    fileShortcut.getFileShortcutId(), 1);
293                    }
294            }
295    
296            @Override
297            public List<DLFileShortcut> getFileShortcuts(
298                            long groupId, long folderId, int status)
299                    throws SystemException {
300    
301                    return dlFileShortcutPersistence.findByG_F_S(groupId, folderId, status);
302            }
303    
304            @Override
305            public int getFileShortcutsCount(long groupId, long folderId, int status)
306                    throws SystemException {
307    
308                    return dlFileShortcutPersistence.countByG_F_S(
309                            groupId, folderId, status);
310            }
311    
312            @Override
313            public List<FileEntry> getNoAssetFileEntries() {
314                    return null;
315            }
316    
317            @Override
318            public void moveFileEntry(FileEntry fileEntry)
319                    throws PortalException, SystemException {
320    
321                    if (isUpdateSync(fileEntry)) {
322                            dlSyncLocalService.updateSync(
323                                    fileEntry.getFileEntryId(), fileEntry.getFolderId(),
324                                    fileEntry.getTitle(), fileEntry.getDescription(),
325                                    DLSyncConstants.EVENT_UPDATE, fileEntry.getVersion());
326                    }
327            }
328    
329            @Override
330            public void moveFolder(Folder folder)
331                    throws PortalException, SystemException {
332    
333                    if (!isStagingGroup(folder.getGroupId())) {
334                            dlSyncLocalService.updateSync(
335                            folder.getFolderId(), folder.getParentFolderId(), folder.getName(),
336                            folder.getDescription(), DLSyncConstants.EVENT_UPDATE, "-1");
337                    }
338            }
339    
340            @Override
341            public AssetEntry updateAsset(
342                            long userId, FileEntry fileEntry, FileVersion fileVersion,
343                            long assetClassPk)
344                    throws PortalException, SystemException {
345    
346                    long[] assetCategoryIds = assetCategoryLocalService.getCategoryIds(
347                            DLFileEntryConstants.getClassName(), assetClassPk);
348                    String[] assetTagNames = assetTagLocalService.getTagNames(
349                            DLFileEntryConstants.getClassName(), assetClassPk);
350    
351                    AssetEntry assetEntry = assetEntryLocalService.getEntry(
352                            DLFileEntryConstants.getClassName(), assetClassPk);
353    
354                    List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(
355                            assetEntry.getEntryId());
356    
357                    long[] assetLinkIds = StringUtil.split(
358                            ListUtil.toString(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR), 0L);
359    
360                    return updateAsset(
361                            userId, fileEntry, fileVersion, assetCategoryIds, assetTagNames,
362                            assetLinkIds);
363            }
364    
365            @Override
366            public AssetEntry updateAsset(
367                            long userId, FileEntry fileEntry, FileVersion fileVersion,
368                            long[] assetCategoryIds, String[] assetTagNames,
369                            long[] assetLinkEntryIds)
370                    throws PortalException, SystemException {
371    
372                    AssetEntry assetEntry = null;
373    
374                    boolean visible = false;
375    
376                    boolean addDraftAssetEntry = false;
377    
378                    if (fileEntry instanceof LiferayFileEntry) {
379                            DLFileVersion dlFileVersion = (DLFileVersion)fileVersion.getModel();
380    
381                            if (dlFileVersion.isApproved()) {
382                                    visible = true;
383                            }
384                            else {
385                                    String version = dlFileVersion.getVersion();
386    
387                                    if (!version.equals(DLFileEntryConstants.VERSION_DEFAULT)) {
388                                            addDraftAssetEntry = true;
389                                    }
390                            }
391                    }
392                    else {
393                            visible = true;
394                    }
395    
396                    long fileEntryTypeId = getFileEntryTypeId(fileEntry);
397    
398                    if (addDraftAssetEntry) {
399                            if (assetCategoryIds == null) {
400                                    assetCategoryIds = assetCategoryLocalService.getCategoryIds(
401                                            DLFileEntryConstants.getClassName(),
402                                            fileEntry.getFileEntryId());
403                            }
404    
405                            if (assetTagNames == null) {
406                                    assetTagNames = assetTagLocalService.getTagNames(
407                                            DLFileEntryConstants.getClassName(),
408                                            fileEntry.getFileEntryId());
409                            }
410    
411                            if (assetLinkEntryIds == null) {
412                                    AssetEntry previousAssetEntry = assetEntryLocalService.getEntry(
413                                            DLFileEntryConstants.getClassName(),
414                                            fileEntry.getFileEntryId());
415    
416                                    List<AssetLink> assetLinks =
417                                            assetLinkLocalService.getDirectLinks(
418                                                    previousAssetEntry.getEntryId(),
419                                                    AssetLinkConstants.TYPE_RELATED);
420    
421                                    assetLinkEntryIds = StringUtil.split(
422                                            ListUtil.toString(
423                                                    assetLinks, AssetLink.ENTRY_ID2_ACCESSOR), 0L);
424                            }
425    
426                            assetEntry = assetEntryLocalService.updateEntry(
427                                    userId, fileEntry.getGroupId(), fileEntry.getCreateDate(),
428                                    fileEntry.getModifiedDate(),
429                                    DLFileEntryConstants.getClassName(),
430                                    fileVersion.getFileVersionId(), fileEntry.getUuid(),
431                                    fileEntryTypeId, assetCategoryIds, assetTagNames, false, null,
432                                    null, null, null, fileEntry.getMimeType(), fileEntry.getTitle(),
433                                    fileEntry.getDescription(), null, null, null, 0, 0, null,
434                                    false);
435                    }
436                    else {
437                            assetEntry = assetEntryLocalService.updateEntry(
438                                    userId, fileEntry.getGroupId(), fileEntry.getCreateDate(),
439                                    fileEntry.getModifiedDate(),
440                                    DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId(),
441                                    fileEntry.getUuid(), fileEntryTypeId, assetCategoryIds,
442                                    assetTagNames, visible, null, null, null, null,
443                                    fileEntry.getMimeType(), fileEntry.getTitle(),
444                                    fileEntry.getDescription(), null, null, null, 0, 0, null,
445                                    false);
446    
447                            List<DLFileShortcut> dlFileShortcuts =
448                                    dlFileShortcutPersistence.findByToFileEntryId(
449                                            fileEntry.getFileEntryId());
450    
451                            for (DLFileShortcut dlFileShortcut : dlFileShortcuts) {
452                                    assetEntryLocalService.updateEntry(
453                                            userId, dlFileShortcut.getGroupId(),
454                                            dlFileShortcut.getCreateDate(),
455                                            dlFileShortcut.getModifiedDate(),
456                                            DLFileShortcut.class.getName(),
457                                            dlFileShortcut.getFileShortcutId(),
458                                            dlFileShortcut.getUuid(), fileEntryTypeId, assetCategoryIds,
459                                            assetTagNames, true, null, null, null, null,
460                                            fileEntry.getMimeType(), fileEntry.getTitle(),
461                                            fileEntry.getDescription(), null, null, null, 0, 0, null,
462                                            false);
463                            }
464                    }
465    
466                    assetLinkLocalService.updateLinks(
467                            userId, assetEntry.getEntryId(), assetLinkEntryIds,
468                            AssetLinkConstants.TYPE_RELATED);
469    
470                    return assetEntry;
471            }
472    
473            @Override
474            public void updateFileEntry(
475                            long userId, FileEntry fileEntry, FileVersion fileVersion,
476                            long assetClassPk)
477                    throws PortalException, SystemException {
478    
479                    boolean updateAsset = true;
480    
481                    if (fileEntry instanceof LiferayFileEntry &&
482                            fileEntry.getVersion().equals(fileVersion.getVersion())) {
483    
484                            updateAsset = false;
485                    }
486    
487                    if (updateAsset) {
488                            updateAsset(userId, fileEntry, fileVersion, assetClassPk);
489                    }
490    
491                    registerDLProcessorCallback(fileEntry);
492            }
493    
494            @Override
495            public void updateFileEntry(
496                            long userId, FileEntry fileEntry, FileVersion fileVersion,
497                            ServiceContext serviceContext)
498                    throws PortalException, SystemException {
499    
500                    updateAsset(
501                            userId, fileEntry, fileVersion,
502                            serviceContext.getAssetCategoryIds(),
503                            serviceContext.getAssetTagNames(),
504                            serviceContext.getAssetLinkEntryIds());
505    
506                    registerDLProcessorCallback(fileEntry);
507            }
508    
509            @Override
510            public void updateFolder(Folder folder, ServiceContext serviceContext)
511                    throws PortalException, SystemException {
512    
513                    if (!isStagingGroup(folder.getGroupId())) {
514                            dlSyncLocalService.updateSync(
515                                    folder.getFolderId(), folder.getParentFolderId(),
516                                    folder.getName(), folder.getDescription(),
517                                    DLSyncConstants.EVENT_UPDATE, "-1");
518                    }
519            }
520    
521            @Override
522            public void updateStatus(
523                            long userId, FileEntry fileEntry, FileVersion latestFileVersion,
524                            int status, Map<String, Serializable> workflowContext)
525                    throws PortalException, SystemException {
526    
527                    if (status == WorkflowConstants.STATUS_APPROVED) {
528    
529                            // Asset
530    
531                            String latestFileVersionVersion = latestFileVersion.getVersion();
532    
533                            if (latestFileVersionVersion.equals(fileEntry.getVersion())) {
534                                    if (!latestFileVersionVersion.equals(
535                                                    DLFileEntryConstants.VERSION_DEFAULT)) {
536    
537                                            AssetEntry draftAssetEntry = null;
538    
539                                            try {
540                                                    long fileEntryTypeId = getFileEntryTypeId(fileEntry);
541    
542                                                    draftAssetEntry = assetEntryLocalService.getEntry(
543                                                            DLFileEntryConstants.getClassName(),
544                                                            latestFileVersion.getPrimaryKey());
545    
546                                                    long[] assetCategoryIds =
547                                                            draftAssetEntry.getCategoryIds();
548                                                    String[] assetTagNames = draftAssetEntry.getTagNames();
549    
550                                                    List<AssetLink> assetLinks =
551                                                            assetLinkLocalService.getDirectLinks(
552                                                                    draftAssetEntry.getEntryId(),
553                                                                    AssetLinkConstants.TYPE_RELATED);
554    
555                                                    long[] assetLinkEntryIds = StringUtil.split(
556                                                            ListUtil.toString(
557                                                                    assetLinks, AssetLink.ENTRY_ID2_ACCESSOR), 0L);
558    
559                                                    AssetEntry assetEntry =
560                                                            assetEntryLocalService.updateEntry(
561                                                                    userId, fileEntry.getGroupId(),
562                                                                    fileEntry.getCreateDate(),
563                                                                    fileEntry.getModifiedDate(),
564                                                                    DLFileEntryConstants.getClassName(),
565                                                                    fileEntry.getFileEntryId(), fileEntry.getUuid(),
566                                                                    fileEntryTypeId, assetCategoryIds,
567                                                                    assetTagNames, true, null, null, null, null,
568                                                                    draftAssetEntry.getMimeType(),
569                                                                    fileEntry.getTitle(),
570                                                                    fileEntry.getDescription(), null, null, null, 0,
571                                                                    0, null, false);
572    
573                                                    assetLinkLocalService.updateLinks(
574                                                            userId, assetEntry.getEntryId(), assetLinkEntryIds,
575                                                            AssetLinkConstants.TYPE_RELATED);
576    
577                                                    assetEntryLocalService.deleteEntry(
578                                                            draftAssetEntry.getEntryId());
579                                            }
580                                            catch (NoSuchEntryException nsee) {
581                                            }
582                                    }
583    
584                                    assetEntryLocalService.updateVisible(
585                                            DLFileEntryConstants.getClassName(),
586                                            fileEntry.getFileEntryId(), true);
587                            }
588    
589                            // Sync
590    
591                            String event = (String)workflowContext.get("event");
592    
593                            if (!isStagingGroup(fileEntry.getGroupId()) &&
594                                    Validator.isNotNull(event)) {
595    
596                                    if (event.equals(DLSyncConstants.EVENT_ADD)) {
597                                            dlSyncLocalService.addSync(
598                                                    fileEntry.getFileEntryId(), fileEntry.getUuid(),
599                                                    fileEntry.getCompanyId(), fileEntry.getRepositoryId(),
600                                                    fileEntry.getFolderId(), fileEntry.getTitle(),
601                                                    fileEntry.getDescription(), DLSyncConstants.TYPE_FILE,
602                                                    fileEntry.getVersion());
603                                    }
604                                    else if (event.equals(DLSyncConstants.EVENT_UPDATE)) {
605                                            dlSyncLocalService.updateSync(
606                                                    fileEntry.getFileEntryId(), fileEntry.getFolderId(),
607                                                    fileEntry.getTitle(), fileEntry.getDescription(),
608                                                    DLSyncConstants.EVENT_UPDATE, fileEntry.getVersion());
609                                    }
610                            }
611    
612                            // Social
613    
614                            int activityType = DLActivityKeys.UPDATE_FILE_ENTRY;
615    
616                            if (event.equals(DLSyncConstants.EVENT_ADD)) {
617                                    activityType = DLActivityKeys.ADD_FILE_ENTRY;
618                            }
619    
620                            JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
621    
622                            extraDataJSONObject.put("title", fileEntry.getTitle());
623    
624                            socialActivityLocalService.addUniqueActivity(
625                                    latestFileVersion.getStatusByUserId(), fileEntry.getGroupId(),
626                                    latestFileVersion.getCreateDate(),
627                                    DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId(),
628                                    activityType, extraDataJSONObject.toString(), 0);
629                    }
630                    else {
631    
632                            // Asset
633    
634                            if (Validator.isNull(fileEntry.getVersion())) {
635                                    assetEntryLocalService.updateVisible(
636                                            DLFileEntryConstants.getClassName(),
637                                            fileEntry.getFileEntryId(), false);
638                            }
639                    }
640            }
641    
642            protected long getFileEntryTypeId(FileEntry fileEntry) {
643                    if (fileEntry instanceof LiferayFileEntry) {
644                            DLFileEntry dlFileEntry = (DLFileEntry)fileEntry.getModel();
645    
646                            return dlFileEntry.getFileEntryTypeId();
647                    }
648                    else {
649                            return 0;
650                    }
651            }
652    
653            protected boolean isStagingGroup(long groupId) {
654                    try {
655                            Group group = groupLocalService.getGroup(groupId);
656    
657                            return group.isStagingGroup();
658                    }
659                    catch (Exception e) {
660                            return false;
661                    }
662            }
663    
664            protected boolean isUpdateSync(FileEntry fileEntry)
665                    throws PortalException, SystemException {
666    
667                    if (isStagingGroup(fileEntry.getGroupId())) {
668                            return false;
669                    }
670    
671                    FileVersion fileVersion = fileEntry.getFileVersion();
672    
673                    if (!fileVersion.isApproved()) {
674                            return false;
675                    }
676    
677                    return true;
678            }
679    
680            protected void registerDLProcessorCallback(final FileEntry fileEntry) {
681                    TransactionCommitCallbackRegistryUtil.registerCallback(
682                            new Callable<Void>() {
683    
684                                    public Void call() throws Exception {
685                                            DLProcessorRegistryUtil.trigger(fileEntry, true);
686    
687                                            return null;
688                                    }
689    
690                            });
691            }
692    
693    }