Merged V3.2 to HEAD

16714: WCM/AVM fixes - ETHREEOH-2697 & ETHREEOH-1847
    16802: Merged V3.1 to V3.2
         16801: AVMTestSuite - add couple of missing unit tests
    16810: WCM locking - minor improvement to include lock owner (when trying to "grabLock")


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16925 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2009-10-14 14:37:18 +00:00
parent 8d2f4f8dd2
commit 3db59a0960
13 changed files with 504 additions and 488 deletions

View File

@@ -359,6 +359,9 @@
<property name="contentService"> <property name="contentService">
<ref bean="contentService"/> <ref bean="contentService"/>
</property> </property>
<property name="avmSnapShotTriggeredIndexingMethodInterceptor">
<ref bean="avmSnapShotTriggeredIndexingMethodInterceptor"/>
</property>
</bean> </bean>

View File

@@ -1,5 +1,5 @@
# AVM related messages # AVM related messages
expiredcontent.workflow.title=Expired Content In ''{0}'' expiredcontent.workflow.title=Expired Content In ''{0}''
avmlockservice.locked=You do not have access to the item at path {0} it is currently locked by another user. avmlockservice.locked=You do not have access to the item at path {0} it is currently locked by another user {1}.
testserver.taken=The test server ''{0}'' you selected has been allocated to another user, if possible, select a different server and try again. testserver.taken=The test server ''{0}'' you selected has been allocated to another user, if possible, select a different server and try again.

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -34,6 +34,8 @@ import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.importer.ImporterBootstrap; import org.alfresco.repo.importer.ImporterBootstrap;
import org.alfresco.repo.node.index.FullIndexRecoveryComponent.RecoveryMode; import org.alfresco.repo.node.index.FullIndexRecoveryComponent.RecoveryMode;
import org.alfresco.repo.search.AVMSnapShotTriggeredIndexingMethodInterceptor;
import org.alfresco.repo.search.IndexMode;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentService;
@@ -92,6 +94,7 @@ public class ConfigurationChecker extends AbstractLifecycleBean
private NodeService nodeService; private NodeService nodeService;
private SearchService searchService; private SearchService searchService;
private ContentService contentService; private ContentService contentService;
private AVMSnapShotTriggeredIndexingMethodInterceptor avmSnapShotTriggeredIndexingMethodInterceptor;
public ConfigurationChecker() public ConfigurationChecker()
{ {
@@ -167,7 +170,12 @@ public class ConfigurationChecker extends AbstractLifecycleBean
{ {
this.contentService = contentService; this.contentService = contentService;
} }
public void setAvmSnapShotTriggeredIndexingMethodInterceptor(AVMSnapShotTriggeredIndexingMethodInterceptor avmSnapShotTriggeredIndexingMethodInterceptor)
{
this.avmSnapShotTriggeredIndexingMethodInterceptor = avmSnapShotTriggeredIndexingMethodInterceptor;
}
@Override @Override
protected void onBootstrap(ApplicationEvent event) protected void onBootstrap(ApplicationEvent event)
{ {
@@ -208,12 +216,6 @@ public class ConfigurationChecker extends AbstractLifecycleBean
List<StoreRef> missingIndexStoreRefs = new ArrayList<StoreRef>(0); List<StoreRef> missingIndexStoreRefs = new ArrayList<StoreRef>(0);
for (StoreRef storeRef : storeRefs) for (StoreRef storeRef : storeRefs)
{ {
// TODO: For now, do not check existence of index for AVM stores
//if (storeRef.getProtocol().equals(StoreRef.PROTOCOL_AVM))
//{
// continue;
//}
@SuppressWarnings("unused") @SuppressWarnings("unused")
NodeRef rootNodeRef = null; NodeRef rootNodeRef = null;
try try
@@ -227,6 +229,19 @@ public class ConfigurationChecker extends AbstractLifecycleBean
} }
if (indexRecoveryMode != RecoveryMode.FULL) if (indexRecoveryMode != RecoveryMode.FULL)
{ {
if (storeRef.getProtocol().equals(StoreRef.PROTOCOL_AVM))
{
IndexMode storeIndexMode = avmSnapShotTriggeredIndexingMethodInterceptor.getIndexMode(storeRef.getIdentifier());
if (storeIndexMode.equals(IndexMode.UNINDEXED))
{
if (logger.isDebugEnabled())
{
logger.debug("Skipping index for store: " + storeRef + " (unindexed AVM store)");
}
continue;
}
}
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("Checking index for store: " + storeRef); logger.debug("Checking index for store: " + storeRef);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -175,7 +175,15 @@ public class AVMLockingAwareService implements AVMService, ApplicationContextAwa
{ {
fService.createStore(name); fService.createStore(name);
} }
/* (non-Javadoc)
* @see org.alfresco.service.cmr.avm.AVMService#createStore(java.lang.String, java.util.Map)
*/
public void createStore(String name, Map<QName, PropertyValue> props)
{
fService.createStore(name, props);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.service.cmr.avm.AVMService#deleteNodeProperties(java.lang.String) * @see org.alfresco.service.cmr.avm.AVMService#deleteNodeProperties(java.lang.String)
*/ */
@@ -915,15 +923,28 @@ public class AVMLockingAwareService implements AVMService, ApplicationContextAwa
if (webProject != null) if (webProject != null)
{ {
String userName = fAuthenticationService.getCurrentUserName(); String userName = fAuthenticationService.getCurrentUserName();
if (!fLockingService.hasAccess(webProject, path, userName))
boolean hasAccess = fLockingService.hasAccess(webProject, path, userName);
AVMLock lock = fLockingService.getLock(webProject, storePath[1]);
if (!hasAccess)
{ {
throw new AVMLockingException("avmlockservice.locked", new Object[]{path}); String owners = null;
if (lock == null)
{
owners = null;
}
else
{
owners = lock.getOwners().toString(); // eg. '[alice]' or '[alice, bob]'
}
throw new AVMLockingException("avmlockservice.locked", new Object[]{path, owners});
} }
if (fLockingService.getLock(webProject, storePath[1]) == null) if (lock == null)
{ {
List<String> owners = new ArrayList<String>(1); List<String> owners = new ArrayList<String>(1);
owners.add(userName); owners.add(userName);
AVMLock lock = new AVMLock(webProject, storePath[0], storePath[1], AVMLockingService.Type.DISCRETIONARY, owners); lock = new AVMLock(webProject, storePath[0], storePath[1], AVMLockingService.Type.DISCRETIONARY, owners);
fLockingService.lockPath(lock); fLockingService.lockPath(lock);
} }
} }

View File

@@ -451,6 +451,11 @@ public class AVMRepository
* The name to give the new AVMStore. * The name to give the new AVMStore.
*/ */
public void createAVMStore(String name) public void createAVMStore(String name)
{
createAVMStore(name, null);
}
public void createAVMStore(String name, Map<QName, PropertyValue> props)
{ {
AlfrescoTransactionSupport.bindListener(fCreateStoreTxnListener); AlfrescoTransactionSupport.bindListener(fCreateStoreTxnListener);
if (getAVMStoreByName(name) != null) if (getAVMStoreByName(name) != null)
@@ -465,6 +470,12 @@ public class AVMRepository
rootNode.setStoreNew(null); rootNode.setStoreNew(null);
fAVMNodeDAO.update(rootNode); fAVMNodeDAO.update(rootNode);
if (props != null)
{
setStoreProperties(name, props);
}
fCreateStoreTxnListener.storeCreated(name); fCreateStoreTxnListener.storeCreated(name);
} }

View File

@@ -474,7 +474,7 @@ public class AVMServiceImpl implements AVMService
} }
/** /**
* Create an AVMStore with the given name. It must not exist. * Create an AVMStore with the given name (it must not exist).
* @param name The name to give the AVMStore. * @param name The name to give the AVMStore.
*/ */
public void createStore(String name) public void createStore(String name)
@@ -485,8 +485,22 @@ public class AVMServiceImpl implements AVMService
} }
fAVMRepository.createAVMStore(name); fAVMRepository.createAVMStore(name);
} }
/** /**
* Create an AVMStore with the given name (it must not exist) and set store properties.
* @param name The name to give the AVMStore.
* @param props A Map of the properties to set.
*/
public void createStore(String name, Map<QName, PropertyValue> props)
{
if (name == null || !FileNameValidator.isValid(name))
{
throw new AVMBadArgumentException("Bad Name.");
}
fAVMRepository.createAVMStore(name, props);
}
/**
* Create a branch. * Create a branch.
* @param version The version to branch from. * @param version The version to branch from.
* @param srcPath The path to the thing to branch from. * @param srcPath The path to the thing to branch from.

View File

@@ -27,6 +27,8 @@ package org.alfresco.repo.avm;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.alfresco.repo.avm.locking.AVMLockingServiceTest;
/** /**
* AVM test suite * AVM test suite
*/ */
@@ -48,6 +50,7 @@ public class AVMTestSuite extends TestSuite
suite.addTestSuite(AVMServiceTestBase.class); suite.addTestSuite(AVMServiceTestBase.class);
suite.addTestSuite(AVMServiceTest.class); suite.addTestSuite(AVMServiceTest.class);
suite.addTestSuite(AVMServiceLocalTest.class); suite.addTestSuite(AVMServiceLocalTest.class);
suite.addTestSuite(AVMLockingServiceTest.class);
suite.addTestSuite(AVMServicePermissionsTest.class); suite.addTestSuite(AVMServicePermissionsTest.class);
suite.addTestSuite(AVMServiceIndexTest.class); suite.addTestSuite(AVMServiceIndexTest.class);

View File

@@ -152,7 +152,15 @@ public class MultiTAVMService implements AVMService
{ {
fService.createStore(getTenantStoreName(storeName)); fService.createStore(getTenantStoreName(storeName));
} }
/* (non-Javadoc)
* @see org.alfresco.service.cmr.avm.AVMService#createStore(java.lang.String, java.util.Map)
*/
public void createStore(String name, Map<QName, PropertyValue> props)
{
fService.createStore(name, props);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.service.cmr.avm.AVMService#deleteNodeProperties(java.lang.String) * @see org.alfresco.service.cmr.avm.AVMService#deleteNodeProperties(java.lang.String)
*/ */

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -31,6 +31,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.model.WCMAppModel; import org.alfresco.model.WCMAppModel;
import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationComponent;
@@ -47,9 +49,8 @@ import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.springframework.context.support.FileSystemXmlApplicationContext; import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
import junit.framework.TestCase;
/** /**
* Tests for AVM locking service. * Tests for AVM locking service.
@@ -57,7 +58,7 @@ import junit.framework.TestCase;
*/ */
public class AVMLockingServiceTest extends TestCase public class AVMLockingServiceTest extends TestCase
{ {
private static FileSystemXmlApplicationContext fContext = null; private static ApplicationContext fContext = null;
private static AVMLockingService fService; private static AVMLockingService fService;
@@ -77,6 +78,8 @@ public class AVMLockingServiceTest extends TestCase
private static NodeRef fWebProject; private static NodeRef fWebProject;
private final static String WP = "alfresco-"+System.currentTimeMillis();
/* (non-Javadoc) /* (non-Javadoc)
* @see junit.framework.TestCase#setUp() * @see junit.framework.TestCase#setUp()
*/ */
@@ -85,7 +88,7 @@ public class AVMLockingServiceTest extends TestCase
{ {
if (fContext == null) if (fContext == null)
{ {
fContext = new FileSystemXmlApplicationContext("config/alfresco/application-context.xml"); fContext = ApplicationContextHelper.getApplicationContext();
fService = (AVMLockingService)fContext.getBean("AVMLockingService"); fService = (AVMLockingService)fContext.getBean("AVMLockingService");
fAttributeService = (AttributeService)fContext.getBean("AttributeService"); fAttributeService = (AttributeService)fContext.getBean("AttributeService");
fPersonService = (PersonService)fContext.getBean("PersonService"); fPersonService = (PersonService)fContext.getBean("PersonService");
@@ -99,9 +102,9 @@ public class AVMLockingServiceTest extends TestCase
// Set up a fake web project. // Set up a fake web project.
NodeRef root = fRepoRemote.getRoot(); NodeRef root = fRepoRemote.getRoot();
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
properties.put(WCMAppModel.PROP_AVMSTORE, "alfresco"); properties.put(WCMAppModel.PROP_AVMSTORE, WP);
fWebProject = fNodeService.createNode(root, ContentModel.ASSOC_CONTAINS, fWebProject = fNodeService.createNode(root, ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "alfresco"), QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, WP),
WCMAppModel.TYPE_AVMWEBFOLDER, properties).getChildRef(); WCMAppModel.TYPE_AVMWEBFOLDER, properties).getChildRef();
// Set up sample users groups and roles. // Set up sample users groups and roles.
fAuthenticationService.createAuthentication("Buffy", "Buffy".toCharArray()); fAuthenticationService.createAuthentication("Buffy", "Buffy".toCharArray());
@@ -134,7 +137,10 @@ public class AVMLockingServiceTest extends TestCase
List<String> webProjects = fService.getWebProjects(); List<String> webProjects = fService.getWebProjects();
for (String webProject : webProjects) for (String webProject : webProjects)
{ {
fService.removeWebProject(webProject); if (webProject.equals(WP))
{
fService.removeWebProject(WP);
}
} }
fAuthenticationService.deleteAuthentication("Buffy"); fAuthenticationService.deleteAuthentication("Buffy");
fAuthenticationService.deleteAuthentication("Willow"); fAuthenticationService.deleteAuthentication("Willow");
@@ -156,25 +162,25 @@ public class AVMLockingServiceTest extends TestCase
{ {
try try
{ {
fService.addWebProject("alfresco"); fService.addWebProject(WP);
System.out.println(fAttributeService.getAttribute(".avm_lock_table")); System.out.println(fAttributeService.getAttribute(".avm_lock_table"));
List<String> owners = new ArrayList<String>(); List<String> owners = new ArrayList<String>();
owners.add("Buffy"); owners.add("Buffy");
owners.add("Spike"); owners.add("Spike");
AVMLock lock = new AVMLock("alfresco", AVMLock lock = new AVMLock(WP,
"Sunnydale", "Sunnydale",
"Revello Drive/1630", "Revello Drive/1630",
AVMLockingService.Type.DISCRETIONARY, AVMLockingService.Type.DISCRETIONARY,
owners); owners);
fService.lockPath(lock); fService.lockPath(lock);
System.out.println(fAttributeService.getAttribute(".avm_lock_table")); System.out.println(fAttributeService.getAttribute(".avm_lock_table"));
assertNotNull(fService.getLock("alfresco", "Revello Drive/1630")); assertNotNull(fService.getLock(WP, "Revello Drive/1630"));
// assertEquals(1, fService.getUsersLocks("Buffy").size()); // assertEquals(1, fService.getUsersLocks("Buffy").size());
assertEquals(1, fService.getWebProjectLocks("alfresco").size()); assertEquals(1, fService.getWebProjectLocks(WP).size());
List<String> owners2 = new ArrayList<String>(); List<String> owners2 = new ArrayList<String>();
owners2.add("Buffy"); owners2.add("Buffy");
owners2.add("Willow"); owners2.add("Willow");
AVMLock lock2 = new AVMLock("alfresco", AVMLock lock2 = new AVMLock(WP,
"Sunnydale", "Sunnydale",
"UC Sunnydale/Stevenson Hall", "UC Sunnydale/Stevenson Hall",
AVMLockingService.Type.DISCRETIONARY, AVMLockingService.Type.DISCRETIONARY,
@@ -182,14 +188,14 @@ public class AVMLockingServiceTest extends TestCase
fService.lockPath(lock2); fService.lockPath(lock2);
System.out.println(fAttributeService.getAttribute(".avm_lock_table")); System.out.println(fAttributeService.getAttribute(".avm_lock_table"));
// assertEquals(2, fService.getUsersLocks("Buffy").size()); // assertEquals(2, fService.getUsersLocks("Buffy").size());
assertEquals(2, fService.getWebProjectLocks("alfresco").size()); assertEquals(2, fService.getWebProjectLocks(WP).size());
System.out.println("Before----------------------------"); System.out.println("Before----------------------------");
fService.removeLock("alfresco", "Revello Drive/1630"); fService.removeLock(WP, "Revello Drive/1630");
System.out.println("After----------------------------"); System.out.println("After----------------------------");
System.out.println(fAttributeService.getAttribute(".avm_lock_table")); System.out.println(fAttributeService.getAttribute(".avm_lock_table"));
// assertEquals(1, fService.getUsersLocks("Buffy").size()); // assertEquals(1, fService.getUsersLocks("Buffy").size());
assertEquals(1, fService.getWebProjectLocks("alfresco").size()); assertEquals(1, fService.getWebProjectLocks(WP).size());
fService.removeWebProject("alfresco"); fService.removeWebProject(WP);
System.out.println(fAttributeService.getAttribute(".avm_lock_table")); System.out.println(fAttributeService.getAttribute(".avm_lock_table"));
// assertEquals(0, fService.getUsersLocks("Spike").size()); // assertEquals(0, fService.getUsersLocks("Spike").size());
// assertEquals(0, fService.getUsersLocks("Buffy").size()); // assertEquals(0, fService.getUsersLocks("Buffy").size());
@@ -207,26 +213,26 @@ public class AVMLockingServiceTest extends TestCase
{ {
try try
{ {
fService.addWebProject("alfresco"); fService.addWebProject(WP);
List<String> owners = new ArrayList<String>(); List<String> owners = new ArrayList<String>();
owners.add("ROLE_SUPER_POWERED"); owners.add("ROLE_SUPER_POWERED");
owners.add("Tara"); owners.add("Tara");
AVMLock lock = new AVMLock("alfresco", AVMLock lock = new AVMLock(WP,
"Sunnydale", "Sunnydale",
"TheInitiative/Adam/plans.txt", "TheInitiative/Adam/plans.txt",
AVMLockingService.Type.DISCRETIONARY, AVMLockingService.Type.DISCRETIONARY,
owners); owners);
fService.lockPath(lock); fService.lockPath(lock);
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Buffy")); assertTrue(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Buffy"));
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Spike")); assertTrue(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Spike"));
assertFalse(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Willow")); assertFalse(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Willow"));
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Tara")); assertTrue(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Tara"));
assertFalse(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Xander")); assertFalse(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Xander"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Buffy")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Buffy"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Spike")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Spike"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Willow")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Willow"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Tara")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Tara"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Xander")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Xander"));
} }
catch (Exception e) catch (Exception e)
{ {
@@ -239,26 +245,26 @@ public class AVMLockingServiceTest extends TestCase
{ {
try try
{ {
fService.addWebProject("alfresco"); fService.addWebProject(WP);
List<String> owners = new ArrayList<String>(); List<String> owners = new ArrayList<String>();
owners.add("GROUP_Scoobies"); owners.add("GROUP_Scoobies");
owners.add("Tara"); owners.add("Tara");
AVMLock lock = new AVMLock("alfresco", AVMLock lock = new AVMLock(WP,
"Sunnydale", "Sunnydale",
"TheInitiative/Adam/plans.txt", "TheInitiative/Adam/plans.txt",
AVMLockingService.Type.DISCRETIONARY, AVMLockingService.Type.DISCRETIONARY,
owners); owners);
fService.lockPath(lock); fService.lockPath(lock);
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Buffy")); assertTrue(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Buffy"));
assertFalse(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Spike")); assertFalse(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Spike"));
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Willow")); assertTrue(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Willow"));
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Tara")); assertTrue(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Tara"));
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Xander")); assertTrue(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Xander"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Buffy")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Buffy"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Spike")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Spike"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Willow")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Willow"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Tara")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Tara"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Xander")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Xander"));
} }
catch (Exception e) catch (Exception e)
{ {
@@ -271,60 +277,60 @@ public class AVMLockingServiceTest extends TestCase
{ {
try try
{ {
fService.addWebProject("alfresco"); fService.addWebProject(WP);
List<String> owners = new ArrayList<String>(); List<String> owners = new ArrayList<String>();
owners.add("GROUP_Scoobies"); owners.add("GROUP_Scoobies");
owners.add("Tara"); owners.add("Tara");
AVMLock lock = new AVMLock("alfresco", AVMLock lock = new AVMLock(WP,
"Sunnydale", "Sunnydale",
"TheInitiative/Adam/plans.txt", "TheInitiative/Adam/plans.txt",
AVMLockingService.Type.DISCRETIONARY, AVMLockingService.Type.DISCRETIONARY,
owners); owners);
fService.lockPath(lock); fService.lockPath(lock);
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Buffy")); assertTrue(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Buffy"));
assertFalse(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Spike")); assertFalse(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Spike"));
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Willow")); assertTrue(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Willow"));
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Tara")); assertTrue(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Tara"));
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/TheInitiative/Adam/plans.txt", "Xander")); assertTrue(fService.hasAccess(WP, "Sunnydale:/TheInitiative/Adam/plans.txt", "Xander"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Buffy")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Buffy"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Spike")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Spike"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Willow")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Willow"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Tara")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Tara"));
assertFalse(fService.hasAccess("alfresco", "LA:/TheInitiative/Adam/plans.txt", "Xander")); assertFalse(fService.hasAccess(WP, "LA:/TheInitiative/Adam/plans.txt", "Xander"));
fService.modifyLock("alfresco", "TheInitiative/Adam/plans.txt", "ScrapHeap/Adam/plans.txt", null, null, null); fService.modifyLock(WP, "TheInitiative/Adam/plans.txt", "ScrapHeap/Adam/plans.txt", null, null, null);
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/ScrapHeap/Adam/plans.txt", "Buffy")); assertTrue(fService.hasAccess(WP, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Buffy"));
assertFalse(fService.hasAccess("alfresco", "Sunnydale:/ScrapHeap/Adam/plans.txt", "Spike")); assertFalse(fService.hasAccess(WP, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Spike"));
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/ScrapHeap/Adam/plans.txt", "Willow")); assertTrue(fService.hasAccess(WP, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Willow"));
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/ScrapHeap/Adam/plans.txt", "Tara")); assertTrue(fService.hasAccess(WP, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Tara"));
assertTrue(fService.hasAccess("alfresco", "Sunnydale:/ScrapHeap/Adam/plans.txt", "Xander")); assertTrue(fService.hasAccess(WP, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Xander"));
fService.modifyLock("alfresco", "ScrapHeap/Adam/plans.txt", null, "LA", null, null); fService.modifyLock(WP, "ScrapHeap/Adam/plans.txt", null, "LA", null, null);
assertTrue(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Buffy")); assertTrue(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Buffy"));
assertFalse(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Spike")); assertFalse(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Spike"));
assertTrue(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Willow")); assertTrue(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Willow"));
assertTrue(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Tara")); assertTrue(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Tara"));
assertTrue(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Xander")); assertTrue(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Xander"));
assertFalse(fService.hasAccess("alfresco", "Sunnydale:/ScrapHeap/Adam/plans.txt", "Buffy")); assertFalse(fService.hasAccess(WP, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Buffy"));
assertFalse(fService.hasAccess("alfresco", "Sunnydale:/ScrapHeap/Adam/plans.txt", "Spike")); assertFalse(fService.hasAccess(WP, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Spike"));
assertFalse(fService.hasAccess("alfresco", "Sunnydale:/ScrapHeap/Adam/plans.txt", "Willow")); assertFalse(fService.hasAccess(WP, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Willow"));
assertFalse(fService.hasAccess("alfresco", "Sunnydale:/ScrapHeap/Adam/plans.txt", "Tara")); assertFalse(fService.hasAccess(WP, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Tara"));
assertFalse(fService.hasAccess("alfresco", "Sunnydale:/ScrapHeap/Adam/plans.txt", "Xander")); assertFalse(fService.hasAccess(WP, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Xander"));
List<String> usersToAdd = new ArrayList<String>(); List<String> usersToAdd = new ArrayList<String>();
usersToAdd.add("Spike"); usersToAdd.add("Spike");
fService.modifyLock("alfresco", "ScrapHeap/Adam/plans.txt", null, null, null, usersToAdd); fService.modifyLock(WP, "ScrapHeap/Adam/plans.txt", null, null, null, usersToAdd);
assertTrue(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Buffy")); assertTrue(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Buffy"));
assertTrue(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Spike")); assertTrue(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Spike"));
assertTrue(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Willow")); assertTrue(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Willow"));
assertTrue(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Tara")); assertTrue(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Tara"));
assertTrue(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Xander")); assertTrue(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Xander"));
List<String> usersToRemove = new ArrayList<String>(); List<String> usersToRemove = new ArrayList<String>();
usersToRemove.add("GROUP_Scoobies"); usersToRemove.add("GROUP_Scoobies");
fService.modifyLock("alfresco", "ScrapHeap/Adam/plans.txt", null, null, usersToRemove, null); fService.modifyLock(WP, "ScrapHeap/Adam/plans.txt", null, null, usersToRemove, null);
assertFalse(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Buffy")); assertFalse(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Buffy"));
assertTrue(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Spike")); assertTrue(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Spike"));
assertFalse(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Willow")); assertFalse(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Willow"));
assertTrue(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Tara")); assertTrue(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Tara"));
assertFalse(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", "Xander")); assertFalse(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", "Xander"));
assertTrue(fService.hasAccess("alfresco", "LA:/ScrapHeap/Adam/plans.txt", AuthenticationUtil.getAdminUserName())); assertTrue(fService.hasAccess(WP, "LA:/ScrapHeap/Adam/plans.txt", AuthenticationUtil.getAdminUserName()));
} }
catch (Exception e) catch (Exception e)
{ {

View File

@@ -1,3 +1,27 @@
/*
* Copyright (C) 2005-2009 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.node.index; package org.alfresco.repo.node.index;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@@ -199,16 +223,7 @@ public class AVMFullIndexRecoveryComponent extends AbstractReindexComponent
// Nothing to do for unindexed stores // Nothing to do for unindexed stores
if (avmSnapShotTriggeredIndexingMethodInterceptor.getIndexMode(store) == IndexMode.UNINDEXED) if (avmSnapShotTriggeredIndexingMethodInterceptor.getIndexMode(store) == IndexMode.UNINDEXED)
{ {
return RecoveryMode.NONE;
if (!avmSnapShotTriggeredIndexingMethodInterceptor.hasIndexBeenCreated(store))
{
logger.warn(" Index for avm store " + store + " is out of date");
return recoveryMode;
}
else
{
return RecoveryMode.NONE;
}
} }
if (recoveryMode == RecoveryMode.FULL) // no validate required if (recoveryMode == RecoveryMode.FULL) // no validate required
@@ -268,22 +283,23 @@ public class AVMFullIndexRecoveryComponent extends AbstractReindexComponent
private void recoverStore(final String store, final RecoveryMode mode) private void recoverStore(final String store, final RecoveryMode mode)
{ {
if (mode == RecoveryMode.AUTO) IndexMode storeIndexMode = avmSnapShotTriggeredIndexingMethodInterceptor.getIndexMode(store);
{ if (storeIndexMode != IndexMode.UNINDEXED)
logger.info(" Auto recovering index for " + store);
}
else if (mode == RecoveryMode.FULL)
{
logger.info(" Rebuilding index for " + store);
}
if (!avmSnapShotTriggeredIndexingMethodInterceptor.hasIndexBeenCreated(store))
{
avmSnapShotTriggeredIndexingMethodInterceptor.createIndex(store);
}
if (avmSnapShotTriggeredIndexingMethodInterceptor.getIndexMode(store) != IndexMode.UNINDEXED)
{ {
if (mode == RecoveryMode.AUTO)
{
logger.info(" Auto recovering index for " + store);
}
else if (mode == RecoveryMode.FULL)
{
logger.info(" Rebuilding index for " + store);
}
if (!avmSnapShotTriggeredIndexingMethodInterceptor.hasIndexBeenCreated(store))
{
avmSnapShotTriggeredIndexingMethodInterceptor.createIndex(store);
}
final int latest = avmService.getLatestSnapshotID(store); final int latest = avmService.getLatestSnapshotID(store);
if (latest <= 0) if (latest <= 0)
{ {
@@ -313,12 +329,18 @@ public class AVMFullIndexRecoveryComponent extends AbstractReindexComponent
} }
}; };
transactionService.getRetryingTransactionHelper().doInTransaction(reindexWork, true, true); transactionService.getRetryingTransactionHelper().doInTransaction(reindexWork, true, true);
if (logger.isDebugEnabled())
{
logger.debug(" Index updated for " + store + "("+storeIndexMode.toString()+")");
}
} }
else
if (logger.isDebugEnabled())
{ {
logger.debug(" Index updated for " + store); if (logger.isDebugEnabled())
{
logger.debug(" Index skipped for " + store+ "("+storeIndexMode.toString()+")");
}
} }
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -42,7 +42,7 @@ import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
/** /**
* Method interceptor for atomic indexing of AVM entries The proeprties can defined how stores are indexed based on type * Method interceptor for atomic indexing of AVM entries The properties can defined how stores are indexed based on type
* (as set by Alfresco the Web site management UI) or based on the name of the store. Creates and deletes are indexed * (as set by Alfresco the Web site management UI) or based on the name of the store. Creates and deletes are indexed
* synchronously. Updates may be asynchronous, synchronous or ignored by the index. * synchronously. Updates may be asynchronous, synchronous or ignored by the index.
* *
@@ -106,12 +106,14 @@ public class AVMSnapShotTriggeredIndexingMethodInterceptor implements MethodInte
{ {
String store = (String) mi.getArguments()[0]; String store = (String) mi.getArguments()[0];
Object returnValue = mi.proceed(); Object returnValue = mi.proceed();
StoreRef storeRef = AVMNodeConverter.ToStoreRef(store);
Indexer indexer = indexerAndSearcher.getIndexer(storeRef); if (getIndexMode(store) != IndexMode.UNINDEXED)
if (indexer instanceof AVMLuceneIndexer)
{ {
AVMLuceneIndexer avmIndexer = (AVMLuceneIndexer) indexer; AVMLuceneIndexer avmIndexer = getIndexer(store);
avmIndexer.deleteIndex(store, IndexMode.SYNCHRONOUS); if (avmIndexer != null)
{
avmIndexer.deleteIndex(store, IndexMode.SYNCHRONOUS);
}
} }
return returnValue; return returnValue;
} }
@@ -119,7 +121,10 @@ public class AVMSnapShotTriggeredIndexingMethodInterceptor implements MethodInte
{ {
String store = (String) mi.getArguments()[0]; String store = (String) mi.getArguments()[0];
Object returnValue = mi.proceed(); Object returnValue = mi.proceed();
createIndex(store); if (getIndexMode(store) != IndexMode.UNINDEXED)
{
createIndex(store);
}
return returnValue; return returnValue;
} }
else if (mi.getMethod().getName().equals("renameStore")) else if (mi.getMethod().getName().equals("renameStore"))
@@ -128,25 +133,25 @@ public class AVMSnapShotTriggeredIndexingMethodInterceptor implements MethodInte
String to = (String) mi.getArguments()[1]; String to = (String) mi.getArguments()[1];
Object returnValue = mi.proceed(); Object returnValue = mi.proceed();
int after = avmService.getLatestSnapshotID(to); int after = avmService.getLatestSnapshotID(to);
StoreRef fromRef = AVMNodeConverter.ToStoreRef(from); if (getIndexMode(from) != IndexMode.UNINDEXED)
StoreRef toRef = AVMNodeConverter.ToStoreRef(to);
Indexer indexer = indexerAndSearcher.getIndexer(fromRef);
if (indexer instanceof AVMLuceneIndexer)
{ {
AVMLuceneIndexer avmIndexer = (AVMLuceneIndexer) indexer; AVMLuceneIndexer avmIndexer = getIndexer(from);
avmIndexer.deleteIndex(from, IndexMode.SYNCHRONOUS); if (avmIndexer != null)
{
avmIndexer.deleteIndex(from, IndexMode.SYNCHRONOUS);
}
} }
indexer = indexerAndSearcher.getIndexer(toRef); if (getIndexMode(to) != IndexMode.UNINDEXED)
if (indexer instanceof AVMLuceneIndexer)
{ {
AVMLuceneIndexer avmIndexer = (AVMLuceneIndexer) indexer; AVMLuceneIndexer avmIndexer = getIndexer(to);
avmIndexer.createIndex(to, IndexMode.SYNCHRONOUS); if (avmIndexer != null)
avmIndexer.index(to, 0, after, getIndexMode(to)); {
avmIndexer.createIndex(to, IndexMode.SYNCHRONOUS);
avmIndexer.index(to, 0, after, getIndexMode(to));
}
} }
return returnValue; return returnValue;
} }
else else
@@ -222,43 +227,56 @@ public class AVMSnapShotTriggeredIndexingMethodInterceptor implements MethodInte
*/ */
public void indexSnapshot(String store, int before, int after) public void indexSnapshot(String store, int before, int after)
{ {
StoreRef storeRef = AVMNodeConverter.ToStoreRef(store); indexSnapshotImpl(store, before, after);
Indexer indexer = indexerAndSearcher.getIndexer(storeRef);
if (indexer instanceof AVMLuceneIndexer)
{
AVMLuceneIndexer avmIndexer = (AVMLuceneIndexer) indexer;
avmIndexer.index(store, before, after, getIndexMode(store));
}
} }
/**
* @param store
* @param after
*/
public void indexSnapshot(String store, int after) public void indexSnapshot(String store, int after)
{ {
StoreRef storeRef = AVMNodeConverter.ToStoreRef(store); indexSnapshotImpl(store, -1, after);
Indexer indexer = indexerAndSearcher.getIndexer(storeRef); }
if (indexer instanceof AVMLuceneIndexer)
private void indexSnapshotImpl(String store, int before, int after)
{
if (getIndexMode(store) != IndexMode.UNINDEXED)
{ {
AVMLuceneIndexer avmIndexer = (AVMLuceneIndexer) indexer; AVMLuceneIndexer avmIndexer = getIndexer(store);
int before = avmIndexer.getLastIndexedSnapshot(store); if (avmIndexer != null)
avmIndexer.index(store, before, after, getIndexMode(store)); {
int last = getLastIndexedSnapshot(avmIndexer, store);
if ((last == -1) && (! hasIndexBeenCreated(store)))
{
createIndex(store);
}
avmIndexer.index(store, (before != -1 ? before : last), after, getIndexMode(store));
}
} }
} }
/** /**
* @param store * @param store
* @return - the last indexed snapshot * @return - the last indexed snapshot
*/ */
public int getLastIndexedSnapshot(String store) public int getLastIndexedSnapshot(String store)
{ {
StoreRef storeRef = AVMNodeConverter.ToStoreRef(store); AVMLuceneIndexer avmIndexer = getIndexer(store);
Indexer indexer = indexerAndSearcher.getIndexer(storeRef); if (avmIndexer != null)
if (indexer instanceof AVMLuceneIndexer)
{ {
AVMLuceneIndexer avmIndexer = (AVMLuceneIndexer) indexer; return getLastIndexedSnapshot(avmIndexer, store);
return avmIndexer.getLastIndexedSnapshot(store);
} }
return -1; return -1;
} }
private int getLastIndexedSnapshot(AVMLuceneIndexer avmIndexer, String store)
{
return avmIndexer.getLastIndexedSnapshot(store);
}
/** /**
* Is the snapshot applied to the index? Is there an entry for any node that was added OR have all the nodes in the * Is the snapshot applied to the index? Is there an entry for any node that was added OR have all the nodes in the
* transaction been deleted as expected? * transaction been deleted as expected?
@@ -269,11 +287,9 @@ public class AVMSnapShotTriggeredIndexingMethodInterceptor implements MethodInte
*/ */
public boolean isSnapshotIndexed(String store, int id) public boolean isSnapshotIndexed(String store, int id)
{ {
StoreRef storeRef = AVMNodeConverter.ToStoreRef(store); AVMLuceneIndexer avmIndexer = getIndexer(store);
Indexer indexer = indexerAndSearcher.getIndexer(storeRef); if (avmIndexer != null)
if (indexer instanceof AVMLuceneIndexer)
{ {
AVMLuceneIndexer avmIndexer = (AVMLuceneIndexer) indexer;
return avmIndexer.isSnapshotIndexed(store, id); return avmIndexer.isSnapshotIndexed(store, id);
} }
return false; return false;
@@ -295,11 +311,9 @@ public class AVMSnapShotTriggeredIndexingMethodInterceptor implements MethodInte
case SYNCHRONOUS: case SYNCHRONOUS:
case ASYNCHRONOUS: case ASYNCHRONOUS:
int last = avmService.getLatestSnapshotID(store); int last = avmService.getLatestSnapshotID(store);
StoreRef storeRef = AVMNodeConverter.ToStoreRef(store); AVMLuceneIndexer avmIndexer = getIndexer(store);
Indexer indexer = indexerAndSearcher.getIndexer(storeRef); if (avmIndexer != null)
if (indexer instanceof AVMLuceneIndexer)
{ {
AVMLuceneIndexer avmIndexer = (AVMLuceneIndexer) indexer;
avmIndexer.flushPending(); avmIndexer.flushPending();
return avmIndexer.isSnapshotSearchable(store, last); return avmIndexer.isSnapshotSearchable(store, last);
} }
@@ -318,7 +332,6 @@ public class AVMSnapShotTriggeredIndexingMethodInterceptor implements MethodInte
*/ */
public boolean isIndexUpToDate(String store) public boolean isIndexUpToDate(String store)
{ {
switch (getIndexMode(store)) switch (getIndexMode(store))
{ {
case UNINDEXED: case UNINDEXED:
@@ -326,13 +339,11 @@ public class AVMSnapShotTriggeredIndexingMethodInterceptor implements MethodInte
case SYNCHRONOUS: case SYNCHRONOUS:
case ASYNCHRONOUS: case ASYNCHRONOUS:
int last = avmService.getLatestSnapshotID(store); int last = avmService.getLatestSnapshotID(store);
StoreRef storeRef = AVMNodeConverter.ToStoreRef(store); AVMLuceneIndexer avmIndexer = getIndexer(store);
Indexer indexer = indexerAndSearcher.getIndexer(storeRef); if (avmIndexer != null)
if (indexer instanceof AVMLuceneIndexer)
{ {
AVMLuceneIndexer avmIndexer = (AVMLuceneIndexer) indexer;
avmIndexer.flushPending(); avmIndexer.flushPending();
return avmIndexer.getLastIndexedSnapshot(store) == last; return getLastIndexedSnapshot(avmIndexer, store) == last;
} }
return false; return false;
default: default:
@@ -472,11 +483,9 @@ public class AVMSnapShotTriggeredIndexingMethodInterceptor implements MethodInte
public boolean hasIndexBeenCreated(String store) public boolean hasIndexBeenCreated(String store)
{ {
StoreRef storeRef = AVMNodeConverter.ToStoreRef(store); AVMLuceneIndexer avmIndexer = getIndexer(store);
Indexer indexer = indexerAndSearcher.getIndexer(storeRef); if (avmIndexer != null)
if (indexer instanceof AVMLuceneIndexer)
{ {
AVMLuceneIndexer avmIndexer = (AVMLuceneIndexer) indexer;
avmIndexer.flushPending(); avmIndexer.flushPending();
return avmIndexer.hasIndexBeenCreated(store); return avmIndexer.hasIndexBeenCreated(store);
} }
@@ -485,11 +494,9 @@ public class AVMSnapShotTriggeredIndexingMethodInterceptor implements MethodInte
public void createIndex(String store) public void createIndex(String store)
{ {
StoreRef storeRef = AVMNodeConverter.ToStoreRef(store); AVMLuceneIndexer avmIndexer = getIndexer(store);
Indexer indexer = indexerAndSearcher.getIndexer(storeRef); if (avmIndexer != null)
if (indexer instanceof AVMLuceneIndexer)
{ {
AVMLuceneIndexer avmIndexer = (AVMLuceneIndexer) indexer;
avmIndexer.createIndex(store, IndexMode.SYNCHRONOUS); avmIndexer.createIndex(store, IndexMode.SYNCHRONOUS);
} }
} }

View File

@@ -1,26 +1,27 @@
/*----------------------------------------------------------------------------- /*
* Copyright 2005-2007 Alfresco Inc. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or
* it under the terms of the GNU General Public License as published by * modify it under the terms of the GNU General Public License
* the Free Software Foundation; either version 2 of the License, or * as published by the Free Software Foundation; either version 2
* (at your option) any later version. * of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful,
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* for more details. * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along * You should have received a copy of the GNU General Public License
* with this program; if not, write to the Free Software Foundation, Inc., * along with this program; if not, write to the Free Software
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* exception to the terms and conditions of version 2.0 of the GPL, you may
* redistribute this Program in connection with Free/Libre and Open Source * As a special exception to the terms and conditions of version 2.0 of
* Software ("FLOSS") applications as described in Alfresco's FLOSS exception. * the GPL, you may redistribute this Program in connection with Free/Libre
* You should have received a copy of the text describing the FLOSS exception, * and Open Source Software ("FLOSS") applications as described in Alfresco's
* and it is also available here: http://www.alfresco.com/legal/licensing * FLOSS exception. You should have recieved a copy of the text describing
* * the FLOSS exception, and it is also available here:
*----------------------------------------------------------------------------*/ * http://www.alfresco.com/legal/licensing
*/
package org.alfresco.service.cmr.avm; package org.alfresco.service.cmr.avm;
@@ -302,6 +303,16 @@ public interface AVMService
*/ */
public void createStore(String name); public void createStore(String name);
/**
* Create a new AVMStore with store properties (equivalent to createStore + setProperties)
*
* @param name The name of the new AVMStore.
* @param props A Map of the properties to set.
* @throws AVMExistsException
* @since 3.2
*/
public void createStore(String name, Map<QName, PropertyValue> props);
/** /**
* Create a branch from a given version and path. As a side effect, * Create a branch from a given version and path. As a side effect,

View File

@@ -27,6 +27,7 @@ package org.alfresco.wcm.sandbox;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -153,7 +154,16 @@ public final class SandboxFactory extends WCMUtil
{ {
// create the 'staging' store for the website // create the 'staging' store for the website
String stagingStoreName = WCMUtil.buildStagingStoreName(storeId); String stagingStoreName = WCMUtil.buildStagingStoreName(storeId);
avmService.createStore(stagingStoreName);
// tag store with properties
Map<QName, PropertyValue> props = new HashMap<QName, PropertyValue>(3);
// tag the store with the store type
props.put(SandboxConstants.PROP_SANDBOX_STAGING_MAIN, new PropertyValue(DataTypeDefinition.TEXT, null));
props.put(SandboxConstants.PROP_WEB_PROJECT_NODE_REF, new PropertyValue(DataTypeDefinition.NODE_REF, webProjectNodeRef));
// tag the store with the DNS name property
addStoreDNSPath(stagingStoreName, props, storeId);
avmService.createStore(stagingStoreName, props);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -182,24 +192,23 @@ public final class SandboxFactory extends WCMUtil
// Add permissions for layers // Add permissions for layers
// tag the store with the store type
avmService.setStoreProperty(stagingStoreName,
SandboxConstants.PROP_SANDBOX_STAGING_MAIN,
new PropertyValue(DataTypeDefinition.TEXT, null));
avmService.setStoreProperty(stagingStoreName,
SandboxConstants.PROP_WEB_PROJECT_NODE_REF,
new PropertyValue(DataTypeDefinition.NODE_REF, webProjectNodeRef));
// tag the store with the DNS name property
tagStoreDNSPath(avmService, stagingStoreName, storeId);
// snapshot the store // snapshot the store
avmService.createSnapshot(stagingStoreName, null, null); avmService.createSnapshot(stagingStoreName, null, null);
// create the 'preview' store for the website // create the 'preview' store for the website
String previewStoreName = WCMUtil.buildStagingPreviewStoreName(storeId); String previewStoreName = WCMUtil.buildStagingPreviewStoreName(storeId);
avmService.createStore(previewStoreName);
// tag store with properties - store type, web project DM nodeRef, DNS name
props = new HashMap<QName, PropertyValue>(3);
// tag the store with the store type
props.put(SandboxConstants.PROP_SANDBOX_STAGING_PREVIEW, new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
addStoreDNSPath(previewStoreName, props, storeId, "preview");
// The preview store depends on the main staging store (dist=1)
addStoreBackgroundLayer(props, stagingStoreName, 1);
avmService.createStore(previewStoreName, props);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -212,22 +221,11 @@ public final class SandboxFactory extends WCMUtil
previewStoreName + ":/", previewStoreName + ":/",
JNDIConstants.DIR_DEFAULT_WWW); JNDIConstants.DIR_DEFAULT_WWW);
// apply READ permissions for all users // apply READ permissions for all users
//dirRef = AVMNodeConverter.ToNodeRef(-1, WCMUtil.buildStoreRootPath(previewStoreName)); //dirRef = AVMNodeConverter.ToNodeRef(-1, WCMUtil.buildStoreRootPath(previewStoreName));
//permissionService.setPermission(dirRef, PermissionService.ALL_AUTHORITIES, PermissionService.READ, true); //permissionService.setPermission(dirRef, PermissionService.ALL_AUTHORITIES, PermissionService.READ, true);
// tag the store with the store type
avmService.setStoreProperty(previewStoreName,
SandboxConstants.PROP_SANDBOX_STAGING_PREVIEW,
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
tagStoreDNSPath(avmService, previewStoreName, storeId, "preview");
// The preview store depends on the main staging store (dist=1)
tagStoreBackgroundLayer(avmService,previewStoreName,stagingStoreName,1);
// snapshot the store // snapshot the store
avmService.createSnapshot(previewStoreName, null, null); avmService.createSnapshot(previewStoreName, null, null);
@@ -580,9 +578,27 @@ public final class SandboxFactory extends WCMUtil
return userSandboxInfo; return userSandboxInfo;
} }
avmService.createStore(userStoreName); QName sandboxIdProp = QName.createQName(null, SandboxConstants.PROP_SANDBOXID + GUID.generate());
String stagingStoreName = WCMUtil.buildStagingStoreName(storeId); String stagingStoreName = WCMUtil.buildStagingStoreName(storeId);
// tag store with properties
Map<QName, PropertyValue> props = new HashMap<QName, PropertyValue>(6);
// tag the store with the store type
props.put(SandboxConstants.PROP_SANDBOX_AUTHOR_MAIN, new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the base name of the website so that corresponding staging areas can be found.
props.put(SandboxConstants.PROP_WEBSITE_NAME, new PropertyValue(DataTypeDefinition.TEXT, storeId));
// tag the store, oddly enough, with its own store name for querying.
props.put(QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + userStoreName), new PropertyValue(DataTypeDefinition.TEXT, null));
// tag all related stores to indicate that they are part of a single sandbox
props.put(sandboxIdProp, new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
addStoreDNSPath(userStoreName, props, storeId, username);
// The user store depends on the main staging store (dist=1)
addStoreBackgroundLayer(props, stagingStoreName, 1);
avmService.createStore(userStoreName, props);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("Created user sandbox: " + userStoreName + " above staging store " + stagingStoreName); logger.debug("Created user sandbox: " + userStoreName + " above staging store " + stagingStoreName);
@@ -611,33 +627,26 @@ public final class SandboxFactory extends WCMUtil
// permissionService.setPermission(dirRef.getStoreRef(), manager, AVMUtil.ROLE_CONTENT_MANAGER, true); // permissionService.setPermission(dirRef.getStoreRef(), manager, AVMUtil.ROLE_CONTENT_MANAGER, true);
// } // }
// tag the store with the store type
avmService.setStoreProperty(userStoreName,
SandboxConstants.PROP_SANDBOX_AUTHOR_MAIN,
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the base name of the website so that corresponding
// staging areas can be found.
avmService.setStoreProperty(userStoreName,
SandboxConstants.PROP_WEBSITE_NAME,
new PropertyValue(DataTypeDefinition.TEXT, storeId));
// tag the store, oddly enough, with its own store name for querying.
avmService.setStoreProperty(userStoreName,
QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + userStoreName),
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
tagStoreDNSPath(avmService, userStoreName, storeId, username);
// The user store depends on the main staging store (dist=1)
tagStoreBackgroundLayer(avmService,userStoreName,stagingStoreName,1);
// snapshot the store // snapshot the store
avmService.createSnapshot(userStoreName, null, null); avmService.createSnapshot(userStoreName, null, null);
// tag store with properties
props = new HashMap<QName, PropertyValue>(6);
// tag the store with the store type
props.put(SandboxConstants.PROP_SANDBOX_AUTHOR_PREVIEW, new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with its own store name for querying.
props.put(QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + previewStoreName), new PropertyValue(DataTypeDefinition.TEXT, null));
// tag all related stores to indicate that they are part of a single sandbox
props.put(sandboxIdProp, new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
addStoreDNSPath(previewStoreName, props, storeId, username, "preview");
// The preview user store depends on the main user store (dist=1)
addStoreBackgroundLayer(props, userStoreName, 1);
// The preview user store depends on the main staging store (dist=2)
addStoreBackgroundLayer(props, stagingStoreName, 2);
// create the user 'preview' store // create the user 'preview' store
avmService.createStore(previewStoreName); avmService.createStore(previewStoreName, props);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -663,39 +672,9 @@ public final class SandboxFactory extends WCMUtil
permissionService.setPermission(dirRef.getStoreRef(), manager, WCMUtil.ROLE_CONTENT_MANAGER, true); permissionService.setPermission(dirRef.getStoreRef(), manager, WCMUtil.ROLE_CONTENT_MANAGER, true);
} }
// tag the store with the store type
avmService.setStoreProperty(previewStoreName,
SandboxConstants.PROP_SANDBOX_AUTHOR_PREVIEW,
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with its own store name for querying.
avmService.setStoreProperty(previewStoreName,
QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + previewStoreName),
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
tagStoreDNSPath(avmService, previewStoreName, storeId, username, "preview");
// The preview user store depends on the main user store (dist=1)
tagStoreBackgroundLayer(avmService,previewStoreName, userStoreName,1);
// The preview user store depends on the main staging store (dist=2)
tagStoreBackgroundLayer(avmService,previewStoreName, stagingStoreName,2);
// snapshot the store // snapshot the store
avmService.createSnapshot(previewStoreName, null, null); avmService.createSnapshot(previewStoreName, null, null);
// tag all related stores to indicate that they are part of a single sandbox
QName sandboxIdProp = QName.createQName(null, SandboxConstants.PROP_SANDBOXID + GUID.generate());
avmService.setStoreProperty(userStoreName,
sandboxIdProp,
new PropertyValue(DataTypeDefinition.TEXT, null));
avmService.setStoreProperty(previewStoreName,
sandboxIdProp,
new PropertyValue(DataTypeDefinition.TEXT, null));
if (logger.isTraceEnabled()) if (logger.isTraceEnabled())
{ {
dumpStoreProperties(avmService, userStoreName); dumpStoreProperties(avmService, userStoreName);
@@ -720,53 +699,62 @@ public final class SandboxFactory extends WCMUtil
public SandboxInfo createWorkflowSandbox(final String storeId) public SandboxInfo createWorkflowSandbox(final String storeId)
{ {
String stagingStoreName = WCMUtil.buildStagingStoreName(storeId); String stagingStoreName = WCMUtil.buildStagingStoreName(storeId);
// create the workflow 'main' store // create the workflow 'main' store
String packageName = WCMUtil.STORE_WORKFLOW + "-" + GUID.generate(); String packageName = WCMUtil.STORE_WORKFLOW + "-" + GUID.generate();
String mainStoreName = WCMUtil.buildWorkflowMainStoreName(storeId, packageName); String mainStoreName = WCMUtil.buildWorkflowMainStoreName(storeId, packageName);
avmService.createStore(mainStoreName); final QName sandboxIdProp = QName.createQName(SandboxConstants.PROP_SANDBOXID + GUID.generate());
// tag store with properties
Map<QName, PropertyValue> props = new HashMap<QName, PropertyValue>(6);
// tag the store with the store type
props.put(SandboxConstants.PROP_SANDBOX_WORKFLOW_MAIN, new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the base name of the website so that corresponding staging areas can be found.
props.put(SandboxConstants.PROP_WEBSITE_NAME, new PropertyValue(DataTypeDefinition.TEXT, storeId));
// tag the store, oddly enough, with its own store name for querying.
props.put(QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + mainStoreName), new PropertyValue(DataTypeDefinition.TEXT, null));
// tag all related stores to indicate that they are part of a single sandbox
props.put(sandboxIdProp, new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
addStoreDNSPath(mainStoreName, props, storeId, packageName);
// The main workflow store depends on the main staging store (dist=1)
addStoreBackgroundLayer(props, stagingStoreName, 1);
avmService.createStore(mainStoreName, props);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("Created workflow sandbox store: " + mainStoreName); logger.debug("Created workflow sandbox store: " + mainStoreName);
} }
// create a layered directory pointing to 'www' in the staging area // create a layered directory pointing to 'www' in the staging area
avmService.createLayeredDirectory(WCMUtil.buildStoreRootPath(stagingStoreName), avmService.createLayeredDirectory(WCMUtil.buildStoreRootPath(stagingStoreName),
mainStoreName + ":/", mainStoreName + ":/",
JNDIConstants.DIR_DEFAULT_WWW); JNDIConstants.DIR_DEFAULT_WWW);
// tag the store with the store type
avmService.setStoreProperty(mainStoreName,
SandboxConstants.PROP_SANDBOX_WORKFLOW_MAIN,
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the base name of the website so that corresponding
// staging areas can be found.
avmService.setStoreProperty(mainStoreName,
SandboxConstants.PROP_WEBSITE_NAME,
new PropertyValue(DataTypeDefinition.TEXT, storeId));
// tag the store, oddly enough, with its own store name for querying.
avmService.setStoreProperty(mainStoreName,
QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + mainStoreName),
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
tagStoreDNSPath(avmService, mainStoreName, storeId, packageName);
// The main workflow store depends on the main staging store (dist=1)
tagStoreBackgroundLayer(avmService,mainStoreName, stagingStoreName ,1);
// snapshot the store // snapshot the store
avmService.createSnapshot(mainStoreName, null, null); avmService.createSnapshot(mainStoreName, null, null);
// create the workflow 'preview' store // create the workflow 'preview' store
final String previewStoreName = WCMUtil.buildWorkflowPreviewStoreName(storeId, packageName); final String previewStoreName = WCMUtil.buildWorkflowPreviewStoreName(storeId, packageName);
avmService.createStore(previewStoreName); // tag store with properties
props = new HashMap<QName, PropertyValue>(6);
// tag the store with the store type
props.put(SandboxConstants.PROP_SANDBOX_WORKFLOW_PREVIEW, new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with its own store name for querying.
props.put(QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + previewStoreName), new PropertyValue(DataTypeDefinition.TEXT, null));
// tag all related stores to indicate that they are part of a single sandbox
props.put(sandboxIdProp, new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
addStoreDNSPath(previewStoreName, props, storeId, packageName, "preview");
// The preview workflow store depends on the main workflow store (dist=1)
addStoreBackgroundLayer(props, mainStoreName, 1);
// The preview workflow store depends on the main staging store (dist=2)
addStoreBackgroundLayer(props, stagingStoreName, 2);
avmService.createStore(previewStoreName, props);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -777,41 +765,9 @@ public final class SandboxFactory extends WCMUtil
avmService.createLayeredDirectory(WCMUtil.buildStoreRootPath(mainStoreName), avmService.createLayeredDirectory(WCMUtil.buildStoreRootPath(mainStoreName),
previewStoreName + ":/", previewStoreName + ":/",
JNDIConstants.DIR_DEFAULT_WWW); JNDIConstants.DIR_DEFAULT_WWW);
// tag the store with the store type
avmService.setStoreProperty(previewStoreName,
SandboxConstants.PROP_SANDBOX_WORKFLOW_PREVIEW,
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with its own store name for querying.
avmService.setStoreProperty(previewStoreName,
QName.createQName(null,
SandboxConstants.PROP_SANDBOX_STORE_PREFIX + previewStoreName),
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
tagStoreDNSPath(avmService, previewStoreName, storeId, packageName, "preview");
// The preview worfkflow store depends on the main workflow store (dist=1)
tagStoreBackgroundLayer(avmService,previewStoreName, mainStoreName,1);
// The preview workflow store depends on the main staging store (dist=2)
tagStoreBackgroundLayer(avmService,previewStoreName, stagingStoreName,2);
// snapshot the store // snapshot the store
avmService.createSnapshot(previewStoreName, null, null); avmService.createSnapshot(previewStoreName, null, null);
// tag all related stores to indicate that they are part of a single sandbox
final QName sandboxIdProp = QName.createQName(SandboxConstants.PROP_SANDBOXID + GUID.generate());
avmService.setStoreProperty(mainStoreName,
sandboxIdProp,
new PropertyValue(DataTypeDefinition.TEXT, null));
avmService.setStoreProperty(previewStoreName,
sandboxIdProp,
new PropertyValue(DataTypeDefinition.TEXT, null));
if (logger.isTraceEnabled()) if (logger.isTraceEnabled())
{ {
@@ -845,12 +801,29 @@ public final class SandboxFactory extends WCMUtil
{ {
String wpStoreId = WCMUtil.getWebProjectStoreId(storeId); String wpStoreId = WCMUtil.getWebProjectStoreId(storeId);
String stagingStoreName = WCMUtil.buildStagingStoreName(storeId); String stagingStoreName = WCMUtil.buildStagingStoreName(storeId);
// create the workflow 'main' store // create the workflow 'main' store
String packageName = WCMUtil.STORE_WORKFLOW + "-" + GUID.generate(); String packageName = WCMUtil.STORE_WORKFLOW + "-" + GUID.generate();
String mainStoreName = WCMUtil.buildWorkflowMainStoreName(storeId, packageName); String mainStoreName = WCMUtil.buildWorkflowMainStoreName(storeId, packageName);
avmService.createStore(mainStoreName); final QName sandboxIdProp = QName.createQName(SandboxConstants.PROP_SANDBOXID + GUID.generate());
// tag store with properties
Map<QName, PropertyValue> props = new HashMap<QName, PropertyValue>(6);
// tag the store with the store type
props.put(SandboxConstants.PROP_SANDBOX_WORKFLOW_MAIN, new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the base name of the website so that corresponding staging areas can be found.
props.put(SandboxConstants.PROP_WEBSITE_NAME, new PropertyValue(DataTypeDefinition.TEXT, storeId));
// tag the store, oddly enough, with its own store name for querying.
props.put(QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + mainStoreName), new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
addStoreDNSPath(mainStoreName, props, storeId, packageName);
// The main workflow store depends on the main staging store (dist=1)
addStoreBackgroundLayer(props, stagingStoreName, 1);
// tag all related stores to indicate that they are part of a single sandbox
props.put(sandboxIdProp, new PropertyValue(DataTypeDefinition.TEXT, null));
avmService.createStore(mainStoreName, props);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -861,35 +834,6 @@ public final class SandboxFactory extends WCMUtil
avmService.createLayeredDirectory(WCMUtil.buildStoreRootPath(stagingStoreName), avmService.createLayeredDirectory(WCMUtil.buildStoreRootPath(stagingStoreName),
mainStoreName + ":/", mainStoreName + ":/",
JNDIConstants.DIR_DEFAULT_WWW); JNDIConstants.DIR_DEFAULT_WWW);
// tag the store with the store type
avmService.setStoreProperty(mainStoreName,
SandboxConstants.PROP_SANDBOX_WORKFLOW_MAIN,
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the base name of the website so that corresponding
// staging areas can be found.
avmService.setStoreProperty(mainStoreName,
SandboxConstants.PROP_WEBSITE_NAME,
new PropertyValue(DataTypeDefinition.TEXT, storeId));
// tag the store, oddly enough, with its own store name for querying.
avmService.setStoreProperty(mainStoreName,
QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + mainStoreName),
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
tagStoreDNSPath(avmService, mainStoreName, storeId, packageName);
// The main workflow store depends on the main staging store (dist=1)
tagStoreBackgroundLayer(avmService,mainStoreName, stagingStoreName ,1);
// tag all related stores to indicate that they are part of a single sandbox
final QName sandboxIdProp = QName.createQName(SandboxConstants.PROP_SANDBOXID + GUID.generate());
avmService.setStoreProperty(mainStoreName,
sandboxIdProp,
new PropertyValue(DataTypeDefinition.TEXT, null));
if (logger.isTraceEnabled()) if (logger.isTraceEnabled())
{ {
@@ -914,8 +858,27 @@ public final class SandboxFactory extends WCMUtil
// create the workflow 'main' store // create the workflow 'main' store
String packageName = "workflow-" + GUID.generate(); String packageName = "workflow-" + GUID.generate();
String workflowStoreName = userStore + STORE_SEPARATOR + packageName; String workflowStoreName = userStore + STORE_SEPARATOR + packageName;
avmService.createStore(workflowStoreName); final QName sandboxIdProp = QName.createQName(SandboxConstants.PROP_SANDBOXID + GUID.generate());
// tag store with properties
Map<QName, PropertyValue> props = new HashMap<QName, PropertyValue>(7);
// tag the store with the store type
props.put(SandboxConstants.PROP_SANDBOX_AUTHOR_WORKFLOW_MAIN, new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the name of the author's store this one is layered over
props.put(SandboxConstants.PROP_AUTHOR_NAME, new PropertyValue(DataTypeDefinition.TEXT, userStore));
// tag the store, oddly enough, with its own store name for querying.
props.put(QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + workflowStoreName), new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
addStoreDNSPath(workflowStoreName, props, stagingStore, packageName);
// the main workflow store depends on the main user store (dist=1)
addStoreBackgroundLayer(props, userStore, 1);
// The main workflow store depends on the main staging store (dist=2)
addStoreBackgroundLayer(props, stagingStore, 2);
// tag all related stores to indicate that they are part of a single sandbox
props.put(sandboxIdProp, new PropertyValue(DataTypeDefinition.TEXT, null));
avmService.createStore(workflowStoreName, props);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -927,52 +890,32 @@ public final class SandboxFactory extends WCMUtil
userStore + ":/" + JNDIConstants.DIR_DEFAULT_WWW, userStore + ":/" + JNDIConstants.DIR_DEFAULT_WWW,
workflowStoreName + ":/", JNDIConstants.DIR_DEFAULT_WWW); workflowStoreName + ":/", JNDIConstants.DIR_DEFAULT_WWW);
// tag the store with the store type
avmService.setStoreProperty(workflowStoreName,
SandboxConstants.PROP_SANDBOX_AUTHOR_WORKFLOW_MAIN,
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the name of the author's store this one is layered over
avmService.setStoreProperty(workflowStoreName,
SandboxConstants.PROP_AUTHOR_NAME,
new PropertyValue(DataTypeDefinition.TEXT, userStore));
// tag the store, oddly enough, with its own store name for querying.
avmService.setStoreProperty(workflowStoreName,
QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + workflowStoreName),
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
String path = workflowStoreName + ":/" + JNDIConstants.DIR_DEFAULT_WWW +
"/" + JNDIConstants.DIR_DEFAULT_APPBASE;
// DNS name mangle the property name - can only contain value DNS characters!
String dnsProp = SandboxConstants.PROP_DNS + DNSNameMangler.MakeDNSName(stagingStore, packageName);
avmService.setStoreProperty(workflowStoreName, QName.createQName(null, dnsProp),
new PropertyValue(DataTypeDefinition.TEXT, path));
// TODO review above and replace with common call to ...
/*
// tag the store with the DNS name property
tagStoreDNSPath(avmService, workflowStoreName, storeId, packageName);
*/
// the main workflow store depends on the main user store (dist=1)
String prop_key = SandboxConstants.PROP_BACKGROUND_LAYER + userStore;
avmService.setStoreProperty(workflowStoreName, QName.createQName(null, prop_key),
new PropertyValue(DataTypeDefinition.INT, 1));
// The main workflow store depends on the main staging store (dist=2)
prop_key = SandboxConstants.PROP_BACKGROUND_LAYER + stagingStore;
avmService.setStoreProperty(workflowStoreName, QName.createQName(null, prop_key),
new PropertyValue(DataTypeDefinition.INT, 2));
// snapshot the store // snapshot the store
avmService.createSnapshot(workflowStoreName, null, null); avmService.createSnapshot(workflowStoreName, null, null);
// create the workflow 'preview' store // create the workflow 'preview' store
String previewStoreName = workflowStoreName + STORE_SEPARATOR + "preview"; String previewStoreName = workflowStoreName + STORE_SEPARATOR + "preview";
avmService.createStore(previewStoreName);
// tag store with properties
props = new HashMap<QName, PropertyValue>(7);
// tag the store with the store type
props.put(SandboxConstants.PROP_SANDBOX_AUTHOR_WORKFLOW_PREVIEW, new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with its own store name for querying.
props.put(QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + previewStoreName), new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
addStoreDNSPath(previewStoreName, props, userStore, packageName, "preview");
// The preview worfkflow store depends on the main workflow store (dist=1)
addStoreBackgroundLayer(props, workflowStoreName, 1);
// The preview workflow store depends on the main user store (dist=2)
addStoreBackgroundLayer(props, userStore, 2);
// The preview workflow store depends on the main staging store (dist=3)
addStoreBackgroundLayer(props, stagingStore, 3);
// tag all related stores to indicate that they are part of a single sandbox
props.put(sandboxIdProp, new PropertyValue(DataTypeDefinition.TEXT, null));
avmService.createStore(previewStoreName, props);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("Created user workflow sandbox preview store: " + previewStoreName); logger.debug("Created user workflow sandbox preview store: " + previewStoreName);
@@ -982,55 +925,10 @@ public final class SandboxFactory extends WCMUtil
avmService.createLayeredDirectory( avmService.createLayeredDirectory(
workflowStoreName + ":/" + JNDIConstants.DIR_DEFAULT_WWW, workflowStoreName + ":/" + JNDIConstants.DIR_DEFAULT_WWW,
previewStoreName + ":/", JNDIConstants.DIR_DEFAULT_WWW); previewStoreName + ":/", JNDIConstants.DIR_DEFAULT_WWW);
// tag the store with the store type
avmService.setStoreProperty(previewStoreName, SandboxConstants.PROP_SANDBOX_WORKFLOW_PREVIEW,
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with its own store name for querying.
avmService.setStoreProperty(previewStoreName,
QName.createQName(null, SandboxConstants.PROP_SANDBOX_STORE_PREFIX + previewStoreName),
new PropertyValue(DataTypeDefinition.TEXT, null));
// tag the store with the DNS name property
path = previewStoreName + ":/" + JNDIConstants.DIR_DEFAULT_WWW +
"/" + JNDIConstants.DIR_DEFAULT_APPBASE;
// DNS name mangle the property name - can only contain value DNS characters!
dnsProp = SandboxConstants.PROP_DNS + DNSNameMangler.MakeDNSName(userStore, packageName, "preview");
avmService.setStoreProperty(previewStoreName, QName.createQName(null, dnsProp),
new PropertyValue(DataTypeDefinition.TEXT, path));
// TODO review above and replace with common call to ...
/*
// tag the store with the DNS name property
tagStoreDNSPath(avmService, previewStoreName, storeId, packageName, "preview");
*/
// The preview worfkflow store depends on the main workflow store (dist=1)
prop_key = SandboxConstants.PROP_BACKGROUND_LAYER + workflowStoreName;
avmService.setStoreProperty(previewStoreName, QName.createQName(null, prop_key),
new PropertyValue(DataTypeDefinition.INT, 1));
// The preview workflow store depends on the main user store (dist=2)
prop_key = SandboxConstants.PROP_BACKGROUND_LAYER + userStore;
avmService.setStoreProperty(previewStoreName, QName.createQName(null, prop_key),
new PropertyValue(DataTypeDefinition.INT, 2));
// The preview workflow store depends on the main staging store (dist=3)
prop_key = SandboxConstants.PROP_BACKGROUND_LAYER + stagingStore;
avmService.setStoreProperty(previewStoreName, QName.createQName(null, prop_key),
new PropertyValue(DataTypeDefinition.INT, 3));
// snapshot the store // snapshot the store
avmService.createSnapshot(previewStoreName, null, null); avmService.createSnapshot(previewStoreName, null, null);
// tag all related stores to indicate that they are part of a single sandbox
QName sandboxIdProp = QName.createQName(SandboxConstants.PROP_SANDBOXID + GUID.generate());
avmService.setStoreProperty(workflowStoreName, sandboxIdProp,
new PropertyValue(DataTypeDefinition.TEXT, null));
avmService.setStoreProperty(previewStoreName, sandboxIdProp,
new PropertyValue(DataTypeDefinition.TEXT, null));
// return the main workflow store name // return the main workflow store name
return workflowStoreName; return workflowStoreName;
} }
@@ -1270,13 +1168,12 @@ public final class SandboxFactory extends WCMUtil
* *
* @param store Name of the store to tag * @param store Name of the store to tag
*/ */
private static void tagStoreDNSPath(AVMService avmService, String store, String... components) private static void addStoreDNSPath(String store, Map<QName, PropertyValue> props, String... components)
{ {
String path = WCMUtil.buildSandboxRootPath(store); String path = WCMUtil.buildSandboxRootPath(store);
// DNS name mangle the property name - can only contain value DNS characters! // DNS name mangle the property name - can only contain value DNS characters!
String dnsProp = SandboxConstants.PROP_DNS + DNSNameMangler.MakeDNSName(components); String dnsProp = SandboxConstants.PROP_DNS + DNSNameMangler.MakeDNSName(components);
avmService.setStoreProperty(store, QName.createQName(null, dnsProp), props.put(QName.createQName(null, dnsProp), new PropertyValue(DataTypeDefinition.TEXT, path));
new PropertyValue(DataTypeDefinition.TEXT, path));
} }
/** /**
@@ -1304,14 +1201,12 @@ public final class SandboxFactory extends WCMUtil
* The backgroundStore 'mysite' is 1 away from the store 'mysite--alice' * The backgroundStore 'mysite' is 1 away from the store 'mysite--alice'
* but 2 away from the store 'mysite--alice--preview'. * but 2 away from the store 'mysite--alice--preview'.
*/ */
private static void tagStoreBackgroundLayer(AVMService avmService, private static void addStoreBackgroundLayer(Map<QName, PropertyValue> props,
String store,
String backgroundStore, String backgroundStore,
int distance) int distance)
{ {
String prop_key = SandboxConstants.PROP_BACKGROUND_LAYER + backgroundStore; String prop_key = SandboxConstants.PROP_BACKGROUND_LAYER + backgroundStore;
avmService.setStoreProperty(store, QName.createQName(null, prop_key), props.put(QName.createQName(null, prop_key), new PropertyValue(DataTypeDefinition.INT, distance));
new PropertyValue(DataTypeDefinition.INT, distance));
} }
/** /**