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.util.test;
016    
017    import com.liferay.portal.kernel.test.util.ServiceContextTestUtil;
018    import com.liferay.portal.kernel.test.util.TestPropsValues;
019    import com.liferay.portal.model.Group;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portlet.dynamicdatamapping.model.DDMFormLayout;
022    import com.liferay.portlet.dynamicdatamapping.model.DDMFormLayoutColumn;
023    import com.liferay.portlet.dynamicdatamapping.model.DDMFormLayoutRow;
024    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureLayout;
025    import com.liferay.portlet.dynamicdatamapping.service.DDMStructureLayoutLocalServiceUtil;
026    
027    import java.util.ArrayList;
028    import java.util.List;
029    
030    /**
031     * @author Marcellus Tavares
032     */
033    public class DDMStructureLayoutTestHelper {
034    
035            public DDMStructureLayoutTestHelper(Group group) throws Exception {
036                    _group = group;
037            }
038    
039            public DDMStructureLayout addStructureLayout(
040                            long structureId, DDMFormLayout ddmFormLayout)
041                    throws Exception {
042    
043                    ServiceContext serviceContext =
044                            ServiceContextTestUtil.getServiceContext(_group.getGroupId());
045    
046                    return DDMStructureLayoutLocalServiceUtil.addStructureLayout(
047                            TestPropsValues.getUserId(), _group.getGroupId(), structureId,
048                            ddmFormLayout, serviceContext);
049            }
050    
051            public List<DDMFormLayoutColumn> createDDMFormLayoutColumns(
052                    String... ddmFormFieldNames) {
053    
054                    List<DDMFormLayoutColumn> ddmFormLayoutColumns = new ArrayList<>();
055    
056                    int size = 12 / ddmFormFieldNames.length;
057    
058                    for (String ddmFormFieldName : ddmFormFieldNames) {
059                            ddmFormLayoutColumns.add(
060                                    new DDMFormLayoutColumn(size, ddmFormFieldName));
061                    }
062    
063                    return ddmFormLayoutColumns;
064            }
065    
066            public DDMFormLayoutRow createDDMFormLayoutRow(
067                    List<DDMFormLayoutColumn> ddmFormLayoutColumns) {
068    
069                    DDMFormLayoutRow ddmFormLayoutRow = new DDMFormLayoutRow();
070    
071                    ddmFormLayoutRow.setDDMFormLayoutColumns(ddmFormLayoutColumns);
072    
073                    return ddmFormLayoutRow;
074            }
075    
076            private final Group _group;
077    
078    }