001    /**
002     * Copyright (c) 2000-2010 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.asset.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.User;
020    import com.liferay.portlet.asset.model.AssetLink;
021    import com.liferay.portlet.asset.service.base.AssetLinkLocalServiceBaseImpl;
022    
023    import java.util.Date;
024    import java.util.List;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class AssetLinkLocalServiceImpl extends AssetLinkLocalServiceBaseImpl {
030    
031            public AssetLink addLink(
032                            long userId, long entryId1, long entryId2, int type, int weight)
033                    throws PortalException, SystemException {
034    
035                    User user = userLocalService.getUser(userId);
036                    Date now = new Date();
037    
038                    long linkId = counterLocalService.increment();
039    
040                    AssetLink link = assetLinkPersistence.create(linkId);
041    
042                    link.setCompanyId(user.getCompanyId());
043                    link.setUserId(user.getUserId());
044                    link.setUserName(user.getFullName());
045                    link.setCreateDate(now);
046                    link.setEntryId1(entryId1);
047                    link.setEntryId2(entryId2);
048                    link.setType(type);
049                    link.setWeight(weight);
050    
051                    assetLinkPersistence.update(link, false);
052    
053                    return link;
054            }
055    
056            public void deleteLink(long linkId)
057                    throws PortalException, SystemException {
058    
059                    assetLinkPersistence.remove(linkId);
060            }
061    
062            public void deleteLinks(long entryId) throws SystemException {
063                    assetLinkPersistence.removeByE1(entryId);
064                    assetLinkPersistence.removeByE2(entryId);
065            }
066    
067            public void deleteLinks(long entryId1, long entryId2)
068                    throws SystemException {
069    
070                    assetLinkPersistence.removeByE_E(entryId1, entryId2);
071            }
072    
073            public List<AssetLink> getLinks(long entryId, int typeId)
074                    throws SystemException {
075    
076                    return assetLinkPersistence.findByE1_T(entryId, typeId);
077            }
078    
079            public List<AssetLink> getReverseLinks(long entryId, int typeId)
080                    throws SystemException {
081    
082                    return assetLinkPersistence.findByE2_T(entryId, typeId);
083            }
084    
085    }