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