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

@@ -364,7 +364,7 @@ public class VirtualVersionServiceExtension extends SpringBeanExtension<VersionS
Map<NodeRef, Reference> materializedNodeRefs = new HashMap<>(); Map<NodeRef, Reference> materializedNodeRefs = new HashMap<>();
for (NodeRef nodeRef : nodeRefs) for (NodeRef nodeRef : nodeRefs)
{ {
Reference reference = Reference.fromNodeRef(nodeRef); Reference reference = Reference.fromNodeRef(nodeRef);
if (reference == null) if (reference == null)
{ {
materialNodeRefs.add(nodeRef); materialNodeRefs.add(nodeRef);

View File

@@ -63,7 +63,8 @@ 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
* Reference representation<br> * Reference representation<br>
@@ -80,89 +81,73 @@ public class Reference
Encoding encoding = Encodings.fromToken(token); Encoding encoding = Encodings.fromToken(token);
if (encoding != null) if (encoding != null)
{ {
// return true;
// 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());
}
}
} }
} }
else
if (logger.isTraceEnabled())
{ {
logger.trace("NodeRef is not a reference: "+nodeRef); if (logger.isDebugEnabled())
{
logger.debug("NodeRef is not a reference.");
}
} }
} }
return false; return false;
} }
/** /**
* *
* {@link NodeRef} {@link Reference} representation decoder/converter * {@link NodeRef} {@link Reference} representation decoder/converter
* method.<br> * method.<br>
* Creates a {@link Reference} representation based on the ID of the given * Creates a {@link Reference} representation based on the ID of the given
* {@link NodeRef}.<br> * {@link NodeRef}.<br>
* It expects a {@link #VIRTUAL_TOKEN} prefixed encoded string. The encoded * It expects a {@link #VIRTUAL_TOKEN} prefixed encoded string. The encoded
* string must start with a valid {@link Encoding} token. The Reference * string must start with a valid {@link Encoding} token. The Reference
* representation structure is (no delimiters between the 3 elements): * representation structure is (no delimiters between the 3 elements):
* VIRTUAL_TOKEN ENCODING_TOKEN referenceString Given that a valid encoding * VIRTUAL_TOKEN ENCODING_TOKEN referenceString Given that a valid encoding
* 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 *
* @return the {@link Reference} object corresponding to the given * @param nodeRef
* {@link NodeRef} * @return the {@link Reference} object corresponding to the given
* * {@link NodeRef}
*/ *
public static final Reference fromNodeRef(NodeRef nodeRef) { */
String id = nodeRef.getId(); public static final Reference fromNodeRef(NodeRef nodeRef)
if (id.startsWith("" + VIRTUAL_TOKEN) && (id.length() > 1)) // belts-and-braces {
{ String id = nodeRef.getId();
char token = id.charAt(1); if (id.startsWith("" + VIRTUAL_TOKEN) && (id.length() > 1)) // belts-and-braces
Encoding encoding = Encodings.fromToken(token); {
if (encoding != null) { char token = id.charAt(1);
try { Encoding encoding = Encodings.fromToken(token);
String referenceString = id.substring(2); if (encoding != null)
if (!encoding.urlNative) { {
referenceString = new String( try
org.apache.commons.codec.binary.Base64.decodeBase64(referenceString)); {
} String referenceString = id.substring(2);
Reference reference = encoding.parser.parse(referenceString); if (!encoding.urlNative)
return reference.propagateNodeRefMutations(nodeRef); {
} catch (ReferenceParseException rpe) { referenceString = new String(org.apache.commons.codec.binary.Base64.decodeBase64(referenceString));
logger.debug("Parse exception:", rpe); }
return null; Reference reference = encoding.parser.parse(referenceString);
}catch (ReferenceEncodingException ree) { return reference.propagateNodeRefMutations(nodeRef);
logger.debug("encoding exception:", ree) ; }
return null; catch (ReferenceParseException rpe)
} {
logger.debug("Parse exception:", rpe);
} return null;
} }
return null; catch (ReferenceEncodingException ree)
} {
logger.debug("Encoding exception:", ree);
return null;
}
}
}
return null;
}
// Average reference length log trace // Average reference length log trace