| VerifyGroup.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * The contents of this file are subject to the terms of the Liferay Enterprise
5 * Subscription License ("License"). You may not use this file except in
6 * compliance with the License. You can obtain a copy of the License by
7 * contacting Liferay, Inc. See the License for the specific language governing
8 * permissions and limitations under the License, including but not limited to
9 * distribution rights of the Software.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17 * SOFTWARE.
18 */
19
20 package com.liferay.portal.verify;
21
22 import com.liferay.portal.GroupFriendlyURLException;
23 import com.liferay.portal.kernel.log.Log;
24 import com.liferay.portal.kernel.log.LogFactoryUtil;
25 import com.liferay.portal.kernel.util.StringPool;
26 import com.liferay.portal.model.Group;
27 import com.liferay.portal.model.User;
28 import com.liferay.portal.service.GroupLocalServiceUtil;
29 import com.liferay.portal.service.UserLocalServiceUtil;
30
31 import java.util.List;
32
33 /**
34 * <a href="VerifyGroup.java.html"><b><i>View Source</i></b></a>
35 *
36 * @author Brian Wing Shun Chan
37 *
38 */
39 public class VerifyGroup extends VerifyProcess {
40
41 public void verify() throws VerifyException {
42 _log.info("Verifying");
43
44 try {
45 verifyGroup();
46 }
47 catch (Exception e) {
48 throw new VerifyException(e);
49 }
50 }
51
52 protected void verifyGroup() throws Exception {
53 List<Group> groups = GroupLocalServiceUtil.getNullFriendlyURLGroups();
54
55 for (Group group : groups) {
56 String friendlyURL = StringPool.SLASH + group.getGroupId();
57
58 User user = null;
59
60 if (group.isUser()) {
61 user = UserLocalServiceUtil.getUserById(group.getClassPK());
62
63 friendlyURL = StringPool.SLASH + user.getScreenName();
64 }
65 else if (group.getClassPK() > 0) {
66 friendlyURL = StringPool.SLASH + group.getClassPK();
67 }
68
69 try {
70 GroupLocalServiceUtil.updateFriendlyURL(
71 group.getGroupId(), friendlyURL);
72 }
73 catch (GroupFriendlyURLException gfurle) {
74 if (user != null) {
75 long userId = user.getUserId();
76 String screenName = user.getScreenName();
77
78 _log.info(
79 "Updating user screen name " + screenName + " to " +
80 userId + " because it is generating an invalid " +
81 "friendly URL");
82
83 UserLocalServiceUtil.updateScreenName(
84 userId, String.valueOf(userId));
85 }
86 else {
87 _log.error("Invalid Friendly URL " + friendlyURL);
88
89 throw gfurle;
90 }
91 }
92 }
93 }
94
95 private static Log _log = LogFactoryUtil.getLog(VerifyGroup.class);
96
97 }