ACE-2030: Remove some patches for V3.1, including Version store migrator

- Deprecated VersionStore V1 is no longer usable by any means
 - Various scripts and other patches retired


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@87775 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2014-10-10 17:12:57 +00:00
parent 7ca8289380
commit c5ac017dfb
21 changed files with 286 additions and 3301 deletions

View File

@@ -458,12 +458,6 @@
<property name="permissionService">
<ref bean="permissionService" />
</property>
<property name="onlyUseDeprecatedV1">
<value>${version.store.onlyUseDeprecatedV1}</value>
</property>
<property name="versionMigrator">
<ref bean="versionMigrator"/>
</property>
<property name="versionComparatorClass">
<value>${version.store.versionComparatorClass}</value>
</property>
@@ -514,38 +508,6 @@
</property>
</bean>
<!-- -->
<bean id="versionMigrator" class="org.alfresco.repo.version.VersionMigrator" init-method="init">
<property name="dbNodeService">
<ref bean="mtAwareNodeService" />
</property>
<property name="versionNodeService">
<ref bean="versionNodeService" />
</property>
<property name="version2ServiceImpl">
<ref bean="versionService" />
</property>
<property name="policyBehaviourFilter">
<ref bean="policyBehaviourFilter" />
</property>
<property name="dictionaryService">
<ref bean="dictionaryService" />
</property>
<property name="transactionService">
<ref bean="transactionService"/>
</property>
<property name="ruleService">
<ref bean="ruleService" />
</property>
<property name="jobLockService">
<ref bean="jobLockService"/>
</property>
<property name="loggingInterval">
<value>500</value>
</property>
</bean>
<bean id="versionableAspect" class="org.alfresco.repo.version.VersionableAspect" init-method="init">
<property name="policyComponent">
<ref bean="policyComponent" />

View File

@@ -53,16 +53,3 @@ CREATE TABLE alf_activity_post
KEY post_jobtasknode_idx (job_task_node),
KEY post_status_idx (status)
) ENGINE=InnoDB;
--
-- Record script finish
--
DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.0-ActivityTables';
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.0-ActivityTables', 'Manually executed script upgrade V3.0: Activity Tables',
0, 125, -1, 126, null, 'UNKNOWN', ${TRUE}, ${TRUE}, 'Script completed'
);

View File

@@ -56,16 +56,3 @@ CREATE TABLE alf_activity_post
);
CREATE INDEX post_jobtasknode_idx ON alf_activity_post (job_task_node);
CREATE INDEX post_status_idx ON alf_activity_post (status);
--
-- Record script finish
--
DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.0-ActivityTables';
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.0-ActivityTables', 'Manually executed script upgrade V3.0: Activity Tables',
0, 125, -1, 126, null, 'UNKNOWN', ${TRUE}, ${TRUE}, 'Script completed'
);

View File

@@ -55,7 +55,6 @@
</property>
<property name="postUpdateScriptPatches">
<list>
<ref bean="patch.db-V3.1-Allow-IPv6" />
<ref bean="patch.db-V3.3-Remove-VersionCount" />
<ref bean="patch.db-V3.3-Fix-Repo-Seqs" />
<ref bean="patch.db-V3.3-Node-Prop-Serializable" />
@@ -89,7 +88,6 @@
<property name="schemaBootstrap" ref="schemaBootstrap" />
<property name="preUpdateScriptPatches">
<list>
<ref bean="patch.db-V3.0-ActivityTables" />
</list>
</property>
<property name="updateActivitiScriptPatches">

View File

@@ -1,21 +0,0 @@
--
-- Title: Increase the ipAddress field length to allow IPv6 adresses
-- Database: MySQL
-- Since: V3.1 schema 1009
--
-- Please contact support@alfresco.com if you need assistance with the upgrade.
--
ALTER TABLE alf_server MODIFY ip_address varchar(39) NOT NULL;
--
-- Record script finish
--
DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.1-Allow-IPv6';
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.1-Allow-IPv6', 'Manually executed script upgrade V3.1: Increase the ipAddress field length',
0, 2019, -1, 2020, null, 'UNKNOWN', ${TRUE}, ${TRUE}, 'Script completed'
);

View File

@@ -1,21 +0,0 @@
--
-- Title: Increase the ipAddress field length to allow IPv6 adresses
-- Database: PostgreSQL
-- Since: V3.1 schema 1009
--
-- Please contact support@alfresco.com if you need assistance with the upgrade.
--
ALTER TABLE alf_server ALTER COLUMN ip_address TYPE varchar(39);
--
-- Record script finish
--
DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.1-Allow-IPv6';
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.1-Allow-IPv6', 'Manually executed script upgrade V3.1: Increase the ipAddress field length',
0, 1009, -1, 1010, null, 'UNKOWN', TRUE, TRUE, 'Script completed'
);

View File

@@ -203,7 +203,6 @@ patch.tagRootCategory.description=Adds 'Tags' as new top-level category root.
patch.sitesFolder.description=Adds 'Sites' folder to Company Home.
patch.updateDmPermissions.description=Update ACLs on all DM node objects to the new 3.0 permission model
patch.updateDmPermissions.result=Updated ACLs. Created {0} defining ACLs.
patch.db-V3.0-0-CreateActivitiesExtras.description=Replaced by 'patch.db-V3.0-ActivityTables', which must run first.
@@ -211,9 +210,6 @@ patch.sitePermissionRefactorPatch.description=Create permission groups for sites
patch.sitePermissionRefactorPatch.result=Groups have been created for all sites and user's allocated accordingly.
patch.migrateVersionStore.description=Version Store migration (from lightWeightVersionStore to version2Store)
patch.migrateVersionStore.incomplete=Version Store migration incomplete.
patch.migrateVersionStore.done=Version Store migration completed.
patch.migrateVersionStore.bypassingPatch=Bypass Version Store migration patch since scheduled to run as job
patch.inviteEmailTemplate.description=Adds invite email template to invite space

View File

@@ -179,7 +179,6 @@
<property name="storesToIgnore">
<list>
<value>${version.store.version2Store}</value>
<!-- <value>${version.store.deprecated.lightWeightVersionStore}</value> -->
</list>
</property>
</bean>

View File

@@ -754,156 +754,74 @@
<value>4.2.x</value>
</property>
</bean>
<bean id="patch.db-V3.0-0-CreateActivitiesExtras" class="org.alfresco.repo.admin.patch.impl.NoOpPatch" parent="basePatch">
<bean id="patch.db-V3.0-0-CreateActivitiesExtras" class="org.alfresco.repo.admin.patch.impl.NoLongerSupportedPatch" parent="basePatch">
<property name="id"><value>patch.db-V3.0-0-CreateActivitiesExtras</value></property>
<property name="description"><value>patch.db-V3.0-0-CreateActivitiesExtras.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>125</value></property>
<property name="targetSchema"><value>126</value></property>
<property name="dependsOn" >
<list>
<ref bean="patch.db-V3.0-ActivityTables" />
</list>
<property name="lastSupportedVersion" >
<value>4.2.x</value>
</property>
</bean>
<bean id="patch.db-V3.0-ActivityTables" class="org.alfresco.repo.admin.patch.impl.SchemaUpgradeScriptPatch" parent="basePatch">
<bean id="patch.db-V3.0-ActivityTables" class="org.alfresco.repo.admin.patch.impl.NoLongerSupportedPatch" parent="basePatch">
<property name="id"><value>patch.db-V3.0-ActivityTables</value></property>
<property name="description"><value>patch.schemaUpgradeScript.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>125</value></property>
<property name="targetSchema"><value>126</value></property>
<property name="alternatives" >
<list>
<ref bean="patch.db-V3.0-0-CreateActivitiesExtras" />
</list>
</property>
<property name="scriptUrl">
<value>classpath:alfresco/dbscripts/create/${db.script.dialect}/AlfrescoCreate-ActivityTables.sql</value>
<property name="lastSupportedVersion" >
<value>4.2.x</value>
</property>
</bean>
<bean id="patch.createSiteStore" class="org.alfresco.repo.admin.patch.impl.NoOpPatch" parent="basePatch">
<bean id="patch.createSiteStore" class="org.alfresco.repo.admin.patch.impl.NoLongerSupportedPatch" parent="basePatch">
<property name="id"><value>patch.createSiteStore</value></property>
<property name="description"><value>patch.noOpPatch.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>126</value></property>
<property name="targetSchema"><value>127</value></property>
<property name="lastSupportedVersion" >
<value>4.2.x</value>
</property>
</bean>
<bean id="patch.sitesFolder" class="org.alfresco.repo.admin.patch.impl.GenericBootstrapPatch" parent="basePatch" >
<bean id="patch.sitesFolder" class="org.alfresco.repo.admin.patch.impl.NoLongerSupportedPatch" parent="basePatch" >
<property name="id"><value>patch.sitesFolder</value></property>
<property name="description"><value>patch.sitesFolder.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>127</value></property>
<property name="targetSchema"><value>128</value></property>
<property name="dependsOn" >
<list>
<ref bean="patch.updateDmPermissions" />
</list>
</property>
<property name="importerBootstrap">
<ref bean="spacesBootstrap" />
</property>
<property name="checkPath">
<value>/${spaces.company_home.childname}/st:sites</value>
</property>
<property name="bootstrapView">
<props>
<prop key="path">/${spaces.company_home.childname}</prop>
<prop key="location">alfresco/bootstrap/sitesSpace.xml</prop>
<prop key="messages">alfresco/messages/bootstrap-spaces</prop>
</props>
<property name="lastSupportedVersion" >
<value>4.2.x</value>
</property>
</bean>
<bean id="patch.sitePermissionRefactorPatch" class="org.alfresco.repo.admin.patch.impl.SitePermissionRefactorPatch" parent="basePatch">
<bean id="patch.sitePermissionRefactorPatch" class="org.alfresco.repo.admin.patch.impl.NoLongerSupportedPatch" parent="basePatch">
<property name="id"><value>patch.sitePermissionRefactorPatch</value></property>
<property name="description"><value>patch.sitePermissionRefactorPatch.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>128</value></property>
<property name="targetSchema"><value>129</value></property>
<property name="dependsOn" >
<list>
<ref bean="patch.updateDmPermissions" />
<ref bean="patch.zonedAuthorities" />
</list>
</property>
<property name="siteService">
<ref bean="siteService" />
</property>
<property name="permissionService">
<ref bean="PermissionService" />
</property>
<property name="authorityService">
<ref bean="AuthorityService" />
<property name="lastSupportedVersion" >
<value>4.2.x</value>
</property>
</bean>
<bean id="patch.migrateVersionStore" class="org.alfresco.repo.admin.patch.impl.MigrateVersionStorePatch" parent="basePatch">
<bean id="patch.migrateVersionStore" class="org.alfresco.repo.admin.patch.impl.NoLongerSupportedPatch" parent="basePatch">
<property name="id"><value>patch.migrateVersionStore</value></property>
<property name="description"><value>patch.migrateVersionStore.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>129</value></property>
<property name="targetSchema"><value>130</value></property>
<property name="dependsOn" >
<list>
<ref bean="patch.updateDmPermissions" />
</list>
</property>
<property name="versionMigrator">
<ref bean="versionMigrator"/>
</property>
<property name="tenantService">
<ref bean="tenantService"/>
</property>
<property name="importerBootstrap">
<ref bean="version2Bootstrap"/>
</property>
<property name="jobLockService">
<ref bean="jobLockService"/>
</property>
<property name="threadCount">
<value>${version.store.migrateVersionStore.threadCount}</value>
</property>
<property name="batchSize">
<value>${version.store.migrateVersionStore.batchSize}</value>
</property>
<property name="runAsScheduledJob">
<value>${version.store.migrateVersionStore.runAsScheduledJob}</value>
</property>
<property name="limitPerJobCycle">
<value>${version.store.migrateVersionStore.limitPerJobCycle}</value>
</property>
<property name="requiresTransaction">
<value>false</value>
<property name="lastSupportedVersion" >
<value>4.2.x</value>
</property>
</bean>
<bean id="patch.inviteEmailTemplate" class="org.alfresco.repo.admin.patch.impl.GenericBootstrapPatch" parent="basePatch" >
<bean id="patch.inviteEmailTemplate" class="org.alfresco.repo.admin.patch.impl.NoLongerSupportedPatch" parent="basePatch" >
<property name="id"><value>patch.inviteEmailTemplate</value></property>
<property name="description"><value>patch.inviteEmailTemplate.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>130</value></property>
<property name="targetSchema"><value>131</value></property>
<property name="dependsOn" >
<list>
<ref bean="patch.updateDmPermissions" />
<ref bean="patch.emailTemplatesFolder" />
</list>
</property>
<property name="importerBootstrap">
<ref bean="spacesBootstrap" />
</property>
<property name="checkPath">
<value>/${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.templates.email.childname}/${spaces.templates.email.invite.childname}</value>
</property>
<property name="bootstrapView">
<props>
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.templates.email.childname}</prop>
<prop key="location">alfresco/bootstrap/invite/invite-email.xml</prop>
<prop key="messages">alfresco/messages/bootstrap-spaces</prop>
</props>
<property name="lastSupportedVersion" >
<value>4.2.x</value>
</property>
</bean>
@@ -1241,14 +1159,14 @@
</property>
</bean>
<bean id="patch.db-V3.1-Allow-IPv6" class="org.alfresco.repo.admin.patch.impl.SchemaUpgradeScriptPatch" parent="basePatch">
<bean id="patch.db-V3.1-Allow-IPv6" class="org.alfresco.repo.admin.patch.impl.NoLongerSupportedPatch" parent="basePatch">
<property name="id"><value>patch.db-V3.1-Allow-IPv6</value></property>
<property name="description"><value>patch.schemaUpgradeScript.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>3003</value></property>
<property name="targetSchema"><value>3004</value></property>
<property name="scriptUrl">
<value>classpath:alfresco/dbscripts/upgrade/3.1/${db.script.dialect}/IPv6-patch.sql</value>
<property name="lastSupportedVersion" >
<value>4.2.x</value>
</property>
</bean>

