Dynamic Models - fix AR-1953

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8015 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2008-01-18 12:25:24 +00:00
parent b4b6f0181c
commit 087b2a1b2a
10 changed files with 135 additions and 32 deletions

View File

@@ -148,6 +148,10 @@
</property> </property>
</bean> </bean>
<bean id="spacesModelsBootstrap" parent="storeImporter">
<!-- NOOP for fresh bootstrap (will skip store creation) - provides ordering when performing a repo restore (bootstrap import) -->
</bean>
<bean id="spacesBootstrap" parent="spacesStoreImporter"> <bean id="spacesBootstrap" parent="spacesStoreImporter">
<property name="bootstrapViews"> <property name="bootstrapViews">
<list> <list>

View File

@@ -56,12 +56,26 @@
</property> </property>
</bean> </bean>
<bean id="spacesModelsBootstrap" parent="spacesStoreImporter">
<property name="bootstrapViews">
<list>
<props>
<prop key="path"></prop>
<prop key="location">alfresco/extension/restore/export_models.acp</prop>
</props>
</list>
</property>
<property name="log"><value>true</value></property>
</bean>
<bean id="spacesBootstrap" parent="spacesStoreImporter"> <bean id="spacesBootstrap" parent="spacesStoreImporter">
<property name="useExistingStore"><value>true</value></property>
<property name="bootstrapViews"> <property name="bootstrapViews">
<list> <list>
<props> <props>
<prop key="path">/</prop> <prop key="path">/</prop>
<prop key="location">alfresco/extension/restore/export_spaces.acp</prop> <prop key="location">alfresco/extension/restore/export_spaces.acp</prop>
<prop key="uuidBinding">UPDATE_EXISTING</prop>
</props> </props>
</list> </list>
</property> </property>

View File

@@ -151,6 +151,11 @@
<prop key="storeRef">${alfresco_user_store.store}</prop> <prop key="storeRef">${alfresco_user_store.store}</prop>
<prop key="packageName">users</prop> <prop key="packageName">users</prop>
</props> </props>
<props>
<prop key="storeRef">${spaces.store}</prop>
<prop key="packageName">models</prop>
<prop key="includedPaths">/app:company_home/app:dictionary/app:models</prop>
</props>
<props> <props>
<prop key="storeRef">${spaces.store}</prop> <prop key="storeRef">${spaces.store}</prop>
<prop key="packageName">spaces</prop> <prop key="packageName">spaces</prop>

View File

@@ -43,4 +43,25 @@
</property> </property>
</bean> </bean>
<!-- for restore, needs to be before bootstrap-context -->
<bean id="dictionaryModelType" class="org.alfresco.repo.dictionary.DictionaryModelType" init-method="init">
<property name="dictionaryDAO" ref="dictionaryDAO"/>
<property name="namespaceDAO" ref="namespaceDAO"/>
<property name="nodeService" ref="NodeService"/>
<property name="contentService" ref="contentService"/>
<property name="policyComponent" ref="policyComponent"/>
<property name="workflowService" ref="WorkflowService"/>
<property name="searchService" ref="SearchService"/>
<property name="namespaceService" ref="namespaceService"/>
<property name="tenantService" ref="tenantService"/>
<property name="tenantDeployerService" ref="tenantAdminService"/>
<property name="storeUrls">
<list>
<value>${spaces.store}</value>
<value>${spaces.archive.store}</value>
</list>
</property>
</bean>
</beans> </beans>

View File

@@ -78,25 +78,5 @@
</property> </property>
</bean> </bean>
<bean id="dictionaryModelType" class="org.alfresco.repo.dictionary.DictionaryModelType" init-method="init">
<property name="dictionaryDAO" ref="dictionaryDAO"/>
<property name="namespaceDAO" ref="namespaceDAO"/>
<property name="nodeService" ref="NodeService"/>
<property name="contentService" ref="contentService"/>
<property name="policyComponent" ref="policyComponent"/>
<property name="workflowService" ref="WorkflowService"/>
<property name="searchService" ref="SearchService"/>
<property name="namespaceService" ref="namespaceService"/>
<property name="tenantService" ref="tenantService"/>
<property name="tenantDeployerService" ref="tenantAdminService"/>
<property name="storeUrls">
<list>
<value>${spaces.store}</value>
<value>${spaces.archive.store}</value>
</list>
</property>
</bean>
</beans> </beans>

View File

@@ -265,7 +265,7 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
// Register interest in the onCreateNode policy for the dictionary model type // Register interest in the onCreateNode policy for the dictionary model type
policyComponent.bindClassBehaviour( policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"), QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"),
ContentModel.TYPE_DICTIONARY_MODEL, this,
new JavaBehaviour(this, "onCreateNode")); new JavaBehaviour(this, "onCreateNode"));
// Create the transaction listener // Create the transaction listener

