mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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:
@@ -9,4 +9,12 @@
|
||||
<sys:versionSchema>${version.schema}</sys:versionSchema>
|
||||
</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>
|
||||
|
@@ -715,6 +715,7 @@
|
||||
<prop key="version.label">${version.label}</prop>
|
||||
<prop key="version.schema">${version.schema}</prop>
|
||||
<prop key="system.descriptor.childname">${system.descriptor.childname}</prop>
|
||||
<prop key="system.descriptor.current.childname">${system.descriptor.current.childname}</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
@@ -23,7 +23,7 @@
|
||||
</type>
|
||||
|
||||
<type name="sys:descriptor">
|
||||
<title>Descriptor</title>
|
||||
<title>Descriptor</title>
|
||||
<parent>sys:base</parent>
|
||||
<properties>
|
||||
<property name="sys:versionMajor">
|
||||
@@ -44,7 +44,7 @@
|
||||
<property name="sys:versionSchema">
|
||||
<type>d:int</type>
|
||||
<mandatory>true</mandatory>
|
||||
<default>0</default>
|
||||
<default>0</default>
|
||||
</property>
|
||||
</properties>
|
||||
</type>
|
||||
|
@@ -71,6 +71,7 @@ mail.password=
|
||||
|
||||
system.store=system://system
|
||||
system.descriptor.childname=sys:descriptor
|
||||
system.descriptor.current.childname=sys:descriptor-current
|
||||
|
||||
# User config
|
||||
|
||||
|
@@ -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 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
|
||||
|
@@ -169,7 +169,7 @@ public class PatchServiceImpl implements PatchService
|
||||
String report = null;
|
||||
boolean success = false;
|
||||
// first check whether the patch is relevant to the repo
|
||||
Descriptor repoDescriptor = descriptorService.getRepositoryDescriptor();
|
||||
Descriptor repoDescriptor = descriptorService.getInstalledRepositoryDescriptor();
|
||||
boolean applies = applies(repoDescriptor, patch);
|
||||
if (!applies)
|
||||
{
|
||||
|
@@ -18,14 +18,16 @@ package org.alfresco.repo.descriptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||
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.NodeService;
|
||||
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.QName;
|
||||
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.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -49,6 +53,8 @@ import org.springframework.core.io.Resource;
|
||||
*/
|
||||
public class DescriptorServiceImpl implements DescriptorService, ApplicationListener, InitializingBean
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(DescriptorServiceImpl.class);
|
||||
|
||||
private Properties serverProperties;
|
||||
|
||||
private ImporterBootstrap systemBootstrap;
|
||||
@@ -58,7 +64,7 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
|
||||
private TransactionService transactionService;
|
||||
|
||||
private Descriptor serverDescriptor;
|
||||
private Descriptor repoDescriptor;
|
||||
private Descriptor installedRepoDescriptor;
|
||||
|
||||
|
||||
|
||||
@@ -126,9 +132,9 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
|
||||
/* (non-Javadoc)
|
||||
* @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)
|
||||
{
|
||||
// initialise server descriptor
|
||||
serverDescriptor = createServerDescriptor();
|
||||
|
||||
// initialise the repository descriptor
|
||||
// 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()
|
||||
{
|
||||
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
|
||||
{
|
||||
// initialise server descriptor
|
||||
serverDescriptor = createServerDescriptor();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +186,7 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
|
||||
*
|
||||
* @return descriptor
|
||||
*/
|
||||
private Descriptor createRepositoryDescriptor()
|
||||
private Descriptor createInstalledRepositoryDescriptor()
|
||||
{
|
||||
// retrieve system descriptor location
|
||||
StoreRef storeRef = systemBootstrap.getStoreRef();
|
||||
@@ -182,30 +194,117 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
|
||||
String path = systemProperties.getProperty("system.descriptor.childname");
|
||||
|
||||
// retrieve system descriptor
|
||||
NodeRef descriptorRef = null;
|
||||
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
|
||||
}
|
||||
|
||||
NodeRef descriptorNodeRef = getDescriptorNodeRef(storeRef, path, false);
|
||||
// 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);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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");
|
||||
|
||||
// descriptor cannot be found
|
||||
return new UnknownDescriptor();
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -88,7 +88,7 @@ public class DescriptorServiceTest extends BaseSpringTest
|
||||
{
|
||||
ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
DescriptorService descriptorService = registry.getDescriptorService();
|
||||
Descriptor repoDescriptor = descriptorService.getRepositoryDescriptor();
|
||||
Descriptor repoDescriptor = descriptorService.getInstalledRepositoryDescriptor();
|
||||
|
||||
String major = repoDescriptor.getVersionMajor();
|
||||
String minor = repoDescriptor.getVersionMinor();
|
||||
|
@@ -84,15 +84,24 @@ public class DescriptorStartupLog implements ApplicationListener
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
Descriptor serverDescriptor = descriptorService.getServerDescriptor();
|
||||
Descriptor repoDescriptor = descriptorService.getRepositoryDescriptor();
|
||||
Descriptor installedRepoDescriptor = descriptorService.getInstalledRepositoryDescriptor();
|
||||
String serverEdition = serverDescriptor.getEdition();
|
||||
String serverVersion = serverDescriptor.getVersion();
|
||||
String repoVersion = repoDescriptor.getVersion();
|
||||
int schemaVersion = repoDescriptor.getSchema();
|
||||
logger.info(String.format("Alfresco started (%s) - v%s; repository v%s; schema %d",
|
||||
serverEdition, serverVersion, repoVersion, schemaVersion));
|
||||
int serverSchemaVersion = serverDescriptor.getSchema();
|
||||
String installedRepoVersion = installedRepoDescriptor.getVersion();
|
||||
int installedSchemaVersion = installedRepoDescriptor.getSchema();
|
||||
logger.info(
|
||||
String.format(
|
||||
"Alfresco started (%s): " +
|
||||
"Current version %s schema %d - " +
|
||||
"Installed version %s schema %d",
|
||||
serverEdition,
|
||||
serverVersion,
|
||||
serverSchemaVersion,
|
||||
installedRepoVersion,
|
||||
installedSchemaVersion));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -33,10 +33,11 @@ public interface DescriptorService
|
||||
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
|
||||
*/
|
||||
public Descriptor getRepositoryDescriptor();
|
||||
|
||||
public Descriptor getInstalledRepositoryDescriptor();
|
||||
}
|
||||
|
Reference in New Issue
Block a user