View File

@@ -504,27 +504,6 @@ version.store.enableAutoVersioning=true
version.store.deprecated.lightWeightVersionStore=workspace://lightWeightVersionStore
version.store.version2Store=workspace://version2Store
version.store.migrateVersionStore.threadCount=3
version.store.migrateVersionStore.batchSize=1
version.store.migrateCleanupJob.threadCount=3
version.store.migrateCleanupJob.batchSize=1
# WARNING: For non-production testing only !!! Do not change (to avoid version store issues, including possible mismatch). Should be false since lightWeightVersionStore is deprecated.
version.store.onlyUseDeprecatedV1=false
# The CRON expression to trigger migration of the version store from V1 (2.x) to V2 (3.x)
# By default, this is effectively 'never' but can be modified as required.
# Examples:
# Never: * * * * * ? 2099
# Once every thirty minutes: 0 0/30 * * * ?
# See http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html
version.store.migrateVersionStore.cronExpression=* * * * * ? 2099
# Limit number of version histories to migrate per job cycle, where -1 = unlimited. Note: if limit > 0 then need to schedule job to run regularly in order to complete the migration.
version.store.migrateVersionStore.limitPerJobCycle=-1
version.store.migrateVersionStore.runAsScheduledJob=false
# Optional Comparator<Version> class name to sort versions.
# Set to: org.alfresco.repo.version.common.VersionLabelComparator
# if upgrading from a version that used unordered sequences in a cluster.

View File

@@ -200,82 +200,6 @@
<!-- note: Activities (feed) jobs have moved to Activities subsystem (since 3.5) -->
<bean id="migrateVersionStoreJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>org.alfresco.repo.admin.patch.impl.MigrateVersionStorePatch$MigrateVersionStoreJob</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="migrateVersionStore">
<ref bean="patch.migrateVersionStore"/>
</entry>
</map>
</property>
</bean>
<bean id="migrateVersionStoreTrigger" class="org.alfresco.util.CronTriggerBean">
<property name="jobDetail">
<ref bean="migrateVersionStoreJobDetail"/>
</property>
<property name="scheduler">
<ref bean="schedulerFactory"/>
</property>
<property name="cronExpression">
<value>${version.store.migrateVersionStore.cronExpression}</value>
</property>
<property name="startDelayMinutes">
<value>${system.cronJob.startDelayMinutes}</value>
</property>
</bean>
<!-- enable scheduler property to activate -->
<bean id="versionStoreMigrationCleanupJob" class="org.alfresco.util.TriggerBean">
<property name="jobDetail">
<bean id="versionStoreMigrationCleanupDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>org.alfresco.repo.version.MigrationCleanupJob</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="versionMigrator">
<ref bean="versionMigrator"/>
</entry>
<entry key="tenantAdminService">
<ref bean="tenantAdminService"/>
</entry>
<entry key="onlyUseDeprecatedV1">
<value>${version.store.onlyUseDeprecatedV1}</value>
</entry>
<entry key="batchSize">
<value>${version.store.migrateCleanupJob.batchSize}</value>
</entry>
<entry key="threadCount">
<value>${version.store.migrateCleanupJob.threadCount}</value>
</entry>
<entry key="migrateRunAsScheduledJob">
<value>${version.store.migrateVersionStore.runAsScheduledJob}</value>
</entry>
</map>
</property>
</bean>
</property>
<!-- enable this to activate bean -->
<property name="scheduler">
<ref bean="schedulerFactory" />
</property>
<!-- start after bootstrap (1 minute) and run once -->
<property name="startDelayMinutes">
<value>1</value>
</property>
<property name="repeatCount">
<value>0</value>
</property>
</bean>
<!-- Tagging Service Scope Updates -->
<!-- (Catches any updates queued but not executed around repo shutdown -->

View File

@@ -1,401 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.admin.patch.impl;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.importer.ImporterBootstrap;
import org.alfresco.repo.lock.JobLockService;
import org.alfresco.repo.lock.LockAcquisitionException;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.version.VersionMigrator;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Migrate version store from workspace://lightWeightVersionStore to workspace://version2Store
*/
public class MigrateVersionStorePatch extends AbstractPatch
{
private static Log logger = LogFactory.getLog(MigrateVersionStorePatch.class);
// Lock key
public static final QName LOCK = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "MigrateVersionStore");
// The maximum time this lock will be held for (30 mins) - unless refreshed
//public static final long LOCK_TTL = 1000 * 60 * 30;
public static final long LOCK_TTL = 30000;
private static final String MSG_DONE = "patch.migrateVersionStore.done";
private static final String MSG_INCOMPLETE = "patch.migrateVersionStore.incomplete";
private VersionMigrator versionMigrator;
private TenantService tenantService;
private ImporterBootstrap version2ImporterBootstrap;
private JobLockService jobLockService;
private int batchSize = 1;
private int threadCount = 2;
private int limitPerJobCycle = -1; // if run as scheduled job then can limit the number of version histories to migrate (per job invocation)
private boolean migrationComplete = false;
private boolean deleteImmediately = false;
private boolean runAsScheduledJob = false;
private boolean useDeprecatedV1 = false;
private ThreadLocal<Boolean> runningAsJob = new ThreadLocal<Boolean>();
/**
* Default constructor
*/
public MigrateVersionStorePatch()
{
runningAsJob.set(Boolean.FALSE);
}
public void setVersionMigrator(VersionMigrator versionMigrator)
{
this.versionMigrator = versionMigrator;
}
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
public void setImporterBootstrap(ImporterBootstrap version2ImporterBootstrap)
{
this.version2ImporterBootstrap = version2ImporterBootstrap;
}
public void setJobLockService(JobLockService jobLockService)
{
this.jobLockService = jobLockService;
}
public void setBatchSize(int batchSize)
{
this.batchSize = batchSize;
}
public void setThreadCount(int threadCount)
{
this.threadCount = threadCount;
}
public void setLimitPerJobCycle(int limitPerJobCycle)
{
this.limitPerJobCycle = limitPerJobCycle;
}
public void setDeleteImmediately(boolean deleteImmediately)
{
this.deleteImmediately = deleteImmediately;
}
/**
* Set whether the patch execution should just bypass any actual work i.e. the admin has
* chosen to manually trigger the work.
*
* @param runAsScheduledJob <tt>true</tt> to leave all work up to the scheduled job
*/
public void setRunAsScheduledJob(boolean runAsScheduledJob)
{
this.runAsScheduledJob = runAsScheduledJob;
}
public void setOnlyUseDeprecatedV1(boolean useDeprecatedV1)
{
this.useDeprecatedV1 = useDeprecatedV1;
}
public void init()
{
if (batchSize < 1)
{
String errorMessage = "batchSize ("+batchSize+") cannot be less than 1";
logger.error(errorMessage);
throw new AlfrescoRuntimeException(errorMessage);
}
if (threadCount < 1)
{
String errorMessage = "threadCount ("+threadCount+") cannot be less than 1";
logger.error(errorMessage);
throw new AlfrescoRuntimeException(errorMessage);
}
super.init();
}
/**
* Method called when executed as a scheduled job.
*/
private void executeViaJob()
{
AuthenticationUtil.RunAsWork<String> patchRunAs = new AuthenticationUtil.RunAsWork<String>()
{
public String doWork() throws Exception
{
RetryingTransactionCallback<String> patchTxn = new RetryingTransactionCallback<String>()
{
public String execute() throws Exception
{
try
{
runningAsJob.set(Boolean.TRUE);
String report = applyInternal();
// done
return report;
}
finally
{
runningAsJob.set(Boolean.FALSE); // Back to default
}
}
};
return transactionHelper.doInTransaction(patchTxn);
}
};
String report = AuthenticationUtil.runAs(patchRunAs, AuthenticationUtil.getSystemUserName());
if (report != null)
{
logger.info(report);
}
}
/**
* Gets a set of work to do and executes it within this transaction.
* Can be kicked off via a job or called as a patch.
*
* Note that this is not wrapped in a transaction. The patch manages
* its own transactions.
*/
@Override
protected String applyInternal() throws Exception
{
if (useDeprecatedV1)
{
// Nothing to do
return null;
}
if (migrationComplete)
{
// Nothing to do
return null;
}
final boolean isRunningAsJob = runningAsJob.get().booleanValue();
// Do we bug out of patch execution
if (runAsScheduledJob && !isRunningAsJob)
{
return I18NUtil.getMessage("patch.migrateVersionStore.bypassingPatch");
}
// Lock
final String lockToken = getLock();
if (lockToken == null)
{
// Some other process is busy
if (isRunningAsJob)
{
// Fine, we're doing batches (or lock still present)
if (logger.isDebugEnabled())
{
logger.debug("Cannot get lock - an earlier job is still busy (or previous lock has not yet expired after failure - TTL was "+LOCK_TTL+" ms)");
}
return null;
}
else
{
throw new RuntimeException("Unable to get job lock during patch execution. Only one server should perform the upgrade.");
}
}
if (isRunningAsJob && (! this.deleteImmediately))
{
if (logger.isDebugEnabled())
{
logger.debug("VersionMigrator is running as a background job will immediately delete old versions (after they are migrated");
}
this.deleteImmediately = true;
}
try
{
RetryingTransactionCallback<Boolean> preMigrate = new RetryingTransactionCallback<Boolean>()
{
public Boolean execute() throws Throwable
{
if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_READ_WRITE)
{
// Nothing to do
return false;
}
if (tenantService.isEnabled() && tenantService.isTenantUser())
{
// bootstrap new version store
StoreRef bootstrapStoreRef = version2ImporterBootstrap.getStoreRef();
if (! nodeService.exists(bootstrapStoreRef))
{
bootstrapStoreRef = tenantService.getName(AuthenticationUtil.getRunAsUser(), bootstrapStoreRef);
version2ImporterBootstrap.setStoreUrl(bootstrapStoreRef.toString());
version2ImporterBootstrap.bootstrap();
}
}
if (AuthenticationUtil.getRunAsUser() == null)
{
logger.info("Set system user");
AuthenticationUtil.setRunAsUser(AuthenticationUtil.getSystemUserName());
}
return true;
}
};
Boolean doMigration = transactionHelper.doInTransaction(preMigrate);
if(!doMigration.booleanValue())
{
return null;
}
Boolean migrated = versionMigrator.migrateVersions(batchSize, threadCount, limitPerJobCycle, deleteImmediately, lockToken, isRunningAsJob);
migrationComplete = (migrated != null ? migrated : true);
// return the result message
if (migrated != null)
{
if (migrationComplete)
{
return I18NUtil.getMessage(MSG_DONE);
}
else if (! isRunningAsJob)
{
return I18NUtil.getMessage(MSG_INCOMPLETE);
}
}
return null;
}
finally
{
releaseLock(lockToken);
}
}
/**
* Attempts to get the lock. If the lock couldn't be taken, then <tt>null</tt> is returned.
*
* @return Returns the lock token or <tt>null</tt>
*/
private String getLock()
{
String lockToken = null;
try
{
lockToken = jobLockService.getLock(LOCK, LOCK_TTL);
if (lockToken != null)
{
if (logger.isTraceEnabled())
{
logger.trace("Got lock: "+lockToken+" with TTL of "+LOCK_TTL+" ms ["+AlfrescoTransactionSupport.getTransactionId()+"]["+Thread.currentThread().getId()+"]");
}
}
}
catch (LockAcquisitionException e)
{
// ignore
}
return lockToken;
}
/**
* Attempts to release the lock.
*/
private void releaseLock(String lockToken)
{
if (lockToken == null)
{
throw new IllegalArgumentException("Must provide existing lockToken");
}
jobLockService.releaseLock(lockToken, LOCK);
if (logger.isTraceEnabled())
{
logger.trace("Released lock: "+lockToken+" ["+AlfrescoTransactionSupport.getTransactionId()+"]["+Thread.currentThread().getId()+"]");
}
}
/**
* Job to initiate the {@link MigrateVersionStorePatch}
*
* @author janv
* @since 3.3.1
*/
public static class MigrateVersionStoreJob implements Job
{
public MigrateVersionStoreJob()
{
}
/**
* Calls the cleaner to do its work
*/
public void execute(JobExecutionContext context) throws JobExecutionException
{
JobDataMap jobData = context.getJobDetail().getJobDataMap();
// extract the migrator to use
Object migrateVersionStoreObj = jobData.get("migrateVersionStore");
if (migrateVersionStoreObj == null || !(migrateVersionStoreObj instanceof MigrateVersionStorePatch))
{
throw new AlfrescoRuntimeException("'migrateVersionStore' data must contain valid 'MigrateVersionStore' reference");
}
MigrateVersionStorePatch migrateVersionStore = (MigrateVersionStorePatch) migrateVersionStoreObj;
migrateVersionStore.executeViaJob();
}
}
}

