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.model.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.language.LanguageUtil;
019    import com.liferay.portal.kernel.util.ListUtil;
020    import com.liferay.portal.kernel.util.PredicateFilter;
021    import com.liferay.portal.model.Group;
022    import com.liferay.portal.service.GroupLocalServiceUtil;
023    import com.liferay.portlet.documentlibrary.model.DLFileEntryType;
024    import com.liferay.portlet.documentlibrary.model.DLFileEntryTypeConstants;
025    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
026    import com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalServiceUtil;
027    
028    import java.util.List;
029    import java.util.Locale;
030    
031    /**
032     * @author Alexander Chow
033     * @author Mate Thurzo
034     */
035    public class DLFileEntryTypeImpl extends DLFileEntryTypeBaseImpl {
036    
037            public DLFileEntryTypeImpl() {
038            }
039    
040            @Override
041            public List<DDMStructure> getDDMStructures() {
042                    return DDMStructureLocalServiceUtil.getDLFileEntryTypeStructures(
043                            getFileEntryTypeId());
044            }
045    
046            @Override
047            public String getName(Locale locale) {
048                    String name = super.getName(locale);
049    
050                    if (getFileEntryTypeId() ==
051                                    DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) {
052    
053                            name = LanguageUtil.get(locale, name);
054                    }
055    
056                    return name;
057            }
058    
059            @Override
060            public String getUnambiguousName(
061                            List<DLFileEntryType> dlFileEntryTypes, long groupId,
062                            final Locale locale)
063                    throws PortalException {
064    
065                    if (getGroupId() == groupId ) {
066                            return getName(locale);
067                    }
068    
069                    boolean hasAmbiguousName = ListUtil.exists(
070                            dlFileEntryTypes,
071                            new PredicateFilter<DLFileEntryType>() {
072    
073                                    @Override
074                                    public boolean filter(DLFileEntryType fileEntryType) {
075                                            String name = fileEntryType.getName(locale);
076    
077                                            if (name.equals(getName(locale)) &&
078                                                    (fileEntryType.getFileEntryTypeId() !=
079                                                            getFileEntryTypeId())) {
080    
081                                                    return true;
082                                            }
083    
084                                            return false;
085                                    }
086                            });
087    
088                    if (hasAmbiguousName) {
089                            Group group = GroupLocalServiceUtil.getGroup(getGroupId());
090    
091                            return group.getUnambiguousName(getName(locale), locale);
092                    }
093    
094                    return getName(locale);
095            }
096    
097            @Override
098            public boolean isExportable() {
099                    if (getFileEntryTypeId() ==
100                                    DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) {
101    
102                            return false;
103                    }
104    
105                    return true;
106            }
107    
108    }