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.dynamicdatamapping.model.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.log.Log;
021    import com.liferay.portal.kernel.log.LogFactoryUtil;
022    import com.liferay.portal.model.CacheField;
023    import com.liferay.portlet.dynamicdatamapping.io.DDMFormJSONDeserializerUtil;
024    import com.liferay.portlet.dynamicdatamapping.model.DDMForm;
025    import com.liferay.portlet.dynamicdatamapping.model.DDMFormLayout;
026    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
027    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureLayout;
028    import com.liferay.portlet.dynamicdatamapping.service.DDMStructureLayoutLocalServiceUtil;
029    import com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalServiceUtil;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     * @author Leonardo Barros
034     */
035    @ProviderType
036    public class DDMStructureVersionImpl extends DDMStructureVersionBaseImpl {
037    
038            @Override
039            public DDMForm getDDMForm() {
040                    if (_ddmForm == null) {
041                            try {
042                                    _ddmForm = DDMFormJSONDeserializerUtil.deserialize(
043                                            getDefinition());
044                            }
045                            catch (Exception e) {
046                                    _log.error(e, e);
047                            }
048                    }
049    
050                    return new DDMForm(_ddmForm);
051            }
052    
053            @Override
054            public DDMFormLayout getDDMFormLayout() throws PortalException {
055                    DDMStructureLayout ddmStructureLayout =
056                            DDMStructureLayoutLocalServiceUtil.
057                                    getStructureLayoutByStructureVersionId(getStructureVersionId());
058    
059                    return ddmStructureLayout.getDDMFormLayout();
060            }
061    
062            @Override
063            public DDMStructure getStructure() throws PortalException {
064                    return DDMStructureLocalServiceUtil.getStructure(getStructureId());
065            }
066    
067            @Override
068            public void setDDMForm(DDMForm ddmForm) {
069                    _ddmForm = ddmForm;
070            }
071    
072            private static final Log _log = LogFactoryUtil.getLog(
073                    DDMStructureVersionImpl.class);
074    
075            @CacheField(methodName = "DDMForm")
076            private DDMForm _ddmForm;
077    
078    }