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