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.dynamicdatalists.model.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portlet.dynamicdatalists.model.DDLRecordSet;
019    import com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion;
020    import com.liferay.portlet.dynamicdatalists.service.DDLRecordSetLocalServiceUtil;
021    import com.liferay.portlet.dynamicdatalists.service.DDLRecordVersionLocalServiceUtil;
022    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
023    import com.liferay.portlet.dynamicdatamapping.storage.DDMFormFieldValue;
024    import com.liferay.portlet.dynamicdatamapping.storage.DDMFormValues;
025    import com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil;
026    
027    import java.io.Serializable;
028    
029    import java.util.List;
030    import java.util.Map;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     * @author Eduardo Lundgren
035     */
036    public class DDLRecordImpl extends DDLRecordBaseImpl {
037    
038            @Override
039            public List<DDMFormFieldValue> getDDMFormFieldValues(String fieldName)
040                    throws PortalException {
041    
042                    DDMFormValues ddmFormValues = getDDMFormValues();
043    
044                    Map<String, List<DDMFormFieldValue>> ddmFormFieldValuesMap =
045                            ddmFormValues.getDDMFormFieldValuesMap();
046    
047                    return ddmFormFieldValuesMap.get(fieldName);
048            }
049    
050            @Override
051            public DDMFormValues getDDMFormValues() throws PortalException {
052                    return StorageEngineUtil.getDDMFormValues(getDDMStorageId());
053            }
054    
055            @Override
056            public Serializable getFieldDataType(String fieldName)
057                    throws PortalException {
058    
059                    DDLRecordSet recordSet = getRecordSet();
060    
061                    DDMStructure ddmStructure = recordSet.getDDMStructure();
062    
063                    return ddmStructure.getFieldDataType(fieldName);
064            }
065    
066            @Override
067            public Serializable getFieldType(String fieldName) throws Exception {
068                    DDLRecordSet recordSet = getRecordSet();
069    
070                    DDMStructure ddmStructure = recordSet.getDDMStructure();
071    
072                    return ddmStructure.getFieldType(fieldName);
073            }
074    
075            @Override
076            public DDLRecordVersion getLatestRecordVersion() throws PortalException {
077                    return DDLRecordVersionLocalServiceUtil.getLatestRecordVersion(
078                            getRecordId());
079            }
080    
081            @Override
082            public DDLRecordSet getRecordSet() throws PortalException {
083                    return DDLRecordSetLocalServiceUtil.getRecordSet(getRecordSetId());
084            }
085    
086            @Override
087            public DDLRecordVersion getRecordVersion() throws PortalException {
088                    return getRecordVersion(getVersion());
089            }
090    
091            @Override
092            public DDLRecordVersion getRecordVersion(String version)
093                    throws PortalException {
094    
095                    return DDLRecordVersionLocalServiceUtil.getRecordVersion(
096                            getRecordId(), version);
097            }
098    
099            @Override
100            public int getStatus() throws PortalException {
101                    DDLRecordVersion recordVersion = getRecordVersion();
102    
103                    return recordVersion.getStatus();
104            }
105    
106    }