mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-30 18:15:39 +00:00
44674: Fix for ALF-17189 - The "Company Home" item in the top navigator menu and in the toolbar panel is invisible, if login as guest first then directly access the login page via URL. 44701: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.1-BUG-FIX 44700: Fix for ALF-10369 - support for OPTIONS requests for WebScript framework and Share proxy 44709: ALF-17164 Fix version.properties which was wrong in sdk zip 44710: ALF-14570 ("Check out" outboud rule works incorrect) 44722: MNT-246: Need the ability to configure a proxy with Enterprise Sync. - RemoteConnectorServiceImpl will now use an http/https proxy if the standard system properties for Java network proxy configuration are found. See http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html (Section 2.1 and 2.2) 44730: Merged V4.1 to V4.1-BUG-FIX 44461: Merged PATCHES/V4.1.1 to V4.1 44060: ALF-16962 / MNT-221 Links from a deleted user cause error in the "Links" page 44129: ALF-17134 / MNT-223: Unbound SOLR result set (from Explorer trashcan query) consumes heap - Now we emulate the behaviour of ACLEntryAfterInvocationProvider in SolrQueryHTTPClient, thus limiting otherwise unconstrained SOLR queries to return a finite number of results - New solr subsystem parameter solr.query.maximumResultsFromUnlimitedQuery introduced - Its default value is ${system.acl.maxPermissionChecks}, thus providing backward compatibility with old behaviour (1000 results max) - When there are no other limits in the search parameters, this value will be used to limit the number of results - SolrJSONResultSet.getResultSetMetata().getLimitedBy() will return an appropriate LimitBy value, according to how the query was limited 44130: ALF-17134 / MNT-223: Unbound SOLR result set (from Explorer trashcan query) consumes heap - Improved calculation of SolrJSONResultSet.getResultSetMetata().getLimitedBy() to better emulate ACLEntryAfterInvocationProvider 44141: ALF-17134 / MNT-223: Unbound SOLR result set (from Explorer trashcan query) consumes heap - Correction to handling of limited queries (Share search works again!) 44291: ALF-17094 / MNT-222 InvalidNodeRefException on user deletion in Share UI 44462: Merged PATCHES/V4.0.2 to V4.1 44221: ALF-17038 / MNT-226: Out-of-order versions for existing data during migration from 3.4.9 to 4.0.2.19 - Have been able to remove the need for any Comparators in the normal case. As Dave said, he thought it was ordered already. It is with "assoc.assoc_index ASC, assoc.id ASC". Required a bit of re factoring of Version2ServiceImpl to do it as they were referenced/used in a couple of other classes. - Modified all 43 Oracle sequences to include ORDER in the create statement. Probably only really was needed to do it on alf_child_assoc_seq to fix this issue, but it will stop similar issues in other clustered database setups. Did not change the upgrade scripts, as this will give us a clue that there will be existing data issues. - The name of a Comparator<Version> may be specified in the Alfresco global property: org.alfresco.repo.version.common.VersionLabelComparator and it will be used by BOTH Version2ServiceImpl and VersionServiceImpl. They in turn pass it on to Version2ServiceImpl instances when they create them. - A VersionLabelComparator already existed (still deprecated as we don't normally use it) and works: org.alfresco.repo.version.common.VersionLabelComparator. - Customers with out of sequence ids on Oracle RDBMS using a clustered database may 'correct on the fly' the order of their versions by setting the alfresco global property described above. - Have tested both with and without a comparator in development environment. Using break points and Collections.shuffle(version) in an expression was able to simulate out of order IDs. - New unit tests added to VersionHistoryImplTest and VersionServiceImplTest to test db ids out of order 44336: ALF-15935: Fixed SecureContext errors when ticket has expired. MNT-180 44467: Fixed compilation failure 44520: ALF-16590: Improved fix after testing by Mark Lugert 44563: Merged DEV to V4.1 (with corrections) 44547: ALF-17132: Possible XSS - arbitrary url parameters re-sent to the browser Escaping of keys and values of request attributes 44610: Merged PATCHES/V4.0.2 to V4.1 44435: ALF-17183: Merged DEV to V4.0.2 (4.0.2.22) 44429: MNT-232: Upgrade from 3.4.9 to 4.0.2 - FAILED - Initialize rootRefs in the property definition to prevent NPE. 44591: Fix to CIFS reported user free space when disk quotas are not enabled. 44595: ALF-17184 / MNT-243 Minimal fix for disk size and user quotas. (Bring values into line with API.) 44601: ALF-17184 / MNT-243 - Implementation of file size on Abstract Tennant Routing Content Store. 44608: ALF-15935 / MNT-180: Moved closeFile() call to closeConnection() cleanup method, always call closeFile() Do not check if file is marked as closed during cleanup, only open files should still be in the file table. 44652: ALF-17117: Created article or publication cant be viewed on WQS site - Fixes by Dmitry Vaserin - Removed unnecessary outer read locks from getRelatedAssets and getRelatedAsset to prevent deadlock - Correct markup error when node doesn't have tags 44653: ALF-17117: Created article or publication cant be viewed on WQS site - Missed file from previous checkin 44682: ALF-17118 WQS: Impossible to upload document to publications space - Only first part to do with the transformation failure has been committed. 44731: Merged V4.1 to V4.1-BUG-FIX (RECORD ONLY) 44441: Merge V4.1-BUG-FIX to V4.1 44270: Merge V3.4-BUG-FIX to V4.1-BUG-FIX 44266: BDE-111: harden generation of Windows installers - make sure build fails if installer generation fails - generate Windows unsigned installers in a place that is cleaned later, avoiding leftovers 44598: Merged V4.1-BUG-FIX to V4.1 44541: Fix for ALF-17151 SOLR - add support to disable permission checks 44577: Final part for ALF-16558 SOLR tracking does not do incremental updates but one single chunk - fixed code so SolrSearchers are held for as little time as possible 44607: Merged V4.1-BUG-FIX to V4.1 44603: ALF-14201: upgrade activiti to 5.7-20121211 44606: ALF-14201: upgrade activiti to 5.7-20121211 in Maven poms git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@44732 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
506 lines
22 KiB
Java
506 lines
22 KiB
Java
/*
|
|
* 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.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
|
|
import org.alfresco.model.ContentModel;
|
|
import org.alfresco.repo.dictionary.DictionaryBootstrap;
|
|
import org.alfresco.repo.dictionary.DictionaryDAO;
|
|
import org.alfresco.repo.node.archive.NodeArchiveService;
|
|
import org.alfresco.repo.policy.BehaviourFilter;
|
|
import org.alfresco.repo.policy.PolicyComponent;
|
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
|
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
|
import org.alfresco.repo.version.common.versionlabel.SerialVersionLabelPolicy;
|
|
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
|
import org.alfresco.service.cmr.repository.ContentData;
|
|
import org.alfresco.service.cmr.repository.ContentService;
|
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
|
import org.alfresco.service.cmr.repository.MLText;
|
|
import org.alfresco.service.cmr.repository.NodeRef;
|
|
import org.alfresco.service.cmr.repository.NodeService;
|
|
import org.alfresco.service.cmr.repository.StoreRef;
|
|
import org.alfresco.service.cmr.search.SearchService;
|
|
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
|
import org.alfresco.service.cmr.security.PermissionService;
|
|
import org.alfresco.service.cmr.version.Version;
|
|
import org.alfresco.service.cmr.version.VersionService;
|
|
import org.alfresco.service.namespace.QName;
|
|
import org.alfresco.service.transaction.TransactionService;
|
|
import org.alfresco.util.BaseSpringTest;
|
|
|
|
public abstract class BaseVersionStoreTest extends BaseSpringTest
|
|
{
|
|
/*
|
|
* Services used by the tests
|
|
*/
|
|
protected NodeService dbNodeService;
|
|
protected VersionService versionService;
|
|
protected ContentService contentService;
|
|
protected DictionaryDAO dictionaryDAO;
|
|
protected MutableAuthenticationService authenticationService;
|
|
protected TransactionService transactionService;
|
|
protected RetryingTransactionHelper txnHelper;
|
|
protected MutableAuthenticationDao authenticationDAO;
|
|
protected NodeArchiveService nodeArchiveService;
|
|
protected NodeService nodeService;
|
|
protected PermissionService permissionService;
|
|
protected CheckOutCheckInService checkOutCheckInService;
|
|
protected VersionMigrator versionMigrator;
|
|
protected SearchService versionSearchService;
|
|
protected DictionaryService dictionaryService;
|
|
protected PolicyComponent policyComponent;
|
|
protected BehaviourFilter policyBehaviourFilter;
|
|
|
|
/*
|
|
* Data used by tests
|
|
*/
|
|
protected StoreRef testStoreRef;
|
|
protected NodeRef rootNodeRef;
|
|
protected Map<String, Serializable> versionProperties;
|
|
protected HashMap<QName, Serializable> nodeProperties;
|
|
|
|
/**
|
|
* The most recent set of versionable nodes created by createVersionableNode
|
|
*/
|
|
protected HashMap<String, NodeRef> versionableNodes;
|
|
|
|
/*
|
|
* Property names and values
|
|
*/
|
|
protected static final String TEST_NAMESPACE = "http://www.alfresco.org/test/versionstorebasetest/1.0";
|
|
protected static final QName TEST_TYPE_QNAME = QName.createQName(TEST_NAMESPACE, "testtype");
|
|
protected static final QName TEST_ASPECT_QNAME = QName.createQName(TEST_NAMESPACE, "testaspect");
|
|
protected static final QName PROP_1 = QName.createQName(TEST_NAMESPACE, "prop1");
|
|
protected static final QName PROP_2 = QName.createQName(TEST_NAMESPACE, "prop2");
|
|
protected static final QName PROP_3 = QName.createQName(TEST_NAMESPACE, "prop3");
|
|
protected static final QName MULTI_PROP = QName.createQName(TEST_NAMESPACE, "multiProp");
|
|
protected static final String VERSION_PROP_1 = "versionProp1";
|
|
protected static final String VERSION_PROP_2 = "versionProp2";
|
|
protected static final String VERSION_PROP_3 = "versionProp3";
|
|
protected static final String VALUE_1 = "value1";
|
|
protected static final String VALUE_2 = "value2";
|
|
protected static final String VALUE_3 = "value3";
|
|
protected static final QName TEST_CHILD_ASSOC_1 = QName.createQName(TEST_NAMESPACE, "childassoc1");
|
|
protected static final QName TEST_CHILD_ASSOC_2 = QName.createQName(TEST_NAMESPACE, "childassoc2");
|
|
protected static final QName TEST_ASSOC = QName.createQName(TEST_NAMESPACE, "assoc1");
|
|
|
|
protected Collection<String> multiValue = null;
|
|
protected static final String MULTI_VALUE_1 = "multi1";
|
|
protected static final String MULTI_VALUE_2 = "multi2";
|
|
|
|
protected MLText mlText;
|
|
protected static final QName MLTEXT_PROP = QName.createQName(TEST_NAMESPACE, "propMl");
|
|
|
|
/**
|
|
* Test content
|
|
*/
|
|
protected static final String TEST_CONTENT = "This is the versioned test content.";
|
|
|
|
/**
|
|
* Test user details
|
|
*/
|
|
private static final String PWD = "admin";
|
|
|
|
/**
|
|
* Sets the meta model dao
|
|
*
|
|
* @param dictionaryDAO the meta model dao
|
|
*/
|
|
public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
|
|
{
|
|
this.dictionaryDAO = dictionaryDAO;
|
|
}
|
|
|
|
public void setVersionService(VersionService versionService)
|
|
{
|
|
this.versionService = versionService;
|
|
}
|
|
|
|
/**
|
|
* Called during the transaction setup
|
|
*/
|
|
protected void onSetUpInTransaction() throws Exception
|
|
{
|
|
// Set the multi value if required
|
|
if (this.multiValue == null)
|
|
{
|
|
this.multiValue = new ArrayList<String>();
|
|
this.multiValue.add(MULTI_VALUE_1);
|
|
this.multiValue.add(MULTI_VALUE_2);
|
|
}
|
|
|
|
// Get the services by name from the application context
|
|
this.dbNodeService = (NodeService)applicationContext.getBean("dbNodeService");
|
|
this.contentService = (ContentService)applicationContext.getBean("contentService");
|
|
this.authenticationService = (MutableAuthenticationService)applicationContext.getBean("authenticationService");
|
|
this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
|
|
this.txnHelper = (RetryingTransactionHelper) applicationContext.getBean("retryingTransactionHelper");
|
|
this.authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("authenticationDao");
|
|
this.nodeArchiveService = (NodeArchiveService) applicationContext.getBean("nodeArchiveService");
|
|
this.nodeService = (NodeService)applicationContext.getBean("nodeService");
|
|
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");
|
|
|
|
setVersionService((VersionService)applicationContext.getBean("versionService"));
|
|
|
|
authenticationService.clearCurrentSecurityContext();
|
|
|
|
// Create the test model
|
|
createTestModel();
|
|
|
|
// Create a bag of properties for later use
|
|
this.versionProperties = new HashMap<String, Serializable>();
|
|
versionProperties.put(VERSION_PROP_1, VALUE_1);
|
|
versionProperties.put(VERSION_PROP_2, VALUE_2);
|
|
versionProperties.put(VERSION_PROP_3, VALUE_3);
|
|
|
|
// Create the node properties
|
|
this.nodeProperties = new HashMap<QName, Serializable>();
|
|
this.nodeProperties.put(PROP_1, VALUE_1);
|
|
this.nodeProperties.put(PROP_2, VALUE_2);
|
|
this.nodeProperties.put(PROP_3, VALUE_3);
|
|
this.nodeProperties.put(MULTI_PROP, (Serializable)multiValue);
|
|
this.nodeProperties.put(ContentModel.PROP_CONTENT, new ContentData(null, "text/plain", 0L, "UTF-8"));
|
|
|
|
// Add mlText property
|
|
this.mlText = new MLText(Locale.UK, "UK value");
|
|
this.mlText.addValue(Locale.US, "Y'all US value");
|
|
this.nodeProperties.put(MLTEXT_PROP, this.mlText);
|
|
|
|
// Create a workspace that contains the 'live' nodes
|
|
this.testStoreRef = this.dbNodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
|
|
|
|
// Get a reference to the root node
|
|
this.rootNodeRef = this.dbNodeService.getRootNode(this.testStoreRef);
|
|
|
|
// Create and authenticate the user
|
|
|
|
if(!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName()))
|
|
{
|
|
authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), PWD.toCharArray());
|
|
}
|
|
|
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
|
}
|
|
|
|
/**
|
|
* Creates the test model used by the tests
|
|
*/
|
|
private void createTestModel()
|
|
{
|
|
// register the test model
|
|
List<String> bootstrapModels = new ArrayList<String>();
|
|
bootstrapModels.add("org/alfresco/repo/version/VersionStoreBaseTest_model.xml");
|
|
|
|
DictionaryBootstrap bootstrap = new DictionaryBootstrap();
|
|
bootstrap.setModels(bootstrapModels);
|
|
bootstrap.setDictionaryDAO(dictionaryDAO);
|
|
|
|
bootstrap.bootstrap();
|
|
}
|
|
|
|
/**
|
|
* Creates a new versionable node
|
|
*
|
|
* @return the node reference
|
|
*/
|
|
protected NodeRef createNewVersionableNode()
|
|
{
|
|
return createNode(true, TEST_TYPE_QNAME);
|
|
}
|
|
|
|
protected NodeRef createNewNode()
|
|
{
|
|
return createNode(false, TEST_TYPE_QNAME);
|
|
}
|
|
|
|
protected NodeRef createNode(boolean versionable, QName nodeType)
|
|
{
|
|
// Use this map to retrive 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("{test}MyVersionableNode"),
|
|
nodeType,
|
|
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);
|
|
|
|
// Add some children to the node
|
|
NodeRef child1 = this.dbNodeService.createNode(
|
|
nodeRef,
|
|
TEST_CHILD_ASSOC_1,
|
|
TEST_CHILD_ASSOC_1,
|
|
nodeType,
|
|
this.nodeProperties).getChildRef();
|
|
|
|
if (versionable)
|
|
{
|
|
this.dbNodeService.addAspect(child1, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
|
|
}
|
|
|
|
assertNotNull(child1);
|
|
this.versionableNodes.put(child1.getId(), child1);
|
|
NodeRef child2 = this.dbNodeService.createNode(
|
|
nodeRef,
|
|
TEST_CHILD_ASSOC_2,
|
|
TEST_CHILD_ASSOC_2,
|
|
nodeType,
|
|
this.nodeProperties).getChildRef();
|
|
|
|
if (versionable)
|
|
{
|
|
this.dbNodeService.addAspect(child2, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
|
|
}
|
|
|
|
assertNotNull(child2);
|
|
this.versionableNodes.put(child2.getId(), child2);
|
|
|
|
// Create a node that can be associated with the root node
|
|
NodeRef assocNode = this.dbNodeService.createNode(
|
|
rootNodeRef,
|
|
ContentModel.ASSOC_CHILDREN,
|
|
QName.createQName("{test}MyAssocNode"),
|
|
nodeType,
|
|
this.nodeProperties).getChildRef();
|
|
assertNotNull(assocNode);
|
|
this.dbNodeService.createAssociation(nodeRef, assocNode, TEST_ASSOC);
|
|
|
|
return nodeRef;
|
|
}
|
|
|
|
/**
|
|
* Creates a new version, checking the properties of the version.
|
|
* <p>
|
|
* The default test propreties are assigned to the version.
|
|
*
|
|
* @param versionableNode the versionable node
|
|
* @return the created (and checked) new version
|
|
*/
|
|
protected Version createVersion(NodeRef versionableNode)
|
|
{
|
|
return createVersion(versionableNode, this.versionProperties);
|
|
}
|
|
|
|
/**
|
|
* Creates a new version, checking the properties of the version.
|
|
*
|
|
* @param versionableNode the versionable node
|
|
* @param versionProperties the version properties
|
|
* @return the created (and checked) new version
|
|
*/
|
|
protected Version createVersion(NodeRef versionableNode, Map<String, Serializable> versionProperties)
|
|
{
|
|
// Get the next version label
|
|
String nextVersionLabel = peekNextVersionLabel(versionableNode, versionProperties);
|
|
|
|
// Snap-shot the node created date-time
|
|
long beforeVersionTime = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
|
|
|
|
// Now lets create a new version for this node
|
|
Version newVersion = versionService.createVersion(versionableNode, this.versionProperties);
|
|
checkNewVersion(beforeVersionTime, nextVersionLabel, newVersion, versionableNode);
|
|
|
|
// Return the new version
|
|
return newVersion;
|
|
}
|
|
|
|
protected Collection<Version> createVersion(NodeRef versionableNode, Map<String, Serializable> versionProperties, boolean versionChildren)
|
|
{
|
|
// Get the next version label
|
|
String nextVersionLabel = peekNextVersionLabel(versionableNode, versionProperties);
|
|
|
|
// Snap-shot the node created date-time
|
|
long beforeVersionTime = ((Date)nodeService.getProperty(versionableNode, ContentModel.PROP_CREATED)).getTime();
|
|
|
|
// Now lets create new version for this node (optionally with children)
|
|
Collection<Version> versions = versionService.createVersion(versionableNode, this.versionProperties, versionChildren);
|
|
|
|
// Check the returned versions are correct
|
|
checkVersionCollection(nextVersionLabel, beforeVersionTime, versions);
|
|
|
|
// Return the new versions
|
|
return versions;
|
|
}
|
|
|
|
/**
|
|
* Gets the next version label
|
|
*/
|
|
protected String peekNextVersionLabel(NodeRef nodeRef, Map<String, Serializable> versionProperties)
|
|
{
|
|
Version version = this.versionService.getCurrentVersion(nodeRef);
|
|
SerialVersionLabelPolicy policy = new SerialVersionLabelPolicy();
|
|
return policy.calculateVersionLabel(ContentModel.TYPE_CMOBJECT, version, versionProperties);
|
|
}
|
|
|
|
/**
|
|
* Checkd the validity of a new version
|
|
*
|
|
* @param beforeVersionTime the time snap shot before the version was created
|
|
* @param newVersion the new version
|
|
* @param versionableNode the versioned node
|
|
*/
|
|
protected void checkVersion(long beforeVersionTime, String expectedVersionLabel, Version newVersion, NodeRef versionableNode)
|
|
{
|
|
assertNotNull(newVersion);
|
|
|
|
// Check the version label
|
|
assertEquals(
|
|
"The expected version label was not used.",
|
|
expectedVersionLabel,
|
|
newVersion.getVersionLabel());
|
|
|
|
// Check the created date
|
|
long afterVersionTime = System.currentTimeMillis();
|
|
long createdDate = newVersion.getFrozenModifiedDate().getTime();
|
|
if (createdDate < beforeVersionTime || createdDate > afterVersionTime)
|
|
{
|
|
fail("The created date of the version is incorrect.");
|
|
}
|
|
|
|
// Check the creator
|
|
assertEquals(AuthenticationUtil.getAdminUserName(), newVersion.getFrozenModifier());
|
|
|
|
// Check the metadata properties of the version
|
|
Map<String, Serializable> props = newVersion.getVersionProperties();
|
|
assertNotNull("The version properties collection should not be null.", props);
|
|
if (versionProperties != null)
|
|
{
|
|
// TODO sort this out - need to check for the reserved properties too
|
|
//assertEquals(versionProperties.size(), props.size());
|
|
for (String key : versionProperties.keySet())
|
|
{
|
|
assertEquals(
|
|
versionProperties.get(key),
|
|
newVersion.getVersionProperty(key));
|
|
}
|
|
}
|
|
|
|
// Check that the node reference is correct
|
|
NodeRef nodeRef = newVersion.getFrozenStateNodeRef();
|
|
assertNotNull(nodeRef);
|
|
|
|
// Switch VersionStore depending on configured impl
|
|
if (versionService.getVersionStoreReference().getIdentifier().equals(Version2Model.STORE_ID))
|
|
{
|
|
// V2 version store (eg. workspace://version2Store)
|
|
assertEquals(
|
|
Version2Model.STORE_ID,
|
|
nodeRef.getStoreRef().getIdentifier());
|
|
assertEquals(
|
|
Version2Model.STORE_PROTOCOL,
|
|
nodeRef.getStoreRef().getProtocol());
|
|
assertNotNull(nodeRef.getId());
|
|
}
|
|
else if (versionService.getVersionStoreReference().getIdentifier().equals(VersionModel.STORE_ID))
|
|
{
|
|
// Deprecated V1 version store (eg. workspace://lightWeightVersionStore)
|
|
assertEquals(
|
|
VersionModel.STORE_ID,
|
|
nodeRef.getStoreRef().getIdentifier());
|
|
assertEquals(
|
|
VersionModel.STORE_PROTOCOL,
|
|
nodeRef.getStoreRef().getProtocol());
|
|
assertNotNull(nodeRef.getId());
|
|
}
|
|
}
|
|
|
|
protected void checkNewVersion(long beforeVersionTime, String expectedVersionLabel, Version newVersion, NodeRef versionableNode)
|
|
{
|
|
checkVersion(beforeVersionTime, expectedVersionLabel, newVersion, versionableNode);
|
|
|
|
// TODO: How do we check the frozen attributes ??
|
|
|
|
// Check the node ref for the current version
|
|
String currentVersionLabel = (String)this.dbNodeService.getProperty(
|
|
versionableNode,
|
|
ContentModel.PROP_VERSION_LABEL);
|
|
assertEquals(newVersion.getVersionLabel(), currentVersionLabel);
|
|
}
|
|
|
|
/**
|
|
* Helper method to check the validity of the list of newly created versions.
|
|
*
|
|
* @param beforeVersionTime the time before the versions where created
|
|
* @param versions the collection of version objects
|
|
*/
|
|
private void checkVersionCollection(String expectedVersionLabel, long beforeVersionTime, Collection<Version> versions)
|
|
{
|
|
for (Version version : versions)
|
|
{
|
|
// Get the frozen id from the version
|
|
String frozenNodeId = null;
|
|
|
|
// Switch VersionStore depending on configured impl
|
|
if (versionService.getVersionStoreReference().getIdentifier().equals(Version2Model.STORE_ID))
|
|
{
|
|
// V2 version store (eg. workspace://version2Store)
|
|
frozenNodeId = ((NodeRef)version.getVersionProperty(Version2Model.PROP_FROZEN_NODE_REF)).getId();
|
|
}
|
|
else if (versionService.getVersionStoreReference().getIdentifier().equals(VersionModel.STORE_ID))
|
|
{
|
|
// Deprecated V1 version store (eg. workspace://lightWeightVersionStore)
|
|
frozenNodeId = (String)version.getVersionProperty(VersionModel.PROP_FROZEN_NODE_ID);
|
|
}
|
|
|
|
assertNotNull("Unable to retrieve the frozen node id from the created version.", frozenNodeId);
|
|
|
|
// Get the original node ref (based on the forzen node)
|
|
NodeRef origionaNodeRef = this.versionableNodes.get(frozenNodeId);
|
|
assertNotNull("The versionable node ref that relates to the frozen node id can not be found.", origionaNodeRef);
|
|
|
|
// Check the new version
|
|
checkNewVersion(beforeVersionTime, expectedVersionLabel, version, origionaNodeRef);
|
|
}
|
|
}
|
|
}
|