001    /**
002     * Copyright (c) 2000-2010 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.portal.model.impl;
016    
017    import com.liferay.portal.NoSuchLayoutException;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.model.Group;
021    import com.liferay.portal.model.Layout;
022    import com.liferay.portal.model.LayoutPrototype;
023    import com.liferay.portal.service.GroupLocalServiceUtil;
024    import com.liferay.portal.service.LayoutLocalServiceUtil;
025    
026    import java.util.List;
027    
028    /**
029     * @author Jorge Ferrer
030     */
031    public class LayoutPrototypeImpl
032            extends LayoutPrototypeModelImpl implements LayoutPrototype {
033    
034            public LayoutPrototypeImpl() {
035            }
036    
037            public Group getGroup() throws PortalException, SystemException {
038                    return GroupLocalServiceUtil.getLayoutPrototypeGroup(
039                            getCompanyId(), getLayoutPrototypeId());
040            }
041    
042            public Layout getLayout() throws PortalException, SystemException {
043                    Group group = getGroup();
044    
045                    if (group.getPrivateLayoutsPageCount() > 0) {
046                            List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(
047                                    group.getGroupId(), true);
048    
049                            return layouts.get(0);
050                    }
051    
052                    throw new NoSuchLayoutException();
053            }
054    
055    }