View File

@@ -361,6 +361,16 @@ public class ExporterComponent
{ {
return; return;
} }
// explicitly included ?
if (parameters.getIncludedPaths() != null)
{
String nodePathPrefixString = nodeService.getPath(nodeRef).toPrefixString(namespaceService);
if (! (isIncludedPath(parameters.getIncludedPaths(), nodePathPrefixString)))
{
return;
}
}
// export node as reference to node, or as the actual node // export node as reference to node, or as the actual node
if (exportAsRef) if (exportAsRef)
@@ -740,6 +750,22 @@ public class ExporterComponent
return false; return false;
} }
private boolean isIncludedPath(String[] includedPaths, String path)
{
for (String includePath : includedPaths)
{
// note: allow parents or children - e.g. if included path is /a/b/c then /, /a, /a/b, /a/b/c, /a/b/c/d, /a/b/c/d/e are all included
if (includePath.startsWith(path) || path.startsWith(includePath))
{
return true;
}
}
return false;
}
/** /**
* Is the aspect unexportable? * Is the aspect unexportable?
* *

View File

@@ -68,6 +68,7 @@ public class RepositoryExporterComponent implements RepositoryExporterService
{ {
private static final String STOREREF_KEY = "storeRef"; private static final String STOREREF_KEY = "storeRef";
private static final String PACKAGENAME_KEY = "packageName"; private static final String PACKAGENAME_KEY = "packageName";
private static final String INCLUDED_PATHS = "includedPaths";
// component dependencies // component dependencies
private ExporterService exporterService; private ExporterService exporterService;
@@ -290,10 +291,15 @@ public class RepositoryExporterComponent implements RepositoryExporterService
storePackageName = storeRef.getIdentifier(); storePackageName = storeRef.getIdentifier();
} }
String completePackageName = (packageName == null) ? storePackageName : packageName + "_" + storePackageName; String completePackageName = (packageName == null) ? storePackageName : packageName + "_" + storePackageName;
// retrieve included paths (optional)
// note: the default exporter will currently include parents and children, relative to the path (to support bootstrap import of Dynamic Models)
String includedPathsStr = (String)store.get(INCLUDED_PATHS);
String[] includedPaths = (includedPathsStr != null ? includedPathsStr.split(",\\s*") : null);
// now export // now export
// NOTE: For now, do not provide exporter progress // NOTE: For now, do not provide exporter progress
ExporterCrawlerParameters exportParameters = getExportParameters(storeRef); ExporterCrawlerParameters exportParameters = getExportParameters(storeRef, includedPaths);
ExportHandleType exportHandle = exportStore.exportStore(exportParameters, completePackageName, null); ExportHandleType exportHandle = exportStore.exportStore(exportParameters, completePackageName, null);
exportHandles.add(exportHandle); exportHandles.add(exportHandle);
} }
@@ -308,7 +314,7 @@ public class RepositoryExporterComponent implements RepositoryExporterService
* @param storeRef store reference to export * @param storeRef store reference to export
* @return the parameters for exporting the complete store * @return the parameters for exporting the complete store
*/ */
private ExporterCrawlerParameters getExportParameters(StoreRef storeRef) private ExporterCrawlerParameters getExportParameters(StoreRef storeRef, String[] includedPaths)
{ {
ExporterCrawlerParameters parameters = new ExporterCrawlerParameters(); ExporterCrawlerParameters parameters = new ExporterCrawlerParameters();
parameters.setExportFrom(new Location(storeRef)); parameters.setExportFrom(new Location(storeRef));
@@ -318,6 +324,7 @@ public class RepositoryExporterComponent implements RepositoryExporterService
parameters.setCrawlAssociations(true); parameters.setCrawlAssociations(true);
parameters.setCrawlNullProperties(true); parameters.setCrawlNullProperties(true);
parameters.setExcludeNamespaceURIs(new String[] {}); parameters.setExcludeNamespaceURIs(new String[] {});
parameters.setIncludedPaths(includedPaths);
parameters.setReferenceType(ReferenceType.NODEREF); parameters.setReferenceType(ReferenceType.NODEREF);
return parameters; return parameters;
} }

View File

