From 345de9c40d61c387260cd0f247a837f86d1388c6 Mon Sep 17 00:00:00 2001 From: Ancuta Morarasu Date: Fri, 23 Jun 2017 11:37:36 +0000 Subject: [PATCH] Merged MNT-17845-5.2.N (5.2.2) to 5.2.N (5.2.2) 137777 anechifor: REPO-2516 - MNT-17845 : Smart Folders - replece isReference with fromNodeRef - Review changes. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@137784 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../bundle/VirtualNodeServiceExtension.java | 6 +- .../VirtualVersionServiceExtension.java | 2 +- .../alfresco/repo/virtual/ref/Reference.java | 135 ++++++++---------- 3 files changed, 64 insertions(+), 79 deletions(-) diff --git a/source/java/org/alfresco/repo/virtual/bundle/VirtualNodeServiceExtension.java b/source/java/org/alfresco/repo/virtual/bundle/VirtualNodeServiceExtension.java index 9d10064f02..7c752236e8 100644 --- a/source/java/org/alfresco/repo/virtual/bundle/VirtualNodeServiceExtension.java +++ b/source/java/org/alfresco/repo/virtual/bundle/VirtualNodeServiceExtension.java @@ -185,13 +185,13 @@ public class VirtualNodeServiceExtension extends VirtualSpringBeanExtension getAspects(NodeRef nodeRef) { NodeServiceTrait theTrait = getTrait(); - Reference vRef = Reference.fromNodeRef(nodeRef); - if (vRef != null) + Reference reference = Reference.fromNodeRef(nodeRef); + if (reference != null) { GetAspectsMethod method = new GetAspectsMethod(theTrait, environment); - return vRef.execute(method); + return reference.execute(method); } else { diff --git a/source/java/org/alfresco/repo/virtual/bundle/VirtualVersionServiceExtension.java b/source/java/org/alfresco/repo/virtual/bundle/VirtualVersionServiceExtension.java index 43668c443a..1a42ab284c 100644 --- a/source/java/org/alfresco/repo/virtual/bundle/VirtualVersionServiceExtension.java +++ b/source/java/org/alfresco/repo/virtual/bundle/VirtualVersionServiceExtension.java @@ -364,7 +364,7 @@ public class VirtualVersionServiceExtension extends SpringBeanExtension materializedNodeRefs = new HashMap<>(); for (NodeRef nodeRef : nodeRefs) { - Reference reference = Reference.fromNodeRef(nodeRef); + Reference reference = Reference.fromNodeRef(nodeRef); if (reference == null) { materialNodeRefs.add(nodeRef); diff --git a/source/java/org/alfresco/repo/virtual/ref/Reference.java b/source/java/org/alfresco/repo/virtual/ref/Reference.java index ae40964e1e..06488d809d 100644 --- a/source/java/org/alfresco/repo/virtual/ref/Reference.java +++ b/source/java/org/alfresco/repo/virtual/ref/Reference.java @@ -63,7 +63,8 @@ public class Reference * NodeRef Reference representations validated by this method should produce * valid Reference objects based on the given {@link NodeRef} when passed to * the {@link #fromNodeRef(NodeRef)} method. - * @deprecated + * + * @deprecated * @param nodeRef * @return true if the given {@link NodeRef} is a valid * Reference representation
@@ -80,89 +81,73 @@ public class Reference Encoding encoding = Encodings.fromToken(token); if (encoding != null) { - // - // TODO experimental step 2 (sub-optimal) - remove & refactor so that we don't parse twice (for smart folder virtual ids) - // - try - { - Reference ref = fromNodeRef(nodeRef); - if (ref != null) - { - return true; - } - } - catch (ReferenceParseException rpe) - { - // ignore - if (logger.isTraceEnabled()) - { - logger.trace("Ignore parse exception: "+rpe.getMessage()); - } - } - catch (ReferenceEncodingException ree) - { - // ignore - if (logger.isTraceEnabled()) - { - logger.trace("Ignore encoding exception: "+ree.getMessage()); - } - } + return true; } } - - if (logger.isTraceEnabled()) + else { - logger.trace("NodeRef is not a reference: "+nodeRef); + if (logger.isDebugEnabled()) + { + logger.debug("NodeRef is not a reference."); + } } } return false; } /** - * - * {@link NodeRef} {@link Reference} representation decoder/converter - * method.
- * Creates a {@link Reference} representation based on the ID of the given - * {@link NodeRef}.
- * It expects a {@link #VIRTUAL_TOKEN} prefixed encoded string. The encoded - * string must start with a valid {@link Encoding} token. The Reference - * representation structure is (no delimiters between the 3 elements): - * VIRTUAL_TOKEN ENCODING_TOKEN referenceString Given that a valid encoding - * was detected {@link Encoding#urlNative} information is used to obtain a - * reference string. The reference string is parsed using the encoding - * configured parser. - * @param nodeRef - * @return the {@link Reference} object corresponding to the given - * {@link NodeRef} - * - */ - public static final Reference fromNodeRef(NodeRef nodeRef) { - String id = nodeRef.getId(); - if (id.startsWith("" + VIRTUAL_TOKEN) && (id.length() > 1)) // belts-and-braces - { - char token = id.charAt(1); - Encoding encoding = Encodings.fromToken(token); - if (encoding != null) { - try { - String referenceString = id.substring(2); - if (!encoding.urlNative) { - referenceString = new String( - org.apache.commons.codec.binary.Base64.decodeBase64(referenceString)); - } - Reference reference = encoding.parser.parse(referenceString); - return reference.propagateNodeRefMutations(nodeRef); - } catch (ReferenceParseException rpe) { - logger.debug("Parse exception:", rpe); - return null; - }catch (ReferenceEncodingException ree) { - logger.debug("encoding exception:", ree) ; - return null; - } - - } - } - return null; - } + * + * {@link NodeRef} {@link Reference} representation decoder/converter + * method.
+ * Creates a {@link Reference} representation based on the ID of the given + * {@link NodeRef}.
+ * It expects a {@link #VIRTUAL_TOKEN} prefixed encoded string. The encoded + * string must start with a valid {@link Encoding} token. The Reference + * representation structure is (no delimiters between the 3 elements): + * VIRTUAL_TOKEN ENCODING_TOKEN referenceString Given that a valid encoding + * was detected {@link Encoding#urlNative} information is used to obtain a + * reference string. The reference string is parsed using the encoding + * configured parser. + * + * @param nodeRef + * @return the {@link Reference} object corresponding to the given + * {@link NodeRef} + * + */ + public static final Reference fromNodeRef(NodeRef nodeRef) + { + String id = nodeRef.getId(); + if (id.startsWith("" + VIRTUAL_TOKEN) && (id.length() > 1)) // belts-and-braces + { + char token = id.charAt(1); + Encoding encoding = Encodings.fromToken(token); + if (encoding != null) + { + try + { + String referenceString = id.substring(2); + if (!encoding.urlNative) + { + referenceString = new String(org.apache.commons.codec.binary.Base64.decodeBase64(referenceString)); + } + Reference reference = encoding.parser.parse(referenceString); + return reference.propagateNodeRefMutations(nodeRef); + } + catch (ReferenceParseException rpe) + { + logger.debug("Parse exception:", rpe); + return null; + } + catch (ReferenceEncodingException ree) + { + logger.debug("Encoding exception:", ree); + return null; + } + + } + } + return null; + } // Average reference length log trace