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.portlet.exportimport.messaging;
016    
017    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
018    import com.liferay.portal.kernel.dao.orm.Order;
019    import com.liferay.portal.kernel.dao.orm.OrderFactoryUtil;
020    import com.liferay.portal.kernel.dao.orm.Property;
021    import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
022    import com.liferay.portal.kernel.dao.orm.QueryUtil;
023    import com.liferay.portal.kernel.exception.PortalException;
024    import com.liferay.portal.kernel.messaging.BaseMessageListener;
025    import com.liferay.portal.kernel.messaging.Message;
026    import com.liferay.portal.kernel.workflow.WorkflowConstants;
027    import com.liferay.portal.util.PropsValues;
028    import com.liferay.portlet.exportimport.model.ExportImportConfiguration;
029    import com.liferay.portlet.exportimport.service.ExportImportConfigurationLocalServiceUtil;
030    
031    import java.util.List;
032    
033    /**
034     * @author Levente Hud??k
035     */
036    public class DraftExportImportConfigurationMessageListener
037            extends BaseMessageListener {
038    
039            @Override
040            protected void doReceive(Message message) throws PortalException {
041                    if (PropsValues.
042                                    STAGING_DRAFT_EXPORT_IMPORT_CONFIGURATION_CLEAN_UP_COUNT ==
043                                            -1) {
044    
045                            return;
046                    }
047    
048                    DynamicQuery dynamicQuery =
049                            ExportImportConfigurationLocalServiceUtil.dynamicQuery();
050    
051                    Property property = PropertyFactoryUtil.forName("status");
052    
053                    dynamicQuery.add(property.eq(WorkflowConstants.STATUS_DRAFT));
054    
055                    Order order = OrderFactoryUtil.asc("createDate");
056    
057                    dynamicQuery.addOrder(order);
058    
059                    dynamicQuery.setLimit(
060                            QueryUtil.ALL_POS,
061                            PropsValues.
062                                    STAGING_DRAFT_EXPORT_IMPORT_CONFIGURATION_CLEAN_UP_COUNT);
063    
064                    List<ExportImportConfiguration> exportImportConfigurations =
065                            ExportImportConfigurationLocalServiceUtil.dynamicQuery(
066                                    dynamicQuery);
067    
068                    for (ExportImportConfiguration exportImportConfiguration :
069                                    exportImportConfigurations) {
070    
071                            ExportImportConfigurationLocalServiceUtil.
072                                    deleteExportImportConfiguration(exportImportConfiguration);
073                    }
074            }
075    
076    }