Cleaned up feed versioning removal code.
@@ -95,6 +95,12 @@ public class MetadataJcrConfigurator {
private void removeVersionableFeedType(Session session) throws RepositoryException {
Node feedsNode = session.getRootNode().getNode("metadata/feeds");
+ NodeTypeManager typeMgr = (NodeTypeManager) session.getWorkspace().getNodeTypeManager();
+ NodeType currentFeedType = typeMgr.getNodeType("tba:feed");
+ List<String> currentSupertypes = Arrays.asList(currentFeedType.getDeclaredSupertypeNames());
+
+ if (currentSupertypes.contains("mix:versionable")) {
+ // Remove feed version history
for (Node catNode : JcrUtil.getNodesOfType(feedsNode, "tba:category")) {
for (Node feedNode : JcrUtil.getNodesOfType(catNode, "tba:feed")) {
log.info("Removing prior versions of feed: {}.{}", catNode.getName(), feedNode.getName());
@@ -121,17 +127,16 @@ public class MetadataJcrConfigurator {
log.info("Feed {} had no versions", feedNode.getName());
}
}
+ }
- NodeTypeManager typeMgr = (NodeTypeManager) session.getWorkspace().getNodeTypeManager();
- NodeType currentFeedType = typeMgr.getNodeType("tba:feed");
- List<String> currentSupertypes = Arrays.asList(currentFeedType.getDeclaredSupertypeNames());
-
- if (currentSupertypes.contains("mix:versionable")) {
- List<Node> currentFeeds = JcrUtil.getNodesOfType(catNode, "tba:feed");
+ // Redefine the NodeType of tba:feed to remove versionable but retain the versionable properties with weaker constraints
+ // Retaining the properties seems to override some residual properties on feed nodes that causes a failure later.
+ // In particular, jcr:predecessors was accessed later but redefining all mix:versionable properties to be safe.
NodeTypeTemplate template = typeMgr.createNodeTypeTemplate(currentFeedType);
-
List<String> newSupertypes = currentSupertypes.stream().filter(type -> ! type.equals("mix:versionable")).collect(Collectors.toList());
+
template.setDeclaredSuperTypeNames(newSupertypes.toArray(new String[newSupertypes.size()]));
+
@SuppressWarnings("unchecked")
List<PropertyDefinitionTemplate> propTemplates = template.getPropertyDefinitionTemplates();
PropertyDefinitionTemplate prop = typeMgr.createPropertyDefinitionTemplate();
@@ -164,7 +169,9 @@ public class MetadataJcrConfigurator {
NodeType newType = typeMgr.registerNodeType(template, true);
log.info("Replaced with new feed type '{}' with a non-versionavble type", newType);
- for (Node feedNode : currentFeeds) {
+ // This step may not be necessary.
+ for (Node catNode : JcrUtil.getNodesOfType(feedsNode, "tba:category")) {
+ for (Node feedNode : JcrUtil.getNodesOfType(catNode, "tba:feed")) {
feedNode.setPrimaryType(newType.getName());
log.info("Replaced type of node {}", feedNode);