View File

@@ -1,140 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.admin.patch.impl;
import java.util.List;
import java.util.Set;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.site.SiteServiceImpl;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Patch's the site permission model to use groups to contain users.
*
* @author Roy Wetherall
*/
public class SitePermissionRefactorPatch extends AbstractPatch
{
/** Messages */
private static final String STATUS_MSG = "patch.sitePermissionRefactorPatch.result";
/** Services */
private SiteService siteService;
private PermissionService permissionService;
private AuthorityService authorityService;
/**
* Set site service
*
* @param siteService the site service
*/
public void setSiteService(SiteService siteService)
{
this.siteService = siteService;
}
/**
* Set the permission service
*
* @param permissionService the permission service
*/
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
/**
* The authority service
*
* @param authorityService the authority service
*/
public void setAuthorityService(AuthorityService authorityService)
{
this.authorityService = authorityService;
}
/**
* @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal()
*/
@Override
protected String applyInternal() throws Exception
{
// NOTE: SiteService is not currently MT-enabled (eg. getSiteRoot) so skip if applied to tenant
if (AuthenticationUtil.isRunAsUserTheSystemUser() || !AuthenticationUtil.isMtEnabled())
{
// Set all the sites in the repository
List<SiteInfo> sites = this.siteService.listSites(null, null);
for (SiteInfo siteInfo : sites)
{
// Create the site's groups
String siteGroup = authorityService.createAuthority(
AuthorityType.GROUP,
((SiteServiceImpl)this.siteService).getSiteGroup(siteInfo.getShortName(),
false));
QName siteType = nodeService.getType(siteInfo.getNodeRef());
Set<String> permissions = permissionService.getSettablePermissions(siteType);
for (String permission : permissions)
{
// Create a group for the permission
String permissionGroup = authorityService.createAuthority(
AuthorityType.GROUP,
((SiteServiceImpl)this.siteService).getSiteRoleGroup(
siteInfo.getShortName(),
permission,
false));
authorityService.addAuthority(siteGroup, permissionGroup);
// Assign the group the relevant permission on the site
permissionService.setPermission(siteInfo.getNodeRef(), permissionGroup, permission, true);
}
// Take the current members and assign them to the appropriate groups
Set<AccessPermission> currentPermissions = this.permissionService.getAllSetPermissions(siteInfo.getNodeRef());
for (AccessPermission permission : currentPermissions)
{
// Only support user's being transfered (if public the everyone group will stay on the node)
if (permission.getAuthorityType() == AuthorityType.USER)
{
// Add this authority to the appropriate group
String group = ((SiteServiceImpl)this.siteService).getSiteRoleGroup(
siteInfo.getShortName(),
permission.getPermission(),
true);
this.authorityService.addAuthority(group, permission.getAuthority());
// Remove the permission from the node
this.permissionService.deletePermission(siteInfo.getNodeRef(), permission.getAuthority(), permission.getPermission());
}
}
}
}
// Report status
return I18NUtil.getMessage(STATUS_MSG);
}
}

View File

