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            @Override
038            public List<DDMStructure> getDDMStructures() {
039                    return DDMStructureLocalServiceUtil.getDLFileEntryTypeStructures(
040                            getFileEntryTypeId());
041            }
042    
043            @Override
044            public String getName(Locale locale) {
045                    String name = super.getName(locale);
046    
047                    if (getFileEntryTypeId() ==
048                                    DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) {
049    
050                            name = LanguageUtil.get(locale, name);
051                    }
052    
053                    return name;
054            }
055    
056            @Override
057            public String getUnambiguousName(
058                            List<DLFileEntryType> dlFileEntryTypes, long groupId,
059                            final Locale locale)
060                    throws PortalException {
061    
062                    if (getGroupId() == groupId ) {
063                            return getName(locale);
064                    }
065    
066                    boolean hasAmbiguousName = ListUtil.exists(
067                            dlFileEntryTypes,
068                            new PredicateFilter<DLFileEntryType>() {
069    
070                                    @Override
071                                    public boolean filter(DLFileEntryType fileEntryType) {
072                                            String name = fileEntryType.getName(locale);
073    
074                                            if (name.equals(getName(locale)) &&
075                                                    (fileEntryType.getFileEntryTypeId() !=
076                                                            getFileEntryTypeId())) {
077    
078                                                    return true;
079                                            }
080    
081                                            return false;
082                                    }
083                            });
084    
085                    if (hasAmbiguousName) {
086                            Group group = GroupLocalServiceUtil.getGroup(getGroupId());
087    
088                            return group.getUnambiguousName(getName(locale), locale);
089                    }
090    
091                    return getName(locale);
092            }
093    
094            @Override
095            public boolean isExportable() {
096                    if (getFileEntryTypeId() ==
097                                    DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) {
098    
099                            return false;
100                    }
101    
102                    return true;
103            }
104    
105    }