001    /**
002     * Copyright (c) 2000-2012 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    /**
031     * @author Brian Wing Shun Chan
032     * @author Eduardo Lundgren
033     */
034    public class DDLRecordImpl extends DDLRecordBaseImpl {
035    
036            public DDLRecordImpl() {
037            }
038    
039            public Field getField(String fieldName) throws PortalException {
040                    Fields fields = getFields();
041    
042                    return fields.get(fieldName);
043            }
044    
045            public Serializable getFieldDataType(String fieldName)
046                    throws PortalException, SystemException {
047    
048                    DDLRecordSet recordSet = getRecordSet();
049    
050                    DDMStructure ddmStructure = recordSet.getDDMStructure();
051    
052                    return ddmStructure.getFieldDataType(fieldName);
053            }
054    
055            public Fields getFields() throws PortalException {
056                    return StorageEngineUtil.getFields(getDDMStorageId());
057            }
058    
059            public Serializable getFieldType(String fieldName) throws Exception {
060                    DDLRecordSet recordSet = getRecordSet();
061    
062                    DDMStructure ddmStructure = recordSet.getDDMStructure();
063    
064                    return ddmStructure.getFieldType(fieldName);
065            }
066    
067            public Serializable getFieldValue(String fieldName) throws PortalException {
068                    Field field = getField(fieldName);
069    
070                    return field.getValue();
071            }
072    
073            public DDLRecordVersion getLatestRecordVersion()
074                    throws PortalException, SystemException {
075    
076                    return DDLRecordLocalServiceUtil.getLatestRecordVersion(getRecordId());
077            }
078    
079            public DDLRecordSet getRecordSet() throws PortalException, SystemException {
080                    return DDLRecordSetLocalServiceUtil.getRecordSet(getRecordSetId());
081            }
082    
083            public DDLRecordVersion getRecordVersion()
084                    throws PortalException, SystemException {
085    
086                    return getRecordVersion(getVersion());
087            }
088    
089            public DDLRecordVersion getRecordVersion(String version)
090                    throws PortalException, SystemException {
091    
092                    return DDLRecordLocalServiceUtil.getRecordVersion(
093                            getRecordId(), version);
094            }
095    
096            public int getStatus() throws PortalException, SystemException {
097                    DDLRecordVersion recordVersion = getRecordVersion();
098    
099                    return recordVersion.getStatus();
100            }
101    
102    }