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.model.Group;
025    import com.liferay.portal.util.PortalUtil;
026    import com.liferay.portlet.social.model.SocialRequest;
027    import com.liferay.portlet.social.service.SocialRequestLocalServiceUtil;
028    
029    /**
030     * @author Bryan Engler
031     * @author Sherry Yang
032     */
033    public class VerifySocial extends VerifyProcess {
034    
035            @Override
036            protected void doVerify() throws Exception {
037                    ActionableDynamicQuery socialRequestActionableDynamicQuery =
038                            SocialRequestLocalServiceUtil.getActionableDynamicQuery();
039    
040                    socialRequestActionableDynamicQuery.setAddCriteriaMethod(
041                            new ActionableDynamicQuery.AddCriteriaMethod() {
042    
043                                    @Override
044                                    public void addCriteria(DynamicQuery dynamicQuery) {
045                                            Property classNameIdProperty = PropertyFactoryUtil.forName(
046                                                    "classNameId");
047    
048                                            long classNameId = PortalUtil.getClassNameId(Group.class);
049    
050                                            dynamicQuery.add(classNameIdProperty.eq(classNameId));
051    
052                                            Property classPKProperty = PropertyFactoryUtil.forName(
053                                                    "classPK");
054    
055                                            DynamicQuery groupDynamicQuery =
056                                                    DynamicQueryFactoryUtil.forClass(Group.class);
057    
058                                            Projection projection = ProjectionFactoryUtil.property(
059                                                    "groupId");
060    
061                                            groupDynamicQuery.setProjection(projection);
062    
063                                            dynamicQuery.add(classPKProperty.notIn(groupDynamicQuery));
064                                    }
065    
066                            });
067                    socialRequestActionableDynamicQuery.setPerformActionMethod(
068                            new ActionableDynamicQuery.PerformActionMethod<SocialRequest>() {
069    
070                                    @Override
071                                    public void performAction(SocialRequest socialRequest) {
072                                            SocialRequestLocalServiceUtil.deleteRequest(socialRequest);
073                                    }
074    
075                            });
076    
077                    socialRequestActionableDynamicQuery.performActions();
078            }
079    
080    }