001
014
015 package com.liferay.portlet.asset.model;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.util.LocaleUtil;
019 import com.liferay.portal.util.PortalUtil;
020 import com.liferay.portlet.dynamicdatamapping.DDMStructure;
021 import com.liferay.portlet.dynamicdatamapping.DDMStructureManagerUtil;
022
023 import java.util.ArrayList;
024 import java.util.List;
025 import java.util.Locale;
026
027
030 public class BaseDDMStructureClassTypeReader implements ClassTypeReader {
031
032 public BaseDDMStructureClassTypeReader(String className) {
033 _className = className;
034 }
035
036 @Override
037 public List<ClassType> getAvailableClassTypes(
038 long[] groupIds, Locale locale) {
039
040 List<ClassType> classTypes = new ArrayList<>();
041
042 List<DDMStructure> ddmStructures =
043 DDMStructureManagerUtil.getStructures(
044 groupIds, PortalUtil.getClassNameId(_className));
045
046 for (DDMStructure ddmStructure : ddmStructures) {
047 classTypes.add(
048 new DDMStructureClassType(
049 ddmStructure.getStructureId(), ddmStructure.getName(locale),
050 LocaleUtil.toLanguageId(locale)));
051 }
052
053 return classTypes;
054 }
055
056 @Override
057 public ClassType getClassType(long classTypeId, Locale locale)
058 throws PortalException {
059
060 DDMStructure ddmStructure = DDMStructureManagerUtil.getStructure(
061 classTypeId);
062
063 return new DDMStructureClassType(
064 classTypeId, ddmStructure.getName(locale),
065 LocaleUtil.toLanguageId(locale));
066 }
067
068 private final String _className;
069
070 }