1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.asset.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.model.User;
20  import com.liferay.portlet.asset.model.AssetLink;
21  import com.liferay.portlet.asset.service.base.AssetLinkLocalServiceBaseImpl;
22  
23  import java.util.Date;
24  import java.util.List;
25  
26  /**
27   * <a href="AssetLinkLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class AssetLinkLocalServiceImpl extends AssetLinkLocalServiceBaseImpl {
32  
33      public AssetLink addLink(
34              long userId, long entryId1, long entryId2, int type, int weight)
35          throws PortalException, SystemException {
36  
37          User user = userLocalService.getUser(userId);
38          Date now = new Date();
39  
40          long linkId = counterLocalService.increment();
41  
42          AssetLink link = assetLinkPersistence.create(linkId);
43  
44          link.setCompanyId(user.getCompanyId());
45          link.setUserId(user.getUserId());
46          link.setUserName(user.getFullName());
47          link.setCreateDate(now);
48          link.setEntryId1(entryId1);
49          link.setEntryId2(entryId2);
50          link.setType(type);
51          link.setWeight(weight);
52  
53          assetLinkPersistence.update(link, false);
54  
55          return link;
56      }
57  
58      public void deleteLink(long linkId)
59          throws PortalException, SystemException {
60  
61          assetLinkPersistence.remove(linkId);
62      }
63  
64      public void deleteLinks(long entryId) throws SystemException {
65          assetLinkPersistence.removeByE1(entryId);
66          assetLinkPersistence.removeByE2(entryId);
67      }
68  
69      public void deleteLinks(long entryId1, long entryId2)
70          throws SystemException {
71  
72          assetLinkPersistence.removeByE_E(entryId1, entryId2);
73      }
74  
75      public List<AssetLink> getLinks(long entryId, int typeId)
76          throws SystemException {
77  
78          return assetLinkPersistence.findByE1_T(entryId, typeId);
79      }
80  
81      public List<AssetLink> getReverseLinks(long entryId, int typeId)
82          throws SystemException {
83  
84          return assetLinkPersistence.findByE2_T(entryId, typeId);
85      }
86  
87  }