mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Audit DAO
- Audit config (alf_audit_cfg) now uses CRC check and persists via ContentService and alf_content_data - Reverted 3.3 references back to 3.2 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@15805 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -55,4 +55,10 @@
|
|||||||
<property name="propertyValueCache" ref="immutableEntityCache"/>
|
<property name="propertyValueCache" ref="immutableEntityCache"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="auditDAO" class="org.alfresco.repo.domain.audit.ibatis.AuditDAOImpl">
|
||||||
|
<property name="sqlMapClientTemplate" ref="auditSqlMapClientTemplate"/>
|
||||||
|
<property name="contentService" ref="contentService"/>
|
||||||
|
<property name="contentDataDAO" ref="contentDataDAO"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
@@ -0,0 +1,30 @@
|
|||||||
|
--
|
||||||
|
-- Title: Audit tables
|
||||||
|
-- Database: MySQL InnoDB
|
||||||
|
-- Since: V3.2 Schema 3002
|
||||||
|
-- Author: Derek Hulley
|
||||||
|
--
|
||||||
|
-- Please contact support@alfresco.com if you need assistance with the upgrade.
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE alf_audit_cfg
|
||||||
|
(
|
||||||
|
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||||
|
content_data_id BIGINT NOT NULL,
|
||||||
|
content_crc BIGINT NOT NULL,
|
||||||
|
UNIQUE INDEX idx_alf_audit_cfg_crc (content_crc),
|
||||||
|
CONSTRAINT fk_alf_audit_cfg_cd FOREIGN KEY (content_data_id) REFERENCES alf_content_data (id),
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Record script finish
|
||||||
|
--
|
||||||
|
DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.2-AuditTables';
|
||||||
|
INSERT INTO alf_applied_patch
|
||||||
|
(id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
'patch.db-V3.2-AuditTables', 'Manually executed script upgrade V3.2: Audit Tables',
|
||||||
|
0, 3001, -1, 3002, null, 'UNKOWN', 1, 1, 'Script completed'
|
||||||
|
);
|
@@ -1,7 +1,7 @@
|
|||||||
--
|
--
|
||||||
-- Title: Property Value tables
|
-- Title: Property Value tables
|
||||||
-- Database: MySQL InnoDB
|
-- Database: MySQL InnoDB
|
||||||
-- Since: V3.3 Schema 3001
|
-- Since: V3.2 Schema 3001
|
||||||
-- Author: Derek Hulley
|
-- Author: Derek Hulley
|
||||||
--
|
--
|
||||||
-- Please contact support@alfresco.com if you need assistance with the upgrade.
|
-- Please contact support@alfresco.com if you need assistance with the upgrade.
|
||||||
@@ -81,11 +81,11 @@ CREATE TABLE alf_prop_link
|
|||||||
--
|
--
|
||||||
-- Record script finish
|
-- Record script finish
|
||||||
--
|
--
|
||||||
-- DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.3-PropertyValueTables';
|
DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.2-PropertyValueTables';
|
||||||
-- INSERT INTO alf_applied_patch
|
INSERT INTO alf_applied_patch
|
||||||
-- (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report)
|
(id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report)
|
||||||
-- VALUES
|
VALUES
|
||||||
-- (
|
(
|
||||||
-- 'patch.db-V3.3-PropertyValueTables', 'Manually executed script upgrade V3.3: PropertyValue Tables',
|
'patch.db-V3.2-PropertyValueTables', 'Manually executed script upgrade V3.2: PropertyValue Tables',
|
||||||
-- 0, 3000, -1, 3001, null, 'UNKOWN', 1, 1, 'Script completed'
|
0, 3000, -1, 3001, null, 'UNKOWN', 1, 1, 'Script completed'
|
||||||
-- );
|
);
|
12
config/alfresco/ibatis/audit-SqlMapConfig.xml
Normal file
12
config/alfresco/ibatis/audit-SqlMapConfig.xml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<!DOCTYPE sqlMapConfig
|
||||||
|
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
|
||||||
|
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
|
||||||
|
|
||||||
|
<sqlMapConfig>
|
||||||
|
|
||||||
|
<sqlMap resource="alfresco/ibatis/#resource.dialect#/audit-common-SqlMap.xml"/>
|
||||||
|
<sqlMap resource="alfresco/ibatis/#resource.dialect#/audit-insert-SqlMap.xml"/>
|
||||||
|
|
||||||
|
</sqlMapConfig>
|
@@ -86,4 +86,16 @@
|
|||||||
<property name="sqlMapClient" ref="propertyValueSqlMapClient"/>
|
<property name="sqlMapClient" ref="propertyValueSqlMapClient"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<!-- iBatis config for Audit domain -->
|
||||||
|
<bean id="auditSqlMapClient" class="org.alfresco.ibatis.HierarchicalSqlMapClientFactoryBean">
|
||||||
|
<property name="dataSource" ref="dataSource"/>
|
||||||
|
<property name="resourceLoader" ref="dialectResourceLoader" />
|
||||||
|
<property name="configLocation">
|
||||||
|
<value>classpath:alfresco/ibatis/audit-SqlMapConfig.xml</value>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
<bean id="auditSqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
|
||||||
|
<property name="sqlMapClient" ref="auditSqlMapClient"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
@@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<!DOCTYPE sqlMap
|
||||||
|
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
|
||||||
|
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
|
||||||
|
|
||||||
|
<sqlMap namespace="alfresco.audit">
|
||||||
|
|
||||||
|
<!-- -->
|
||||||
|
<!-- Type Defs -->
|
||||||
|
<!-- -->
|
||||||
|
|
||||||
|
<typeAlias alias="AuditConfig" type="org.alfresco.repo.domain.audit.AuditConfigEntity"/>
|
||||||
|
|
||||||
|
<!-- -->
|
||||||
|
<!-- Result Maps -->
|
||||||
|
<!-- -->
|
||||||
|
|
||||||
|
<resultMap id="result.AuditConfig" class="AuditConfig">
|
||||||
|
<result property="id" column="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
|
||||||
|
<result property="contentDataId" column="content_data_id" jdbcType="BIGINT" javaType="java.lang.Long"/>
|
||||||
|
<result property="contentCrc" column="content_crc" jdbcType="BIGINT" javaType="long"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- -->
|
||||||
|
<!-- Parameter Maps -->
|
||||||
|
<!-- -->
|
||||||
|
|
||||||
|
<parameterMap id="parameter.IdMap" class="map">
|
||||||
|
<parameter property="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
|
||||||
|
</parameterMap>
|
||||||
|
|
||||||
|
<!-- -->
|
||||||
|
<!-- SQL Snippets -->
|
||||||
|
<!-- -->
|
||||||
|
|
||||||
|
<sql id="insert.AuditConfig.AutoIncrement">
|
||||||
|
insert into alf_audit_cfg (content_data_id, content_crc)
|
||||||
|
values (#contentDataId#, #contentCrc#)
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<!-- -->
|
||||||
|
<!-- Statements -->
|
||||||
|
<!-- -->
|
||||||
|
|
||||||
|
<!-- Get the mimetype entity by mimetype -->
|
||||||
|
<select id="select.AuditConfigByCrc" parameterClass="AuditConfig" resultMap="result.AuditConfig">
|
||||||
|
select
|
||||||
|
*
|
||||||
|
from
|
||||||
|
alf_audit_cfg
|
||||||
|
where
|
||||||
|
content_crc = #contentCrc#
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</sqlMap>
|
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<!DOCTYPE sqlMap
|
||||||
|
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
|
||||||
|
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
|
||||||
|
|
||||||
|
<sqlMap namespace="alfresco.audit">
|
||||||
|
|
||||||
|
<insert id="insert.AuditConfig" parameterClass="AuditConfig" >
|
||||||
|
<include refid="insert.AuditConfig.AutoIncrement"/>
|
||||||
|
<selectKey resultClass="long" keyProperty="id" type="post">
|
||||||
|
KEY_COLUMN:GENERATED_KEY
|
||||||
|
</selectKey>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
</sqlMap>
|
@@ -1969,15 +1969,27 @@
|
|||||||
<property name="scriptsACP"><value>alfresco/templates/imap/command_processor_scripts.acp</value></property>
|
<property name="scriptsACP"><value>alfresco/templates/imap/command_processor_scripts.acp</value></property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="patch.db-V3.3-PropertyValueTables" class="org.alfresco.repo.admin.patch.impl.SchemaUpgradeScriptPatch" parent="basePatch">
|
<bean id="patch.db-V3.2-PropertyValueTables" class="org.alfresco.repo.admin.patch.impl.SchemaUpgradeScriptPatch" parent="basePatch">
|
||||||
<property name="id"><value>patch.db-V3.3-PropertyValueTables</value></property>
|
<property name="id"><value>patch.db-V3.2-PropertyValueTables</value></property>
|
||||||
<property name="description"><value>patch.schemaUpgradeScript.description</value></property>
|
<property name="description"><value>patch.schemaUpgradeScript.description</value></property>
|
||||||
<property name="fixesFromSchema"><value>0</value></property>
|
<property name="fixesFromSchema"><value>0</value></property>
|
||||||
<property name="fixesToSchema"><value>3000</value></property>
|
<property name="fixesToSchema"><value>3000</value></property>
|
||||||
<property name="targetSchema"><value>3001</value></property>
|
<property name="targetSchema"><value>3001</value></property>
|
||||||
<property name="scriptUrl">
|
<property name="scriptUrl">
|
||||||
<!-- Share a create script -->
|
<!-- Share a create script -->
|
||||||
<value>classpath:alfresco/dbscripts/create/3.3/${db.script.dialect}/AlfrescoPostCreate-3.3-PropertyValueTables.sql</value>
|
<value>classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-PropertyValueTables.sql</value>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="patch.db-V3.2-AuditTables" class="org.alfresco.repo.admin.patch.impl.SchemaUpgradeScriptPatch" parent="basePatch">
|
||||||
|
<property name="id"><value>patch.db-V3.2-AuditTables</value></property>
|
||||||
|
<property name="description"><value>patch.schemaUpgradeScript.description</value></property>
|
||||||
|
<property name="fixesFromSchema"><value>0</value></property>
|
||||||
|
<property name="fixesToSchema"><value>3001</value></property>
|
||||||
|
<property name="targetSchema"><value>3002</value></property>
|
||||||
|
<property name="scriptUrl">
|
||||||
|
<!-- Share a create script -->
|
||||||
|
<value>classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-AuditTables.sql</value>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
# Version label
|
# Version label
|
||||||
|
|
||||||
version.major=3
|
version.major=3
|
||||||
version.minor=3
|
version.minor=2
|
||||||
version.revision=0
|
version.revision=0
|
||||||
version.label=
|
version.label=
|
||||||
|
|
||||||
@@ -19,4 +19,4 @@ version.build=@build-number@
|
|||||||
|
|
||||||
# Schema number
|
# Schema number
|
||||||
|
|
||||||
version.schema=3001
|
version.schema=3002
|
||||||
|
@@ -32,7 +32,7 @@ import org.alfresco.util.Pair;
|
|||||||
* Helper class to calculate CRC values for string persistence.
|
* Helper class to calculate CRC values for string persistence.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class CrcHelper
|
public class CrcHelper
|
||||||
{
|
{
|
||||||
|
@@ -0,0 +1,150 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
* As a special exception to the terms and conditions of version 2.0 of
|
||||||
|
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||||
|
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||||
|
* FLOSS exception. You should have recieved a copy of the text describing
|
||||||
|
* the FLOSS exception, and it is also available here:
|
||||||
|
* http://www.alfresco.com/legal/licensing"
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.domain.audit;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.zip.CRC32;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
|
import org.alfresco.repo.domain.contentdata.ContentDataDAO;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentData;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentService;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
|
import org.alfresco.util.Pair;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract helper DAO for <b>alf_audit_XXX</b> tables.
|
||||||
|
*
|
||||||
|
* @author Derek Hulley
|
||||||
|
* @since 3.2
|
||||||
|
*/
|
||||||
|
public abstract class AbstractAuditDAOImpl implements AuditDAO
|
||||||
|
{
|
||||||
|
private static final Log logger = LogFactory.getLog(AbstractAuditDAOImpl.class);
|
||||||
|
|
||||||
|
private ContentService contentService;
|
||||||
|
private ContentDataDAO contentDataDAO;
|
||||||
|
|
||||||
|
public void setContentService(ContentService contentService)
|
||||||
|
{
|
||||||
|
this.contentService = contentService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContentDataDAO(ContentDataDAO contentDataDAO)
|
||||||
|
{
|
||||||
|
this.contentDataDAO = contentDataDAO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public Pair<Long, ContentData> getOrCreateAuditConfig(URL url)
|
||||||
|
{
|
||||||
|
InputStream is = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
is = url.openStream();
|
||||||
|
// Calculate the CRC and find an entry that matches
|
||||||
|
CRC32 crcCalc = new CRC32();
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int read = -1;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
read = is.read(buffer);
|
||||||
|
if (read < 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
crcCalc.update(buffer, 0, read);
|
||||||
|
}
|
||||||
|
while (true);
|
||||||
|
long crc = crcCalc.getValue();
|
||||||
|
// Find an existing entry
|
||||||
|
AuditConfigEntity existingEntity = getAuditConfigByCrc(crc);
|
||||||
|
if (existingEntity != null)
|
||||||
|
{
|
||||||
|
Long existingEntityId = existingEntity.getId();
|
||||||
|
// Locate the content
|
||||||
|
ContentData existingContentData = contentDataDAO.getContentData(
|
||||||
|
existingEntity.getContentDataId()
|
||||||
|
).getSecond();
|
||||||
|
Pair<Long, ContentData> result = new Pair<Long, ContentData>(existingEntityId, existingContentData);
|
||||||
|
// Done
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug(
|
||||||
|
"Found existing configuration with same CRC: \n" +
|
||||||
|
" URL: " + url + "\n" +
|
||||||
|
" CRC: " + crc + "\n" +
|
||||||
|
" Result: " + result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Upload the content afresh
|
||||||
|
is.close();
|
||||||
|
is = url.openStream();
|
||||||
|
ContentWriter writer = contentService.getWriter(null, null, false);
|
||||||
|
writer.setEncoding("UTF-8");
|
||||||
|
writer.setMimetype(MimetypeMap.MIMETYPE_XML);
|
||||||
|
writer.putContent(is);
|
||||||
|
ContentData newContentData = writer.getContentData();
|
||||||
|
Long newContentDataId = contentDataDAO.createContentData(newContentData).getFirst();
|
||||||
|
AuditConfigEntity newEntity = createAuditConfig(newContentDataId, crc);
|
||||||
|
Pair<Long, ContentData> result = new Pair<Long, ContentData>(newEntity.getId(), newContentData);
|
||||||
|
// Done
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug(
|
||||||
|
"Created new audit config: \n" +
|
||||||
|
" URL: " + url + "\n" +
|
||||||
|
" CRC: " + crc + "\n" +
|
||||||
|
" Result: " + result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Failed to read Audit configuration: " + url);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (is != null)
|
||||||
|
{
|
||||||
|
try { is.close(); } catch (Throwable e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract AuditConfigEntity getAuditConfigByCrc(long crc);
|
||||||
|
protected abstract AuditConfigEntity createAuditConfig(Long contentDataId, long crc);
|
||||||
|
}
|
@@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
* As a special exception to the terms and conditions of version 2.0 of
|
||||||
|
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||||
|
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||||
|
* FLOSS exception. You should have recieved a copy of the text describing
|
||||||
|
* the FLOSS exception, and it is also available here:
|
||||||
|
* http://www.alfresco.com/legal/licensing"
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.domain.audit;
|
||||||
|
|
||||||
|
import org.alfresco.util.EqualsHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity bean for <b>alf_audit_cfg</b> table.
|
||||||
|
*
|
||||||
|
* @author Derek Hulley
|
||||||
|
* @since 3.2
|
||||||
|
*/
|
||||||
|
public class AuditConfigEntity
|
||||||
|
{
|
||||||
|
private Long id;
|
||||||
|
private Long contentDataId;
|
||||||
|
private long contentCrc;
|
||||||
|
|
||||||
|
public AuditConfigEntity()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return (int) contentCrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if (this == obj)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (obj instanceof AuditConfigEntity)
|
||||||
|
{
|
||||||
|
AuditConfigEntity that = (AuditConfigEntity) obj;
|
||||||
|
return EqualsHelper.nullSafeEquals(this.id, that.id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder(512);
|
||||||
|
sb.append("AuditConfigEntity")
|
||||||
|
.append("[ ID=").append(id)
|
||||||
|
.append(", contentDataId=").append(contentDataId)
|
||||||
|
.append(", contentCrc=").append(contentCrc)
|
||||||
|
.append("]");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getContentDataId()
|
||||||
|
{
|
||||||
|
return contentDataId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContentDataId(Long contentDataId)
|
||||||
|
{
|
||||||
|
this.contentDataId = contentDataId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getContentCrc()
|
||||||
|
{
|
||||||
|
return contentCrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContentCrc(long contentCrc)
|
||||||
|
{
|
||||||
|
this.contentCrc = contentCrc;
|
||||||
|
}
|
||||||
|
}
|
48
source/java/org/alfresco/repo/domain/audit/AuditDAO.java
Normal file
48
source/java/org/alfresco/repo/domain/audit/AuditDAO.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
* As a special exception to the terms and conditions of version 2.0 of
|
||||||
|
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||||
|
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||||
|
* FLOSS exception. You should have recieved a copy of the text describing
|
||||||
|
* the FLOSS exception, and it is also available here:
|
||||||
|
* http://www.alfresco.com/legal/licensing"
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.domain.audit;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.repository.ContentData;
|
||||||
|
import org.alfresco.util.Pair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DAO services for <b>alf_audit_XXX</b> tables.
|
||||||
|
*
|
||||||
|
* @author Derek Hulley
|
||||||
|
* @since 3.2
|
||||||
|
*/
|
||||||
|
public interface AuditDAO
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Creates a new audit config entry or finds an existing one
|
||||||
|
*
|
||||||
|
* @param the URL of the configuration
|
||||||
|
* @return Returns the ID of the config matching the input stream and the
|
||||||
|
* content storage details
|
||||||
|
*/
|
||||||
|
Pair<Long, ContentData> getOrCreateAuditConfig(URL url);
|
||||||
|
}
|
87
source/java/org/alfresco/repo/domain/audit/AuditDAOTest.java
Normal file
87
source/java/org/alfresco/repo/domain/audit/AuditDAOTest.java
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
* As a special exception to the terms and conditions of version 2.0 of
|
||||||
|
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||||
|
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||||
|
* FLOSS exception. You should have recieved a copy of the text describing
|
||||||
|
* the FLOSS exception, and it is also available here:
|
||||||
|
* http://www.alfresco.com/legal/licensing"
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.domain.audit;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
|
||||||
|
import org.alfresco.repo.domain.contentdata.ContentDataDAO;
|
||||||
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||||
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentData;
|
||||||
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
|
import org.alfresco.util.ApplicationContextHelper;
|
||||||
|
import org.alfresco.util.Pair;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ContentDataDAO
|
||||||
|
*
|
||||||
|
* @author Derek Hulley
|
||||||
|
* @since 3.2
|
||||||
|
*/
|
||||||
|
public class AuditDAOTest extends TestCase
|
||||||
|
{
|
||||||
|
private ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) ApplicationContextHelper.getApplicationContext();
|
||||||
|
|
||||||
|
private TransactionService transactionService;
|
||||||
|
private RetryingTransactionHelper txnHelper;
|
||||||
|
private AuditDAO auditDAO;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() throws Exception
|
||||||
|
{
|
||||||
|
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||||
|
transactionService = serviceRegistry.getTransactionService();
|
||||||
|
txnHelper = transactionService.getRetryingTransactionHelper();
|
||||||
|
|
||||||
|
auditDAO = (AuditDAO) ctx.getBean("auditDAO");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAuditConfig() throws Exception
|
||||||
|
{
|
||||||
|
final File file = AbstractContentTransformerTest.loadQuickTestFile("pdf");
|
||||||
|
assertNotNull(file);
|
||||||
|
final URL url = new URL("file:" + file.getAbsolutePath());
|
||||||
|
RetryingTransactionCallback<Pair<Long, ContentData>> callback = new RetryingTransactionCallback<Pair<Long, ContentData>>()
|
||||||
|
{
|
||||||
|
public Pair<Long, ContentData> execute() throws Throwable
|
||||||
|
{
|
||||||
|
Pair<Long, ContentData> contentDataPair = auditDAO.getOrCreateAuditConfig(url);
|
||||||
|
return contentDataPair;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Pair<Long, ContentData> configPair = txnHelper.doInTransaction(callback);
|
||||||
|
assertNotNull(configPair);
|
||||||
|
// Now repeat. The results should be exactly the same.
|
||||||
|
Pair<Long, ContentData> configPairCheck = txnHelper.doInTransaction(callback);
|
||||||
|
assertNotNull(configPairCheck);
|
||||||
|
assertEquals(configPair, configPairCheck);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
* As a special exception to the terms and conditions of version 2.0 of
|
||||||
|
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||||
|
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||||
|
* FLOSS exception. You should have recieved a copy of the text describing
|
||||||
|
* the FLOSS exception, and it is also available here:
|
||||||
|
* http://www.alfresco.com/legal/licensing"
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.domain.audit.ibatis;
|
||||||
|
|
||||||
|
import org.alfresco.repo.domain.audit.AbstractAuditDAOImpl;
|
||||||
|
import org.alfresco.repo.domain.audit.AuditConfigEntity;
|
||||||
|
import org.springframework.orm.ibatis.SqlMapClientTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iBatis-specific implementation of the DAO for <b>alf_audit_XXX</b> tables.
|
||||||
|
*
|
||||||
|
* @author Derek Hulley
|
||||||
|
* @since 3.2
|
||||||
|
*/
|
||||||
|
public class AuditDAOImpl extends AbstractAuditDAOImpl
|
||||||
|
{
|
||||||
|
private static final String SELECT_CONFIG_BY_CRC = "select.AuditConfigByCrc";
|
||||||
|
private static final String INSERT_CONFIG = "insert.AuditConfig";
|
||||||
|
|
||||||
|
private SqlMapClientTemplate template;
|
||||||
|
|
||||||
|
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
|
||||||
|
{
|
||||||
|
this.template = sqlMapClientTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AuditConfigEntity getAuditConfigByCrc(long crc)
|
||||||
|
{
|
||||||
|
AuditConfigEntity entity = new AuditConfigEntity();
|
||||||
|
entity.setContentCrc(crc);
|
||||||
|
entity = (AuditConfigEntity) template.queryForObject(
|
||||||
|
SELECT_CONFIG_BY_CRC,
|
||||||
|
entity);
|
||||||
|
// Done
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AuditConfigEntity createAuditConfig(Long contentDataId, long crc)
|
||||||
|
{
|
||||||
|
AuditConfigEntity entity = new AuditConfigEntity();
|
||||||
|
entity.setContentDataId(contentDataId);
|
||||||
|
entity.setContentCrc(crc);
|
||||||
|
Long id = (Long) template.insert(INSERT_CONFIG, entity);
|
||||||
|
entity.setId(id);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
@@ -52,7 +52,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
* for CRUD operations.
|
* for CRUD operations.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||||
{
|
{
|
||||||
|
@@ -33,7 +33,7 @@ import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
|||||||
* the {@link DefaultTypeConverter} is used.
|
* the {@link DefaultTypeConverter} is used.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class DefaultPropertyTypeConverter implements PropertyTypeConverter
|
public class DefaultPropertyTypeConverter implements PropertyTypeConverter
|
||||||
{
|
{
|
||||||
|
@@ -33,7 +33,7 @@ import org.alfresco.util.Pair;
|
|||||||
* Entity bean for <b>alf_prop_class</b> table.
|
* Entity bean for <b>alf_prop_class</b> table.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class PropertyClassEntity
|
public class PropertyClassEntity
|
||||||
{
|
{
|
||||||
|
@@ -36,7 +36,7 @@ import org.alfresco.util.Pair;
|
|||||||
* Entity bean for <b>alf_prop_date_value</b> table.
|
* Entity bean for <b>alf_prop_date_value</b> table.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class PropertyDateValueEntity
|
public class PropertyDateValueEntity
|
||||||
{
|
{
|
||||||
|
@@ -31,7 +31,7 @@ import org.alfresco.util.Pair;
|
|||||||
* Entity bean for <b>alf_prop_numeric_value</b> table.
|
* Entity bean for <b>alf_prop_numeric_value</b> table.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class PropertyDoubleValueEntity
|
public class PropertyDoubleValueEntity
|
||||||
{
|
{
|
||||||
|
@@ -30,7 +30,7 @@ import java.io.Serializable;
|
|||||||
* Entity bean search results from <b>alf_prop_collections_link</b> and <b>alf_prop_value</b> tables.
|
* Entity bean search results from <b>alf_prop_collections_link</b> and <b>alf_prop_value</b> tables.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class PropertyIdSearchRow
|
public class PropertyIdSearchRow
|
||||||
{
|
{
|
||||||
|
@@ -28,7 +28,7 @@ package org.alfresco.repo.domain.propval;
|
|||||||
* Entity bean for <b>alf_prop_link</b> table.
|
* Entity bean for <b>alf_prop_link</b> table.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class PropertyLinkEntity
|
public class PropertyLinkEntity
|
||||||
{
|
{
|
||||||
|
@@ -31,7 +31,7 @@ import org.alfresco.util.Pair;
|
|||||||
* Entity bean for <b>alf_prop_string_value</b> table.
|
* Entity bean for <b>alf_prop_string_value</b> table.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class PropertyStringValueEntity
|
public class PropertyStringValueEntity
|
||||||
{
|
{
|
||||||
|
@@ -31,7 +31,7 @@ package org.alfresco.repo.domain.propval;
|
|||||||
* and back again.
|
* and back again.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public interface PropertyTypeConverter
|
public interface PropertyTypeConverter
|
||||||
{
|
{
|
||||||
|
@@ -33,7 +33,7 @@ import org.alfresco.util.Pair;
|
|||||||
* DAO services for <b>alf_prop_XXX</b> tables.
|
* DAO services for <b>alf_prop_XXX</b> tables.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public interface PropertyValueDAO
|
public interface PropertyValueDAO
|
||||||
{
|
{
|
||||||
|
@@ -46,7 +46,7 @@ import org.springframework.context.ApplicationContext;
|
|||||||
* @see PropertyValueDAO
|
* @see PropertyValueDAO
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class PropertyValueDAOTest extends TestCase
|
public class PropertyValueDAOTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@@ -44,7 +44,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
* or will be references to data in other tables.
|
* or will be references to data in other tables.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class PropertyValueEntity
|
public class PropertyValueEntity
|
||||||
{
|
{
|
||||||
@@ -65,7 +65,7 @@ public class PropertyValueEntity
|
|||||||
* and should not be used in public interfaces.
|
* and should not be used in public interfaces.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public static enum PersistedType
|
public static enum PersistedType
|
||||||
{
|
{
|
||||||
|
@@ -44,7 +44,7 @@ import org.springframework.orm.ibatis.SqlMapClientTemplate;
|
|||||||
* iBatis-specific implementation of the PropertyValue DAO.
|
* iBatis-specific implementation of the PropertyValue DAO.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @since 3.3
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class PropertyValueDAOImpl extends AbstractPropertyValueDAOImpl
|
public class PropertyValueDAOImpl extends AbstractPropertyValueDAOImpl
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user