001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.verify;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.workflow.WorkflowConstants;
020    import com.liferay.portlet.blogs.model.BlogsEntry;
021    import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
022    import com.liferay.portlet.blogs.util.LinkbackConsumerUtil;
023    import com.liferay.portlet.messageboards.model.MBDiscussion;
024    import com.liferay.portlet.messageboards.model.MBMessage;
025    import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
026    
027    import java.util.List;
028    
029    /**
030     * <p>
031     * This class looks at every blog comment to see if it is a trackback and
032     * verifies that the source URL is a valid URL. Do not run this unless you want
033     * to do this.
034     * </p>
035     *
036     * @author Alexander Chow
037     */
038    public class VerifyBlogsTrackbacks extends VerifyProcess {
039    
040            protected void doVerify() throws Exception {
041                    List<MBDiscussion> discussions =
042                            MBMessageLocalServiceUtil.getDiscussions(
043                                    BlogsEntry.class.getName());
044    
045                    for (MBDiscussion discussion : discussions) {
046                            long entryId = discussion.getClassPK();
047                            long threadId = discussion.getThreadId();
048    
049                            try {
050                                    BlogsEntry entry = BlogsEntryLocalServiceUtil.getBlogsEntry(
051                                            entryId);
052    
053                                    List<MBMessage> messages =
054                                            MBMessageLocalServiceUtil.getThreadMessages(
055                                                    threadId, WorkflowConstants.STATUS_APPROVED);
056    
057                                    for (MBMessage message : messages) {
058                                            LinkbackConsumerUtil.verifyPost(entry, message);
059                                    }
060                            }
061                            catch (Exception e) {
062                                    _log.error(e, e);
063                            }
064                    }
065            }
066    
067            private static Log _log = LogFactoryUtil.getLog(
068                    VerifyBlogsTrackbacks.class);
069    
070    }