001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.exception.SystemException;
019    import com.liferay.portal.kernel.language.LanguageUtil;
020    import com.liferay.portal.kernel.util.ListUtil;
021    import com.liferay.portal.kernel.util.PredicateFilter;
022    import com.liferay.portal.model.Group;
023    import com.liferay.portal.service.GroupLocalServiceUtil;
024    import com.liferay.portlet.documentlibrary.model.DLFileEntryType;
025    import com.liferay.portlet.documentlibrary.model.DLFileEntryTypeConstants;
026    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
027    import com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalServiceUtil;
028    
029    import java.util.List;
030    import java.util.Locale;
031    
032    /**
033     * @author Alexander Chow
034     * @author Mate Thurzo
035     */
036    public class DLFileEntryTypeImpl extends DLFileEntryTypeBaseImpl {
037    
038            public DLFileEntryTypeImpl() {
039            }
040    
041            @Override
042            public List<DDMStructure> getDDMStructures() throws SystemException {
043                    return DDMStructureLocalServiceUtil.getDLFileEntryTypeStructures(
044                            getFileEntryTypeId());
045            }
046    
047            @Override
048            public String getName(Locale locale) {
049                    String name = super.getName(locale);
050    
051                    if (getFileEntryTypeId() ==
052                                    DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) {
053    
054                            name = LanguageUtil.get(locale, name);
055                    }
056    
057                    return name;
058            }
059    
060            @Override
061            public String getUnambiguousName(
062                            List<DLFileEntryType> dlFileEntryTypes, long groupId,
063                            final Locale locale)
064                    throws PortalException, SystemException {
065    
066                    if (getGroupId() == groupId ) {
067                            return getName(locale);
068                    }
069    
070                    boolean hasAmbiguousName = ListUtil.exists(
071                            dlFileEntryTypes,
072                            new PredicateFilter<DLFileEntryType>() {
073    
074                                    @Override
075                                    public boolean filter(DLFileEntryType fileEntryType) {
076                                            String name = fileEntryType.getName(locale);
077    
078                                            if (name.equals(getName(locale)) &&
079                                                    (fileEntryType.getFileEntryTypeId() !=
080                                                            getFileEntryTypeId())) {
081    
082                                                    return true;
083                                            }
084    
085                                            return false;
086                                    }
087                            });
088    
089                    if (hasAmbiguousName) {
090                            Group group = GroupLocalServiceUtil.getGroup(getGroupId());
091    
092                            return group.getUnambiguousName(getName(locale), locale);
093                    }
094    
095                    return getName(locale);
096            }
097    
098            @Override
099            public boolean isExportable() {
100                    if (getFileEntryTypeId() ==
101                                    DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) {
102    
103                            return false;
104                    }
105    
106                    return true;
107            }
108    
109    }