001
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
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 }