mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merge from HEAD to WCM-DEV2.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3659 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
158
source/java/org/alfresco/repo/audit/hibernate/Audit.hbm.xml
Normal file
158
source/java/org/alfresco/repo/audit/hibernate/Audit.hbm.xml
Normal file
@@ -0,0 +1,158 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
'-//Hibernate/Hibernate Mapping DTD 3.0//EN'
|
||||
'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>
|
||||
|
||||
<!-- Hibernate mapping for storing audit information -->
|
||||
<!-- -->
|
||||
<!-- This generates a simple star schema for audit -->
|
||||
<!-- breakdown and roll up. -->
|
||||
<!-- -->
|
||||
|
||||
<hibernate-mapping>
|
||||
|
||||
<!-- The fact -->
|
||||
|
||||
<class name="org.alfresco.repo.audit.hibernate.AuditFactImpl" proxy="org.alfresco.repo.audit.hibernate.AuditFact" table="alf_audit_fact" dynamic-update="false" dynamic-insert="false"
|
||||
select-before-update="false" lazy="true" optimistic-lock="version">
|
||||
|
||||
<!-- An auto-generated id -->
|
||||
<id name="id" column="id" type="long">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
|
||||
<!-- Fact properties -->
|
||||
|
||||
<property name="userId" column="user_id" type="string" length="255" not-null="true" index="adt_user_idx"/>
|
||||
<property name="date" column="timestamp" type="timestamp" not-null="true"/>
|
||||
<property name="transactionId" column="transaction_id" type="string" length="56" not-null="true"/>
|
||||
<property name="sessionId" column="session_id" type="string" length="56" not-null="false"/>
|
||||
<property name="storeProtocol" column="store_protocol" type="string" length="50" not-null="false" index="adt_store_idx"/>
|
||||
<property name="storeId" column="store_id" type="string" length="100" not-null="false" index="adt_store_idx"/>
|
||||
<property name="nodeUUID" column="node_uuid" type="string" length="36" not-null="false" index="adt_store_idx"/>
|
||||
<property name="path" column="path" type="string" length="512" not-null="false"/>
|
||||
<property name="filtered" column="filtered" type="boolean" not-null="true"/>
|
||||
<property name="returnValue" column="return_val" type="string" length="1024" not-null="false"/>
|
||||
<property name="arg1" column="arg_1" type="string" length="1024" not-null="false"/>
|
||||
<property name="arg2" column="arg_2" type="string" length="1024" not-null="false"/>
|
||||
<property name="arg3" column="arg_3" type="string" length="1024" not-null="false"/>
|
||||
<property name="arg4" column="arg_4" type="string" length="1024" not-null="false"/>
|
||||
<property name="arg5" column="arg_5" type="string" length="1024" not-null="false"/>
|
||||
<property name="fail" column="fail" type="boolean" not-null="true"/>
|
||||
<!-- TODO: Check the URL length ...-->
|
||||
<property name="serialisedURL" column="serialized_url" type="string" length="1024" not-null="false"/>
|
||||
<property name="exception" column="exception" type="string" length="1024" not-null="false"/>
|
||||
<property name="hostInetAddress" column="host_address" type="string" length="1024" not-null="false"/>
|
||||
<property name="clientInetAddress" column="client_address" type="string" length="1024" not-null="false"/>
|
||||
<property name="message" column="message" type="string" length="1024" not-null="false"/>
|
||||
|
||||
<!-- Links to dimensions -->
|
||||
|
||||
<many-to-one name="auditDate" class="org.alfresco.repo.audit.hibernate.AuditDateImpl" not-null="true" lazy="proxy" column="audit_date_id" cascade="none" optimistic-lock="true" fetch="join"/>
|
||||
<many-to-one name="auditConfig" class="org.alfresco.repo.audit.hibernate.AuditConfigImpl" not-null="true" lazy="proxy" column="audit_conf_id" cascade="none" optimistic-lock="true" fetch="join"/>
|
||||
<many-to-one name="auditSource" class="org.alfresco.repo.audit.hibernate.AuditSourceImpl" not-null="true" lazy="proxy" column="audit_source_id" cascade="none" optimistic-lock="true" fetch="join"/>
|
||||
|
||||
</class>
|
||||
|
||||
<!-- The audit date dimension -->
|
||||
|
||||
<class name="org.alfresco.repo.audit.hibernate.AuditDateImpl" proxy="org.alfresco.repo.audit.hibernate.AuditDate" table="alf_audit_date" dynamic-update="false" dynamic-insert="false"
|
||||
select-before-update="false" lazy="true" optimistic-lock="version">
|
||||
|
||||
<!-- An auto-generated id -->
|
||||
<id name="id" column="id" type="long">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
|
||||
<!-- Date is used as the key for look up -->
|
||||
|
||||
<property name="date" column="date" type="date" index="adt_date_idx" not-null="true"/>
|
||||
<property name="dayOfYear" column="day_of_year" type="integer" index="adt_doy_idx" not-null="true"/>
|
||||
<property name="dayOfMonth" column="day_of_month" type="integer" index="adt_dom_idx" not-null="true"/>
|
||||
<property name="dayOfWeek" column="day_of_week" type="integer" index="adt_dow_idx" not-null="true"/>
|
||||
<property name="weekOfYear" column="week_of_year" type="integer" index="adt_woy_idx" not-null="true"/>
|
||||
<property name="weekOfMonth" column="week_of_month" type="integer" index="adt_wom_idx" not-null="true"/>
|
||||
<property name="month" column="month" type="integer" index="adt_m_idx" not-null="true"/>
|
||||
<property name="quarter" column="quarter" type="integer" index="adt_q_idx" not-null="true"/>
|
||||
<property name="halfYear" column="halfYear" type="integer" index="adt_hy_idx" not-null="true"/>
|
||||
<property name="year" column="year" type="integer" index="adt_y_idx" not-null="true"/>
|
||||
|
||||
</class>
|
||||
|
||||
<!-- The audit configuration dimension -->
|
||||
|
||||
<class name="org.alfresco.repo.audit.hibernate.AuditConfigImpl" proxy="org.alfresco.repo.audit.hibernate.AuditConfig" table="alf_audit_config" dynamic-update="false" dynamic-insert="false"
|
||||
select-before-update="false" lazy="true" optimistic-lock="version">
|
||||
|
||||
<!-- Max id is used to find the latest audit configuration -->
|
||||
|
||||
<!-- An auto-generated id -->
|
||||
<id name="id" column="id" type="long">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
|
||||
<property name="configURL" column="config_url" type="string" length="256" not-null="true"/>
|
||||
|
||||
</class>
|
||||
|
||||
<!-- The audit source dimension -->
|
||||
|
||||
<class name="org.alfresco.repo.audit.hibernate.AuditSourceImpl" proxy="org.alfresco.repo.audit.hibernate.AuditSource" table="alf_audit_source" dynamic-update="false" dynamic-insert="false"
|
||||
select-before-update="false" lazy="true" optimistic-lock="version">
|
||||
|
||||
<!-- An auto-generated id -->
|
||||
<id name="id" column="id" type="long">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
|
||||
<!-- The app_source_idx index is used to find the app source -->
|
||||
<!-- The look up is always the tripple, the service and method or just the method may be null -->
|
||||
|
||||
<property name="application" column="application" type="string" length="256" not-null="true" index="app_source_idx"/>
|
||||
<property name="service" column="service" type="string" length="256" not-null="false" index="app_source_idx"/>
|
||||
<property name="method" column="method" type="string" length="256" not-null="false" index="app_source_idx"/>
|
||||
|
||||
</class>
|
||||
|
||||
<query name="audit.GetLatestAuditDate">
|
||||
select
|
||||
audit_date
|
||||
from
|
||||
org.alfresco.repo.audit.hibernate.AuditDateImpl as audit_date
|
||||
where
|
||||
audit_date.id = (select max(audit_date_2.id) from org.alfresco.repo.audit.hibernate.AuditDateImpl as audit_date_2)
|
||||
</query>
|
||||
|
||||
<query name="audit.GetLatestAuditConfig">
|
||||
select
|
||||
audit_config
|
||||
from
|
||||
org.alfresco.repo.audit.hibernate.AuditConfigImpl as audit_config
|
||||
where
|
||||
audit_config.id = (select max(audit_config_2.id) from org.alfresco.repo.audit.hibernate.AuditConfigImpl as audit_config_2)
|
||||
</query>
|
||||
|
||||
<query name="audit.GetAuditSourceByApplication">
|
||||
select
|
||||
audit_store
|
||||
from
|
||||
org.alfresco.repo.audit.hibernate.AuditSourceImpl as audit_store
|
||||
where
|
||||
audit_store.application = :application and
|
||||
audit_store.service is null and
|
||||
audit_store.method is null
|
||||
</query>
|
||||
|
||||
<query name="audit.GetAuditSourceByApplicationServiceMethod">
|
||||
select
|
||||
audit_store
|
||||
from
|
||||
org.alfresco.repo.audit.hibernate.AuditSourceImpl as audit_store
|
||||
where
|
||||
audit_store.application = :application and
|
||||
audit_store.service = :service and
|
||||
audit_store.method = :method
|
||||
</query>
|
||||
|
||||
</hibernate-mapping>
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.audit.hibernate;
|
||||
|
||||
|
||||
/**
|
||||
* Hibernate interface for audit configuration persistence.
|
||||
*
|
||||
* @author Andy Hind
|
||||
*/
|
||||
public interface AuditConfig
|
||||
{
|
||||
/**
|
||||
* Get the content URL for a copy of the configuration file.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String getConfigURL();
|
||||
|
||||
/**
|
||||
* Get the surrogate key for the configuration entry.
|
||||
* The creation is managed by hibernate.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract long getId();
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.audit.hibernate;
|
||||
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
public class AuditConfigImpl implements AuditConfig, InitializingBean
|
||||
{
|
||||
/**
|
||||
* The hibernate generated internal key.
|
||||
*/
|
||||
private long id;
|
||||
|
||||
/**
|
||||
* The URL to the content that contains the configuration file
|
||||
*/
|
||||
private String configURL;
|
||||
|
||||
public AuditConfigImpl()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditContig#getConfigURL()
|
||||
*/
|
||||
public String getConfigURL()
|
||||
{
|
||||
return configURL;
|
||||
}
|
||||
|
||||
public void setConfigURL(String configURL)
|
||||
{
|
||||
this.configURL = configURL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
// Read the audit configuration
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditContig#getId()
|
||||
*/
|
||||
public long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal setter for hibernate.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void setId(long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get the latest audit config
|
||||
*/
|
||||
public static AuditConfigImpl getLatestConfig(Session session)
|
||||
{
|
||||
Query query = session.getNamedQuery(HibernateAuditDAO.QUERY_LAST_AUDIT_CONFIG);
|
||||
return (AuditConfigImpl) query.uniqueResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(!(o instanceof AuditConfigImpl))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
AuditConfigImpl other = (AuditConfigImpl)o;
|
||||
return EqualsHelper.nullSafeEquals(this.configURL, other.configURL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return configURL == null ? 0 : configURL.hashCode();
|
||||
}
|
||||
|
||||
|
||||
}
|
106
source/java/org/alfresco/repo/audit/hibernate/AuditDate.java
Normal file
106
source/java/org/alfresco/repo/audit/hibernate/AuditDate.java
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.audit.hibernate;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Hibernate date dimension for audit roll ups
|
||||
*
|
||||
* @author Andy Hind
|
||||
*/
|
||||
public interface AuditDate
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the date
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract Date getDate();
|
||||
|
||||
/**
|
||||
* Get the day of the year.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getDayOfYear();
|
||||
|
||||
/**
|
||||
* Get the day of the month.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getDayOfMonth();
|
||||
|
||||
/**
|
||||
* Get the day of the week
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getDayOfWeek();
|
||||
|
||||
/**
|
||||
* Get the half year;
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getHalfYear();
|
||||
|
||||
|
||||
/**
|
||||
* Get the surrogate key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract long getId();
|
||||
|
||||
/**
|
||||
* Get the month
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getMonth();
|
||||
|
||||
/**
|
||||
* Get the quarter
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getQuarter();
|
||||
|
||||
/**
|
||||
* Get the week of the month.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getWeekOfMonth();
|
||||
|
||||
/**
|
||||
* Get the week of the year.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getWeekOfYear();
|
||||
|
||||
/**
|
||||
* Get the year.
|
||||
* @return
|
||||
*/
|
||||
public abstract int getYear();
|
||||
|
||||
}
|
289
source/java/org/alfresco/repo/audit/hibernate/AuditDateImpl.java
Normal file
289
source/java/org/alfresco/repo/audit/hibernate/AuditDateImpl.java
Normal file
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.audit.hibernate;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
|
||||
/**
|
||||
* Hibernate persistence for a date dimension.
|
||||
*
|
||||
* @author Andy Hind
|
||||
*/
|
||||
public class AuditDateImpl implements AuditDate
|
||||
{
|
||||
/**
|
||||
* Surrogate key
|
||||
*/
|
||||
private long id;
|
||||
|
||||
/**
|
||||
* The date
|
||||
*/
|
||||
private Date date;
|
||||
|
||||
/**
|
||||
* The day
|
||||
*/
|
||||
private int dayOfYear;
|
||||
|
||||
/**
|
||||
* Day of month.
|
||||
*/
|
||||
private int dayOfMonth;
|
||||
|
||||
/**
|
||||
* The day of the week
|
||||
*/
|
||||
private int dayOfWeek;
|
||||
|
||||
/**
|
||||
* The week in the year
|
||||
*/
|
||||
private int weekOfYear;
|
||||
|
||||
/**
|
||||
* The week of the month
|
||||
*/
|
||||
private int weekOfMonth;
|
||||
|
||||
/**
|
||||
* The month in the year
|
||||
*/
|
||||
private int month;
|
||||
|
||||
/**
|
||||
* The quarter in the year
|
||||
*/
|
||||
private int quarter;
|
||||
|
||||
/**
|
||||
* The half year in the year
|
||||
*/
|
||||
private int halfYear;
|
||||
|
||||
/**
|
||||
* The year
|
||||
*/
|
||||
private int year;
|
||||
|
||||
protected AuditDateImpl()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public AuditDateImpl(Date date)
|
||||
{
|
||||
super();
|
||||
setDate(date);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditDate#getDate()
|
||||
*/
|
||||
public Date getDate()
|
||||
{
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date)
|
||||
{
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
cal.setTime(date);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
this.date = cal.getTime();
|
||||
|
||||
this.setDayOfYear(cal.get(Calendar.DAY_OF_YEAR));
|
||||
this.setDayOfMonth(cal.get(Calendar.DAY_OF_MONTH));
|
||||
this.setDayOfWeek(cal.get(Calendar.DAY_OF_WEEK));
|
||||
this.setMonth(cal.get(Calendar.MONTH));
|
||||
this.setHalfYear(getMonth() <= Calendar.JUNE ? 0 : 1);
|
||||
this.setQuarter((getMonth()/3));
|
||||
this.setWeekOfMonth(cal.get(Calendar.WEEK_OF_MONTH));
|
||||
this.setWeekOfYear(cal.get(Calendar.WEEK_OF_YEAR));
|
||||
this.setYear(cal.get(Calendar.YEAR));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditDate#getDayOfYear()
|
||||
*/
|
||||
public int getDayOfYear()
|
||||
{
|
||||
return dayOfYear;
|
||||
}
|
||||
|
||||
protected void setDayOfYear(int dayOfYear)
|
||||
{
|
||||
this.dayOfYear = dayOfYear;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditDate#getDayOfMonth()
|
||||
*/
|
||||
public int getDayOfMonth()
|
||||
{
|
||||
return dayOfMonth;
|
||||
}
|
||||
|
||||
protected void setDayOfMonth(int dayOfMonth)
|
||||
{
|
||||
this.dayOfMonth = dayOfMonth;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditDate#getDayOfWeek()
|
||||
*/
|
||||
public int getDayOfWeek()
|
||||
{
|
||||
return dayOfWeek;
|
||||
}
|
||||
|
||||
protected void setDayOfWeek(int dayOfWeek)
|
||||
{
|
||||
this.dayOfWeek = dayOfWeek;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditDate#getHalfYear()
|
||||
*/
|
||||
public int getHalfYear()
|
||||
{
|
||||
return halfYear;
|
||||
}
|
||||
|
||||
protected void setHalfYear(int halfYear)
|
||||
{
|
||||
this.halfYear = halfYear;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditDate#getId()
|
||||
*/
|
||||
public long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
protected void setId(long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditDate#getMonth()
|
||||
*/
|
||||
public int getMonth()
|
||||
{
|
||||
return month;
|
||||
}
|
||||
|
||||
protected void setMonth(int month)
|
||||
{
|
||||
this.month = month;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditDate#getQuarter()
|
||||
*/
|
||||
public int getQuarter()
|
||||
{
|
||||
return quarter;
|
||||
}
|
||||
|
||||
protected void setQuarter(int quarter)
|
||||
{
|
||||
this.quarter = quarter;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditDate#getWeekOfMonth()
|
||||
*/
|
||||
public int getWeekOfMonth()
|
||||
{
|
||||
return weekOfMonth;
|
||||
}
|
||||
|
||||
protected void setWeekOfMonth(int weekOfMonth)
|
||||
{
|
||||
this.weekOfMonth = weekOfMonth;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditDate#getWeekOfYear()
|
||||
*/
|
||||
public int getWeekOfYear()
|
||||
{
|
||||
return weekOfYear;
|
||||
}
|
||||
|
||||
protected void setWeekOfYear(int weekOfYear)
|
||||
{
|
||||
this.weekOfYear = weekOfYear;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditDate#getYear()
|
||||
*/
|
||||
public int getYear()
|
||||
{
|
||||
return year;
|
||||
}
|
||||
|
||||
protected void setYear(int year)
|
||||
{
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if(this == o)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(!(o instanceof AuditDateImpl))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
AuditDateImpl that = (AuditDateImpl)o;
|
||||
return EqualsHelper.nullSafeEquals(this.date, that.date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.date.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get the latest audit date
|
||||
*/
|
||||
public static AuditDateImpl getLatestDate(Session session)
|
||||
{
|
||||
Query query = session.getNamedQuery(HibernateAuditDAO.QUERY_LAST_AUDIT_DATE);
|
||||
return (AuditDateImpl) query.uniqueResult();
|
||||
}
|
||||
|
||||
}
|
74
source/java/org/alfresco/repo/audit/hibernate/AuditFact.java
Normal file
74
source/java/org/alfresco/repo/audit/hibernate/AuditFact.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.audit.hibernate;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public interface AuditFact
|
||||
{
|
||||
|
||||
public abstract String getArg1();
|
||||
|
||||
public abstract String getArg2();
|
||||
|
||||
public abstract String getArg3();
|
||||
|
||||
public abstract String getArg4();
|
||||
|
||||
public abstract String getArg5();
|
||||
|
||||
public abstract AuditConfig getAuditConfig();
|
||||
|
||||
public abstract AuditDate getAuditDate();
|
||||
|
||||
public abstract AuditSource getAuditSource();
|
||||
|
||||
public abstract String getClientInetAddress();
|
||||
|
||||
public abstract Date getDate();
|
||||
|
||||
public abstract String getException();
|
||||
|
||||
public abstract boolean isFail();
|
||||
|
||||
public abstract boolean isFiltered();
|
||||
|
||||
public abstract String getHostInetAddress();
|
||||
|
||||
public abstract long getId();
|
||||
|
||||
public abstract String getMessage();
|
||||
|
||||
public abstract String getNodeUUID();
|
||||
|
||||
public abstract String getPath();
|
||||
|
||||
public abstract String getReturnValue();
|
||||
|
||||
public abstract String getSerialisedURL();
|
||||
|
||||
public abstract String getSessionId();
|
||||
|
||||
public abstract String getStoreId();
|
||||
|
||||
public abstract String getStoreProtocol();
|
||||
|
||||
public abstract String getTransactionId();
|
||||
|
||||
public abstract String getUserId();
|
||||
|
||||
}
|
578
source/java/org/alfresco/repo/audit/hibernate/AuditFactImpl.java
Normal file
578
source/java/org/alfresco/repo/audit/hibernate/AuditFactImpl.java
Normal file
@@ -0,0 +1,578 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.audit.hibernate;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* An Audit fact Rely on standard equals and hash code as they should all be unique.
|
||||
*
|
||||
* @author Andy Hind
|
||||
*/
|
||||
public class AuditFactImpl implements AuditFact
|
||||
{
|
||||
private long id;
|
||||
|
||||
private AuditDate auditDate;
|
||||
|
||||
private AuditConfig auditConfig;
|
||||
|
||||
private AuditSource auditSource;
|
||||
|
||||
private String userId;
|
||||
|
||||
private Date date;
|
||||
|
||||
private String transactionId;
|
||||
|
||||
private String sessionId;
|
||||
|
||||
private String storeProtocol;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String nodeUUID;
|
||||
|
||||
private String path;
|
||||
|
||||
private boolean filtered;
|
||||
|
||||
private String returnValue;
|
||||
|
||||
private String arg1;
|
||||
|
||||
private String arg2;
|
||||
|
||||
private String arg3;
|
||||
|
||||
private String arg4;
|
||||
|
||||
private String arg5;
|
||||
|
||||
private boolean fail;
|
||||
|
||||
private String serialisedURL;
|
||||
|
||||
private String exception;
|
||||
|
||||
private String hostInetAddress;
|
||||
|
||||
private String clientInetAddress;
|
||||
|
||||
private String message;
|
||||
|
||||
public AuditFactImpl()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getArg1()
|
||||
*/
|
||||
public String getArg1()
|
||||
{
|
||||
return arg1;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setArg1(java.lang.String)
|
||||
*/
|
||||
public void setArg1(String arg1)
|
||||
{
|
||||
this.arg1 = arg1;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getArg2()
|
||||
*/
|
||||
public String getArg2()
|
||||
{
|
||||
return arg2;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setArg2(java.lang.String)
|
||||
*/
|
||||
public void setArg2(String arg2)
|
||||
{
|
||||
this.arg2 = arg2;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getArg3()
|
||||
*/
|
||||
public String getArg3()
|
||||
{
|
||||
return arg3;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setArg3(java.lang.String)
|
||||
*/
|
||||
public void setArg3(String arg3)
|
||||
{
|
||||
this.arg3 = arg3;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getArg4()
|
||||
*/
|
||||
public String getArg4()
|
||||
{
|
||||
return arg4;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setArg4(java.lang.String)
|
||||
*/
|
||||
public void setArg4(String arg4)
|
||||
{
|
||||
this.arg4 = arg4;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getArg5()
|
||||
*/
|
||||
public String getArg5()
|
||||
{
|
||||
return arg5;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setArg5(java.lang.String)
|
||||
*/
|
||||
public void setArg5(String arg5)
|
||||
{
|
||||
this.arg5 = arg5;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getAuditConfig()
|
||||
*/
|
||||
public AuditConfig getAuditConfig()
|
||||
{
|
||||
return auditConfig;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setAuditConfig(org.alfresco.repo.audit.hibernate.AuditConfig)
|
||||
*/
|
||||
public void setAuditConfig(AuditConfig auditConfig)
|
||||
{
|
||||
this.auditConfig = auditConfig;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getAuditDate()
|
||||
*/
|
||||
public AuditDate getAuditDate()
|
||||
{
|
||||
return auditDate;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setAuditDate(org.alfresco.repo.audit.hibernate.AuditDate)
|
||||
*/
|
||||
public void setAuditDate(AuditDate auditDate)
|
||||
{
|
||||
this.auditDate = auditDate;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getAuditSource()
|
||||
*/
|
||||
public AuditSource getAuditSource()
|
||||
{
|
||||
return auditSource;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setAuditSource(org.alfresco.repo.audit.hibernate.AuditSource)
|
||||
*/
|
||||
public void setAuditSource(AuditSource auditSource)
|
||||
{
|
||||
this.auditSource = auditSource;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getClientInetAddress()
|
||||
*/
|
||||
public String getClientInetAddress()
|
||||
{
|
||||
return clientInetAddress;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setClientInetAddress(java.net.InetAddress)
|
||||
*/
|
||||
public void setClientInetAddress(String clientInetAddress)
|
||||
{
|
||||
this.clientInetAddress = clientInetAddress;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getDate()
|
||||
*/
|
||||
public Date getDate()
|
||||
{
|
||||
return date;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setDate(java.util.Date)
|
||||
*/
|
||||
public void setDate(Date date)
|
||||
{
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getException()
|
||||
*/
|
||||
public String getException()
|
||||
{
|
||||
return exception;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setException(java.lang.String)
|
||||
*/
|
||||
public void setException(String exception)
|
||||
{
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#isFail()
|
||||
*/
|
||||
public boolean isFail()
|
||||
{
|
||||
return fail;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setFail(boolean)
|
||||
*/
|
||||
public void setFail(boolean fail)
|
||||
{
|
||||
this.fail = fail;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#isFiltered()
|
||||
*/
|
||||
public boolean isFiltered()
|
||||
{
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setFiltered(boolean)
|
||||
*/
|
||||
public void setFiltered(boolean filtered)
|
||||
{
|
||||
this.filtered = filtered;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getHostInetAddress()
|
||||
*/
|
||||
public String getHostInetAddress()
|
||||
{
|
||||
return hostInetAddress;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setHostInetAddress(java.net.InetAddress)
|
||||
*/
|
||||
public void setHostInetAddress(String hostInetAddress)
|
||||
{
|
||||
this.hostInetAddress = hostInetAddress;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getId()
|
||||
*/
|
||||
public long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
protected void setId(long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getMessage()
|
||||
*/
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setMessage(java.lang.String)
|
||||
*/
|
||||
public void setMessage(String message)
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getNodeGUID()
|
||||
*/
|
||||
public String getNodeUUID()
|
||||
{
|
||||
return nodeUUID;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setNodeGUID(java.lang.String)
|
||||
*/
|
||||
public void setNodeUUID(String nodeUUID)
|
||||
{
|
||||
this.nodeUUID = nodeUUID;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getPath()
|
||||
*/
|
||||
public String getPath()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setPath(java.lang.String)
|
||||
*/
|
||||
public void setPath(String path)
|
||||
{
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getReturnValue()
|
||||
*/
|
||||
public String getReturnValue()
|
||||
{
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setReturnValue(java.lang.String)
|
||||
*/
|
||||
public void setReturnValue(String returnValue)
|
||||
{
|
||||
this.returnValue = returnValue;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getSerialisedURL()
|
||||
*/
|
||||
public String getSerialisedURL()
|
||||
{
|
||||
return serialisedURL;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setSerialisedURL(java.lang.String)
|
||||
*/
|
||||
public void setSerialisedURL(String serialisedURL)
|
||||
{
|
||||
this.serialisedURL = serialisedURL;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getSessionId()
|
||||
*/
|
||||
public String getSessionId()
|
||||
{
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setSessionId(java.lang.String)
|
||||
*/
|
||||
public void setSessionId(String sessionId)
|
||||
{
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getStoreId()
|
||||
*/
|
||||
public String getStoreId()
|
||||
{
|
||||
return storeId;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setStoreId(java.lang.String)
|
||||
*/
|
||||
public void setStoreId(String storeId)
|
||||
{
|
||||
this.storeId = storeId;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getStoreProtocol()
|
||||
*/
|
||||
public String getStoreProtocol()
|
||||
{
|
||||
return storeProtocol;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setStoreProtocol(java.lang.String)
|
||||
*/
|
||||
public void setStoreProtocol(String storeProtocol)
|
||||
{
|
||||
this.storeProtocol = storeProtocol;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getTransactionId()
|
||||
*/
|
||||
public String getTransactionId()
|
||||
{
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setTransactionId(java.lang.String)
|
||||
*/
|
||||
public void setTransactionId(String transactionId)
|
||||
{
|
||||
this.transactionId = transactionId;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#getUserId()
|
||||
*/
|
||||
public String getUserId()
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.audit.hibernate.AuditFact#setUserId(java.lang.String)
|
||||
*/
|
||||
public void setUserId(String userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.audit.hibernate;
|
||||
|
||||
public interface AuditSource
|
||||
{
|
||||
public String getApplication();
|
||||
|
||||
public long getId();
|
||||
|
||||
public String getMethod();
|
||||
|
||||
public String getService();
|
||||
|
||||
}
|
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.audit.hibernate;
|
||||
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
|
||||
public class AuditSourceImpl implements AuditSource
|
||||
{
|
||||
/**
|
||||
* The surrogate key
|
||||
*/
|
||||
private long id;
|
||||
|
||||
/**
|
||||
* The auditing application (System for method audits)
|
||||
*/
|
||||
private String application;
|
||||
|
||||
/**
|
||||
* The audited service
|
||||
*/
|
||||
private String service;
|
||||
|
||||
/**
|
||||
* The audited method
|
||||
*/
|
||||
private String method;
|
||||
|
||||
public AuditSourceImpl()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public String getApplication()
|
||||
{
|
||||
return application;
|
||||
}
|
||||
|
||||
public void setApplication(String application)
|
||||
{
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
protected void setId(long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getMethod()
|
||||
{
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method)
|
||||
{
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getService()
|
||||
{
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service)
|
||||
{
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public static AuditSourceImpl getApplicationSource(Session session, String application)
|
||||
{
|
||||
Query query = session.getNamedQuery(HibernateAuditDAO.QUERY_AUDIT_APP_SOURCE);
|
||||
query.setParameter(HibernateAuditDAO.QUERY_AUDIT_APP_SOURCE_APP, application);
|
||||
return (AuditSourceImpl) query.uniqueResult();
|
||||
}
|
||||
|
||||
public static AuditSourceImpl getApplicationSource(Session session, String application, String service,
|
||||
String method)
|
||||
{
|
||||
Query query = session.getNamedQuery(HibernateAuditDAO.QUERY_AUDIT_METHOD_SOURCE);
|
||||
query.setParameter(HibernateAuditDAO.QUERY_AUDIT_APP_SOURCE_APP, application);
|
||||
query.setParameter(HibernateAuditDAO.QUERY_AUDIT_APP_SOURCE_SER, service);
|
||||
query.setParameter(HibernateAuditDAO.QUERY_AUDIT_APP_SOURCE_MET, method);
|
||||
return (AuditSourceImpl) query.uniqueResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof AuditSourceImpl))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
AuditSourceImpl other = (AuditSourceImpl) o;
|
||||
return EqualsHelper.nullSafeEquals(this.application, other.application)
|
||||
&& EqualsHelper.nullSafeEquals(this.service, other.service)
|
||||
&& EqualsHelper.nullSafeEquals(this.method, other.method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = application.hashCode();
|
||||
if(service != null)
|
||||
{
|
||||
hash = (hash * 37) + service.hashCode();
|
||||
}
|
||||
if(method != null)
|
||||
{
|
||||
hash = (hash * 37) + method.hashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,439 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.audit.hibernate;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.audit.AuditConfiguration;
|
||||
import org.alfresco.repo.audit.AuditDAO;
|
||||
import org.alfresco.repo.audit.AuditInfo;
|
||||
import org.alfresco.repo.content.AbstractContentStore;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.transaction.TransactionalDao;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.datatype.Duration;
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.hibernate.Session;
|
||||
import org.springframework.orm.hibernate3.HibernateCallback;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
/**
|
||||
* Assumes mimetype and encoding sent to the content store (we are not saving this anywhere)
|
||||
*
|
||||
* @author Andy Hind
|
||||
*/
|
||||
public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO, TransactionalDao
|
||||
{
|
||||
public static final String QUERY_LAST_AUDIT_DATE = "audit.GetLatestAuditDate";
|
||||
|
||||
public static final String QUERY_LAST_AUDIT_CONFIG = "audit.GetLatestAuditConfig";
|
||||
|
||||
public static final String QUERY_AUDIT_APP_SOURCE = "audit.GetAuditSourceByApplication";
|
||||
|
||||
public static final String QUERY_AUDIT_METHOD_SOURCE = "audit.GetAuditSourceByApplicationServiceMethod";
|
||||
|
||||
public static final String QUERY_AUDIT_APP_SOURCE_APP = "application";
|
||||
|
||||
public static final String QUERY_AUDIT_APP_SOURCE_SER = "service";
|
||||
|
||||
public static final String QUERY_AUDIT_APP_SOURCE_MET = "method";
|
||||
|
||||
/** a uuid identifying this unique instance */
|
||||
private String uuid;
|
||||
|
||||
private ContentStore contentStore;
|
||||
|
||||
private ThreadLocal<AuditConfiguration> auditConfiguration = new ThreadLocal<AuditConfiguration>();
|
||||
|
||||
private ThreadLocal<Long> auditConfigImplId = new ThreadLocal<Long>();
|
||||
|
||||
private ThreadLocal<Long> auditDateImplId = new ThreadLocal<Long>();
|
||||
|
||||
private ThreadLocal<HashMap<SourceKey, Long>> sourceIds = new ThreadLocal<HashMap<SourceKey, Long>>();
|
||||
|
||||
public HibernateAuditDAO()
|
||||
{
|
||||
super();
|
||||
this.uuid = GUID.generate();
|
||||
}
|
||||
|
||||
public ContentStore getContentStore()
|
||||
{
|
||||
return contentStore;
|
||||
}
|
||||
|
||||
public void setContentStore(ContentStore contentStore)
|
||||
{
|
||||
this.contentStore = contentStore;
|
||||
}
|
||||
|
||||
public void audit(AuditInfo auditInfo)
|
||||
{
|
||||
// Find/Build the configuraton entry
|
||||
AuditConfigImpl auditConfig = getAuditConfig(auditInfo);
|
||||
|
||||
// Find/Build any dates
|
||||
AuditDateImpl auditDate = getAuditDate(auditInfo);
|
||||
|
||||
// Find/Build the source
|
||||
AuditSourceImpl auditSource = getAuditSource(auditInfo);
|
||||
|
||||
// Build the new audit fact information
|
||||
AuditFactImpl auditFact = new AuditFactImpl();
|
||||
auditFact.setAuditConfig(auditConfig);
|
||||
auditFact.setAuditDate(auditDate);
|
||||
auditFact.setAuditSource(auditSource);
|
||||
|
||||
// Properties
|
||||
|
||||
Serializable[] args = auditInfo.getMethodArguments();
|
||||
|
||||
if (args != null)
|
||||
{
|
||||
switch (args.length)
|
||||
{
|
||||
default:
|
||||
case 5:
|
||||
auditFact.setArg5(getStringOrNull(args[4]));
|
||||
case 4:
|
||||
auditFact.setArg4(getStringOrNull(args[3]));
|
||||
case 3:
|
||||
auditFact.setArg3(getStringOrNull(args[2]));
|
||||
case 2:
|
||||
auditFact.setArg2(getStringOrNull(args[1]));
|
||||
case 1:
|
||||
auditFact.setArg1(getStringOrNull(args[0]));
|
||||
case 0:
|
||||
}
|
||||
}
|
||||
|
||||
auditFact.setClientInetAddress(auditInfo.getClientAddress() == null ? null : auditInfo.getClientAddress()
|
||||
.toString());
|
||||
auditFact.setDate(auditInfo.getDate());
|
||||
auditFact.setException(auditInfo.getThrowable() == null ? null : auditInfo.getThrowable().getMessage());
|
||||
auditFact.setFail(auditInfo.isFail());
|
||||
auditFact.setFiltered(auditInfo.isFiltered());
|
||||
auditFact.setHostInetAddress(auditInfo.getHostAddress() == null ? null : auditInfo.getHostAddress().toString());
|
||||
auditFact.setMessage(auditInfo.getMessage());
|
||||
auditFact.setNodeUUID(auditInfo.getKeyGUID());
|
||||
auditFact.setPath(auditInfo.getPath());
|
||||
auditFact.setReturnValue(auditInfo.getReturnObject() == null ? null : auditInfo.getReturnObject().toString());
|
||||
// auditFact.setSerialisedURL()
|
||||
auditFact.setSessionId(auditInfo.getSessionId());
|
||||
if (auditInfo.getKeyStore() != null)
|
||||
{
|
||||
auditFact.setStoreId(auditInfo.getKeyStore().getIdentifier());
|
||||
auditFact.setStoreProtocol(auditInfo.getKeyStore().getProtocol());
|
||||
}
|
||||
auditFact.setTransactionId(auditInfo.getTxId());
|
||||
auditFact.setUserId(auditInfo.getUserIdentifier());
|
||||
|
||||
// Save
|
||||
getSession().save(auditFact);
|
||||
|
||||
}
|
||||
|
||||
private String getStringOrNull(Object o)
|
||||
{
|
||||
if (o == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return o.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private AuditSourceImpl getAuditSource(AuditInfo auditInfo)
|
||||
{
|
||||
AuditSourceImpl auditSourceImpl;
|
||||
|
||||
SourceKey sourceKey = new SourceKey(auditInfo.getAuditApplication(), auditInfo.getAuditService(), auditInfo.getAuditMethod());
|
||||
if(sourceIds.get() == null)
|
||||
{
|
||||
sourceIds.set(new HashMap<SourceKey, Long>());
|
||||
}
|
||||
Long id = sourceIds.get().get(sourceKey);
|
||||
if(id != null)
|
||||
{
|
||||
auditSourceImpl = (AuditSourceImpl) getSession().get(AuditSourceImpl.class, id.longValue());
|
||||
if(auditSourceImpl != null)
|
||||
{
|
||||
return auditSourceImpl;
|
||||
}
|
||||
}
|
||||
|
||||
if ((auditInfo.getAuditService() != null)
|
||||
&& (auditInfo.getAuditService().length() > 0) && (auditInfo.getAuditMethod() != null)
|
||||
&& (auditInfo.getAuditMethod().length() > 0))
|
||||
{
|
||||
auditSourceImpl = AuditSourceImpl.getApplicationSource(getSession(), auditInfo.getAuditApplication(),
|
||||
auditInfo.getAuditService(), auditInfo.getAuditMethod());
|
||||
if (auditSourceImpl == null)
|
||||
{
|
||||
auditSourceImpl = new AuditSourceImpl();
|
||||
auditSourceImpl.setApplication(auditInfo.getAuditApplication());
|
||||
auditSourceImpl.setService(auditInfo.getAuditService());
|
||||
auditSourceImpl.setMethod(auditInfo.getAuditMethod());
|
||||
getSession().save(auditSourceImpl);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auditSourceImpl = AuditSourceImpl.getApplicationSource(getSession(), auditInfo.getAuditApplication());
|
||||
if (auditSourceImpl == null)
|
||||
{
|
||||
auditSourceImpl = new AuditSourceImpl();
|
||||
auditSourceImpl.setApplication(auditInfo.getAuditApplication());
|
||||
getSession().save(auditSourceImpl);
|
||||
}
|
||||
}
|
||||
sourceIds.get().put(sourceKey, Long.valueOf(auditSourceImpl.getId()));
|
||||
return auditSourceImpl;
|
||||
}
|
||||
|
||||
private AuditDateImpl getAuditDate(AuditInfo auditInfo)
|
||||
{
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
cal.setTime(auditInfo.getDate());
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
Date required = cal.getTime();
|
||||
|
||||
AuditDateImpl auditDate;
|
||||
if (auditDateImplId.get() == null)
|
||||
{
|
||||
auditDate = AuditDateImpl.getLatestDate(getSession());
|
||||
if (auditDate == null)
|
||||
{
|
||||
// The first entry ever so we just make it
|
||||
auditDate = new AuditDateImpl(auditInfo.getDate());
|
||||
getSession().save(auditDate);
|
||||
}
|
||||
auditDateImplId.set(Long.valueOf(auditDate.getId()));
|
||||
}
|
||||
else
|
||||
{
|
||||
auditDate = (AuditDateImpl) getSession().get(AuditDateImpl.class, auditDateImplId.get().longValue());
|
||||
if ((auditDate == null) || (!required.equals(auditDate.getDate())))
|
||||
{
|
||||
auditDate = AuditDateImpl.getLatestDate(getSession());
|
||||
if (auditDate == null)
|
||||
{
|
||||
// The first entry ever so we just make it
|
||||
auditDate = new AuditDateImpl(auditInfo.getDate());
|
||||
getSession().save(auditDate);
|
||||
}
|
||||
auditDateImplId.set(Long.valueOf(auditDate.getId()));
|
||||
}
|
||||
}
|
||||
while (!required.equals(auditDate.getDate()))
|
||||
{
|
||||
Date nextDate = Duration.add(auditDate.getDate(), new Duration("P1D"));
|
||||
auditDate = new AuditDateImpl(nextDate);
|
||||
getSession().save(auditDate);
|
||||
auditDateImplId.set(Long.valueOf(auditDate.getId()));
|
||||
}
|
||||
return auditDate;
|
||||
}
|
||||
|
||||
private AuditConfigImpl getAuditConfig(AuditInfo auditInfo)
|
||||
{
|
||||
AuditConfigImpl auditConfig;
|
||||
if ((auditConfiguration.get() == null) || (auditConfiguration.get() != auditInfo.getAuditConfiguration()))
|
||||
{
|
||||
auditConfig = AuditConfigImpl.getLatestConfig(getSession());
|
||||
if (auditConfig == null)
|
||||
{
|
||||
auditConfig = createNewAuditConfigImpl(auditInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
InputStream current = new BufferedInputStream(auditInfo.getAuditConfiguration().getInputStream());
|
||||
ContentReader reader = contentStore.getReader(auditConfig.getConfigURL());
|
||||
reader.setMimetype(MimetypeMap.MIMETYPE_XML);
|
||||
reader.setEncoding("UTF-8");
|
||||
InputStream last = new BufferedInputStream(reader.getContentInputStream());
|
||||
int currentValue = -2;
|
||||
int lastValue = -2;
|
||||
try
|
||||
{
|
||||
while ((currentValue != -1) && (lastValue != -1) && (currentValue == lastValue))
|
||||
{
|
||||
currentValue = current.read();
|
||||
lastValue = last.read();
|
||||
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new AlfrescoRuntimeException(
|
||||
"Failed to read and validate current audit configuration against the last", e);
|
||||
}
|
||||
if (currentValue != lastValue)
|
||||
{
|
||||
// Files are different - require a new entry
|
||||
auditConfig = createNewAuditConfigImpl(auditInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No change
|
||||
}
|
||||
}
|
||||
auditConfigImplId.set(Long.valueOf(auditConfig.getId()));
|
||||
auditConfiguration.set(auditInfo.getAuditConfiguration());
|
||||
}
|
||||
else
|
||||
{
|
||||
auditConfig = (AuditConfigImpl) getSession()
|
||||
.get(AuditConfigImpl.class, auditConfigImplId.get().longValue());
|
||||
if (auditConfig == null)
|
||||
{
|
||||
auditConfig = createNewAuditConfigImpl(auditInfo);
|
||||
}
|
||||
}
|
||||
return auditConfig;
|
||||
}
|
||||
|
||||
private AuditConfigImpl createNewAuditConfigImpl(AuditInfo auditInfo)
|
||||
{
|
||||
AuditConfigImpl auditConfig = new AuditConfigImpl();
|
||||
InputStream is = new BufferedInputStream(auditInfo.getAuditConfiguration().getInputStream());
|
||||
String url = AbstractContentStore.createNewUrl();
|
||||
ContentWriter writer = contentStore.getWriter(null, url);
|
||||
writer.setMimetype(MimetypeMap.MIMETYPE_XML);
|
||||
writer.setEncoding("UTF-8");
|
||||
writer.putContent(is);
|
||||
auditConfig.setConfigURL(url);
|
||||
getSession().save(auditConfig);
|
||||
return auditConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks equality by type and uuid
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!(obj instanceof HibernateAuditDAO))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
HibernateAuditDAO that = (HibernateAuditDAO) obj;
|
||||
return this.uuid.equals(that.uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #uuid
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return uuid.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this <tt>Session</tt> contain any changes which must be synchronized with the store?
|
||||
*
|
||||
* @return true => changes are pending
|
||||
*/
|
||||
public boolean isDirty()
|
||||
{
|
||||
// create a callback for the task
|
||||
HibernateCallback callback = new HibernateCallback()
|
||||
{
|
||||
public Object doInHibernate(Session session)
|
||||
{
|
||||
return session.isDirty();
|
||||
}
|
||||
};
|
||||
// execute the callback
|
||||
return ((Boolean) getHibernateTemplate().execute(callback)).booleanValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Just flushes the session
|
||||
*/
|
||||
public void flush()
|
||||
{
|
||||
getSession().flush();
|
||||
}
|
||||
|
||||
static class SourceKey
|
||||
{
|
||||
String application;
|
||||
|
||||
String service;
|
||||
|
||||
String method;
|
||||
|
||||
SourceKey(String application, String service, String method)
|
||||
{
|
||||
this.application = application;
|
||||
this.service = service;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!(this instanceof SourceKey))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
SourceKey other = (SourceKey) o;
|
||||
return EqualsHelper.nullSafeEquals(this.application, other.application)
|
||||
&& EqualsHelper.nullSafeEquals(this.service, other.service)
|
||||
&& EqualsHelper.nullSafeEquals(this.method, other.method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = application.hashCode();
|
||||
if (service != null)
|
||||
{
|
||||
hash = (hash * 37) + service.hashCode();
|
||||
}
|
||||
if (method != null)
|
||||
{
|
||||
hash = (hash * 37) + method.hashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user