001    /**
002     * Copyright (c) 2000-2012 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 com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.service.ServiceContext;
020    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureLink;
021    import com.liferay.portlet.dynamicdatamapping.service.base.DDMStructureLinkLocalServiceBaseImpl;
022    
023    import java.util.List;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     * @author Bruno Basto
028     */
029    public class DDMStructureLinkLocalServiceImpl
030            extends DDMStructureLinkLocalServiceBaseImpl {
031    
032            public DDMStructureLink addStructureLink(
033                            long classNameId, long classPK, long structureId,
034                            ServiceContext serviceContext)
035                    throws SystemException {
036    
037                    long structureLinkId = counterLocalService.increment();
038    
039                    DDMStructureLink structureLink = ddmStructureLinkPersistence.create(
040                            structureLinkId);
041    
042                    structureLink.setClassNameId(classNameId);
043                    structureLink.setClassPK(classPK);
044                    structureLink.setStructureId(structureId);
045    
046                    ddmStructureLinkPersistence.update(structureLink, false);
047    
048                    return structureLink;
049            }
050    
051            public void deleteClassStructureLink(long classPK)
052                    throws PortalException, SystemException {
053    
054                    DDMStructureLink structureLink =
055                            ddmStructureLinkPersistence.findByClassPK(classPK);
056    
057                    deleteStructureLink(structureLink);
058            }
059    
060            public void deleteStructureLink(DDMStructureLink structureLink)
061                    throws SystemException {
062    
063                    ddmStructureLinkPersistence.remove(structureLink);
064            }
065    
066            public void deleteStructureLink(long structureLinkId)
067                    throws PortalException, SystemException {
068    
069                    DDMStructureLink structureLink =
070                            ddmStructureLinkPersistence.findByPrimaryKey(structureLinkId);
071    
072                    deleteStructureLink(structureLink);
073            }
074    
075            public void deleteStructureStructureLinks(long structureId)
076                    throws SystemException {
077    
078                    List<DDMStructureLink> structureLinks =
079                            ddmStructureLinkPersistence.findByStructureId(structureId);
080    
081                    for (DDMStructureLink structureLink : structureLinks) {
082                            deleteStructureLink(structureLink);
083                    }
084            }
085    
086            public DDMStructureLink getClassStructureLink(long classPK)
087                    throws PortalException, SystemException {
088    
089                    return ddmStructureLinkPersistence.findByClassPK(classPK);
090            }
091    
092            public List<DDMStructureLink> getClassStructureLinks(long classNameId)
093                    throws SystemException {
094    
095                    return ddmStructureLinkPersistence.findByStructureId(classNameId);
096            }
097    
098            public DDMStructureLink getStructureLink(long structureLinkId)
099                    throws PortalException, SystemException {
100    
101                    return ddmStructureLinkPersistence.findByPrimaryKey(structureLinkId);
102            }
103    
104            public List<DDMStructureLink> getStructureLinks(
105                            long structureId, int start, int end)
106                    throws SystemException {
107    
108                    return ddmStructureLinkPersistence.findByStructureId(
109                            structureId, start, end);
110            }
111    
112            public DDMStructureLink updateStructureLink(
113                            long structureLinkId, long classNameId, long classPK,
114                            long structureId)
115                    throws PortalException, SystemException {
116    
117                    DDMStructureLink structureLink =
118                            ddmStructureLinkPersistence.findByPrimaryKey(structureLinkId);
119    
120                    structureLink.setClassNameId(classNameId);
121                    structureLink.setClassPK(classPK);
122                    structureLink.setStructureId(structureId);
123    
124                    ddmStructureLinkPersistence.update(structureLink, false);
125    
126                    return structureLink;
127            }
128    
129    }