@@ -1,182 +0,0 @@
/*
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.version;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.Tenant;
import org.alfresco.repo.tenant.TenantAdminService;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
/**
* Cleanup of Version Store Migration - to delete old/migrated version histories from old version store. Typically this is configured to run once on startup.
*/
public class MigrationCleanupJob implements Job
{
private static Log logger = LogFactory.getLog(MigrationCleanupJob.class);
private static final String KEY_VERSION_MIGRATOR = "versionMigrator";
private static final String KEY_TENANT_ADMIN_SERVICE = "tenantAdminService";
private static final String KEY_BATCH_SIZE = "batchSize";
private static final String KEY_THREAD_COUNT = "threadCount";
private static final String KEY_ONLY_USE_DEPRECATED_V1 = "onlyUseDeprecatedV1";
private static final String KEY_MIGRATE_RUN_AS_JOB = "migrateRunAsScheduledJob";
private int batchSize = 1;
private int threadCount = 2;
private boolean useDeprecatedV1 = false;
private boolean migrateRunAsJob = false;
public void execute(JobExecutionContext context) throws JobExecutionException
{
JobDataMap jobData = context.getJobDetail().getJobDataMap();
String migrateRunAsJobStr = (String)jobData.get(KEY_MIGRATE_RUN_AS_JOB);
if (migrateRunAsJobStr != null)
{
try
{
migrateRunAsJob = new Boolean(migrateRunAsJobStr);
}
catch (Exception e)
{
logger.warn("Invalid 'migrateRunAsJob' value, using default: " + migrateRunAsJob, e);
}
}
if (migrateRunAsJob)
{
// skip cleanup
if (logger.isDebugEnabled())
{
logger.debug("Skipping migration cleanup since migration is running as a job (which walso performs the delete)");
}
return;
}
String onlyUseDeprecatedV1Str = (String)jobData.get(KEY_ONLY_USE_DEPRECATED_V1);
if (onlyUseDeprecatedV1Str != null)
{
try
{
useDeprecatedV1 = new Boolean(onlyUseDeprecatedV1Str);
}
catch (Exception e)
{
logger.warn("Invalid 'onlyUseDeprecatedV1' value, using default: " + useDeprecatedV1, e);
}
}
if (useDeprecatedV1)
{
// skip cleanup
if (logger.isDebugEnabled())
{
logger.debug("Skipping migration cleanup since only using deprecated version1 store");
}
return;
}
final VersionMigrator migrationCleanup = (VersionMigrator)jobData.get(KEY_VERSION_MIGRATOR);
final TenantAdminService tenantAdminService = (TenantAdminService)jobData.get(KEY_TENANT_ADMIN_SERVICE);
if (migrationCleanup == null)
{
throw new JobExecutionException("Missing job data: " + KEY_VERSION_MIGRATOR);
}
String batchSizeStr = (String)jobData.get(KEY_BATCH_SIZE);
if (batchSizeStr != null)
{
try
{
batchSize = new Integer(batchSizeStr);
}
catch (Exception e)
{
logger.warn("Invalid 'batchSize' value, using default: " + batchSize, e);
}
}
if (batchSize < 1)
{
String errorMessage = "batchSize ("+batchSize+") cannot be less than 1";
logger.error(errorMessage);
throw new AlfrescoRuntimeException(errorMessage);
}
String threadCountStr = (String)jobData.get(KEY_THREAD_COUNT);
if (threadCountStr != null)
{
try
{
threadCount = new Integer(threadCountStr);
}
catch (Exception e)
{
logger.warn("Invalid 'threadCount' value, using default: " + threadCount, e);
}
}
if (threadCount < 1)
{
String errorMessage = "threadCount ("+threadCount+") cannot be less than 1";
logger.error(errorMessage);
throw new AlfrescoRuntimeException(errorMessage);
}
if (AuthenticationUtil.getRunAsUser() == null)
{
logger.info("Set system user");
AuthenticationUtil.setRunAsUser(AuthenticationUtil.getSystemUserName());
}
// perform the cleanup of the old version store
migrationCleanup.executeCleanup(batchSize, threadCount);
if ((tenantAdminService != null) && tenantAdminService.isEnabled())
{
List<Tenant> tenants = tenantAdminService.getAllTenants();
for (Tenant tenant : tenants)
{
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Object>()
{
public Object doWork() throws Exception
{
migrationCleanup.executeCleanup(batchSize, threadCount);
return null;
}
}, tenant.getTenantDomain());
}
}
}
}

View File

