Search in sources :

Example 11 with GetActualNodeRefMethod

use of org.alfresco.repo.virtual.ref.GetActualNodeRefMethod in project alfresco-repository by Alfresco.

the class VirtualVersionServiceExtensionTest method testCreateVersion.

@Test
public void testCreateVersion() throws Exception {
    ChildAssociationRef contentWithVersionsAssocRef = createContent(node2_1, "ContentWithVersions");
    NodeRef contentWithVersionsNodeRef = contentWithVersionsAssocRef.getChildRef();
    Reference reference = Reference.fromNodeRef(contentWithVersionsNodeRef);
    assertNotNull(reference);
    NodeRef actualContentWithVersionsNodeRef = reference.execute(new GetActualNodeRefMethod(environment));
    VersionHistory versionHistory = versionService.getVersionHistory(contentWithVersionsNodeRef);
    assertNull(versionHistory);
    VersionHistory actualVersionHistory = versionService.getVersionHistory(actualContentWithVersionsNodeRef);
    assertNull(actualVersionHistory);
    Version newVersion = versionService.createVersion(contentWithVersionsNodeRef, null);
    NodeRef newVersionNodeRef = newVersion.getVersionedNodeRef();
    assertNotNull(Reference.fromNodeRef(newVersionNodeRef));
    versionHistory = versionService.getVersionHistory(newVersionNodeRef);
    assertNotNull(versionHistory);
    Collection<Version> allVersions = versionHistory.getAllVersions();
    assertEquals(1, allVersions.size());
    actualVersionHistory = versionService.getVersionHistory(actualContentWithVersionsNodeRef);
    assertNotNull(actualVersionHistory);
    Collection<Version> allActualVersions = versionHistory.getAllVersions();
    assertEquals(1, allActualVersions.size());
    Version actualVersion = actualVersionHistory.getHeadVersion();
    NodeRef newActualVersionNodeRef = actualVersion.getVersionedNodeRef();
    assertNull(Reference.fromNodeRef(newActualVersionNodeRef));
    assertEquals(newActualVersionNodeRef, actualContentWithVersionsNodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) Reference(org.alfresco.repo.virtual.ref.Reference) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) Test(org.junit.Test) VirtualizationIntegrationTest(org.alfresco.repo.virtual.VirtualizationIntegrationTest)

Example 12 with GetActualNodeRefMethod

use of org.alfresco.repo.virtual.ref.GetActualNodeRefMethod in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtensionTest method testCreate_NodeProtocolParent.

@Test
public void testCreate_NodeProtocolParent() throws Exception {
    NodeRef assocNode2 = nodeService.getChildByName(virtualFolder1NodeRef, ContentModel.ASSOC_CONTAINS, "Node2");
    NodeRef assocNode2_1 = nodeService.getChildByName(assocNode2, ContentModel.ASSOC_CONTAINS, "Node2_1");
    ChildAssociationRef childAssocRef = createContent(assocNode2_1, "Content");
    NodeRef node = childAssocRef.getChildRef();
    Reference reference = Reference.fromNodeRef(node);
    assertNotNull(reference);
    assertTrue(reference.getProtocol().equals(Protocols.NODE.protocol));
    QName nodeTypeQName = ContentModel.TYPE_THUMBNAIL;
    QName assocQName = QName.createQName("cm", "contentThumbnail", environment.getNamespacePrefixResolver());
    QName assocTypeQName = RenditionModel.ASSOC_RENDITION;
    ChildAssociationRef assoc = nodeService.createNode(node, assocTypeQName, assocQName, nodeTypeQName);
    NodeRef virtualRenditionNode = assoc.getChildRef();
    NodeRef virtualRenditionParent = assoc.getParentRef();
    assertEquals(node, virtualRenditionParent);
    Reference child = Reference.fromNodeRef(virtualRenditionNode);
    Reference parent = Reference.fromNodeRef(virtualRenditionParent);
    NodeRef physicalRenditionNode = child.execute(new GetActualNodeRefMethod(environment));
    NodeRef physicalRenditionParent = parent.execute(new GetActualNodeRefMethod(environment));
    List<ChildAssociationRef> refs = nodeService.getChildAssocs(physicalRenditionParent);
    // the association exists for the physical nodes
    assertEquals(physicalRenditionNode, refs.get(0).getChildRef());
    List<ChildAssociationRef> virtualRefs = nodeService.getChildAssocs(virtualRenditionParent);
    // the association exists for the virtual nodes
    assertEquals(physicalRenditionNode, virtualRefs.get(0).getChildRef());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Test(org.junit.Test) VirtualizationIntegrationTest(org.alfresco.repo.virtual.VirtualizationIntegrationTest)

Aggregations

GetActualNodeRefMethod (org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)12 NodeRef (org.alfresco.service.cmr.repository.NodeRef)12 Reference (org.alfresco.repo.virtual.ref.Reference)8 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)5 Serializable (java.io.Serializable)4 QName (org.alfresco.service.namespace.QName)4 VirtualizationIntegrationTest (org.alfresco.repo.virtual.VirtualizationIntegrationTest)3 Test (org.junit.Test)3 GetParentReferenceMethod (org.alfresco.repo.virtual.ref.GetParentReferenceMethod)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 NodeServiceTrait (org.alfresco.repo.node.db.traitextender.NodeServiceTrait)1 NodePermissionEntry (org.alfresco.repo.security.permissions.NodePermissionEntry)1 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)1 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)1