001    /**
002     * Copyright (c) 2000-2013 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.portal.kernel.exception.SystemException;
019    import com.liferay.portlet.dynamicdatalists.model.DDLRecordSet;
020    import com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion;
021    import com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalServiceUtil;
022    import com.liferay.portlet.dynamicdatalists.service.DDLRecordSetLocalServiceUtil;
023    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
024    import com.liferay.portlet.dynamicdatamapping.storage.Field;
025    import com.liferay.portlet.dynamicdatamapping.storage.Fields;
026    import com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil;
027    
028    import java.io.Serializable;
029    
030    import java.util.List;
031    import java.util.Locale;
032    
033    /**
034     * @author Brian Wing Shun Chan
035     * @author Eduardo Lundgren
036     */
037    public class DDLRecordImpl extends DDLRecordBaseImpl {
038    
039            public DDLRecordImpl() {
040            }
041    
042            @Override
043            public Field getField(String fieldName) throws PortalException {
044                    Fields fields = getFields();
045    
046                    return fields.get(fieldName);
047            }
048    
049            @Override
050            public Serializable getFieldDataType(String fieldName)
051                    throws PortalException, SystemException {
052    
053                    DDLRecordSet recordSet = getRecordSet();
054    
055                    DDMStructure ddmStructure = recordSet.getDDMStructure();
056    
057                    return ddmStructure.getFieldDataType(fieldName);
058            }
059    
060            @Override
061            public Fields getFields() throws PortalException {
062                    return StorageEngineUtil.getFields(getDDMStorageId());
063            }
064    
065            @Override
066            public Serializable getFieldType(String fieldName) throws Exception {
067                    DDLRecordSet recordSet = getRecordSet();
068    
069                    DDMStructure ddmStructure = recordSet.getDDMStructure();
070    
071                    return ddmStructure.getFieldType(fieldName);
072            }
073    
074            @Override
075            public Serializable getFieldValue(String fieldName) throws PortalException {
076                    Field field = getField(fieldName);
077    
078                    if (field == null) {
079                            return null;
080                    }
081    
082                    return field.getValue();
083            }
084    
085            @Override
086            public Serializable getFieldValue(String fieldName, Locale locale)
087                    throws PortalException {
088    
089                    Field field = getField(fieldName);
090    
091                    if (field == null) {
092                            return null;
093                    }
094    
095                    return field.getValue(locale);
096            }
097    
098            @Override
099            public List<Serializable> getFieldValues(String fieldName, Locale locale)
100                    throws PortalException {
101    
102                    Field field = getField(fieldName);
103    
104                    if (field == null) {
105                            return null;
106                    }
107    
108                    return field.getValues(locale);
109            }
110    
111            @Override
112            public DDLRecordVersion getLatestRecordVersion()
113                    throws PortalException, SystemException {
114    
115                    return DDLRecordLocalServiceUtil.getLatestRecordVersion(getRecordId());
116            }
117    
118            @Override
119            public DDLRecordSet getRecordSet() throws PortalException, SystemException {
120                    return DDLRecordSetLocalServiceUtil.getRecordSet(getRecordSetId());
121            }
122    
123            @Override
124            public DDLRecordVersion getRecordVersion()
125                    throws PortalException, SystemException {
126    
127                    return getRecordVersion(getVersion());
128            }
129    
130            @Override
131            public DDLRecordVersion getRecordVersion(String version)
132                    throws PortalException, SystemException {
133    
134                    return DDLRecordLocalServiceUtil.getRecordVersion(
135                            getRecordId(), version);
136            }
137    
138            @Override
139            public int getStatus() throws PortalException, SystemException {
140                    DDLRecordVersion recordVersion = getRecordVersion();
141    
142                    return recordVersion.getStatus();
143            }
144    
145    }