getChildElements(key) would be b
. The key's last path
+ * element represents the key's property name, and can therefore be any value without affecting
+ * the outcome of the call.
+ *
+ * @param key the registry key with the path. The last element in the path
+ * will be ignored, and can be any acceptable property localname.
+ * @return Returns all child elements (not values) for the given key, ignoring
+ * the last element in the key.
+ */
+ Collection getChildElements(RegistryKey key);
}
diff --git a/source/java/org/alfresco/repo/admin/registry/RegistryServiceImpl.java b/source/java/org/alfresco/repo/admin/registry/RegistryServiceImpl.java
index 3a979bd901..770d000589 100644
--- a/source/java/org/alfresco/repo/admin/registry/RegistryServiceImpl.java
+++ b/source/java/org/alfresco/repo/admin/registry/RegistryServiceImpl.java
@@ -25,6 +25,9 @@
package org.alfresco.repo.admin.registry;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
@@ -36,8 +39,10 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
+import org.alfresco.service.namespace.NamespaceException;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
+import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.Pair;
import org.alfresco.util.PropertyCheck;
import org.alfresco.util.PropertyMap;
@@ -256,6 +261,13 @@ public class RegistryServiceImpl implements RegistryService
*/
public void addValue(RegistryKey key, Serializable value)
{
+ // Check the namespace being used in the key
+ String namespaceUri = key.getNamespaceUri();
+ if (!namespaceService.getURIs().contains(namespaceUri))
+ {
+ throw new NamespaceException("Unable to add a registry value with an unregistered namespace: " + namespaceUri);
+ }
+
// Get the path, with creation support
Pair keyPair = getPath(key, true);
// We know that the node exists, so just set the value
@@ -287,4 +299,35 @@ public class RegistryServiceImpl implements RegistryService
}
return value;
}
+
+ public Collection getChildElements(RegistryKey key)
+ {
+ // Get the path without creating it
+ Pair keyPair = getPath(key, false);
+ if (keyPair == null)
+ {
+ // Nothing at that path
+ return Collections.emptyList();
+ }
+ // Use a query to find the children
+ RegexQNamePattern qnamePattern = new RegexQNamePattern(key.getNamespaceUri(), ".*");
+ List childAssocRefs = nodeService.getChildAssocs(
+ keyPair.getFirst(),
+ ContentModel.ASSOC_CHILDREN,
+ qnamePattern);
+ // The localname of each one of the child associations represents a path element
+ Collection results = new ArrayList(childAssocRefs.size());
+ for (ChildAssociationRef assocRef : childAssocRefs)
+ {
+ results.add(assocRef.getQName().getLocalName());
+ }
+ // Done
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Retrieved child elements from registry: \n" +
+ " Key: " + key + "\n" +
+ " Elements: " + results);
+ }
+ return results;
+ }
}
diff --git a/source/java/org/alfresco/repo/admin/registry/RegistryServiceImplTest.java b/source/java/org/alfresco/repo/admin/registry/RegistryServiceImplTest.java
index f02900ac66..5180858bba 100644
--- a/source/java/org/alfresco/repo/admin/registry/RegistryServiceImplTest.java
+++ b/source/java/org/alfresco/repo/admin/registry/RegistryServiceImplTest.java
@@ -24,6 +24,8 @@
*/
package org.alfresco.repo.admin.registry;
+import java.util.Collection;
+
import junit.framework.TestCase;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
@@ -73,6 +75,8 @@ public class RegistryServiceImplTest extends TestCase
private static final Long VALUE_ONE = 1L;
private static final Long VALUE_TWO = 2L;
private static final Long VALUE_THREE = 3L;
+ private static final RegistryKey KEY_A_B_0 = new RegistryKey(null, "a", "b", "0");
+ private static final RegistryKey KEY_A_B_1 = new RegistryKey(null, "a", "b", "1");
private static final RegistryKey KEY_A_B_C_0 = new RegistryKey(null, "a", "b", "c", "0");
private static final RegistryKey KEY_A_B_C_1 = new RegistryKey(null, "a", "b", "c", "1");
private static final RegistryKey KEY_A_B_C_2 = new RegistryKey(null, "a", "b", "c", "2");
@@ -83,6 +87,7 @@ public class RegistryServiceImplTest extends TestCase
private static final RegistryKey KEY_A_B_C_D_3 = new RegistryKey(null, "a", "b", "c", "d", "3");
private static final RegistryKey KEY_X_Y_Z_0 = new RegistryKey(null, "x", "y", "z", "0");
private static final RegistryKey KEY_SPECIAL = new RegistryKey(null, "me & you", "whatever");
+ private static final RegistryKey KEY_DOES_NOT_EXIST = new RegistryKey(null, "does", "not", "exist");
/**
* General writing and reading back.
*/
@@ -107,6 +112,22 @@ public class RegistryServiceImplTest extends TestCase
assertNull("Missing key should return null value", registryService.getValue(KEY_X_Y_Z_0));
}
+ public void testGetElements() throws Exception
+ {
+ registryService.addValue(KEY_A_B_C_1, VALUE_ONE);
+ registryService.addValue(KEY_A_B_C_2, VALUE_TWO);
+
+ // Check that we get an empty list for a random query
+ assertEquals("Excpected empty collection for random query", 0, registryService.getChildElements(KEY_DOES_NOT_EXIST).size());
+
+ // Check that the property part of the key is ignored
+ assertEquals("Incorrect number ofchild elements", 1, registryService.getChildElements(KEY_A_B_0).size());
+ assertEquals("Incorrect number ofchild elements", 1, registryService.getChildElements(KEY_A_B_1).size());
+
+ Collection childElements = registryService.getChildElements(KEY_A_B_0);
+ assertTrue("Incorrect child elements retrieved", childElements.contains("c"));
+ }
+
public void testSpecialCharacters()
{
registryService.addValue(KEY_SPECIAL, VALUE_THREE);
diff --git a/source/java/org/alfresco/repo/module/ModuleComponentHelper.java b/source/java/org/alfresco/repo/module/ModuleComponentHelper.java
index 1d96cb7e9a..eeb0e68c66 100644
--- a/source/java/org/alfresco/repo/module/ModuleComponentHelper.java
+++ b/source/java/org/alfresco/repo/module/ModuleComponentHelper.java
@@ -24,6 +24,7 @@
*/
package org.alfresco.repo.module;
+import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@@ -64,6 +65,7 @@ public class ModuleComponentHelper
private static final String REGISTRY_PROPERTY_CURRENT_VERSION = "currentVersion";
private static final String REGISTRY_PATH_COMPONENTS = "components";
private static final String REGISTRY_PROPERTY_EXECUTION_DATE = "executionDate";
+ private static final String REGISTRY_PROPERTY_DUMMY = "dummy";
private static final String MSG_FOUND_MODULES = "module.msg.found_modules";
private static final String MSG_STARTING = "module.msg.starting";
@@ -71,6 +73,7 @@ public class ModuleComponentHelper
private static final String MSG_UPGRADING = "module.msg.upgrading";
private static final String ERR_NO_DOWNGRADE = "module.err.downgrading_not_supported";
private static final String ERR_COMPONENT_ALREADY_REGISTERED = "module.err.component_already_registered";
+ private static final String MSG_MISSING = "module.msg.missing";
private static Log logger = LogFactory.getLog(ModuleComponentHelper.class);
private static Log loggerService = LogFactory.getLog(ModuleServiceImpl.class);
@@ -205,17 +208,60 @@ public class ModuleComponentHelper
};
TransactionUtil.executeInNonPropagatingUserTransaction(transactionService, startModuleWork);
}
- // Done
+ // We have finished executing any components
if (logger.isDebugEnabled())
{
logger.debug("Executed " + executedComponents.size() + " components");
}
- }
- finally
- {
+
+ // Check for missing modules.
+ checkForMissingModules();
+
// Restore the original authentication
authenticationComponent.setCurrentAuthentication(authentication);
}
+ catch (Throwable e)
+ {
+ throw new AlfrescoRuntimeException("Failed to start modules", e);
+ }
+ }
+
+ /**
+ * Checks to see if there are any modules registered as installed that aren't in the
+ * list of modules taken from the WAR.
+ *
+ * Currently, the behaviour specified is that a warning is generated only.
+ */
+ private void checkForMissingModules()
+ {
+ // Get the IDs of all modules from the registry
+ RegistryKey moduleKeyAllIds = new RegistryKey(
+ ModuleComponentHelper.URI_MODULES_1_0,
+ REGISTRY_PATH_MODULES, REGISTRY_PROPERTY_DUMMY);
+ Collection moduleIds = registryService.getChildElements(moduleKeyAllIds);
+
+ // Check that each module is present in the distribution
+ for (String moduleId : moduleIds)
+ {
+ ModuleDetails moduleDetails = moduleService.getModule(moduleId);
+ if (moduleDetails != null)
+ {
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Installed module found in distribution: " + moduleId);
+ }
+ }
+ else
+ {
+ // Get the specifics of the missing module
+ RegistryKey moduleKeyCurrentVersion = new RegistryKey(
+ ModuleComponentHelper.URI_MODULES_1_0,
+ REGISTRY_PATH_MODULES, moduleId, REGISTRY_PROPERTY_CURRENT_VERSION);
+ VersionNumber versionCurrent = (VersionNumber) registryService.getValue(moduleKeyCurrentVersion);
+ // The module is missing, so warn
+ loggerService.warn(I18NUtil.getMessage(MSG_MISSING, moduleId, versionCurrent));
+ }
+ }
}
/**
diff --git a/source/java/org/alfresco/repo/module/ModuleComponentHelperTest.java b/source/java/org/alfresco/repo/module/ModuleComponentHelperTest.java
index f0c12bee7f..389e8e0808 100644
--- a/source/java/org/alfresco/repo/module/ModuleComponentHelperTest.java
+++ b/source/java/org/alfresco/repo/module/ModuleComponentHelperTest.java
@@ -215,7 +215,19 @@ public class ModuleComponentHelperTest extends BaseAlfrescoTestCase
public ModuleDetails getModule(String moduleId)
{
- throw new UnsupportedOperationException();
+ for (int i = 0; i < MODULE_IDS.length; i++)
+ {
+ if (!MODULE_IDS[i].equals(moduleId))
+ {
+ continue;
+ }
+ new ModuleDetailsImpl(
+ MODULE_IDS[i],
+ currentVersion,
+ "Module-" + i,
+ "Description-" + i);
+ }
+ return null;
}
public void startModules()
diff --git a/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java b/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java
index b91fb459bc..3af3721c08 100644
--- a/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java
+++ b/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java
@@ -313,6 +313,13 @@ public class ModuleManagementTool
// Update the zip file's
File.update();
+
+ // Set the modified date
+ java.io.File warFile = new java.io.File(warFileLocation);
+ if (warFile.exists())
+ {
+ warFile.setLastModified(System.currentTimeMillis());
+ }
}
}
catch (ZipWarningException ignore)