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.service.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.systemevent.SystemEvent;
021    import com.liferay.portal.model.SystemEventConstants;
022    import com.liferay.portal.model.User;
023    import com.liferay.portal.service.ServiceContext;
024    import com.liferay.portlet.dynamicdatamapping.io.DDMFormLayoutJSONSerializerUtil;
025    import com.liferay.portlet.dynamicdatamapping.model.DDMFormLayout;
026    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureLayout;
027    import com.liferay.portlet.dynamicdatamapping.service.base.DDMStructureLayoutLocalServiceBaseImpl;
028    
029    /**
030     * @author Marcellus Tavares
031     */
032    @ProviderType
033    public class DDMStructureLayoutLocalServiceImpl
034            extends DDMStructureLayoutLocalServiceBaseImpl {
035    
036            @Override
037            public DDMStructureLayout addStructureLayout(
038                            long userId, long groupId, long structureVersionId,
039                            DDMFormLayout ddmFormLayout, ServiceContext serviceContext)
040                    throws PortalException {
041    
042                    User user = userPersistence.findByPrimaryKey(userId);
043    
044                    long structureLayoutId = counterLocalService.increment();
045    
046                    DDMStructureLayout structureLayout =
047                            ddmStructureLayoutPersistence.create(structureLayoutId);
048    
049                    structureLayout.setUuid(serviceContext.getUuid());
050                    structureLayout.setGroupId(groupId);
051                    structureLayout.setCompanyId(user.getCompanyId());
052                    structureLayout.setUserId(user.getUserId());
053                    structureLayout.setUserName(user.getFullName());
054                    structureLayout.setStructureVersionId(structureVersionId);
055                    structureLayout.setDefinition(
056                            DDMFormLayoutJSONSerializerUtil.serialize(ddmFormLayout));
057    
058                    return ddmStructureLayoutPersistence.update(structureLayout);
059            }
060    
061            @Override
062            @SystemEvent(type = SystemEventConstants.TYPE_DELETE)
063            public void deleteStructureLayout(DDMStructureLayout structureLayout) {
064                    ddmStructureLayoutPersistence.remove(structureLayout);
065            }
066    
067            @Override
068            public void deleteStructureLayout(long structureLayoutId)
069                    throws PortalException {
070    
071                    DDMStructureLayout structureLayout =
072                            ddmStructureLayoutPersistence.findByPrimaryKey(structureLayoutId);
073    
074                    ddmStructureLayoutLocalService.deleteStructureLayout(structureLayout);
075            }
076    
077            @Override
078            public DDMStructureLayout getStructureLayout(long structureLayoutId)
079                    throws PortalException {
080    
081                    return ddmStructureLayoutPersistence.findByPrimaryKey(
082                            structureLayoutId);
083            }
084    
085            @Override
086            public DDMStructureLayout getStructureLayoutByStructureVersionId(
087                            long structureVersionId)
088                    throws PortalException {
089    
090                    return ddmStructureLayoutPersistence.findByStructureVersionId(
091                            structureVersionId);
092            }
093    
094            @Override
095            public DDMStructureLayout updateStructureLayout(
096                            long structureLayoutId, DDMFormLayout ddmFormLayout,
097                            ServiceContext serviceContext)
098                    throws PortalException {
099    
100                    DDMStructureLayout structureLayout =
101                            ddmStructureLayoutPersistence.findByPrimaryKey(structureLayoutId);
102    
103                    structureLayout.setDefinition(
104                            DDMFormLayoutJSONSerializerUtil.serialize(ddmFormLayout));
105    
106                    return ddmStructureLayoutPersistence.update(structureLayout);
107            }
108    
109    }