Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.
/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.db.jpa;
import org.opencms.configuration.CmsConfigurationManager;
import org.opencms.configuration.CmsParameterConfiguration;
import org.opencms.db.CmsDbContext;
import org.opencms.db.CmsDbSqlException;
import org.opencms.db.CmsDriverManager;
import org.opencms.db.CmsSubscriptionFilter;
import org.opencms.db.CmsSubscriptionReadMode;
import org.opencms.db.CmsVisitEntry;
import org.opencms.db.CmsVisitEntryFilter;
import org.opencms.db.CmsVisitedByFilter;
import org.opencms.db.I_CmsDriver;
import org.opencms.db.I_CmsSubscriptionDriver;
import org.opencms.db.generic.Messages;
import org.opencms.db.jpa.persistence.CmsDAOSubscription;
import org.opencms.db.jpa.persistence.CmsDAOSubscriptionVisit;
import org.opencms.db.jpa.utils.CmsQueryLongParameter;
import org.opencms.db.jpa.utils.CmsQueryStringParameter;
import org.opencms.db.jpa.utils.I_CmsQueryParameter;
import org.opencms.file.CmsDataAccessException;
import org.opencms.file.CmsGroup;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsUser;
import org.opencms.file.history.I_CmsHistoryResource;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPrincipal;
import org.opencms.util.CmsFileUtil;
import org.opencms.util.CmsPair;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.persistence.PersistenceException;
import javax.persistence.Query;
import org.apache.commons.logging.Log;
/**
* JPA database server implementation of the subscription driver methods.
*
* @since 8.0.0
*/
public class CmsSubscriptionDriver implements I_CmsDriver, I_CmsSubscriptionDriver {
/** Query key. */
private static final String C_RESOURCES_SELECT_BY_PARENT_UUID = "C_RESOURCES_SELECT_BY_PARENT_UUID";
/** Query key. */
private static final String C_RESOURCES_SELECT_BY_PATH_PREFIX = "C_RESOURCES_SELECT_BY_PATH_PREFIX";
/** Query key. */
private static final String C_SUBSCRIPTION_CHECK_2 = "C_SUBSCRIPTION_CHECK_2";
/** Query key. */
private static final String C_SUBSCRIPTION_DELETE = "C_SUBSCRIPTION_DELETE";
/** Query key. */
private static final String C_SUBSCRIPTION_DELETE_FILTER_DATE = "C_SUBSCRIPTION_DELETE_FILTER_DATE";
/** Query key. */
private static final String C_SUBSCRIPTION_DELETE_FILTER_PRINCIPAL = "C_SUBSCRIPTION_DELETE_FILTER_PRINCIPAL";
/** Query key. */
private static final String C_SUBSCRIPTION_DELETE_FILTER_STRUCTURE = "C_SUBSCRIPTION_DELETE_FILTER_STRUCTURE";
/** Query key. */
private static final String C_SUBSCRIPTION_DELETED = "C_SUBSCRIPTION_DELETED";
/** Query key. */
private static final String C_SUBSCRIPTION_DELETED_FILTER_PRINCIPAL_SINGLE = "C_SUBSCRIPTION_DELETED_FILTER_PRINCIPAL_SINGLE";
/** Query key. */
private static final String C_SUBSCRIPTION_DELETED_FILTER_PRINCIPALS = "C_SUBSCRIPTION_DELETED_FILTER_PRINCIPALS";
/** Query key. */
private static final String C_SUBSCRIPTION_FILTER_PRINCIPAL_SINGLE = "C_SUBSCRIPTION_FILTER_PRINCIPAL_SINGLE";
/** Query key. */
private static final String C_SUBSCRIPTION_FILTER_PRINCIPALS = "C_SUBSCRIPTION_FILTER_PRINCIPALS";
/** Query key. */
private static final String C_SUBSCRIPTION_FILTER_PRINCIPALS_END = "C_SUBSCRIPTION_FILTER_PRINCIPALS_END";
/** Query key. */
private static final String C_SUBSCRIPTION_FILTER_READ = "C_SUBSCRIPTION_FILTER_READ";
/** Query key. */
private static final String C_SUBSCRIPTION_FILTER_RESOURCES_DATE_MODIFIED = "C_SUBSCRIPTION_FILTER_RESOURCES_DATE_MODIFIED";
/** Query key. */
private static final String C_SUBSCRIPTION_READ_ALL_1 = "C_SUBSCRIPTION_READ_ALL_1";
/** Query key. */
private static final String C_SUBSCRIPTION_UPDATE_DATE_2 = "C_SUBSCRIPTION_UPDATE_DATE_2";
/** Query key. */
private static final String C_VISIT_DELETE_ENTRIES = "C_VISIT_DELETE_ENTRIES";
/** Query key. */
private static final String C_VISIT_FILTER_DATE_FROM = "C_VISIT_FILTER_DATE_FROM";
/** Query key. */
private static final String C_VISIT_FILTER_DATE_TO = "C_VISIT_FILTER_DATE_TO";
/** Query key. */
private static final String C_VISIT_FILTER_STRUCTURE_ID = "C_VISIT_FILTER_STRUCTURE_ID";
/** Query key. */
private static final String C_VISIT_FILTER_USER_ID = "C_VISIT_FILTER_USER_ID";
/** Query key. */
private static final String C_VISIT_READ_ENTRIES = "C_VISIT_READ_ENTRIES";
/** Query key. */
private static final String C_VISITED_USER_COUNT_1 = "C_VISITED_USER_COUNT_1";
/** Query key. */
private static final String C_VISITED_USER_DELETE_GETDATE_2 = "C_VISITED_USER_DELETE_GETDATE_2";
/** Query key. */
private static final String C_VISITED_USER_READ_4 = "C_VISITED_USER_READ_4";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(org.opencms.db.generic.CmsSubscriptionDriver.class);
/** A reference to the driver manager used by this driver. */
protected CmsDriverManager m_driverManager;
/** The SQL manager used by this driver. */
protected CmsSqlManager m_sqlManager;
/**
* @see org.opencms.db.I_CmsSubscriptionDriver#deleteVisits(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.db.CmsVisitEntryFilter)
*/
public void deleteVisits(CmsDbContext dbc, String poolName, CmsVisitEntryFilter filter)
throws CmsDataAccessException {
try {
// compose statement
StringBuffer queryBuf = new StringBuffer(256);
queryBuf.append(m_sqlManager.readQuery(C_VISIT_DELETE_ENTRIES));
CmsPair> conditionsAndParams = prepareVisitConditions(filter);
queryBuf.append(conditionsAndParams.getFirst());
if (LOG.isDebugEnabled()) {
LOG.debug(queryBuf.toString());
}
Query q = m_sqlManager.createQueryFromJPQL(dbc, queryBuf.toString());
List params = conditionsAndParams.getSecond();
for (int i = 0; i < params.size(); i++) {
I_CmsQueryParameter param = conditionsAndParams.getSecond().get(i);
param.insertIntoQuery(q, i + 1);
}
// execute
q.executeUpdate();
} catch (PersistenceException e) {
throw new CmsDbSqlException(
Messages.get().container(Messages.ERR_GENERIC_SQL_1, C_VISIT_DELETE_ENTRIES),
e);
}
}
/**
* @see org.opencms.db.I_CmsSubscriptionDriver#getDateLastVisitedBy(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.file.CmsUser, org.opencms.file.CmsResource)
*/
public long getDateLastVisitedBy(CmsDbContext dbc, String poolName, CmsUser user, CmsResource resource)
throws CmsException {
CmsVisitEntryFilter filter = CmsVisitEntryFilter.ALL.filterResource(resource.getStructureId()).filterUser(
user.getId());
List entries = readVisits(dbc, poolName, filter);
if (!entries.isEmpty()) {
return entries.get(0).getDate();
}
return 0;
}
/**
* @see org.opencms.db.I_CmsSubscriptionDriver#getSqlManager()
*/
public CmsSqlManager getSqlManager() {
return m_sqlManager;
}
/**
* @see org.opencms.db.I_CmsDriver#init(org.opencms.db.CmsDbContext, org.opencms.configuration.CmsConfigurationManager, java.util.List, org.opencms.db.CmsDriverManager)
*/
public void init(
CmsDbContext dbc,
CmsConfigurationManager configurationManager,
List successiveDrivers,
CmsDriverManager driverManager) {
// TODO: Auto-generated method stub
CmsParameterConfiguration config = configurationManager.getConfiguration();
String poolUrl = config.get("db.subscription.pool");
String classname = config.get("db.subscription.sqlmanager");
m_sqlManager = initSqlManager(classname);
m_driverManager = driverManager;
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ASSIGNED_POOL_1, poolUrl));
}
if ((successiveDrivers != null) && !successiveDrivers.isEmpty()) {
if (LOG.isWarnEnabled()) {
LOG.warn(
Messages.get().getBundle().key(
Messages.LOG_SUCCESSIVE_DRIVERS_UNSUPPORTED_1,
getClass().getName()));
}
}
}
/**
* @see org.opencms.db.I_CmsSubscriptionDriver#initSqlManager(java.lang.String)
*/
public CmsSqlManager initSqlManager(String classname) {
return CmsSqlManager.getInstance(classname);
}
/**
* @see org.opencms.db.I_CmsSubscriptionDriver#markResourceAsVisitedBy(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.file.CmsResource, org.opencms.file.CmsUser)
*/
public void markResourceAsVisitedBy(CmsDbContext dbc, String poolName, CmsResource resource, CmsUser user)
throws CmsDataAccessException {
boolean entryExists = false;
CmsVisitEntryFilter filter = CmsVisitEntryFilter.ALL.filterResource(resource.getStructureId()).filterUser(
user.getId());
// delete existing visited entry for the resource
if (readVisits(dbc, OpenCms.getSubscriptionManager().getPoolName(), filter).size() > 0) {
entryExists = true;
deleteVisits(dbc, OpenCms.getSubscriptionManager().getPoolName(), filter);
}
CmsVisitEntry entry = new CmsVisitEntry(user.getId(), System.currentTimeMillis(), resource.getStructureId());
addVisit(dbc, poolName, entry);
if (!entryExists) {
// new entry, check if maximum number of stored visited resources is exceeded
int count = 0;
try {
Query q = m_sqlManager.createQuery(dbc, dbc.currentProject(), C_VISITED_USER_COUNT_1);
q.setParameter(1, user.getId().toString());
count = ((Number)q.getSingleResult()).intValue();
int maxCount = OpenCms.getSubscriptionManager().getMaxVisitedCount();
if (count > maxCount) {
// delete old visited entries
q = m_sqlManager.createQuery(dbc, dbc.currentProject(), C_VISITED_USER_DELETE_GETDATE_2);
q.setParameter(1, user.getId().toString());
q.setMaxResults(count - maxCount);
@SuppressWarnings("unchecked")
List res = q.getResultList();
long deleteDate = 0;
for (Number n : res) {
// get last date of result set
deleteDate = n.longValue();
}
if (deleteDate > 0) {
filter = CmsVisitEntryFilter.ALL.filterUser(user.getId()).filterTo(deleteDate);
deleteVisits(dbc, OpenCms.getSubscriptionManager().getPoolName(), filter);
}
}
} catch (PersistenceException e) {
throw new CmsDbSqlException(
Messages.get().container(Messages.ERR_GENERIC_SQL_1, C_VISITED_USER_DELETE_GETDATE_2),
e);
}
}
}
/**
* @see org.opencms.db.I_CmsSubscriptionDriver#readAllSubscribedResources(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.security.CmsPrincipal)
*/
public List readAllSubscribedResources(CmsDbContext dbc, String poolName, CmsPrincipal principal)
throws CmsDataAccessException {
CmsResource currentResource = null;
List resources = new ArrayList();
try {
Query q = m_sqlManager.createQuery(dbc, dbc.currentProject(), C_SUBSCRIPTION_READ_ALL_1);
q.setParameter(1, principal.getId().toString());
@SuppressWarnings("unchecked")
List