1
22
23 package com.liferay.portal.verify;
24
25 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
26 import com.liferay.portal.kernel.util.StringPool;
27 import com.liferay.portlet.social.service.SocialActivityLocalServiceUtil;
28 import com.liferay.portlet.social.service.SocialRequestLocalServiceUtil;
29
30 import java.sql.Connection;
31 import java.sql.PreparedStatement;
32 import java.sql.ResultSet;
33
34 import org.apache.commons.logging.Log;
35 import org.apache.commons.logging.LogFactory;
36
37
43 public class VerifySocial extends VerifyProcess {
44
45 public void verify() throws VerifyException {
46 _log.info("Verifying");
47
48 try {
49 verifySocial();
50 }
51 catch (Exception e) {
52 throw new VerifyException(e);
53 }
54 }
55
56 protected void deleteDuplicateActivities() throws Exception {
57 StringBuilder sb = new StringBuilder();
58
59 sb.append("select distinct sa1.* from SocialActivity sa1 ");
60 sb.append("inner join SocialActivity sa2 on ");
61 sb.append("sa1.activityId != sa2.activityId and ");
62 sb.append("sa1.groupId = sa2.groupId and ");
63 sb.append("sa1.userId = sa2.userId and ");
64 sb.append("sa1.classNameId = sa2.classNameId and ");
65 sb.append("sa1.classPK = sa2.classPK and ");
66 sb.append("sa1.type_ = sa2.type_ and ");
67 sb.append("sa1.extraData = sa2.extraData and ");
68 sb.append("sa1.receiverUserId = sa2.receiverUserId ");
69 sb.append("where sa1.mirrorActivityId = 0 ");
70 sb.append("order by sa1.groupId, sa1.userId, sa1.classNameId, ");
71 sb.append("sa1.classPK, sa1.type_, sa1.extraData, ");
72 sb.append("sa1.receiverUserId, sa1.createDate desc");
73
74 String sql = sb.toString();
75
76 Connection con = null;
77 PreparedStatement ps = null;
78 ResultSet rs = null;
79
80 try {
81 con = DataAccess.getConnection();
82
83 ps = con.prepareStatement(sql);
84
85 rs = ps.executeQuery();
86
87 long groupId = 0;
88 long userId = 0;
89 long classNameId = 0;
90 long classPK = 0;
91 long type = 0;
92 String extraData = StringPool.BLANK;
93 long receiverUserId = 0;
94
95 while (rs.next()) {
96 long curActivityId = rs.getLong("activityId");
97 long curGroupId = rs.getLong("groupId");
98 long curUserId = rs.getLong("userId");
99 long curClassNameId = rs.getLong("classNameId");
100 long curClassPK = rs.getLong("classPK");
101 long curType = rs.getLong("type_");
102 String curExtraData = rs.getString("extraData");
103 long curReceiverUserId = rs.getLong("receiverUserId");
104
105 if ((curGroupId == groupId) && (curUserId == userId) &&
106 (curClassNameId == classNameId) &&
107 (curClassPK == classPK) && (curType == type) &&
108 (curExtraData.equals(extraData)) &&
109 (curReceiverUserId == receiverUserId)) {
110
111 SocialActivityLocalServiceUtil.deleteActivity(
112 curActivityId);
113 }
114 else {
115 groupId = curGroupId;
116 userId = curUserId;
117 classNameId = curClassNameId;
118 classPK = curClassPK;
119 type = curType;
120 extraData = curExtraData;
121 receiverUserId = curReceiverUserId;
122 }
123 }
124 }
125 finally {
126 DataAccess.cleanUp(con, ps, rs);
127 }
128 }
129
130 protected void deleteDuplicateRequests() throws Exception {
131 StringBuilder sb = new StringBuilder();
132
133 sb.append("select distinct sr1.* from SocialRequest sr1 ");
134 sb.append("inner join SocialRequest sr2 on ");
135 sb.append("sr1.requestId != sr2.requestId and ");
136 sb.append("sr1.groupId = sr2.groupId and ");
137 sb.append("sr1.userId = sr2.userId and ");
138 sb.append("sr1.classNameId = sr2.classNameId and ");
139 sb.append("sr1.classPK = sr2.classPK and ");
140 sb.append("sr1.type_ = sr2.type_ and ");
141 sb.append("sr1.extraData = sr2.extraData and ");
142 sb.append("sr1.receiverUserId = sr2.receiverUserId ");
143 sb.append("order by sr1.groupId, sr1.userId, sr1.classNameId, ");
144 sb.append("sr1.classPK, sr1.type_, sr1.extraData, ");
145 sb.append("sr1.receiverUserId, sr1.createDate desc");
146
147 String sql = sb.toString();
148
149 Connection con = null;
150 PreparedStatement ps = null;
151 ResultSet rs = null;
152
153 try {
154 con = DataAccess.getConnection();
155
156 ps = con.prepareStatement(sql);
157
158 rs = ps.executeQuery();
159
160 long groupId = 0;
161 long userId = 0;
162 long classNameId = 0;
163 long classPK = 0;
164 long type = 0;
165 String extraData = StringPool.BLANK;
166 long receiverUserId = 0;
167
168 while (rs.next()) {
169 long curRequestId = rs.getLong("requestId");
170 long curGroupId = rs.getLong("groupId");
171 long curUserId = rs.getLong("userId");
172 long curClassNameId = rs.getLong("classNameId");
173 long curClassPK = rs.getLong("classPK");
174 long curType = rs.getLong("type_");
175 String curExtraData = rs.getString("extraData");
176 long curReceiverUserId = rs.getLong("receiverUserId");
177
178 if ((curGroupId == groupId) && (curUserId == userId) &&
179 (curClassNameId == classNameId) &&
180 (curClassPK == classPK) && (curType == type) &&
181 (curExtraData.equals(extraData)) &&
182 (curReceiverUserId == receiverUserId)) {
183
184 SocialRequestLocalServiceUtil.deleteRequest(curRequestId);
185 }
186 else {
187 groupId = curGroupId;
188 userId = curUserId;
189 classNameId = curClassNameId;
190 classPK = curClassPK;
191 type = curType;
192 extraData = curExtraData;
193 receiverUserId = curReceiverUserId;
194 }
195 }
196 }
197 finally {
198 DataAccess.cleanUp(con, ps, rs);
199 }
200 }
201
202 protected void verifySocial() throws Exception {
203
204
208 }
211
212 private static Log _log = LogFactory.getLog(VerifySocial.class);
213
214 }