001    /**
002     * Copyright (c) 2000-2012 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.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.util.ObjectValuePair;
022    import com.liferay.portal.kernel.util.OrderByComparator;
023    import com.liferay.portal.kernel.util.ParamUtil;
024    import com.liferay.portal.kernel.util.StringPool;
025    import com.liferay.portal.kernel.workflow.WorkflowConstants;
026    import com.liferay.portal.model.Group;
027    import com.liferay.portal.model.ResourceConstants;
028    import com.liferay.portal.model.User;
029    import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;
030    import com.liferay.portal.service.ServiceContext;
031    import com.liferay.portal.util.PropsValues;
032    import com.liferay.portlet.asset.util.AssetUtil;
033    import com.liferay.portlet.documentlibrary.DuplicateFileException;
034    import com.liferay.portlet.documentlibrary.DuplicateFolderNameException;
035    import com.liferay.portlet.documentlibrary.FolderNameException;
036    import com.liferay.portlet.documentlibrary.NoSuchDirectoryException;
037    import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
038    import com.liferay.portlet.documentlibrary.model.DLFileEntryTypeConstants;
039    import com.liferay.portlet.documentlibrary.model.DLFolder;
040    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
041    import com.liferay.portlet.documentlibrary.service.base.DLFolderLocalServiceBaseImpl;
042    import com.liferay.portlet.documentlibrary.store.DLStoreUtil;
043    
044    import java.util.ArrayList;
045    import java.util.Collections;
046    import java.util.Date;
047    import java.util.List;
048    
049    /**
050     * @author Brian Wing Shun Chan
051     * @author Alexander Chow
052     */
053    public class DLFolderLocalServiceImpl extends DLFolderLocalServiceBaseImpl {
054    
055            public DLFolder addFolder(
056                            long userId, long groupId, long repositoryId, boolean mountPoint,
057                            long parentFolderId, String name, String description,
058                            ServiceContext serviceContext)
059                    throws PortalException, SystemException {
060    
061                    // Folder
062    
063                    User user = userPersistence.findByPrimaryKey(userId);
064                    parentFolderId = getParentFolderId(groupId, parentFolderId);
065                    Date now = new Date();
066    
067                    validateFolder(groupId, parentFolderId, name);
068    
069                    long folderId = counterLocalService.increment();
070    
071                    DLFolder dlFolder = dlFolderPersistence.create(folderId);
072    
073                    dlFolder.setUuid(serviceContext.getUuid());
074                    dlFolder.setGroupId(groupId);
075                    dlFolder.setCompanyId(user.getCompanyId());
076                    dlFolder.setUserId(user.getUserId());
077                    dlFolder.setCreateDate(serviceContext.getCreateDate(now));
078                    dlFolder.setModifiedDate(serviceContext.getModifiedDate(now));
079                    dlFolder.setRepositoryId(repositoryId);
080                    dlFolder.setMountPoint(mountPoint);
081                    dlFolder.setParentFolderId(parentFolderId);
082                    dlFolder.setName(name);
083                    dlFolder.setDescription(description);
084                    dlFolder.setOverrideFileEntryTypes(false);
085                    dlFolder.setExpandoBridgeAttributes(serviceContext);
086    
087                    dlFolderPersistence.update(dlFolder, false);
088    
089                    // Resources
090    
091                    if (serviceContext.isAddGroupPermissions() ||
092                            serviceContext.isAddGuestPermissions()) {
093    
094                            addFolderResources(
095                                    dlFolder, serviceContext.isAddGroupPermissions(),
096                                    serviceContext.isAddGuestPermissions());
097                    }
098                    else {
099                            if (serviceContext.isDeriveDefaultPermissions()) {
100                                    serviceContext.deriveDefaultPermissions(
101                                            repositoryId, DLFolderConstants.getClassName());
102                            }
103    
104                            addFolderResources(
105                                    dlFolder, serviceContext.getGroupPermissions(),
106                                    serviceContext.getGuestPermissions());
107                    }
108    
109                    // Parent folder
110    
111                    if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
112                            DLFolder parentDLFolder = dlFolderPersistence.findByPrimaryKey(
113                                    parentFolderId);
114    
115                            parentDLFolder.setLastPostDate(now);
116    
117                            dlFolderPersistence.update(parentDLFolder, false);
118                    }
119    
120                    // App helper
121    
122                    dlAppHelperLocalService.addFolder(
123                            new LiferayFolder(dlFolder), serviceContext);
124    
125                    return dlFolder;
126            }
127    
128            public void deleteAll(long groupId)
129                    throws PortalException, SystemException {
130    
131                    Group group = groupLocalService.getGroup(groupId);
132    
133                    List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(
134                            groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
135    
136                    for (DLFolder dlFolder : dlFolders) {
137                            deleteFolder(dlFolder);
138                    }
139    
140                    dlFileEntryLocalService.deleteFileEntries(
141                            groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
142    
143                    try {
144                            DLStoreUtil.deleteDirectory(
145                                    group.getCompanyId(), groupId, StringPool.BLANK);
146                    }
147                    catch (NoSuchDirectoryException nsde) {
148                            if (_log.isDebugEnabled()) {
149                                    _log.debug(nsde.getMessage());
150                            }
151                    }
152            }
153    
154            public void deleteFolder(long folderId)
155                    throws PortalException, SystemException {
156    
157                    DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
158    
159                    deleteFolder(dlFolder);
160            }
161    
162            public List<DLFolder> getCompanyFolders(long companyId, int start, int end)
163                    throws SystemException {
164    
165                    return dlFolderPersistence.findByCompanyId(companyId, start, end);
166            }
167    
168            public int getCompanyFoldersCount(long companyId) throws SystemException {
169                    return dlFolderPersistence.countByCompanyId(companyId);
170            }
171    
172            public List<Object> getFileEntriesAndFileShortcuts(
173                            long groupId, long folderId, int status, int start, int end)
174                    throws SystemException {
175    
176                    return dlFolderFinder.findFE_FS_ByG_F_S(
177                            groupId, folderId, status, start, end);
178            }
179    
180            public int getFileEntriesAndFileShortcutsCount(
181                            long groupId, long folderId, int status)
182                    throws SystemException {
183    
184                    int fileEntriesCount = 0;
185    
186                    if ((status == WorkflowConstants.STATUS_ANY)) {
187                            fileEntriesCount = dlFileEntryPersistence.countByG_F(
188                                    groupId, folderId);
189                    }
190                    else {
191                            fileEntriesCount = dlFolderFinder.countFE_ByG_F_S(
192                                    groupId, folderId, status);
193                    }
194    
195                    int fileShortcutsCount = dlFileShortcutPersistence.countByG_F_S(
196                            groupId, folderId, 0);
197    
198                    return fileEntriesCount + fileShortcutsCount;
199            }
200    
201            public DLFolder getFolder(long folderId)
202                    throws PortalException, SystemException {
203    
204                    return dlFolderPersistence.findByPrimaryKey(folderId);
205            }
206    
207            public DLFolder getFolder(long groupId, long parentFolderId, String name)
208                    throws PortalException, SystemException {
209    
210                    return dlFolderPersistence.findByG_P_N(groupId, parentFolderId, name);
211            }
212    
213            public long getFolderId(long companyId, long folderId)
214                    throws SystemException {
215    
216                    if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
217    
218                            // Ensure folder exists and belongs to the proper company
219    
220                            DLFolder dlFolder = dlFolderPersistence.fetchByPrimaryKey(folderId);
221    
222                            if ((dlFolder == null) || (companyId != dlFolder.getCompanyId())) {
223                                    folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
224                            }
225                    }
226    
227                    return folderId;
228            }
229    
230            public List<DLFolder> getFolders(long groupId, long parentFolderId)
231                    throws SystemException {
232    
233                    return getFolders(groupId, parentFolderId, true);
234            }
235    
236            public List<DLFolder> getFolders(
237                            long groupId, long parentFolderId, boolean includeMountfolders)
238                    throws SystemException {
239    
240                    if (includeMountfolders) {
241                            return dlFolderPersistence.findByG_P(groupId, parentFolderId);
242                    }
243                    else {
244                            return dlFolderPersistence.findByG_P_M(
245                                    groupId, parentFolderId, false);
246                    }
247            }
248    
249            public List<DLFolder> getFolders(
250                            long groupId, long parentFolderId, boolean includeMountfolders,
251                            int start, int end, OrderByComparator obc)
252                    throws SystemException {
253    
254                    if (includeMountfolders) {
255                            return dlFolderPersistence.findByG_P(
256                                    groupId, parentFolderId, start, end, obc);
257                    }
258                    else {
259                            return dlFolderPersistence.findByG_P_M(
260                                    groupId, parentFolderId, false, start, end, obc);
261                    }
262            }
263    
264            public List<DLFolder> getFolders(
265                            long groupId, long parentFolderId, int start, int end,
266                            OrderByComparator obc)
267                    throws SystemException {
268    
269                    return getFolders(groupId, parentFolderId, true, start, end, obc);
270            }
271    
272            public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
273                            long groupId, long folderId, int status,
274                            boolean includeMountFolders, int start, int end,
275                            OrderByComparator obc)
276                    throws SystemException {
277    
278                    return dlFolderFinder.findF_FE_FS_ByG_F_S_M_M(
279                            groupId, folderId, status, null, includeMountFolders, start, end,
280                            obc);
281            }
282    
283            public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
284                            long groupId, long folderId, int status, String[] mimeTypes,
285                            boolean includeMountFolders, int start, int end,
286                            OrderByComparator obc)
287                    throws SystemException {
288    
289                    return dlFolderFinder.findF_FE_FS_ByG_F_S_M_M(
290                            groupId, folderId, status, mimeTypes, includeMountFolders, start,
291                            end, obc);
292            }
293    
294            public int getFoldersAndFileEntriesAndFileShortcutsCount(
295                            long groupId, long folderId, int status,
296                            boolean includeMountFolders)
297                    throws SystemException {
298    
299                    return dlFolderFinder.countF_FE_FS_ByG_F_S_M_M(
300                            groupId, folderId, status, null, includeMountFolders);
301            }
302    
303            public int getFoldersAndFileEntriesAndFileShortcutsCount(
304                            long groupId, long folderId, int status, String[] mimeTypes,
305                            boolean includeMountFolders)
306                    throws SystemException {
307    
308                    return dlFolderFinder.countF_FE_FS_ByG_F_S_M_M(
309                            groupId, folderId, status, mimeTypes, includeMountFolders);
310            }
311    
312            public int getFoldersCount(long groupId, long parentFolderId)
313                    throws SystemException {
314    
315                    return getFoldersCount(groupId, parentFolderId, true);
316            }
317    
318            public int getFoldersCount(
319                            long groupId, long parentFolderId, boolean includeMountfolders)
320                    throws SystemException {
321    
322                    if (includeMountfolders) {
323                            return dlFolderPersistence.countByG_P(groupId, parentFolderId);
324                    }
325                    else {
326                            return dlFolderPersistence.countByG_P_M(
327                                    groupId, parentFolderId, false);
328                    }
329            }
330    
331            public int getFoldersFileEntriesCount(
332                            long groupId, List<Long> folderIds, int status)
333                    throws SystemException {
334    
335                    if (folderIds.size() <= PropsValues.SQL_DATA_MAX_PARAMETERS) {
336                            return dlFileEntryFinder.countByG_F_S(groupId, folderIds, status);
337                    }
338                    else {
339                            int start = 0;
340                            int end = PropsValues.SQL_DATA_MAX_PARAMETERS;
341    
342                            int filesCount = dlFileEntryFinder.countByG_F_S(
343                                    groupId, folderIds.subList(start, end), status);
344    
345                            folderIds.subList(start, end).clear();
346    
347                            filesCount += getFoldersFileEntriesCount(
348                                    groupId, folderIds, status);
349    
350                            return filesCount;
351                    }
352            }
353    
354            public DLFolder getMountFolder(long repositoryId)
355                    throws PortalException, SystemException {
356    
357                    return dlFolderPersistence.findByRepositoryId(repositoryId);
358            }
359    
360            public List<DLFolder> getMountFolders(
361                            long groupId, long parentFolderId, int start, int end,
362                            OrderByComparator obc)
363                    throws SystemException {
364    
365                    return dlFolderPersistence.findByG_P_M(
366                            groupId, parentFolderId, true, start, end, obc);
367            }
368    
369            public int getMountFoldersCount(long groupId, long parentFolderId)
370                    throws SystemException {
371    
372                    return dlFolderPersistence.countByG_P_M(groupId, parentFolderId, true);
373            }
374    
375            public void getSubfolderIds(
376                            List<Long> folderIds, long groupId, long folderId)
377                    throws SystemException {
378    
379                    List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(
380                            groupId, folderId);
381    
382                    for (DLFolder dlFolder : dlFolders) {
383                            folderIds.add(dlFolder.getFolderId());
384    
385                            getSubfolderIds(
386                                    folderIds, dlFolder.getGroupId(), dlFolder.getFolderId());
387                    }
388            }
389    
390            public DLFolder moveFolder(
391                            long folderId, long parentFolderId, ServiceContext serviceContext)
392                    throws PortalException, SystemException {
393    
394                    DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
395    
396                    parentFolderId = getParentFolderId(dlFolder, parentFolderId);
397    
398                    validateFolder(
399                            dlFolder.getFolderId(), dlFolder.getGroupId(), parentFolderId,
400                            dlFolder.getName());
401    
402                    dlFolder.setModifiedDate(serviceContext.getModifiedDate(null));
403                    dlFolder.setParentFolderId(parentFolderId);
404                    dlFolder.setExpandoBridgeAttributes(serviceContext);
405    
406                    dlFolderPersistence.update(dlFolder, false);
407    
408                    dlAppHelperLocalService.moveFolder(new LiferayFolder(dlFolder));
409    
410                    return dlFolder;
411            }
412    
413            public DLFolder updateFolder(
414                            long folderId, long parentFolderId, String name,
415                            String description, long defaultFileEntryTypeId,
416                            List<Long> fileEntryTypeIds, boolean overrideFileEntryTypes,
417                            ServiceContext serviceContext)
418                    throws PortalException, SystemException {
419    
420                    // File entry types
421    
422                    DLFolder dlFolder = null;
423    
424                    if (folderId > DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
425                            dlFolder = dlFolderLocalService.updateFolderAndFileEntryTypes(
426                                    folderId, parentFolderId, name, description,
427                                    defaultFileEntryTypeId, fileEntryTypeIds,
428                                    overrideFileEntryTypes, serviceContext);
429    
430                            dlFileEntryTypeLocalService.cascadeFileEntryTypes(
431                                    serviceContext.getUserId(), dlFolder);
432                    }
433    
434                    // Workflow definitions
435    
436                    List<ObjectValuePair<Long, String>> workflowDefinitions =
437                            new ArrayList<ObjectValuePair<Long, String>>();
438    
439                    if (fileEntryTypeIds.isEmpty()) {
440                            fileEntryTypeIds.add(
441                                    DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL);
442                    }
443                    else {
444                            workflowDefinitions.add(
445                                    new ObjectValuePair<Long, String>(
446                                            DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL,
447                                            StringPool.BLANK));
448                    }
449    
450                    for (long fileEntryTypeId : fileEntryTypeIds) {
451                            String workflowDefinition = ParamUtil.getString(
452                                    serviceContext, "workflowDefinition" + fileEntryTypeId);
453    
454                            workflowDefinitions.add(
455                                    new ObjectValuePair<Long, String>(
456                                            fileEntryTypeId, workflowDefinition));
457                    }
458    
459                    workflowDefinitionLinkLocalService.updateWorkflowDefinitionLinks(
460                            serviceContext.getUserId(), serviceContext.getCompanyId(),
461                            serviceContext.getScopeGroupId(), DLFolder.class.getName(),
462                            folderId, workflowDefinitions);
463    
464                    return dlFolder;
465            }
466    
467            public DLFolder updateFolder(
468                            long folderId, String name, String description,
469                            long defaultFileEntryTypeId, List<Long> fileEntryTypeIds,
470                            boolean overrideFileEntryTypes, ServiceContext serviceContext)
471                    throws PortalException, SystemException {
472    
473                    return updateFolder(
474                            folderId, folderId, name, description, defaultFileEntryTypeId,
475                            fileEntryTypeIds, overrideFileEntryTypes, serviceContext);
476            }
477    
478            public DLFolder updateFolderAndFileEntryTypes(
479                            long folderId, long parentFolderId, String name, String description,
480                            long defaultFileEntryTypeId, List<Long> fileEntryTypeIds,
481                            boolean overrideFileEntryTypes, ServiceContext serviceContext)
482                    throws PortalException, SystemException {
483    
484                    // Folder
485    
486                    if (!overrideFileEntryTypes) {
487                            fileEntryTypeIds = Collections.emptyList();
488                    }
489    
490                    DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
491    
492                    parentFolderId = getParentFolderId(dlFolder, parentFolderId);
493    
494                    validateFolder(folderId, dlFolder.getGroupId(), parentFolderId, name);
495    
496                    dlFolder.setModifiedDate(serviceContext.getModifiedDate(null));
497                    dlFolder.setParentFolderId(parentFolderId);
498                    dlFolder.setName(name);
499                    dlFolder.setDescription(description);
500                    dlFolder.setExpandoBridgeAttributes(serviceContext);
501                    dlFolder.setOverrideFileEntryTypes(overrideFileEntryTypes);
502                    dlFolder.setDefaultFileEntryTypeId(defaultFileEntryTypeId);
503    
504                    dlFolderPersistence.update(dlFolder, false);
505    
506                    // File entry types
507    
508                    if (fileEntryTypeIds != null) {
509                            dlFileEntryTypeLocalService.updateFolderFileEntryTypes(
510                                    dlFolder, fileEntryTypeIds, defaultFileEntryTypeId,
511                                    serviceContext);
512                    }
513    
514                    // App helper
515    
516                    dlAppHelperLocalService.updateFolder(
517                            new LiferayFolder(dlFolder), serviceContext);
518    
519                    return dlFolder;
520            }
521    
522            public void updateLastPostDate(long folderId, Date lastPostDate)
523                    throws PortalException, SystemException {
524    
525                    DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
526    
527                    dlFolder.setLastPostDate(lastPostDate);
528    
529                    dlFolderPersistence.update(dlFolder, false);
530            }
531    
532            protected void addFolderResources(
533                            DLFolder dlFolder, boolean addGroupPermissions,
534                            boolean addGuestPermissions)
535                    throws PortalException, SystemException {
536    
537                    resourceLocalService.addResources(
538                            dlFolder.getCompanyId(), dlFolder.getGroupId(),
539                            dlFolder.getUserId(), DLFolder.class.getName(),
540                            dlFolder.getFolderId(), false, addGroupPermissions,
541                            addGuestPermissions);
542            }
543    
544            protected void addFolderResources(
545                            DLFolder dlFolder, String[] groupPermissions,
546                            String[] guestPermissions)
547                    throws PortalException, SystemException {
548    
549                    resourceLocalService.addModelResources(
550                            dlFolder.getCompanyId(), dlFolder.getGroupId(),
551                            dlFolder.getUserId(), DLFolder.class.getName(),
552                            dlFolder.getFolderId(), groupPermissions, guestPermissions);
553            }
554    
555            protected void addFolderResources(
556                            long folderId, boolean addGroupPermissions,
557                            boolean addGuestPermissions)
558                    throws PortalException, SystemException {
559    
560                    DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
561    
562                    addFolderResources(dlFolder, addGroupPermissions, addGuestPermissions);
563            }
564    
565            protected void addFolderResources(
566                            long folderId, String[] groupPermissions, String[] guestPermissions)
567                    throws PortalException, SystemException {
568    
569                    DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
570    
571                    addFolderResources(dlFolder, groupPermissions, guestPermissions);
572            }
573    
574            protected void deleteFolder(DLFolder dlFolder)
575                    throws PortalException, SystemException {
576    
577                    // Folders
578    
579                    List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(
580                            dlFolder.getGroupId(), dlFolder.getFolderId());
581    
582                    for (DLFolder curDLFolder : dlFolders) {
583                            deleteFolder(curDLFolder);
584                    }
585    
586                    // Folder
587    
588                    dlFolderPersistence.remove(dlFolder);
589    
590                    // Resources
591    
592                    resourceLocalService.deleteResource(
593                            dlFolder.getCompanyId(), DLFolder.class.getName(),
594                            ResourceConstants.SCOPE_INDIVIDUAL, dlFolder.getFolderId());
595    
596                    // WebDAVProps
597    
598                    webDAVPropsLocalService.deleteWebDAVProps(
599                            DLFolder.class.getName(), dlFolder.getFolderId());
600    
601                    // File entries
602    
603                    dlFileEntryLocalService.deleteFileEntries(
604                            dlFolder.getGroupId(), dlFolder.getFolderId());
605    
606                    // File entry types
607    
608                    dlFileEntryTypeLocalService.unsetFolderFileEntryTypes(
609                            dlFolder.getFolderId());
610    
611                    // Expando
612    
613                    expandoValueLocalService.deleteValues(
614                            DLFolder.class.getName(), dlFolder.getFolderId());
615    
616                    // App helper
617    
618                    dlAppHelperLocalService.deleteFolder(new LiferayFolder(dlFolder));
619    
620                    // Directory
621    
622                    try {
623                            DLStoreUtil.deleteDirectory(
624                                    dlFolder.getCompanyId(), dlFolder.getFolderId(),
625                                    StringPool.BLANK);
626                    }
627                    catch (NoSuchDirectoryException nsde) {
628                            if (_log.isDebugEnabled()) {
629                                    _log.debug(nsde.getMessage());
630                            }
631                    }
632            }
633    
634            protected long getParentFolderId(DLFolder dlFolder, long parentFolderId)
635                    throws SystemException {
636    
637                    if (parentFolderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
638                            return parentFolderId;
639                    }
640    
641                    if (dlFolder.getFolderId() == parentFolderId) {
642                            return dlFolder.getParentFolderId();
643                    }
644                    else {
645                            DLFolder parentDLFolder = dlFolderPersistence.fetchByPrimaryKey(
646                                    parentFolderId);
647    
648                            if ((parentDLFolder == null) ||
649                                    (dlFolder.getGroupId() != parentDLFolder.getGroupId())) {
650    
651                                    return dlFolder.getParentFolderId();
652                            }
653    
654                            List<Long> subfolderIds = new ArrayList<Long>();
655    
656                            getSubfolderIds(
657                                    subfolderIds, dlFolder.getGroupId(), dlFolder.getFolderId());
658    
659                            if (subfolderIds.contains(parentFolderId)) {
660                                    return dlFolder.getParentFolderId();
661                            }
662    
663                            return parentFolderId;
664                    }
665            }
666    
667            protected long getParentFolderId(long groupId, long parentFolderId)
668                    throws SystemException {
669    
670                    if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
671                            DLFolder parentDLFolder = dlFolderPersistence.fetchByPrimaryKey(
672                                    parentFolderId);
673    
674                            if ((parentDLFolder == null) ||
675                                    (groupId != parentDLFolder.getGroupId())) {
676    
677                                    parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
678                            }
679                    }
680    
681                    return parentFolderId;
682            }
683    
684            protected void validateFolder(
685                            long folderId, long groupId, long parentFolderId, String name)
686                    throws PortalException, SystemException {
687    
688                    validateFolderName(name);
689    
690                    try {
691                            dlFileEntryLocalService.getFileEntry(groupId, parentFolderId, name);
692    
693                            throw new DuplicateFileException(name);
694                    }
695                    catch (NoSuchFileEntryException nsfee) {
696                    }
697    
698                    DLFolder dlFolder = dlFolderPersistence.fetchByG_P_N(
699                            groupId, parentFolderId, name);
700    
701                    if ((dlFolder != null) && (dlFolder.getFolderId() != folderId)) {
702                            throw new DuplicateFolderNameException(name);
703                    }
704            }
705    
706            protected void validateFolder(
707                            long groupId, long parentFolderId, String name)
708                    throws PortalException, SystemException {
709    
710                    long folderId = 0;
711    
712                    validateFolder(folderId, groupId, parentFolderId, name);
713            }
714    
715            protected void validateFolderName(String name) throws PortalException {
716                    if (!AssetUtil.isValidWord(name)) {
717                            throw new FolderNameException();
718                    }
719            }
720    
721            private static Log _log = LogFactoryUtil.getLog(
722                    DLFolderLocalServiceImpl.class);
723    
724    }