001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.db.generic; 029 030import org.opencms.util.CmsUUID; 031 032import java.util.ArrayList; 033import java.util.Collections; 034import java.util.List; 035 036/** 037 * Filter object that describes what to clean up in a publish history cleanup operation. 038 */ 039public class CmsPublishHistoryCleanupFilter { 040 041 /** Mode of operation for publish history cleanup. */ 042 public enum Mode { 043 044 /** Removes all publish history entries unreferenced by publish jobs, with a fixed set of exceptions */ 045 allUnreferenced, 046 047 /** Remove entries for single publish history id. */ 048 single; 049 } 050 051 /** List of history ids for which the entries should not be deleted. */ 052 private List<CmsUUID> m_exceptions = new ArrayList<>(); 053 054 /** History id for which entries should be deleted. */ 055 private CmsUUID m_historyId = null; 056 057 /** The mode. */ 058 private Mode m_mode; 059 060 /** 061 * Hidden constructor. 062 */ 063 private CmsPublishHistoryCleanupFilter() { 064 065 // do nothing 066 } 067 068 /** 069 * Creates a new filter for removing all unreferenced publish history entries, except the ones with the given history ids. 070 * 071 * @param exceptions the history ids for which entries should not be deleted 072 * @return the filter 073 */ 074 public static CmsPublishHistoryCleanupFilter allUnreferencedExcept(List<CmsUUID> exceptions) { 075 076 CmsPublishHistoryCleanupFilter result = new CmsPublishHistoryCleanupFilter(); 077 result.m_mode = Mode.allUnreferenced; 078 result.m_exceptions.addAll(exceptions); 079 return result; 080 } 081 082 /** 083 * Creates a filter for removing the publish history entries for a single history id. 084 * 085 * @param publishJobId the history id 086 * @return the filter 087 */ 088 public static CmsPublishHistoryCleanupFilter forHistoryId(CmsUUID publishJobId) { 089 090 CmsPublishHistoryCleanupFilter result = new CmsPublishHistoryCleanupFilter(); 091 result.m_mode = Mode.single; 092 result.m_historyId = publishJobId; 093 return result; 094 } 095 096 /** 097 * Gets the list of history ids for which entries should not be deleted. 098 * 099 * @return the list of history ids for which entries should not be deleted 100 */ 101 public List<CmsUUID> getExceptions() { 102 103 return Collections.unmodifiableList(m_exceptions); 104 } 105 106 /** 107 * Gets the history id. 108 * 109 * @return the history id 110 */ 111 public CmsUUID getHistoryId() { 112 113 return m_historyId; 114 } 115 116 /** 117 * Gets the mode. 118 * 119 * @return the mode 120 */ 121 public Mode getMode() { 122 123 return m_mode; 124 } 125 126}