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; 029 030import org.opencms.util.CmsUUID; 031 032import java.util.Date; 033 034/** 035 * A filter which contains criteria for reading {@link CmsVisitEntry} instances from the database.<p> 036 * 037 * @since 8.0.0 038 */ 039public final class CmsVisitEntryFilter implements Cloneable { 040 041 /** To filter all. */ 042 public static final CmsVisitEntryFilter ALL = new CmsVisitEntryFilter(); 043 044 /** The starting date to filter. */ 045 private long m_dateFrom; 046 047 /** The end date to filter. */ 048 private long m_dateTo = Long.MAX_VALUE; 049 050 /** The structure id of the resource to filter. */ 051 private CmsUUID m_structureId; 052 053 /** The user id to filter. */ 054 private CmsUUID m_userId; 055 056 /** 057 * Private constructor.<p> 058 */ 059 private CmsVisitEntryFilter() { 060 061 // empty 062 } 063 064 /** 065 * @see java.lang.Object#clone() 066 */ 067 @Override 068 public Object clone() { 069 070 CmsVisitEntryFilter filter = new CmsVisitEntryFilter(); 071 filter.m_structureId = m_structureId; 072 filter.m_userId = m_userId; 073 filter.m_dateFrom = m_dateFrom; 074 filter.m_dateTo = m_dateTo; 075 return filter; 076 } 077 078 /** 079 * Returns an extended filter with the starting date restriction.<p> 080 * 081 * @param from the starting date to filter 082 * 083 * @return an extended filter with the starting date restriction 084 */ 085 public CmsVisitEntryFilter filterFrom(long from) { 086 087 CmsVisitEntryFilter filter = (CmsVisitEntryFilter)clone(); 088 filter.m_dateFrom = from; 089 return filter; 090 } 091 092 /** 093 * Returns an extended filter with the given resource restriction.<p> 094 * 095 * @param structureId the structure id to filter 096 * 097 * @return an extended filter with the given resource restriction 098 */ 099 public CmsVisitEntryFilter filterResource(CmsUUID structureId) { 100 101 CmsVisitEntryFilter filter = (CmsVisitEntryFilter)clone(); 102 filter.m_structureId = structureId; 103 return filter; 104 } 105 106 /** 107 * Returns an extended filter with the end date restriction.<p> 108 * 109 * @param to the end date to filter 110 * 111 * @return an extended filter with the end date restriction 112 */ 113 public CmsVisitEntryFilter filterTo(long to) { 114 115 CmsVisitEntryFilter filter = (CmsVisitEntryFilter)clone(); 116 filter.m_dateTo = to; 117 return filter; 118 } 119 120 /** 121 * Returns an extended filter with the given user ID restriction.<p> 122 * 123 * @param userId the user ID to filter 124 * 125 * @return an extended filter with the given user ID restriction 126 */ 127 public CmsVisitEntryFilter filterUser(CmsUUID userId) { 128 129 CmsVisitEntryFilter filter = (CmsVisitEntryFilter)clone(); 130 filter.m_userId = userId; 131 return filter; 132 } 133 134 /** 135 * Returns the starting date restriction.<p> 136 * 137 * @return the starting date restriction 138 */ 139 public long getDateFrom() { 140 141 return m_dateFrom; 142 } 143 144 /** 145 * Returns the end date restriction.<p> 146 * 147 * @return the end date restriction 148 */ 149 public long getDateTo() { 150 151 return m_dateTo; 152 } 153 154 /** 155 * Returns the structure Id of the resource to filter.<p> 156 * 157 * @return the structure Id of the resource to filter 158 */ 159 public CmsUUID getStructureId() { 160 161 return m_structureId; 162 } 163 164 /** 165 * Returns the user ID restriction.<p> 166 * 167 * @return the user ID restriction 168 */ 169 public CmsUUID getUserId() { 170 171 return m_userId; 172 } 173 174 /** 175 * @see java.lang.Object#toString() 176 */ 177 @Override 178 public String toString() { 179 180 StringBuffer str = new StringBuffer(128); 181 str.append("["); 182 str.append("resource").append("=").append(m_structureId).append(", "); 183 str.append("user").append("=").append(m_userId).append(", "); 184 str.append("from").append("=").append(new Date(m_dateFrom)).append(", "); 185 str.append("to").append("=").append(new Date(m_dateTo)); 186 str.append("]"); 187 return str.toString(); 188 } 189}