001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.verify;
016    
017    import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
018    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
019    import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
020    import com.liferay.portal.kernel.dao.orm.Projection;
021    import com.liferay.portal.kernel.dao.orm.ProjectionFactoryUtil;
022    import com.liferay.portal.kernel.dao.orm.Property;
023    import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
024    import com.liferay.portal.kernel.model.Group;
025    import com.liferay.portal.kernel.util.LoggingTimer;
026    import com.liferay.portal.kernel.util.PortalUtil;
027    import com.liferay.social.kernel.model.SocialRequest;
028    import com.liferay.social.kernel.service.SocialRequestLocalServiceUtil;
029    
030    /**
031     * @author Bryan Engler
032     * @author Sherry Yang
033     */
034    public class VerifySocial extends VerifyProcess {
035    
036            @Override
037            protected void doVerify() throws Exception {
038                    ActionableDynamicQuery socialRequestActionableDynamicQuery =
039                            SocialRequestLocalServiceUtil.getActionableDynamicQuery();
040    
041                    socialRequestActionableDynamicQuery.setAddCriteriaMethod(
042                            new ActionableDynamicQuery.AddCriteriaMethod() {
043    
044                                    @Override
045                                    public void addCriteria(DynamicQuery dynamicQuery) {
046                                            Property classNameIdProperty = PropertyFactoryUtil.forName(
047                                                    "classNameId");
048    
049                                            long classNameId = PortalUtil.getClassNameId(Group.class);
050    
051                                            dynamicQuery.add(classNameIdProperty.eq(classNameId));
052    
053                                            Property classPKProperty = PropertyFactoryUtil.forName(
054                                                    "classPK");
055    
056                                            DynamicQuery groupDynamicQuery =
057                                                    DynamicQueryFactoryUtil.forClass(Group.class);
058    
059                                            Projection projection = ProjectionFactoryUtil.property(
060                                                    "groupId");
061    
062                                            groupDynamicQuery.setProjection(projection);
063    
064                                            dynamicQuery.add(classPKProperty.notIn(groupDynamicQuery));
065                                    }
066    
067                            });
068                    socialRequestActionableDynamicQuery.setPerformActionMethod(
069                            new ActionableDynamicQuery.PerformActionMethod<SocialRequest>() {
070    
071                                    @Override
072                                    public void performAction(SocialRequest socialRequest) {
073                                            try (LoggingTimer loggingTimer = new LoggingTimer()) {
074                                                    SocialRequestLocalServiceUtil.deleteRequest(
075                                                            socialRequest);
076                                            }
077                                    }
078    
079                            });
080    
081                    socialRequestActionableDynamicQuery.performActions();
082            }
083    
084    }