Fixed AR-451: Display both current version of repo and installed version of repo

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2485 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-02-23 16:40:53 +00:00
parent 75fe6196f4
commit d7a8ab1065
10 changed files with 167 additions and 42 deletions

View File

@@ -9,4 +9,12 @@
<sys:versionSchema>${version.schema}</sys:versionSchema> <sys:versionSchema>${version.schema}</sys:versionSchema>
</sys:descriptor> </sys:descriptor>
<sys:descriptor view:childName="${system.descriptor.current.childname}">
<sys:versionMajor>${version.major}</sys:versionMajor>
<sys:versionMinor>${version.minor}</sys:versionMinor>
<sys:versionRevision>${version.revision}</sys:versionRevision>
<sys:versionLabel>${version.label}</sys:versionLabel>
<sys:versionSchema>${version.schema}</sys:versionSchema>
</sys:descriptor>
</view:view> </view:view>

View File

@@ -715,6 +715,7 @@
<prop key="version.label">${version.label}</prop> <prop key="version.label">${version.label}</prop>
<prop key="version.schema">${version.schema}</prop> <prop key="version.schema">${version.schema}</prop>
<prop key="system.descriptor.childname">${system.descriptor.childname}</prop> <prop key="system.descriptor.childname">${system.descriptor.childname}</prop>
<prop key="system.descriptor.current.childname">${system.descriptor.current.childname}</prop>
</props> </props>
</property> </property>
</bean> </bean>

View File

@@ -23,7 +23,7 @@
</type> </type>
<type name="sys:descriptor"> <type name="sys:descriptor">
<title>Descriptor</title> <title>Descriptor</title>
<parent>sys:base</parent> <parent>sys:base</parent>
<properties> <properties>
<property name="sys:versionMajor"> <property name="sys:versionMajor">
@@ -44,7 +44,7 @@
<property name="sys:versionSchema"> <property name="sys:versionSchema">
<type>d:int</type> <type>d:int</type>
<mandatory>true</mandatory> <mandatory>true</mandatory>
<default>0</default> <default>0</default>
</property> </property>
</properties> </properties>
</type> </type>

View File

@@ -71,6 +71,7 @@ mail.password=
system.store=system://system system.store=system://system
system.descriptor.childname=sys:descriptor system.descriptor.childname=sys:descriptor
system.descriptor.current.childname=sys:descriptor-current
# User config # User config

View File

@@ -49,6 +49,12 @@ public interface ContentModel
static final QName ASPECT_ROOT = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "aspect_root"); static final QName ASPECT_ROOT = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "aspect_root");
static final QName TYPE_STOREROOT = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "store_root"); static final QName TYPE_STOREROOT = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "store_root");
// descriptor properties
static final QName PROP_SYS_VERSION_MAJOR = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "versionMajor");
static final QName PROP_SYS_VERSION_MINOR = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "versionMinor");
static final QName PROP_SYS_VERSION_REVISION = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "versionRevision");
static final QName PROP_SYS_VERSION_LABEL = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "versionLabel");
static final QName PROP_SYS_VERSION_SCHEMA = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "versionSchema");
// //
// Content Model Definitions // Content Model Definitions

View File

