Author: sascharodekamp
Date: Mon May 30 16:25:42 2011 New Revision: 1129242 URL: http://svn.apache.org/viewvc?rev=1129242&view=rev Log: Update - update the content deletion. Modified: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java Modified: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java?rev=1129242&r1=1129241&r2=1129242&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/jcr/orm/OfbizRepositoryMappingJackrabbit.java Mon May 30 16:25:42 2011 @@ -370,11 +370,7 @@ public class OfbizRepositoryMappingJackr */ @Override public void removeRepositoryNode() throws RepositoryException, GenericEntityException { - if (node.hasNodes()) { - // make sure all child nodes are checked out before deleting them - checkOutChildNodes(node); - } - checkOutNode(node); + checkOutRelatedNodes(node); node.remove(); try { @@ -750,22 +746,46 @@ public class OfbizRepositoryMappingJackr } /** - * Checks out recusivly all child nodes + * Checks out recursively all related nodes (parent, all child's (if exists) + * and the node itself) * * @param startNode * @throws RepositoryException */ - private void checkOutChildNodes(Node startNode) throws RepositoryException { + private void checkOutRelatedNodes(Node startNode) throws RepositoryException { + List<Node> nodesToCheckOut = new ArrayList<Node>(); + nodesToCheckOut.add(startNode); + nodesToCheckOut.add(startNode.getParent()); + if (startNode.hasNodes()) { + nodesToCheckOut.addAll(getAllChildNodes(startNode)); + } + + for (Node node : nodesToCheckOut) { + checkOutNode(node); + } + + } + + /** + * Return recursively all child nodes + * + * @param startNode + * @return + * @throws RepositoryException + */ + private List<Node> getAllChildNodes(Node startNode) throws RepositoryException { + List<Node> nodes = new ArrayList<Node>(); NodeIterator ni = startNode.getNodes(); while (ni.hasNext()) { Node nextNode = ni.nextNode(); - checkOutNode(nextNode); if (nextNode.hasNodes()) { - checkOutChildNodes(nextNode); + nodes.addAll(getAllChildNodes(nextNode)); } + + nodes.add(nextNode); } - // checkOutNode(startNode); + return nodes; } /** @@ -852,6 +872,7 @@ public class OfbizRepositoryMappingJackr List<GenericValue> returnList = null; try { + // find all content assoc links where the current content object is returnList = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", content.getString("contentId"))); if (UtilValidate.isNotEmpty(returnList)) { @@ -860,11 +881,9 @@ public class OfbizRepositoryMappingJackr returnList.addAll(getAllRelatedContents(delegator.findOne("Content", false, UtilMisc.toMap("contentId", c.getString("contentIdTo"))))); } } - // find all content assoc links where the current content object is - // the child object returnList.addAll(delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentIdTo", content.getString("contentId")))); + returnList.addAll(delegator.findByAnd("ContentKeyword", UtilMisc.toMap("contentId", content.getString("contentId")))); returnList.add(content); - } catch (GenericEntityException e) { Debug.logError(e, module); return null; |
Free forum by Nabble | Edit this page |