1
22
23 package com.liferay.portlet.social.service.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.model.User;
28 import com.liferay.portlet.social.NoSuchRelationException;
29 import com.liferay.portlet.social.RelationUserIdException;
30 import com.liferay.portlet.social.model.SocialRelation;
31 import com.liferay.portlet.social.service.base.SocialRelationLocalServiceBaseImpl;
32
33 import java.util.Date;
34 import java.util.List;
35
36
43 public class SocialRelationLocalServiceImpl
44 extends SocialRelationLocalServiceBaseImpl {
45
46 public SocialRelation addRelation(long userId1, long userId2, int type)
47 throws PortalException, SystemException {
48
49 if (userId1 == userId2) {
50 throw new RelationUserIdException();
51 }
52
53 User user1 = userPersistence.findByPrimaryKey(userId1);
54 User user2 = userPersistence.findByPrimaryKey(userId2);
55
56 if (user1.getCompanyId() != user2.getCompanyId()) {
57 throw new RelationUserIdException();
58 }
59
60 SocialRelation relation = null;
61
62 try {
63 relation = socialRelationFinder.findByU_U_T(
64 userId1, userId2, type);
65 }
66 catch (NoSuchRelationException nsre) {
67 long relationId = counterLocalService.increment();
68
69 relation = socialRelationPersistence.create(relationId);
70
71 relation.setCompanyId(user1.getCompanyId());
72 relation.setCreateDate(new Date());
73 relation.setUserId1(userId1);
74 relation.setUserId2(userId2);
75 relation.setType(type);
76
77 socialRelationPersistence.update(relation, false);
78 }
79
80 return relation;
81 }
82
83 public void deleteRelation(long relationId)
84 throws PortalException, SystemException {
85
86 socialRelationPersistence.remove(relationId);
87 }
88
89 public void deleteRelations(long userId) throws SystemException {
90 socialRelationPersistence.removeByUserId1(userId);
91 socialRelationPersistence.removeByUserId2(userId);
92 }
93
94 public List<SocialRelation> getRelations(
95 long userId, int type, int begin, int end)
96 throws SystemException {
97
98 return socialRelationFinder.findByU_T(userId, type, begin, end);
99 }
100
101 }