001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.DDLRecord;
020    import com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalServiceUtil;
021    import com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException;
022    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
023    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
024    import com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalServiceUtil;
025    import com.liferay.portlet.dynamicdatamapping.service.DDMTemplateLocalServiceUtil;
026    import com.liferay.portlet.dynamicdatamapping.storage.Fields;
027    
028    import java.util.ArrayList;
029    import java.util.List;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    public class DDLRecordSetImpl extends DDLRecordSetBaseImpl {
035    
036            public DDLRecordSetImpl() {
037            }
038    
039            @Override
040            public DDMStructure getDDMStructure()
041                    throws PortalException, SystemException {
042    
043                    return DDMStructureLocalServiceUtil.getStructure(getDDMStructureId());
044            }
045    
046            @Override
047            public DDMStructure getDDMStructure(long detailDDMTemplateId)
048                    throws PortalException, SystemException {
049    
050                    DDMStructure ddmStructure = getDDMStructure();
051    
052                    if (detailDDMTemplateId > 0) {
053                            try {
054                                    DDMTemplate ddmTemplate =
055                                            DDMTemplateLocalServiceUtil.getTemplate(
056                                                    detailDDMTemplateId);
057    
058                                    ddmStructure.setXsd(ddmTemplate.getScript());
059                            }
060                            catch (NoSuchTemplateException nste) {
061                            }
062                    }
063    
064                    return ddmStructure;
065            }
066    
067            @Override
068            public List<DDLRecord> getRecords() throws SystemException {
069                    return DDLRecordLocalServiceUtil.getRecords(getRecordSetId());
070            }
071    
072            @Override
073            public List<Fields> getRecordsFieldsList()
074                    throws PortalException, SystemException {
075    
076                    List<Fields> fieldsList = new ArrayList<Fields>();
077    
078                    for (DDLRecord record : getRecords()) {
079                            fieldsList.add(record.getFields());
080                    }
081    
082                    return fieldsList;
083            }
084    
085    }