diff --git a/source/java/org/alfresco/repo/virtual/ref/Reference.java b/source/java/org/alfresco/repo/virtual/ref/Reference.java index 1043787f95..a87a988cec 100644 --- a/source/java/org/alfresco/repo/virtual/ref/Reference.java +++ b/source/java/org/alfresco/repo/virtual/ref/Reference.java @@ -74,23 +74,20 @@ public class Reference if (nodeRef != null) { String id = nodeRef.getId(); - if ((id != null) && (id.length() > 1) && (id.startsWith("" + VIRTUAL_TOKEN))) + if ((id != null) && (id.length() > 1)) { - char token = id.charAt(1); - Encoding encoding = Encodings.fromToken(token); - if (encoding != null) - { - return true; - } + char zeroChar = id.charAt(0); + return VIRTUAL_TOKEN.equals(zeroChar); } else { if (logger.isDebugEnabled()) { - logger.debug("NodeRef is not a reference."); + logger.debug("NodeRef with null ID."); } } } + return false; } @@ -110,16 +107,18 @@ 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); @@ -151,7 +150,7 @@ public class Reference private static long _trace_refCount = 0; - private static final long _trace_refBatchSize = 4096 * 2; + private static final long _trace_refBatchSize = 4096*2; private static synchronized void _trace_avg_ref_length(long refLength) { @@ -176,14 +175,12 @@ 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 parameters) { @@ -195,7 +192,10 @@ public class Reference public Reference(Encoding encoding, Protocol protocol, Resource resource) { - this(encoding, protocol, resource, Collections. emptyList()); + this(encoding, + protocol, + resource, + Collections. emptyList()); } /** @@ -261,7 +261,8 @@ public class Reference */ public NodeRef toNodeRef(StoreRef storeRef) throws ReferenceEncodingException { - return toNodeRef(storeRef, this.encoding); + return toNodeRef(storeRef, + this.encoding); } /** @@ -277,14 +278,16 @@ 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()) { @@ -307,7 +310,8 @@ public class Reference */ public R execute(ProtocolMethod method) throws ProtocolMethodException { - return this.protocol.dispatch(method, this); + return this.protocol.dispatch(method, + this); } /** @@ -319,12 +323,13 @@ public class Reference * * @param mutatedNodeRef * @return a mutated version of this {@link Reference} corresponding to the - * given mutated node or this Reference if no mutations - * are detected + * given mutated node or + * this Reference if no mutations are detected */ public Reference propagateNodeRefMutations(NodeRef mutatedNodeRef) { - return protocol.propagateNodeRefMutations(mutatedNodeRef, this); + return protocol.propagateNodeRefMutations(mutatedNodeRef, + this); } @Override @@ -336,7 +341,8 @@ public class Reference } catch (ReferenceEncodingException e) { - logger.error("Invalid reference", e); + logger.error("Invalid reference", + e); return super.toString(); } } diff --git a/source/test-java/org/alfresco/repo/virtual/VirtualizationIntegrationTest.java b/source/test-java/org/alfresco/repo/virtual/VirtualizationIntegrationTest.java index b2adc13671..8beffc454d 100644 --- a/source/test-java/org/alfresco/repo/virtual/VirtualizationIntegrationTest.java +++ b/source/test-java/org/alfresco/repo/virtual/VirtualizationIntegrationTest.java @@ -83,9 +83,7 @@ public abstract class VirtualizationIntegrationTest extends TestCase implements protected static final String VIRTUAL_FOLDER_1_NAME = "VirtualFolder1"; - protected static final String VIRTUAL_FOLDER_2_NAME = "VirtualFolder2"; - - protected static final String VIRTUAL_FOLDER_3_NAME = "VirtualFolder3"; + protected static final String VIRTUAL_FOLDER_2_NAME = "VirtualFolder2"; protected static final String TEST_ROOT_FOLDER_NAME = "TestFolder"; diff --git a/source/test-java/org/alfresco/repo/virtual/store/VirtualStoreImplTest.java b/source/test-java/org/alfresco/repo/virtual/store/VirtualStoreImplTest.java index 183be59626..089daa2edf 100644 --- a/source/test-java/org/alfresco/repo/virtual/store/VirtualStoreImplTest.java +++ b/source/test-java/org/alfresco/repo/virtual/store/VirtualStoreImplTest.java @@ -236,27 +236,4 @@ public class VirtualStoreImplTest extends VirtualizationIntegrationTest false); } - - @Test - public void testCanExistsFolderNameV() - { - String vFile = "vfile.txt"; - - ChildAssociationRef vChildRef = createContent(companyHomeNodeRef, vFile); - assertFalse(Reference.isReference(vChildRef.getChildRef())); - assertTrue(nodeService.exists(vChildRef.getChildRef())); - - String nFile = "nfile.txt"; - ChildAssociationRef nfileRef = createFolder(companyHomeNodeRef, nFile); - assertFalse(Reference.isReference(nfileRef.getChildRef())); - assertTrue(nodeService.exists(nfileRef.getChildRef())); - - 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)); - - } }