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
This commit is contained in:
Ancuta Morarasu
2017-06-23 11:37:36 +00:00
parent f6f20a31f9
commit 345de9c40d
3 changed files with 64 additions and 79 deletions

View File

@@ -185,13 +185,13 @@ public class VirtualNodeServiceExtension extends VirtualSpringBeanExtension<Node
public Set<QName> getAspects(NodeRef nodeRef) public Set<QName> getAspects(NodeRef nodeRef)
{ {
NodeServiceTrait theTrait = getTrait(); NodeServiceTrait theTrait = getTrait();
Reference vRef = Reference.fromNodeRef(nodeRef); Reference reference = Reference.fromNodeRef(nodeRef);
if (vRef != null) if (reference != null)
{ {
GetAspectsMethod method = new GetAspectsMethod(theTrait, GetAspectsMethod method = new GetAspectsMethod(theTrait,
environment); environment);
return vRef.execute(method); return reference.execute(method);
} }
else else
{ {

View File

@@ -63,6 +63,7 @@ public class Reference
* NodeRef Reference representations validated by this method should produce * NodeRef Reference representations validated by this method should produce
* valid Reference objects based on the given {@link NodeRef} when passed to * valid Reference objects based on the given {@link NodeRef} when passed to
* the {@link #fromNodeRef(NodeRef)} method. * the {@link #fromNodeRef(NodeRef)} method.
*
* @deprecated * @deprecated
* @param nodeRef * @param nodeRef
* @return <code>true</code> if the given {@link NodeRef} is a valid * @return <code>true</code> if the given {@link NodeRef} is a valid
@@ -79,41 +80,17 @@ public class Reference
char token = id.charAt(1); char token = id.charAt(1);
Encoding encoding = Encodings.fromToken(token); Encoding encoding = Encodings.fromToken(token);
if (encoding != null) 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; return true;
} }
} }
catch (ReferenceParseException rpe) else
{ {
// ignore if (logger.isDebugEnabled())
if (logger.isTraceEnabled())
{ {
logger.trace("Ignore parse exception: "+rpe.getMessage()); logger.debug("NodeRef is not a reference.");
} }
} }
catch (ReferenceEncodingException ree)
{
// ignore
if (logger.isTraceEnabled())
{
logger.trace("Ignore encoding exception: "+ree.getMessage());
}
}
}
}
if (logger.isTraceEnabled())
{
logger.trace("NodeRef is not a reference: "+nodeRef);
}
} }
return false; return false;
} }
@@ -131,31 +108,39 @@ public class Reference
* was detected {@link Encoding#urlNative} information is used to obtain a * was detected {@link Encoding#urlNative} information is used to obtain a
* reference string. The reference string is parsed using the encoding * reference string. The reference string is parsed using the encoding
* configured parser. * configured parser.
*
* @param nodeRef * @param nodeRef
* @return the {@link Reference} object corresponding to the given * @return the {@link Reference} object corresponding to the given
* {@link NodeRef} * {@link NodeRef}
* *
*/ */
public static final Reference fromNodeRef(NodeRef nodeRef) { public static final Reference fromNodeRef(NodeRef nodeRef)
{
String id = nodeRef.getId(); String id = nodeRef.getId();
if (id.startsWith("" + VIRTUAL_TOKEN) && (id.length() > 1)) // belts-and-braces if (id.startsWith("" + VIRTUAL_TOKEN) && (id.length() > 1)) // belts-and-braces
{ {
char token = id.charAt(1); char token = id.charAt(1);
Encoding encoding = Encodings.fromToken(token); Encoding encoding = Encodings.fromToken(token);
if (encoding != null) { if (encoding != null)
try { {
try
{
String referenceString = id.substring(2); String referenceString = id.substring(2);
if (!encoding.urlNative) { if (!encoding.urlNative)
referenceString = new String( {
org.apache.commons.codec.binary.Base64.decodeBase64(referenceString)); referenceString = new String(org.apache.commons.codec.binary.Base64.decodeBase64(referenceString));
} }
Reference reference = encoding.parser.parse(referenceString); Reference reference = encoding.parser.parse(referenceString);
return reference.propagateNodeRefMutations(nodeRef); return reference.propagateNodeRefMutations(nodeRef);
} catch (ReferenceParseException rpe) { }
catch (ReferenceParseException rpe)
{
logger.debug("Parse exception:", rpe); logger.debug("Parse exception:", rpe);
return null; return null;
}catch (ReferenceEncodingException ree) { }
logger.debug("encoding exception:", ree) ; catch (ReferenceEncodingException ree)
{
logger.debug("Encoding exception:", ree);
return null; return null;
} }