@@ -169,7 +169,7 @@ public class PatchServiceImpl implements PatchService
String report = null; String report = null;
boolean success = false; boolean success = false;
// first check whether the patch is relevant to the repo // first check whether the patch is relevant to the repo
Descriptor repoDescriptor = descriptorService.getRepositoryDescriptor(); Descriptor repoDescriptor = descriptorService.getInstalledRepositoryDescriptor();
boolean applies = applies(repoDescriptor, patch); boolean applies = applies(repoDescriptor, patch);
if (!applies) if (!applies)
{ {

View File

@@ -18,14 +18,16 @@ package org.alfresco.repo.descriptor;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.importer.ImporterBootstrap; import org.alfresco.repo.importer.ImporterBootstrap;
import org.alfresco.repo.transaction.TransactionUtil; import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.service.cmr.repository.InvalidStoreRefException; import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
@@ -35,6 +37,8 @@ import org.alfresco.service.descriptor.DescriptorService;
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;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
@@ -49,6 +53,8 @@ import org.springframework.core.io.Resource;
*/ */
public class DescriptorServiceImpl implements DescriptorService, ApplicationListener, InitializingBean public class DescriptorServiceImpl implements DescriptorService, ApplicationListener, InitializingBean
{ {
private static Log logger = LogFactory.getLog(DescriptorServiceImpl.class);
private Properties serverProperties; private Properties serverProperties;
private ImporterBootstrap systemBootstrap; private ImporterBootstrap systemBootstrap;
@@ -58,7 +64,7 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
private TransactionService transactionService; private TransactionService transactionService;
private Descriptor serverDescriptor; private Descriptor serverDescriptor;
private Descriptor repoDescriptor; private Descriptor installedRepoDescriptor;
@@ -126,9 +132,9 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.service.descriptor.DescriptorService#getRepositoryDescriptor() * @see org.alfresco.service.descriptor.DescriptorService#getRepositoryDescriptor()
*/ */
public Descriptor getRepositoryDescriptor() public Descriptor getInstalledRepositoryDescriptor()
{ {
return repoDescriptor; return installedRepoDescriptor;
} }
/** /**
@@ -138,15 +144,23 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
{ {
if (event instanceof ContextRefreshedEvent) if (event instanceof ContextRefreshedEvent)
{ {
// initialise server descriptor
serverDescriptor = createServerDescriptor();
// initialise the repository descriptor // initialise the repository descriptor
// note: this requires that the repository schema has already been initialised // note: this requires that the repository schema has already been initialised
repoDescriptor = TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<Descriptor>() TransactionWork<Descriptor> createDescriptorWork = new TransactionUtil.TransactionWork<Descriptor>()
{ {
public Descriptor doWork() public Descriptor doWork()
{ {
return createRepositoryDescriptor(); // persist the server descriptor values
updateCurrentRepositoryDescriptor(serverDescriptor);
// return the repository installed descriptor
return createInstalledRepositoryDescriptor();
} }
}); };
installedRepoDescriptor = TransactionUtil.executeInUserTransaction(transactionService, createDescriptorWork);
} }
} }
@@ -155,8 +169,6 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
*/ */
public void afterPropertiesSet() throws Exception public void afterPropertiesSet() throws Exception
{ {
// initialise server descriptor
serverDescriptor = createServerDescriptor();
} }
/** /**
@@ -174,7 +186,7 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
* *
* @return descriptor * @return descriptor
*/ */
private Descriptor createRepositoryDescriptor() private Descriptor createInstalledRepositoryDescriptor()
{ {
// retrieve system descriptor location // retrieve system descriptor location
StoreRef storeRef = systemBootstrap.getStoreRef(); StoreRef storeRef = systemBootstrap.getStoreRef();
@@ -182,30 +194,117 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
String path = systemProperties.getProperty("system.descriptor.childname"); String path = systemProperties.getProperty("system.descriptor.childname");
// retrieve system descriptor // retrieve system descriptor
NodeRef descriptorRef = null; NodeRef descriptorNodeRef = getDescriptorNodeRef(storeRef, path, false);
try
{
NodeRef rootNode = nodeService.getRootNode(storeRef);
List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, "/" + path, null, namespaceService, false);
if (nodeRefs.size() > 0)
{
descriptorRef = nodeRefs.get(0);
}
}
catch(InvalidStoreRefException e)
{
// handle as system descriptor not found
}
// create appropriate descriptor // create appropriate descriptor
if (descriptorRef != null) if (descriptorNodeRef != null)
{ {
Map<QName, Serializable> properties = nodeService.getProperties(descriptorRef); Map<QName, Serializable> properties = nodeService.getProperties(descriptorNodeRef);
return new RepositoryDescriptor(properties); return new RepositoryDescriptor(properties);
} }
else
{
// descriptor cannot be found
return new UnknownDescriptor();
}
}
// descriptor cannot be found /**
return new UnknownDescriptor(); * Push the current server descriptor properties into persistence.
*
* @param serverDescriptor the current server descriptor
*/
private void updateCurrentRepositoryDescriptor(Descriptor serverDescriptor)
{
// retrieve system descriptor location
StoreRef storeRef = systemBootstrap.getStoreRef();
Properties systemProperties = systemBootstrap.getConfiguration();
String path = systemProperties.getProperty("system.descriptor.current.childname");
// retrieve system descriptor
NodeRef currentDescriptorNodeRef = getDescriptorNodeRef(storeRef, path, true);
// if the node is missing but it should have been created
if (currentDescriptorNodeRef == null)
{
return;
}
// set the properties
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(17);
properties.put(ContentModel.PROP_SYS_VERSION_MAJOR, serverDescriptor.getVersionMajor());
properties.put(ContentModel.PROP_SYS_VERSION_MINOR, serverDescriptor.getVersionMinor());
properties.put(ContentModel.PROP_SYS_VERSION_REVISION, serverDescriptor.getVersionRevision());
properties.put(ContentModel.PROP_SYS_VERSION_LABEL, serverDescriptor.getVersionLabel());
properties.put(ContentModel.PROP_SYS_VERSION_SCHEMA, serverDescriptor.getSchema());
nodeService.setProperties(currentDescriptorNodeRef, properties);
// done
if (logger.isDebugEnabled())
{
logger.debug("Updated current repository descriptor properties: \n" +
" node: " + currentDescriptorNodeRef + "\n" +
" descriptor: " + serverDescriptor);
}
}
/**
*
* @param storeRef the store to search
* @param path the path below the root node to search
* @param create true if the node must be created if missing. No properties will be set.
* @return Returns the node for the path, or null
*/
private NodeRef getDescriptorNodeRef(StoreRef storeRef, String path, boolean create)
{
// check for the store and create if necessary
if (!nodeService.exists(storeRef) && create)
{
storeRef = nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
}
String searchPath = "/" + path;
NodeRef descriptorNodeRef = null;
NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
List<NodeRef> nodeRefs = searchService.selectNodes(rootNodeRef, searchPath, null, namespaceService, false);
if (nodeRefs.size() == 1)
{
descriptorNodeRef = nodeRefs.get(0);
}
else if (nodeRefs.size() == 0)
{
}
else if (nodeRefs.size() > 1)
{
if (logger.isDebugEnabled())
{
logger.debug("Multiple descriptors: \n" +
" store: " + storeRef + "\n" +
" path: " + searchPath);
}
// get the first one
descriptorNodeRef = nodeRefs.get(0);
}
if (descriptorNodeRef == null)
{
if (logger.isDebugEnabled())
{
logger.debug("Descriptor not found: \n" +
" store: " + storeRef + "\n" +
" path: " + searchPath);
}
// create if necessary
if (create)
{
descriptorNodeRef = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(path, namespaceService),
QName.createQName("sys:descriptor", namespaceService)).getChildRef();
if (logger.isDebugEnabled())
{
logger.debug("Created missing descriptor node: " + descriptorNodeRef);
}
}
}
return descriptorNodeRef;
} }
/** /**

View File

@@ -88,7 +88,7 @@ public class DescriptorServiceTest extends BaseSpringTest
{ {
ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY); ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
DescriptorService descriptorService = registry.getDescriptorService(); DescriptorService descriptorService = registry.getDescriptorService();
Descriptor repoDescriptor = descriptorService.getRepositoryDescriptor(); Descriptor repoDescriptor = descriptorService.getInstalledRepositoryDescriptor();
String major = repoDescriptor.getVersionMajor(); String major = repoDescriptor.getVersionMajor();
String minor = repoDescriptor.getVersionMinor(); String minor = repoDescriptor.getVersionMinor();

View File

@@ -84,13 +84,22 @@ public class DescriptorStartupLog implements ApplicationListener
if (logger.isInfoEnabled()) if (logger.isInfoEnabled())
{ {
Descriptor serverDescriptor = descriptorService.getServerDescriptor(); Descriptor serverDescriptor = descriptorService.getServerDescriptor();
Descriptor repoDescriptor = descriptorService.getRepositoryDescriptor(); Descriptor installedRepoDescriptor = descriptorService.getInstalledRepositoryDescriptor();
String serverEdition = serverDescriptor.getEdition(); String serverEdition = serverDescriptor.getEdition();
String serverVersion = serverDescriptor.getVersion(); String serverVersion = serverDescriptor.getVersion();
String repoVersion = repoDescriptor.getVersion(); int serverSchemaVersion = serverDescriptor.getSchema();
int schemaVersion = repoDescriptor.getSchema(); String installedRepoVersion = installedRepoDescriptor.getVersion();
logger.info(String.format("Alfresco started (%s) - v%s; repository v%s; schema %d", int installedSchemaVersion = installedRepoDescriptor.getSchema();
serverEdition, serverVersion, repoVersion, schemaVersion)); logger.info(
String.format(
"Alfresco started (%s): " +
"Current version %s schema %d - " +
"Installed version %s schema %d",
serverEdition,
serverVersion,
serverSchemaVersion,
installedRepoVersion,
installedSchemaVersion));
} }
} }
} }

View File

@@ -33,10 +33,11 @@ public interface DescriptorService
public Descriptor getServerDescriptor(); public Descriptor getServerDescriptor();
/** /**
* Get descriptor for the repository * Get descriptor for the repository as it was when first installed. The current
* repository descriptor will always be the same as the
* {@link #getServerDescriptor() server descriptor}.
* *
* @return repository descriptor * @return repository descriptor
*/ */
public Descriptor getRepositoryDescriptor(); public Descriptor getInstalledRepositoryDescriptor();
} }