@@ -66,28 +66,13 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
{
private static Log logger = LogFactory.getLog(Version2ServiceImpl.class);
protected boolean useDeprecatedV1 = false; // bypass V2, only use V1
private PermissionService permissionService;
private VersionServiceImpl version1Service = new VersionServiceImpl();
private VersionMigrator versionMigrator;
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
public void setVersionMigrator(VersionMigrator versionMigrator)
{
this.versionMigrator = versionMigrator;
}
public void setOnlyUseDeprecatedV1(boolean useDeprecatedV1)
{
this.useDeprecatedV1 = useDeprecatedV1;
}
/**
* Initialise method
*/
@@ -95,22 +80,9 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
public void initialise()
{
super.initialise();
if (useDeprecatedV1)
{
logger.warn("version.store.onlyUseDeprecatedV1=true - using deprecated 'lightWeightVersionStore' by default (not 'version2Store')");
}
else
{
version1Service.setNodeService(dbNodeService);
version1Service.setDbNodeService(dbNodeService);
}
}
/* (non-Javadoc)
* @see org.alfresco.repo.service.cmr.version.VersionService#getVersionStoreReference()
*/
@Override
public StoreRef getVersionStoreReference()
{
@@ -120,14 +92,10 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
if (useDeprecatedV1)
{
return super.getVersionStoreReference();
}
return new StoreRef(StoreRef.PROTOCOL_WORKSPACE, Version2Model.STORE_ID);
}
@Override
public Version createVersion(
NodeRef nodeRef,
Map<String, Serializable> versionProperties)
@@ -139,11 +107,6 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
if (useDeprecatedV1)
{
return super.createVersion(nodeRef, versionProperties);
}
long startTime = System.currentTimeMillis();
int versionNumber = 0; // deprecated (unused)
@@ -159,9 +122,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
return version;
}
/* (non-Javadoc)
* @see org.alfresco.repo.service.cmr.version.VersionService#createVersion(java.util.Collection, java.util.Map)
*/
@Override
public Collection<Version> createVersion(
Collection<NodeRef> nodeRefs,
Map<String, Serializable> versionProperties)
@@ -178,11 +139,6 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
* parents get versioned before the children and the children are not already versioned then the parents
* child references will be pointing to the node ref, rather than the version history.
*/
if (useDeprecatedV1)
{
return super.createVersion(nodeRefs, versionProperties);
}
long startTime = System.currentTimeMillis();
Collection<Version> result = new ArrayList<Version>(nodeRefs.size());
@@ -203,6 +159,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
return result;
}
@Override
protected Version createVersion(
NodeRef nodeRef,
Map<String, Serializable> origVersionProperties,
@@ -215,11 +172,6 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
if (useDeprecatedV1)
{
return super.createVersion(nodeRef, origVersionProperties, versionNumber);
}
long startTime = System.currentTimeMillis();
// Copy the version properties (to prevent unexpected side effects to the caller)
@@ -259,39 +211,6 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
NodeRef versionHistoryRef = getVersionHistoryNodeRef(nodeRef);
NodeRef currentVersionRef = null;
if (versionHistoryRef == null)
{
// check for lazy migration
if (! versionMigrator.isMigrationComplete())
{
NodeRef oldVHRef = version1Service.getVersionHistoryNodeRef(nodeRef);
if (oldVHRef != null)
{
if (logger.isDebugEnabled())
{
logger.debug("Lazily migrate old version history (background migration in progress): "+oldVHRef);
}
try
{
versionMigrator.migrateVersion(oldVHRef, true);
}
catch (Throwable t)
{
throw new AlfrescoRuntimeException("Failed to lazily migrate old version history: "+oldVHRef, t);
}
// should now be able to get new version history
versionHistoryRef = getVersionHistoryNodeRef(nodeRef);
if (versionHistoryRef == null)
{
throw new AlfrescoRuntimeException("Failed to find lazily migrated version history for node: "+nodeRef);
}
}
}
}
Version currentVersion = null;
if (versionHistoryRef == null)
@@ -438,9 +357,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
return childAssocRef.getChildRef();
}
/* (non-Javadoc)
* @see org.alfresco.repo.service.cmr.version.VersionService#getVersionHistory(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public VersionHistory getVersionHistory(NodeRef nodeRef)
{
if (logger.isDebugEnabled())
@@ -449,11 +366,6 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
if (useDeprecatedV1)
{
return super.getVersionHistory(nodeRef);
}
VersionHistory versionHistory = null;
// Get the version history regardless of whether the node is still 'live' or not
@@ -462,30 +374,10 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
{
versionHistory = buildVersionHistory(versionHistoryRef, nodeRef);
}
else
{
// to allow (optional) lazy migration
if (! versionMigrator.isMigrationComplete())
{
NodeRef oldVHRef = version1Service.getVersionHistoryNodeRef(nodeRef);
if (oldVHRef != null)
{
if (logger.isDebugEnabled())
{
logger.debug("Get old version history (background migration in progress): "+oldVHRef);
}
versionHistory = version1Service.getVersionHistory(nodeRef);
}
}
}
return versionHistory;
}
/* (non-Javadoc)
* @see org.alfresco.repo.service.cmr.version.VersionService#getCurrentVersion(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public Version getCurrentVersion(NodeRef nodeRef)
{
if (logger.isDebugEnabled())
@@ -494,11 +386,6 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
if (useDeprecatedV1)
{
return super.getCurrentVersion(nodeRef);
}
Version version = null;
// get the current version, if the 'live' (versioned) node has the "versionable" aspect
@@ -807,13 +694,9 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
* @param nodeRef the node reference
* @return a constructed version history object
*/
@Override
protected VersionHistory buildVersionHistory(NodeRef versionHistoryRef, NodeRef nodeRef)
{
if (useDeprecatedV1)
{
return super.buildVersionHistory(versionHistoryRef, nodeRef);
}
VersionHistory versionHistory = null;
// List of versions with current one last and root one first.
@@ -850,13 +733,9 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
* @param versionRef the version reference
* @return object containing verison data
*/
@Override
protected Version getVersion(NodeRef versionRef)
{
if (useDeprecatedV1)
{
return super.getVersion(versionRef);
}
if (versionRef == null)
{
return null;
@@ -894,16 +773,10 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
{
versionProperties.put(VersionBaseModel.PROP_VERSION_LABEL, (String)value);
}
else if (key.equals(Version2Model.PROP_QNAME_VERSION_NUMBER))
{
// deprecated (unused)
//versionProperties.put(VersionBaseModel.PROP_VERSION_NUMBER, (Integer)value);
}
else
{
if (keyName.equals(Version.PROP_DESCRIPTION) ||
keyName.equals(VersionBaseModel.PROP_VERSION_LABEL) ||
keyName.equals(VersionBaseModel.PROP_VERSION_NUMBER))
keyName.equals(VersionBaseModel.PROP_VERSION_LABEL))
{
// ignore reserved localname (including cm:description, cm:versionLabel)
}
@@ -935,13 +808,9 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
* @param nodeRef a node reference
* @return a reference to the version history node, null of none
*/
@Override
protected NodeRef getVersionHistoryNodeRef(NodeRef nodeRef)
{
if (useDeprecatedV1)
{
return super.getVersionHistoryNodeRef(nodeRef);
}
// assume noderef is a 'live' node
NodeRef vhNodeRef = this.dbNodeService.getChildByName(getRootNode(), Version2Model.CHILD_QNAME_VERSION_HISTORIES, nodeRef.getId());
@@ -1070,9 +939,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
}
}
/**
* @see org.alfresco.cms.version.VersionService#revert(NodeRef)
*/
@Override
public void revert(NodeRef nodeRef)
{
if (logger.isDebugEnabled())
@@ -1081,19 +948,10 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
if (useDeprecatedV1)
{
super.revert(nodeRef, getCurrentVersion(nodeRef), true);
}
else
{
revert(nodeRef, getCurrentVersion(nodeRef), true);
}
revert(nodeRef, getCurrentVersion(nodeRef), true);
}
/**
* @see org.alfresco.service.cmr.version.VersionService#revert(org.alfresco.service.cmr.repository.NodeRef, boolean)
*/
@Override
public void revert(NodeRef nodeRef, boolean deep)
{
if (logger.isDebugEnabled())
@@ -1102,19 +960,10 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
if (useDeprecatedV1)
{
super.revert(nodeRef, getCurrentVersion(nodeRef), deep);
}
else
{
revert(nodeRef, getCurrentVersion(nodeRef), deep);
}
revert(nodeRef, getCurrentVersion(nodeRef), deep);
}
/**
* @see org.alfresco.service.cmr.version.VersionService#revert(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.version.Version)
*/
@Override
public void revert(NodeRef nodeRef, Version version)
{
if (logger.isDebugEnabled())
@@ -1123,19 +972,10 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
if (useDeprecatedV1)
{
super.revert(nodeRef, version, true);
}
else
{
revert(nodeRef, version, true);
}
revert(nodeRef, version, true);
}
/**
* @see org.alfresco.service.cmr.version.VersionService#revert(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.version.Version, boolean)
*/
@Override
public void revert(NodeRef nodeRef, Version version, boolean deep)
{
if (logger.isDebugEnabled())
@@ -1149,261 +989,245 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
logger.debug("revert nodeRef:" + nodeRef);
}
if (useDeprecatedV1)
// Check the mandatory parameters
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("version", version);
// Cross check that the version provided relates to the node reference provided
if (nodeRef.getId().equals(((NodeRef)version.getVersionProperty(Version2Model.PROP_FROZEN_NODE_REF)).getId()) == false)
{
super.revert(nodeRef, version, deep);
// Error since the version provided does not correspond to the node reference provided
throw new VersionServiceException(MSGID_ERR_REVERT_MISMATCH);
}
else
{
// Check the mandatory parameters
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("version", version);
// Cross check that the version provided relates to the node reference provided
if (nodeRef.getId().equals(((NodeRef)version.getVersionProperty(Version2Model.PROP_FROZEN_NODE_REF)).getId()) == false)
// Turn off any auto-version policy behaviours
this.policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
try
{
// The current (old) values
Map<QName, Serializable> oldProps = this.nodeService.getProperties(nodeRef);
Set<QName> oldAspectQNames = this.nodeService.getAspects(nodeRef);
QName oldNodeTypeQName = nodeService.getType(nodeRef);
// Store the current version label
String currentVersionLabel = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);
// The frozen (which will become new) values
// Get the node that represents the frozen state
NodeRef versionNodeRef = version.getFrozenStateNodeRef();
Map<QName, Serializable> newProps = this.nodeService.getProperties(versionNodeRef);
VersionUtil.convertFrozenToOriginalProps(newProps);
Set<QName> newAspectQNames = this.nodeService.getAspects(versionNodeRef);
// RevertDetails - given to policy behaviours
VersionRevertDetailsImpl revertDetails = new VersionRevertDetailsImpl();
revertDetails.setNodeRef(nodeRef);
revertDetails.setNodeType(oldNodeTypeQName);
// Do we want to maintain any existing property values?
Collection<QName> propsToLeaveAlone = new ArrayList<QName>();
Collection<QName> assocsToLeaveAlone = new ArrayList<QName>();
TypeDefinition typeDef = dictionaryService.getType(oldNodeTypeQName);
if(typeDef != null)
{
// Error since the version provided does not correspond to the node reference provided
throw new VersionServiceException(MSGID_ERR_REVERT_MISMATCH);
for(QName assocName : typeDef.getAssociations().keySet())
{
if(getRevertAssocAction(oldNodeTypeQName, assocName, revertDetails) == RevertAssocAction.IGNORE)
{
assocsToLeaveAlone.add(assocName);
}
}
}
// Turn off any auto-version policy behaviours
this.policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
try
{
// The current (old) values
Map<QName, Serializable> oldProps = this.nodeService.getProperties(nodeRef);
Set<QName> oldAspectQNames = this.nodeService.getAspects(nodeRef);
QName oldNodeTypeQName = nodeService.getType(nodeRef);
// Store the current version label
String currentVersionLabel = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);
// The frozen (which will become new) values
// Get the node that represents the frozen state
NodeRef versionNodeRef = version.getFrozenStateNodeRef();
Map<QName, Serializable> newProps = this.nodeService.getProperties(versionNodeRef);
VersionUtil.convertFrozenToOriginalProps(newProps);
Set<QName> newAspectQNames = this.nodeService.getAspects(versionNodeRef);
// RevertDetails - given to policy behaviours
VersionRevertDetailsImpl revertDetails = new VersionRevertDetailsImpl();
revertDetails.setNodeRef(nodeRef);
revertDetails.setNodeType(oldNodeTypeQName);
// Do we want to maintain any existing property values?
Collection<QName> propsToLeaveAlone = new ArrayList<QName>();
Collection<QName> assocsToLeaveAlone = new ArrayList<QName>();
TypeDefinition typeDef = dictionaryService.getType(oldNodeTypeQName);
if(typeDef != null)
{
for(QName assocName : typeDef.getAssociations().keySet())
{
if(getRevertAssocAction(oldNodeTypeQName, assocName, revertDetails) == RevertAssocAction.IGNORE)
for (QName aspect : oldAspectQNames)
{
AspectDefinition aspectDef = dictionaryService.getAspect(aspect);
if(aspectDef != null)
{
if (getRevertAspectAction(aspect, revertDetails) == RevertAspectAction.IGNORE)
{
propsToLeaveAlone.addAll(aspectDef.getProperties().keySet());
}
for(QName assocName : aspectDef.getAssociations().keySet())
{
if(getRevertAssocAction(aspect, assocName, revertDetails) == RevertAssocAction.IGNORE)
{
assocsToLeaveAlone.add(assocName);
}
}
}
for (QName aspect : oldAspectQNames)
{
AspectDefinition aspectDef = dictionaryService.getAspect(aspect);
if(aspectDef != null)
{
if (getRevertAspectAction(aspect, revertDetails) == RevertAspectAction.IGNORE)
{
propsToLeaveAlone.addAll(aspectDef.getProperties().keySet());
}
for(QName assocName : aspectDef.getAssociations().keySet())
{
if(getRevertAssocAction(aspect, assocName, revertDetails) == RevertAssocAction.IGNORE)
{
assocsToLeaveAlone.addAll(aspectDef.getAssociations().keySet());
}
}
}
}
for(QName prop : propsToLeaveAlone)
assocsToLeaveAlone.addAll(aspectDef.getAssociations().keySet());
}
}
}
}
for(QName prop : propsToLeaveAlone)
{
if(oldProps.containsKey(prop))
{
if(oldProps.containsKey(prop))
{
newProps.put(prop, oldProps.get(prop));
}
newProps.put(prop, oldProps.get(prop));
}
this.nodeService.setProperties(nodeRef, newProps);
}
this.nodeService.setProperties(nodeRef, newProps);
Set<QName> aspectsToRemove = new HashSet<QName>(oldAspectQNames);
aspectsToRemove.removeAll(newAspectQNames);
Set<QName> aspectsToAdd = new HashSet<QName>(newAspectQNames);
aspectsToAdd.removeAll(oldAspectQNames);
// add aspects that are not on the current node
for (QName aspect : aspectsToAdd)
Set<QName> aspectsToRemove = new HashSet<QName>(oldAspectQNames);
aspectsToRemove.removeAll(newAspectQNames);
Set<QName> aspectsToAdd = new HashSet<QName>(newAspectQNames);
aspectsToAdd.removeAll(oldAspectQNames);
// add aspects that are not on the current node
for (QName aspect : aspectsToAdd)
{
if (getRevertAspectAction(aspect, revertDetails) != RevertAspectAction.IGNORE)
{
this.nodeService.addAspect(nodeRef, aspect, null);
}
}
// remove aspects that are not on the frozen node
for (QName aspect : aspectsToRemove)
{
if (getRevertAspectAction(aspect, revertDetails) != RevertAspectAction.IGNORE)
{
if (getRevertAspectAction(aspect, revertDetails) != RevertAspectAction.IGNORE)
{
this.nodeService.addAspect(nodeRef, aspect, null);
}
this.nodeService.removeAspect(nodeRef, aspect);
}
// remove aspects that are not on the frozen node
for (QName aspect : aspectsToRemove)
}
// Re-add the versionable aspect to the reverted node
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == false)
{
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
}
// Re-set the version label property (since it should not be modified from the original)
this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, currentVersionLabel);
// Add/remove the child nodes
List<ChildAssociationRef> children = new ArrayList<ChildAssociationRef>(this.nodeService.getChildAssocs(nodeRef));
List<ChildAssociationRef> versionedChildren = this.nodeService.getChildAssocs(versionNodeRef);
for (ChildAssociationRef versionedChild : versionedChildren)
{
if (children.contains(versionedChild) == false)
{
if (getRevertAspectAction(aspect, revertDetails) != RevertAspectAction.IGNORE)
{
this.nodeService.removeAspect(nodeRef, aspect);
}
}
// Re-add the versionable aspect to the reverted node
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == false)
{
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
}
// Re-set the version label property (since it should not be modified from the original)
this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, currentVersionLabel);
// Add/remove the child nodes
List<ChildAssociationRef> children = new ArrayList<ChildAssociationRef>(this.nodeService.getChildAssocs(nodeRef));
List<ChildAssociationRef> versionedChildren = this.nodeService.getChildAssocs(versionNodeRef);
for (ChildAssociationRef versionedChild : versionedChildren)
{
if (children.contains(versionedChild) == false)
NodeRef childRef = null;
ChildAssociationRef assocToKeep = null;
if (this.nodeService.exists(versionedChild.getChildRef()) == true)
{
NodeRef childRef = null;
ChildAssociationRef assocToKeep = null;
if (this.nodeService.exists(versionedChild.getChildRef()) == true)
// The node was a primary child of the parent, but that is no longer the case. Despite this
// the node still exits so this means it has been moved.
// The best thing to do in this situation will be to re-add the node as a child, but it will not
// be a primary child
String childRefName = (String) this.nodeService.getProperty(versionedChild.getChildRef(), ContentModel.PROP_NAME);
childRef = this.nodeService.getChildByName(nodeRef, versionedChild.getTypeQName(), childRefName);
// we can faced with association that allow duplicate names
if (childRef == null)
{
// The node was a primary child of the parent, but that is no longer the case. Despite this
// the node still exits so this means it has been moved.
// The best thing to do in this situation will be to re-add the node as a child, but it will not
// be a primary child
String childRefName = (String) this.nodeService.getProperty(versionedChild.getChildRef(), ContentModel.PROP_NAME);
childRef = this.nodeService.getChildByName(nodeRef, versionedChild.getTypeQName(), childRefName);
// we can faced with association that allow duplicate names
if (childRef == null)
List<ChildAssociationRef> allAssocs = nodeService.getParentAssocs(versionedChild.getChildRef(), versionedChild.getTypeQName(), RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef assocToCheck : allAssocs)
{
List<ChildAssociationRef> allAssocs = nodeService.getParentAssocs(versionedChild.getChildRef(), versionedChild.getTypeQName(), RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef assocToCheck : allAssocs)
if (children.contains(assocToCheck))
{
if (children.contains(assocToCheck))
{
childRef = assocToCheck.getChildRef();
assocToKeep = assocToCheck;
break;
}
childRef = assocToCheck.getChildRef();
assocToKeep = assocToCheck;
break;
}
}
if (childRef == null )
{
childRef = this.nodeService.addChild(nodeRef, versionedChild.getChildRef(), versionedChild.getTypeQName(), versionedChild.getQName()).getChildRef();
}
}
else
if (childRef == null )
{
if (versionedChild.isPrimary() == true)
{
// Only try to restore missing children if we are doing a deep revert
// Look and see if we have a version history for the child node
if (deep == true && getVersionHistoryNodeRef(versionedChild.getChildRef()) != null)
{
// We're going to try and restore the missing child node and recreate the assoc
childRef = restore(
versionedChild.getChildRef(),
nodeRef,
versionedChild.getTypeQName(),
versionedChild.getQName());
}
// else the deleted child did not have a version history so we can't restore the child
// and so we can't revert the association
}
// else
// Since this was never a primary assoc and the child has been deleted we won't recreate
// the missing node as it was never owned by the node and we wouldn't know where to put it.
}
if (childRef != null)
{
if (assocToKeep != null)
{
children.remove(assocToKeep);
}
else
{
children.remove(nodeService.getPrimaryParent(childRef));
}
}
childRef = this.nodeService.addChild(nodeRef, versionedChild.getChildRef(), versionedChild.getTypeQName(), versionedChild.getQName()).getChildRef();
}
}
else
{
children.remove(versionedChild);
}
}
for (ChildAssociationRef ref : children)
{
if (!assocsToLeaveAlone.contains(ref.getTypeQName()))
{
this.nodeService.removeChild(nodeRef, ref.getChildRef());
}
}
// Add/remove the target associations
for (AssociationRef assocRef : this.nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL))
{
if (!assocsToLeaveAlone.contains(assocRef.getTypeQName()))
{
this.nodeService.removeAssociation(assocRef.getSourceRef(), assocRef.getTargetRef(), assocRef.getTypeQName());
}
}
for (AssociationRef versionedAssoc : this.nodeService.getTargetAssocs(versionNodeRef, RegexQNamePattern.MATCH_ALL))
{
if (!assocsToLeaveAlone.contains(versionedAssoc.getTypeQName()))
{
if (this.nodeService.exists(versionedAssoc.getTargetRef()) == true)
if (versionedChild.isPrimary() == true)
{
this.nodeService.createAssociation(nodeRef, versionedAssoc.getTargetRef(), versionedAssoc.getTypeQName());
// Only try to restore missing children if we are doing a deep revert
// Look and see if we have a version history for the child node
if (deep == true && getVersionHistoryNodeRef(versionedChild.getChildRef()) != null)
{
// We're going to try and restore the missing child node and recreate the assoc
childRef = restore(
versionedChild.getChildRef(),
nodeRef,
versionedChild.getTypeQName(),
versionedChild.getQName());
}
// else the deleted child did not have a version history so we can't restore the child
// and so we can't revert the association
}
}
// else
// Since the target of the assoc no longer exists we can't recreate the assoc
// else
// Since this was never a primary assoc and the child has been deleted we won't recreate
// the missing node as it was never owned by the node and we wouldn't know where to put it.
}
if (childRef != null)
{
if (assocToKeep != null)
{
children.remove(assocToKeep);
}
else
{
children.remove(nodeService.getPrimaryParent(childRef));
}
}
}
else
{
children.remove(versionedChild);
}
}
finally
for (ChildAssociationRef ref : children)
{
// Turn auto-version policies back on
this.policyBehaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
if (!assocsToLeaveAlone.contains(ref.getTypeQName()))
{
this.nodeService.removeChild(nodeRef, ref.getChildRef());
}
}
invokeAfterVersionRevert(nodeRef, version);
// Add/remove the target associations
for (AssociationRef assocRef : this.nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL))
{
if (!assocsToLeaveAlone.contains(assocRef.getTypeQName()))
{
this.nodeService.removeAssociation(assocRef.getSourceRef(), assocRef.getTargetRef(), assocRef.getTypeQName());
}
}
for (AssociationRef versionedAssoc : this.nodeService.getTargetAssocs(versionNodeRef, RegexQNamePattern.MATCH_ALL))
{
if (!assocsToLeaveAlone.contains(versionedAssoc.getTypeQName()))
{
if (this.nodeService.exists(versionedAssoc.getTargetRef()) == true)
{
this.nodeService.createAssociation(nodeRef, versionedAssoc.getTargetRef(), versionedAssoc.getTypeQName());
}
}
// else
// Since the target of the assoc no longer exists we can't recreate the assoc
}
}
finally
{
// Turn auto-version policies back on
this.policyBehaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
}
invokeAfterVersionRevert(nodeRef, version);
}
/* (non-Javadoc)
* @see org.alfresco.repo.service.cmr.version.VersionService#restore(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName)
*/
@Override
public NodeRef restore(
NodeRef nodeRef,
NodeRef parentNodeRef,
QName assocTypeQName,
QName assocQName)
{
if (useDeprecatedV1)
{
return super.restore(nodeRef, parentNodeRef, assocTypeQName, assocQName, true);
}
return restore(nodeRef, parentNodeRef, assocTypeQName, assocQName, true);
}
/* (non-Javadoc)
* @see org.alfresco.repo.service.cmr.version.VersionService#restore(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName, boolean)
*/
@Override
public NodeRef restore(
NodeRef nodeRef,
NodeRef parentNodeRef,
@@ -1417,11 +1241,6 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
if (useDeprecatedV1)
{
return super.restore(nodeRef, parentNodeRef, assocTypeQName, assocQName, deep);
}
NodeRef restoredNodeRef = null;
// Check that the node does not exist
@@ -1493,9 +1312,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
return headVersion;
}
/* (non-Javadoc)
* @see org.alfresco.repo.service.cmr.version.VersionService#deleteVersionHistory(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public void deleteVersionHistory(NodeRef nodeRef)
throws AspectMissingException
{
@@ -1505,45 +1322,35 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
if (useDeprecatedV1)
// Get the version history node for the node is question and delete it
NodeRef versionHistoryNodeRef = getVersionHistoryNodeRef(nodeRef);
if (versionHistoryNodeRef != null)
{
super.deleteVersionHistory(nodeRef);
}
else
{
// Get the version history node for the node is question and delete it
NodeRef versionHistoryNodeRef = getVersionHistoryNodeRef(nodeRef);
if (versionHistoryNodeRef != null)
try
{
try
// Disable auto-version behaviour
this.policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
// Delete the version history node
this.dbNodeService.deleteNode(versionHistoryNodeRef);
if (this.nodeService.exists(nodeRef) == true && this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
{
// Disable auto-version behaviour
this.policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
// Delete the version history node
this.dbNodeService.deleteNode(versionHistoryNodeRef);
if (this.nodeService.exists(nodeRef) == true && this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
{
// Reset the version label property on the versionable node
this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, null);
}
// Reset the version label property on the versionable node
this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, null);
}
finally
{
this.policyBehaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
}
}
finally
{
this.policyBehaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
}
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.version.VersionService#deleteVersion(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.version.Version)
*/
@Override
public void deleteVersion(NodeRef nodeRef, Version version)
{
if (logger.isDebugEnabled())
@@ -1552,47 +1359,37 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
if (useDeprecatedV1)
// Check the mandatory parameters
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("version", version);
Version currentVersion = getCurrentVersion(nodeRef);
// Delete the version node
this.dbNodeService.deleteNode(VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()));
if (currentVersion.getVersionLabel().equals(version.getVersionLabel()))
{
super.deleteVersion(nodeRef, version); // throws UnsupportedOperationException
}
else
{
// Check the mandatory parameters
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("version", version);
Version currentVersion = getCurrentVersion(nodeRef);
// Delete the version node
this.dbNodeService.deleteNode(VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()));
if (currentVersion.getVersionLabel().equals(version.getVersionLabel()))
Version headVersion = getHeadVersion(nodeRef);
if (headVersion != null)
{
Version headVersion = getHeadVersion(nodeRef);
if (headVersion != null)
{
// Reset the version label property on the versionable node to new head version
// Disable the VersionableAspect for this change though, we don't want
// to have this create a new version for the property change!
policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, headVersion.getVersionLabel());
}
else
{
deleteVersionHistory(nodeRef);
}
// Reset the version label property on the versionable node to new head version
// Disable the VersionableAspect for this change though, we don't want
// to have this create a new version for the property change!
policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, headVersion.getVersionLabel());
}
else
{
deleteVersionHistory(nodeRef);
}
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.version.VersionService#isAVersion(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
@Override
public boolean isAVersion(NodeRef nodeRef)
{
if (logger.isDebugEnabled())
if (logger.isDebugEnabled())
{
logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
@@ -1606,13 +1403,10 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
return this.dbNodeService.hasAspect(realNodeRef, Version2Model.ASPECT_VERSION);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.version.VersionService#isVersioned(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public boolean isVersioned(NodeRef nodeRef)
{
if (logger.isDebugEnabled())
if (logger.isDebugEnabled())
{
logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
@@ -1625,5 +1419,4 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
}
return this.dbNodeService.hasAspect(realNodeRef, ContentModel.ASPECT_VERSIONABLE);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -72,7 +72,8 @@ import org.springframework.extensions.surf.util.ParameterCheck;
*
* NOTE: deprecated since 3.1 (migrate and use Version2 Service)
*/
public class VersionServiceImpl extends AbstractVersionServiceImpl implements VersionService, VersionModel
@SuppressWarnings("deprecation")
public abstract class VersionServiceImpl extends AbstractVersionServiceImpl implements VersionService, VersionModel
{
private static Log logger = LogFactory.getLog(VersionServiceImpl.class);
@@ -182,12 +183,6 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
super.initialise();
}
// TODO - temp
protected void initialiseWithoutBind()
{
super.initialise();
}
/**
* Gets the reference to the version store
*

View File

@@ -73,7 +73,6 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
protected NodeService nodeService;
protected PermissionService permissionService;
protected CheckOutCheckInService checkOutCheckInService;
protected VersionMigrator versionMigrator;
protected SearchService versionSearchService;
protected DictionaryService dictionaryService;
protected PolicyComponent policyComponent;
@@ -174,7 +173,6 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
this.permissionService = (PermissionService)this.applicationContext.getBean("permissionService");
this.checkOutCheckInService = (CheckOutCheckInService) applicationContext.getBean("checkOutCheckInService");
this.versionSearchService = (SearchService)this.applicationContext.getBean("versionSearchService");
this.versionMigrator = (VersionMigrator)this.applicationContext.getBean("versionMigrator");
this.dictionaryService = (DictionaryService)this.applicationContext.getBean("dictionaryService");
this.policyComponent = (PolicyComponent)this.applicationContext.getBean("policyComponent");
this.policyBehaviourFilter = (BehaviourFilter)this.applicationContext.getBean("policyBehaviourFilter");

View File

@@ -1,628 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.version;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.node.integrity.IntegrityChecker;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.EqualsHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.experimental.categories.Category;
/**
* Test simple version store migration
*/
@Category(OwnJVMTestsCategory.class)
public class VersionMigratorTest extends BaseVersionStoreTest
{
private static Log logger = LogFactory.getLog(VersionMigratorTest.class);
protected VersionServiceImpl version1Service = new VersionServiceImpl();
protected Version2ServiceImpl version2Service;
protected NodeService versionNodeService;
protected VersionMigrator versionMigrator;
protected PolicyComponent policyComponent;
protected DictionaryService dictionaryService;
protected CheckOutCheckInService cociService;
protected IntegrityChecker integrityChecker;
public VersionMigratorTest()
{
//super.setDefaultRollback(false); // default is true
}
protected void onSetUpInTransaction() throws Exception
{
super.onSetUpInTransaction();
this.versionMigrator = (VersionMigrator)applicationContext.getBean("versionMigrator");
this.policyComponent = (PolicyComponent)applicationContext.getBean("policyComponent");
this.dictionaryService = (DictionaryService)applicationContext.getBean("dictionaryService");
this.version2Service = (Version2ServiceImpl)applicationContext.getBean("versionService");
this.versionNodeService = (NodeService)applicationContext.getBean("versionNodeService"); // note: auto-switches between V1 and V2
this.cociService = (CheckOutCheckInService)applicationContext.getBean("CheckoutCheckinService");
this.integrityChecker = (IntegrityChecker)applicationContext.getBean("integrityChecker");
// Version1Service is used to create the version nodes in Version1Store (workspace://lightWeightVersionStore)
version1Service.setDbNodeService(dbNodeService);
version1Service.setNodeService(dbNodeService);
version1Service.setPolicyComponent(policyComponent);
version1Service.setDictionaryService(dictionaryService);
version1Service.initialiseWithoutBind(); // TODO - temp - if use intialise, get: "More than one CalculateVersionLabelPolicy behaviour has been registered for the type {http://www.alfresco.org/model/content/1.0}content"
super.setVersionService(version1Service);
}
/**
* Test migration of a simple versioned node (one version, no children)
*/
public void testMigrateOneVersion() throws Exception
{
if (version2Service.useDeprecatedV1 == true)
{
logger.info("testMigrateOneVersion: skip");
return;
}
NodeRef versionableNode = createNewVersionableNode();
logger.info("testMigrateOneVersion: versionedNodeRef = " + versionableNode);
// Get the next version label
String nextVersionLabel = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
Date beforeVersionDate = (Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED);
long beforeVersionTime = beforeVersionDate.getTime();
logger.info("beforeVersion Date/Time: " + beforeVersionDate + " [" + beforeVersionTime + "]");
Version oldVersion = createVersion(versionableNode);
// get and store old version details for later comparison - versionNodeService will retrieve these from the old version store
QName oldVersionType = versionNodeService.getType(oldVersion.getFrozenStateNodeRef());
Set<QName> oldVersionAspects = versionNodeService.getAspects(oldVersion.getFrozenStateNodeRef());
Map<QName, Serializable> oldVersionProps = versionNodeService.getProperties(oldVersion.getFrozenStateNodeRef());
logger.info("oldVersion props: " + oldVersion);
logger.info("oldVersion created: " + oldVersion.getFrozenModifiedDate() + " [" + oldVersion.getFrozenModifiedDate().getTime()+"]");
logger.info("oldVersion props via versionNodeService: " + oldVersionProps);
VersionHistory vh = version1Service.getVersionHistory(versionableNode);
assertEquals(1, vh.getAllVersions().size());
NodeRef oldVHNodeRef = version1Service.getVersionHistoryNodeRef(versionableNode);
Thread.sleep(70000);
// Migrate and delete old version history !
NodeRef versionedNodeRef = versionMigrator.v1GetVersionedNodeRef(oldVHNodeRef);
NodeRef newVHNodeRef = versionMigrator.migrateVersionHistory(oldVHNodeRef, versionedNodeRef);
versionMigrator.v1DeleteVersionHistory(oldVHNodeRef);
VersionHistory vh2 = version2Service.getVersionHistory(versionableNode);
assertEquals(1, vh2.getAllVersions().size());
Version newVersion = vh2.getRootVersion();
logger.info("newVersion props: " + newVersion);
logger.info("newVersion created: " + newVersion.getFrozenModifiedDate() + " [" + newVersion.getFrozenModifiedDate().getTime()+"]");
// check new version - switch to new version service to do the check
super.setVersionService(version2Service);
checkNewVersion(beforeVersionTime, nextVersionLabel, newVersion, versionableNode);
// get and compare new version details - - versionNodeService will retrieve these from the new version store
QName newVersionType = versionNodeService.getType(newVersion.getFrozenStateNodeRef());
Set<QName> newVersionAspects = versionNodeService.getAspects(newVersion.getFrozenStateNodeRef());
Map<QName, Serializable> newVersionProps = versionNodeService.getProperties(newVersion.getFrozenStateNodeRef());
logger.info("newVersion props via versionNodeService: " + newVersionProps);
assertEquals(oldVersionType, newVersionType);
assertEquals(oldVersionAspects.size(), newVersionAspects.size());
for (QName key : oldVersionAspects)
{
assertTrue(""+key, newVersionAspects.contains(key));
}
// note: since 3.4, "cm:accessed" is not returned/migrated if null
int expectedPropCount = oldVersionProps.size();
if (oldVersionProps.get(ContentModel.PROP_ACCESSED) == null)
{
expectedPropCount--;
}
assertEquals(expectedPropCount, newVersionProps.size());
for (QName key : oldVersionProps.keySet())
{
if (! (key.equals(ContentModel.PROP_ACCESSED) && (oldVersionProps.get(key) == null)))
{
assertEquals(""+key, oldVersionProps.get(key), newVersionProps.get(key));
}
}
// ALFCOM-2658
assertEquals(oldVersion.getFrozenStateNodeRef().getId(), newVersion.getFrozenStateNodeRef().getId());
logger.info("testMigrateOneVersion: Migrated from oldVHNodeRef = " + oldVHNodeRef + " to newVHNodeRef = " + newVHNodeRef);
}
/**
* Test migration of a multiple versioned nodes
*/
public void testMigrateMultipleVersions() throws Exception
{
if (version2Service.useDeprecatedV1 == true)
{
logger.info("testMigrateOneVersion: skip");
return;
}
NodeRef versionableNode = createNewVersionableNode();
// Get the next version label and snapshot the date-time
String nextVersionLabel1 = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime1 = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
Version version1 = createVersion(versionableNode);
logger.info(version1);
// Get the next version label and snapshot the date-time
String nextVersionLabel2 = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime2 = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
Version version2 = createVersion(versionableNode);
logger.info(version2);
// Get the next version label and snapshot the date-time
String nextVersionLabel3 = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime3 = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
Version version3 = createVersion(versionableNode);
logger.info(version3);
VersionHistory vh1 = version1Service.getVersionHistory(versionableNode);
assertEquals(3, vh1.getAllVersions().size());
logger.info("testMigrateMultipleVersions: versionedNodeRef = " + versionableNode);
NodeRef oldVHNodeRef = version1Service.getVersionHistoryNodeRef(versionableNode);
// Migrate and delete old version history !
NodeRef versionedNodeRef = versionMigrator.v1GetVersionedNodeRef(oldVHNodeRef);
NodeRef newVHNodeRef = versionMigrator.migrateVersionHistory(oldVHNodeRef, versionedNodeRef);
versionMigrator.v1DeleteVersionHistory(oldVHNodeRef);
VersionHistory vh2 = version2Service.getVersionHistory(versionableNode);
assertEquals(3, vh2.getAllVersions().size());
// TODO move check version history into BaseVersionStoreTest
// check new versions - switch to new version service to do the check
super.setVersionService(version2Service);
Version[] newVersions = vh2.getAllVersions().toArray(new Version[]{});
checkVersion(beforeVersionTime1, nextVersionLabel1, newVersions[2], versionableNode);
checkVersion(beforeVersionTime2, nextVersionLabel2, newVersions[1], versionableNode);
checkNewVersion(beforeVersionTime3, nextVersionLabel3, newVersions[0], versionableNode);
// ALFCOM-2658
assertEquals(version1.getFrozenStateNodeRef().getId(), newVersions[2].getFrozenStateNodeRef().getId());
assertEquals(version2.getFrozenStateNodeRef().getId(), newVersions[1].getFrozenStateNodeRef().getId());
assertEquals(version3.getFrozenStateNodeRef().getId(), newVersions[0].getFrozenStateNodeRef().getId());
logger.info("testMigrateMultipleVersions: Migrated from oldVHNodeRef = " + oldVHNodeRef + " to newVHNodeRef = " + newVHNodeRef);
}
public void testMigrateMultipleNodesSuccessful() throws Exception
{
testMigrateMultipleNodes(false);
}
public void test_ETHREEOH_2091() throws Exception
{
// test partial migration (with skipped nodes)
testMigrateMultipleNodes(true);
}
/**
* Test migration of a multiple nodes (each with one version)
*/
private void testMigrateMultipleNodes(final boolean withSkip)
{
if (version2Service.useDeprecatedV1 == true)
{
logger.info("testMigrateOneVersion: skip");
return;
}
final int nodeCount = 5;
assert(nodeCount > 3);
final NodeRef[] versionableNodes = new NodeRef[nodeCount];
setComplete();
endTransaction();
RetryingTransactionHelper txHelper = transactionService.getRetryingTransactionHelper();
for (int i = 0; i < nodeCount; i++)
{
final int idx = i;
txHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute() throws Throwable
{
NodeRef versionableNode = null;
if ((idx % 2) == 0)
{
versionableNode = createNewVersionableNode();
}
else
{
versionableNode = createNewVersionableContentNode(true);
}
createVersion(versionableNode);
versionableNodes[idx] = versionableNode;
return null;
}
});
}
setComplete();
endTransaction();
txHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute() throws Throwable
{
// check old version histories
for (int i = 0; i< nodeCount; i++)
{
VersionHistory vh1 = version1Service.getVersionHistory(versionableNodes[i]);
assertNotNull(vh1);
assertEquals(1, vh1.getAllVersions().size());
}
return null;
}
});
setComplete();
endTransaction();
if (withSkip)
{
// remove test model - those nodes should fail - currently all - add separate create ...
// TODO ...
dictionaryDAO.removeModel(QName.createQName("http://www.alfresco.org/test/versionstorebasetest/1.0", "versionstorebasetestmodel"));
}
txHelper = transactionService.getRetryingTransactionHelper();
txHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute() throws Throwable
{
// Migrate (and don't delete old version history) !
versionMigrator.migrateVersions(1, 1, -1, false, null, false);
return null;
}
});
setComplete();
endTransaction();
txHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute() throws Throwable
{
// check new version histories
for (int i = 0; i < nodeCount; i++)
{
VersionHistory vh2 = version2Service.getVersionHistory(versionableNodes[i]);
if (withSkip && ((i % 2) == 0))
{
assertNull(vh2);
}
else
{
assertNotNull(vh2);
assertEquals(1, vh2.getAllVersions().size());
}
}
return null;
}
});
}
private NodeRef createNewVersionableContentNode(boolean versionable)
{
// Use this map to retrieve the versionable nodes in later tests
this.versionableNodes = new HashMap<String, NodeRef>();
// Create node (this node has some content)
NodeRef nodeRef = this.dbNodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myNode"),
ContentModel.TYPE_CONTENT,
this.nodeProperties).getChildRef();
if (versionable)
{
this.dbNodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
}
assertNotNull(nodeRef);
this.versionableNodes.put(nodeRef.getId(), nodeRef);
// Add the content to the node
ContentWriter contentWriter = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.putContent(TEST_CONTENT);
// Set author
Map<QName, Serializable> authorProps = new HashMap<QName, Serializable>(1, 1.0f);
authorProps.put(ContentModel.PROP_AUTHOR, "Charles Dickens");
this.dbNodeService.addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, authorProps);
return nodeRef;
}
public void test_ETHREEOH_1540() throws Exception
{
// Create the node used for tests
NodeRef nodeRef = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(TEST_NAMESPACE, "MyVersionableNode"),
TEST_TYPE_QNAME,
this.nodeProperties).getChildRef();
nodeService.addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, "name");
// Add the initial content to the node
ContentWriter contentWriter = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype("text/plain");
contentWriter.setEncoding("UTF-8");
contentWriter.putContent("my content");
VersionHistory vh1 = version1Service.getVersionHistory(nodeRef);
assertNull(vh1);
version2Service.useDeprecatedV1 = true;
// Add the version aspect to the created node
nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
vh1 = version1Service.getVersionHistory(nodeRef);
assertNull(vh1);
NodeRef workingCopyNodeRef = cociService.checkout(nodeRef);
vh1 = version1Service.getVersionHistory(nodeRef);
assertNull(vh1);
int v1count = 3;
for (int i = 1; i <= v1count; i++)
{
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
versionProperties.put(Version.PROP_DESCRIPTION, "This is a test checkin - " + i);
cociService.checkin(workingCopyNodeRef, versionProperties);
vh1 = version1Service.getVersionHistory(nodeRef);
assertEquals(i, vh1.getAllVersions().size());
workingCopyNodeRef = cociService.checkout(nodeRef);
vh1 = version1Service.getVersionHistory(nodeRef);
assertEquals(i, vh1.getAllVersions().size());
}
NodeRef oldVHNodeRef = version1Service.getVersionHistoryNodeRef(nodeRef);
version2Service.useDeprecatedV1 = false;
// Migrate and delete old version history !
NodeRef versionedNodeRef = versionMigrator.v1GetVersionedNodeRef(oldVHNodeRef);
//int nextVersionNumber = versionCounterService.nextVersionNumber(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, VersionModel.STORE_ID));
//versionCounterService.setVersionNumber(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, Version2Model.STORE_ID), nextVersionNumber);
// to force the error: https://issues.alfresco.com/jira/browse/ETHREEOH-1540
//versionCounterService.setVersionNumber(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, Version2Model.STORE_ID), 0);
NodeRef newVHNodeRef = versionMigrator.migrateVersionHistory(oldVHNodeRef, versionedNodeRef);
versionMigrator.v1DeleteVersionHistory(oldVHNodeRef);
VersionHistory vh2 = version2Service.getVersionHistory(nodeRef);
assertEquals(v1count, vh2.getAllVersions().size());
int v2count = 3;
for (int i = 1; i <= v2count; i++)
{
versionProperties = new HashMap<String, Serializable>();
versionProperties.put(Version.PROP_DESCRIPTION, "This is a test checkin - " + (v1count + i));
cociService.checkin(workingCopyNodeRef, versionProperties);
vh2 = version2Service.getVersionHistory(nodeRef);
assertEquals((v1count + i), vh2.getAllVersions().size());
workingCopyNodeRef = cociService.checkout(nodeRef);
vh2 = version2Service.getVersionHistory(nodeRef);
assertEquals((v1count + i), vh2.getAllVersions().size());
}
logger.info("testMigrateOneCheckoutVersion: Migrated from oldVHNodeRef = " + oldVHNodeRef + " to newVHNodeRef = " + newVHNodeRef);
}
/**
* Test migration of a single versioned node with versioned child assocs & peer assocs
*
* @since 3.3 Ent - applies only to direct upgrade from 2.x to 3.3 Ent or higher
*/
public void testMigrateVersionWithAssocs() throws Exception
{
if (version2Service.useDeprecatedV1 == true)
{
logger.info("testMigrateVersionWithAssocs: skip");
return;
}
NodeRef versionableNode = createNewVersionableNode();
NodeRef targetNode = createNewNode();
nodeService.createAssociation(versionableNode, targetNode, TEST_ASSOC);
// Get the next version label and snapshot the date-time
String nextVersionLabel1 = peekNextVersionLabel(versionableNode, versionProperties);
// Snap-shot the node created date-time
long beforeVersionTime1 = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
Version version1 = createVersion(versionableNode);
logger.info(version1);
VersionHistory vh1 = version1Service.getVersionHistory(versionableNode);
assertEquals(1, vh1.getAllVersions().size());
List<ChildAssociationRef> oldChildAssocs = nodeService.getChildAssocs(version1.getFrozenStateNodeRef());
List<AssociationRef> oldAssocs = nodeService.getTargetAssocs(version1.getFrozenStateNodeRef(), RegexQNamePattern.MATCH_ALL);
logger.info("testMigrateVersionWithAssocs: versionedNodeRef = " + versionableNode);
NodeRef oldVHNodeRef = version1Service.getVersionHistoryNodeRef(versionableNode);
// Migrate and delete old version history !
NodeRef versionedNodeRef = versionMigrator.v1GetVersionedNodeRef(oldVHNodeRef);
NodeRef newVHNodeRef = versionMigrator.migrateVersionHistory(oldVHNodeRef, versionedNodeRef);
versionMigrator.v1DeleteVersionHistory(oldVHNodeRef);
VersionHistory vh2 = version2Service.getVersionHistory(versionableNode);
assertEquals(1, vh2.getAllVersions().size());
// check new version - switch to new version service to do the check
super.setVersionService(version2Service);
Version[] newVersions = vh2.getAllVersions().toArray(new Version[]{});
Version newVersion1 = newVersions[0];
checkVersion(beforeVersionTime1, nextVersionLabel1, newVersion1, versionableNode);
List<ChildAssociationRef> newChildAssocs = nodeService.getChildAssocs(newVersion1.getFrozenStateNodeRef());
assertEquals(oldChildAssocs.size(), newChildAssocs.size());
for (ChildAssociationRef oldChildAssoc : oldChildAssocs)
{
boolean found = false;
for (ChildAssociationRef newChildAssoc : newChildAssocs)
{
if (newChildAssoc.getParentRef().getId().equals(oldChildAssoc.getParentRef().getId()) &&
newChildAssoc.getChildRef().equals(oldChildAssoc.getChildRef()) &&
newChildAssoc.getTypeQName().equals(oldChildAssoc.getTypeQName()) &&
newChildAssoc.getQName().equals(oldChildAssoc.getQName()) &&
(newChildAssoc.isPrimary() == oldChildAssoc.isPrimary()) &&
(newChildAssoc.getNthSibling() == oldChildAssoc.getNthSibling()))
{
found = true;
break;
}
}
if (! found)
{
fail(oldChildAssoc.toString()+ " not found");
}
}
List<AssociationRef> newAssocs = nodeService.getTargetAssocs(newVersion1.getFrozenStateNodeRef(), RegexQNamePattern.MATCH_ALL);
assertEquals(oldAssocs.size(), newAssocs.size());
for (AssociationRef oldAssoc : oldAssocs)
{
boolean found = false;
for (AssociationRef newAssoc : newAssocs)
{
if (newAssoc.getSourceRef().getId().equals(oldAssoc.getSourceRef().getId()) &&
newAssoc.getTargetRef().equals(oldAssoc.getTargetRef()) &&
newAssoc.getTypeQName().equals(oldAssoc.getTypeQName()) &&
EqualsHelper.nullSafeEquals(newAssoc.getId(), oldAssoc.getId()))
{
found = true;
break;
}
}
if (! found)
{
fail(oldAssoc.toString()+ " not found");
}
}
logger.info("testMigrateVersionWithAssocs: Migrated from oldVHNodeRef = " + oldVHNodeRef + " to newVHNodeRef = " + newVHNodeRef);
}
}

View File

@@ -426,8 +426,6 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
versionService.setPolicyComponent(policyComponent);
versionService.setPolicyBehaviourFilter(policyBehaviourFilter);
versionService.setPermissionService(permissionService);
versionService.setOnlyUseDeprecatedV1(false);
versionService.setVersionMigrator(versionMigrator);
versionService.setVersionComparatorClass(versionComparatorClass);
versionService.initialise();
setVersionService(versionService);
@@ -2471,10 +2469,6 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
authenticationComponent.setSystemUserAsCurrentUser();
// TEMP - for migration testing - force V1 store (override repository property)
final Version2ServiceImpl version2ServiceImpl = (Version2ServiceImpl)ctx.getBean("versionService");
version2ServiceImpl.setOnlyUseDeprecatedV1(true);
System.out.println("Using: " + versionService.getVersionStoreReference());
// Create a new store

View File

@@ -60,7 +60,6 @@ public class VersionTestSuite extends TestSuite
suite.addTestSuite(VersionServiceImplTest.class);
suite.addTestSuite(NodeServiceImplTest.class);
suite.addTestSuite(ContentServiceImplTest.class);
suite.addTestSuite(VersionMigratorTest.class);
return suite;
}
}