@@ -53,6 +53,7 @@ import org.alfresco.service.cmr.view.ImporterException;
import org.alfresco.service.cmr.view.ImporterProgress; import org.alfresco.service.cmr.view.ImporterProgress;
import org.alfresco.service.cmr.view.ImporterService; import org.alfresco.service.cmr.view.ImporterService;
import org.alfresco.service.cmr.view.Location; import org.alfresco.service.cmr.view.Location;
import org.alfresco.service.cmr.view.ImporterBinding.UUID_BINDING;
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.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
@@ -60,9 +61,6 @@ import org.alfresco.util.AbstractLifecycleBean;
import org.alfresco.util.TempFileProvider; import org.alfresco.util.TempFileProvider;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
@@ -79,6 +77,7 @@ public class ImporterBootstrap extends AbstractLifecycleBean
public static final String VIEW_MESSAGES_PROPERTY = "messages"; public static final String VIEW_MESSAGES_PROPERTY = "messages";
public static final String VIEW_LOCATION_VIEW = "location"; public static final String VIEW_LOCATION_VIEW = "location";
public static final String VIEW_ENCODING = "encoding"; public static final String VIEW_ENCODING = "encoding";
public static final String VIEW_UUID_BINDING = "uuidBinding";
// Logger // Logger
private static final Log logger = LogFactory.getLog(ImporterBootstrap.class); private static final Log logger = LogFactory.getLog(ImporterBootstrap.class);
@@ -317,10 +316,13 @@ public class ImporterBootstrap extends AbstractLifecycleBean
} }
if (storeRef == null) if (storeRef == null)
{ {
throw new ImporterException("Store URL must be provided"); if (logger.isDebugEnabled())
{
logger.debug("No Store URL - bootstrap import ignored");
}
return;
} }
UserTransaction userTransaction = transactionService.getUserTransaction(); UserTransaction userTransaction = transactionService.getUserTransaction();
Authentication authentication = authenticationComponent.getCurrentAuthentication(); Authentication authentication = authenticationComponent.getCurrentAuthentication();
@@ -409,6 +411,19 @@ public class ImporterBootstrap extends AbstractLifecycleBean
ResourceBundle bundle = ResourceBundle.getBundle(messages, bindingLocale); ResourceBundle bundle = ResourceBundle.getBundle(messages, bindingLocale);
binding.setResourceBundle(bundle); binding.setResourceBundle(bundle);
} }
String uuidBinding = bootstrapView.getProperty(VIEW_UUID_BINDING);
if (uuidBinding != null && uuidBinding.length() > 0)
{
try
{
binding.setUUIDBinding(UUID_BINDING.valueOf(UUID_BINDING.class, uuidBinding));
}
catch(IllegalArgumentException e)
{
throw new ImporterException("The value " + uuidBinding + " is an invalid uuidBinding");
}
}
// Now import... // Now import...
ImporterProgress importProgress = null; ImporterProgress importProgress = null;
@@ -522,6 +537,8 @@ public class ImporterBootstrap extends AbstractLifecycleBean
private static final String IMPORT_LOCATION_NODEREF = "bootstrap.location.noderef"; private static final String IMPORT_LOCATION_NODEREF = "bootstrap.location.noderef";
private static final String IMPORT_LOCATION_PATH = "bootstrap.location.path"; private static final String IMPORT_LOCATION_PATH = "bootstrap.location.path";
// by default, use create new strategy for bootstrap import
private UUID_BINDING uuidBinding = UUID_BINDING.CREATE_NEW_WITH_UUID;
/** /**
* Set Import Configuration * Set Import Configuration
@@ -602,8 +619,17 @@ public class ImporterBootstrap extends AbstractLifecycleBean
*/ */
public UUID_BINDING getUUIDBinding() public UUID_BINDING getUUIDBinding()
{ {
// always use create new strategy for bootstrap import return uuidBinding;
return UUID_BINDING.CREATE_NEW_WITH_UUID; }
/**
* Allow bootstrap to override default Node UUID Binding
*
* @param uuidBinding UUID_BINDING
*/
private void setUUIDBinding(UUID_BINDING uuidBinding)
{
this.uuidBinding = uuidBinding;
} }
/* /*

View File

@@ -45,7 +45,7 @@ public class ExporterCrawlerParameters
private boolean crawlNullProperties = true; private boolean crawlNullProperties = true;
private ReferenceType referenceType = ReferenceType.PATHREF; private ReferenceType referenceType = ReferenceType.PATHREF;
private String[] excludeNamespaceURIs = new String[] { NamespaceService.REPOSITORY_VIEW_1_0_URI }; private String[] excludeNamespaceURIs = new String[] { NamespaceService.REPOSITORY_VIEW_1_0_URI };
private String[] includedPaths = null;
/** /**
* Crawl and export child nodes * Crawl and export child nodes
@@ -166,6 +166,26 @@ public class ExporterCrawlerParameters
{ {
this.excludeNamespaceURIs = excludeNamespaceURIs; this.excludeNamespaceURIs = excludeNamespaceURIs;
} }
/**
* Gets the list of included paths to explicitly include in the Export
*
* @return the list of included paths
*/
public String[] getIncludedPaths()
{
return includedPaths;
}
/**
* Sets the list of included paths to explicitly include in the Export
*
* @param includedPaths
*/
public void setIncludedPaths(String[] includedPaths)
{
this.includedPaths = includedPaths;
}
/** /**
* Gets the path to export from * Gets the path to export from