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

@@ -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
*