Merged MNT-17845-5.2.N (5.2.2) to 5.2.N (5.2.2)

137723 jvonka: REPO-2516 - MNT-17845 : Smart Folders - node id (sys:node-uuid) that starts with 'v'
   - follow-on to previous commits to update test for step 1
   - this should fix node ids that begin with 'v' (but not with valid encodings, eg. 'v0', 'vH', 'vP', .. see step 2/3)
   - tweak isReference (set as "trace" debug logging)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@137780 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2017-06-23 11:31:49 +00:00
parent 05af878987
commit 069d6bcc57
2 changed files with 66 additions and 41 deletions

View File

@@ -74,20 +74,21 @@ public class Reference
if (nodeRef != null)
{
String id = nodeRef.getId();
if ((id != null) && (id.length() > 1))
if ((id != null) && (id.length() > 1) && (id.startsWith("" + VIRTUAL_TOKEN)))
{
char zeroChar = id.charAt(0);
return VIRTUAL_TOKEN.equals(zeroChar);
}
else
char token = id.charAt(1);
Encoding encoding = Encodings.fromToken(token);
if (encoding != null)
{
if (logger.isDebugEnabled())
{
logger.debug("NodeRef with null ID.");
}
return true;
}
}
if (logger.isTraceEnabled())
{
logger.trace("NodeRef is not a reference: "+nodeRef);
}
}
return false;
}
@@ -107,18 +108,16 @@ public class Reference
* @param nodeRef
* @return the {@link Reference} object corresponding to the given
* {@link NodeRef}
* @throws ReferenceParseException if an error occurs during the reference
* string parsing
* @throws ReferenceEncodingException if the {@link NodeRef} ID has an
* invalid virtual token prefix or it uses an invalid encoding
* token
* @throws ReferenceParseException
* if an error occurs during the reference string parsing
* @throws ReferenceEncodingException
* if the {@link NodeRef} ID has an invalid virtual token prefix
* or it uses an invalid encoding token
*/
public static final Reference fromNodeRef(NodeRef nodeRef) throws ReferenceParseException,
ReferenceEncodingException
public static final Reference fromNodeRef(NodeRef nodeRef) throws ReferenceParseException, ReferenceEncodingException
{
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);
Encoding encoding = Encodings.fromToken(token);
@@ -175,12 +174,14 @@ public class Reference
/**
* Constructor
*
* @param encoding the default {@link Encoding} of the new resource - to be
* used where an encoding is required and none is specified
* @param encoding
* the default {@link Encoding} of the new resource - to be used
* where an encoding is required and none is specified
* @param protocol
* @param resource
* @param parameters resource parameters - a copy of the provided list will
* be stored by this reference
* @param parameters
* resource parameters - a copy of the provided list will be
* stored by this reference
*/
public Reference(Encoding encoding, Protocol protocol, Resource resource, List<? extends Parameter> parameters)
{
@@ -192,10 +193,7 @@ public class Reference
public Reference(Encoding encoding, Protocol protocol, Resource resource)
{
this(encoding,
protocol,
resource,
Collections.<Parameter> emptyList());
this(encoding, protocol, resource, Collections.<Parameter> emptyList());
}
/**
@@ -261,8 +259,7 @@ public class Reference
*/
public NodeRef toNodeRef(StoreRef storeRef) throws ReferenceEncodingException
{
return toNodeRef(storeRef,
this.encoding);
return toNodeRef(storeRef, this.encoding);
}
/**
@@ -278,16 +275,14 @@ public class Reference
// TODO: move non-native encoding to encoding object itself
if (!encoding.urlNative)
{
id = new String(org.apache.commons.codec.binary.Base64.encodeBase64(id.getBytes(),
false));
id = new String(org.apache.commons.codec.binary.Base64.encodeBase64(id.getBytes(), false));
}
StringBuilder idBuilder = new StringBuilder();
idBuilder.append(VIRTUAL_TOKEN);
idBuilder.append(encoding.token);
idBuilder.append(id);
NodeRef theNode = new NodeRef(storeRef,
idBuilder.toString());
NodeRef theNode = new NodeRef(storeRef, idBuilder.toString());
if (logger.isTraceEnabled())
{
@@ -310,8 +305,7 @@ public class Reference
*/
public <R> R execute(ProtocolMethod<R> method) throws ProtocolMethodException
{
return this.protocol.dispatch(method,
this);
return this.protocol.dispatch(method, this);
}
/**
@@ -323,13 +317,12 @@ public class Reference
*
* @param mutatedNodeRef
* @return a mutated version of this {@link Reference} corresponding to the
* given mutated node or
* <code>this</code> Reference if no mutations are detected
* given mutated node or <code>this</code> Reference if no mutations
* are detected
*/
public Reference propagateNodeRefMutations(NodeRef mutatedNodeRef)
{
return protocol.propagateNodeRefMutations(mutatedNodeRef,
this);
return protocol.propagateNodeRefMutations(mutatedNodeRef, this);
}
@Override
@@ -341,8 +334,7 @@ public class Reference
}
catch (ReferenceEncodingException e)
{
logger.error("Invalid reference",
e);
logger.error("Invalid reference", e);
return super.toString();
}
}

View File

@@ -26,7 +26,10 @@
package org.alfresco.repo.virtual.store;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
@@ -41,6 +44,8 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
@@ -236,4 +241,32 @@ public class VirtualStoreImplTest extends VirtualizationIntegrationTest
false);
}
// MNT-17845
@Test
public void testCanExistNodeIDwithV()
{
Map<QName, Serializable> properties = new HashMap<>(1);
properties.put(ContentModel.PROP_NODE_UUID, "vfile");
QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("specialFile1.txt"));
NodeRef vfileNodeRef = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, assocQName, ContentModel.TYPE_CONTENT, properties).getChildRef();
assertFalse(Reference.isReference(vfileNodeRef));
assertTrue(nodeService.exists(vfileNodeRef));
properties = new HashMap<>(1);
properties.put(ContentModel.PROP_NODE_UUID, "nfile");
assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("specialFile2.txt"));
NodeRef nfileNodeRef = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, assocQName, ContentModel.TYPE_CONTENT, properties).getChildRef();
assertFalse(Reference.isReference(nfileNodeRef));
assertTrue(nodeService.exists(nfileNodeRef));
NodeRef virtualFolder = createVirtualizedFolder(testRootFolder.getNodeRef(), VIRTUAL_FOLDER_3_NAME, TEST_TEMPLATE_4_JSON_SYS_PATH);
assertTrue(smartStore.canVirtualize(virtualFolder));
virtualFolder = smartStore.virtualize(virtualFolder).toNodeRef();
assertTrue(Reference.isReference(virtualFolder));
assertTrue(nodeService.exists(virtualFolder));
}
}