Search in sources :

Example 46 with Reference

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

the class TemplateFilingRuleTest method testFilingPath_specialCharacters.

@Test
public void testFilingPath_specialCharacters() throws Exception {
    NodeRef vfNodeRef = createVirtualizedFolder(testRootFolder.getNodeRef(), "Template 6 With Spaces", TEST_TEMPLATE_5_JSON_SYS_PATH);
    NodeRef sfpNodeRef = nodeService.getChildByName(vfNodeRef, ContentModel.ASSOC_CONTAINS, "SpecialFilingPath4");
    Reference sfpReference = Reference.fromNodeRef(sfpNodeRef);
    ApplyTemplateMethod applyTemplateMethod = new ApplyTemplateMethod(environment);
    VirtualFolderDefinition structure = sfpReference.execute(applyTemplateMethod);
    FilingRule filingRule = structure.getFilingRule();
    assertTrue(filingRule instanceof TemplateFilingRule);
    NodeRef fn = filingRule.filingNodeRefFor(new FilingParameters(sfpReference));
    assertNotNull(fn);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Reference(org.alfresco.repo.virtual.ref.Reference) VirtualizationIntegrationTest(org.alfresco.repo.virtual.VirtualizationIntegrationTest) Test(org.junit.Test)

Example 47 with Reference

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

the class VirtualNodeServiceExtension method getPrimaryParent.

@Override
public ChildAssociationRef getPrimaryParent(NodeRef nodeRef) {
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference != null) {
        Reference parent = reference.execute(new GetParentReferenceMethod());
        if (parent == null) {
            return getTrait().getPrimaryParent(reference.execute(new GetActualNodeRefMethod(environment)));
        } else {
            Reference parentsParent = parent.execute(new GetParentReferenceMethod());
            NodeRef parentNodeRef = parent.toNodeRef();
            if (parentsParent == null) {
                parentNodeRef = parent.execute(new GetActualNodeRefMethod(environment));
            }
            NodeRef referenceNodeRef = reference.toNodeRef();
            Map<QName, Serializable> refProperties = smartStore.getProperties(reference);
            Serializable childName = refProperties.get(ContentModel.PROP_NAME);
            QName childAssocQName = QName.createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, childName.toString());
            ChildAssociationRef assoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentNodeRef, childAssocQName, referenceNodeRef, true, -1);
            return assoc;
        }
    } else {
        return getTrait().getPrimaryParent(nodeRef);
    }
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) 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)

Example 48 with Reference

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

the class VirtualNodeServiceExtension method getChildAssocsWithoutParentAssocsOfType.

@Override
public Collection<ChildAssociationRef> getChildAssocsWithoutParentAssocsOfType(NodeRef nodeRef, QName assocTypeQName) {
    NodeServiceTrait theTrait = getTrait();
    boolean canVirtualize = canVirtualizeAssocNodeRef(nodeRef);
    if (canVirtualize) {
        Reference reference = smartStore.virtualize(nodeRef);
        Collection<ChildAssociationRef> virtualAssociations = smartStore.getChildAssocsWithoutParentAssocsOfType(reference, assocTypeQName);
        List<ChildAssociationRef> associations = new LinkedList<>(virtualAssociations);
        if (smartStore.canMaterialize(reference)) {
            NodeRef materialReference = smartStore.materialize(reference);
            Collection<ChildAssociationRef> actualAssociations = theTrait.getChildAssocsWithoutParentAssocsOfType(materialReference, assocTypeQName);
            associations.addAll(actualAssociations);
        }
        return associations;
    } else {
        return theTrait.getChildAssocsWithoutParentAssocsOfType(nodeRef, assocTypeQName);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) LinkedList(java.util.LinkedList)

Example 49 with Reference

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

the class VirtualNodeServiceExtension method getChildByName.

@Override
public NodeRef getChildByName(NodeRef nodeRef, QName assocTypeQName, String childName) {
    if (smartStore.canVirtualize(nodeRef)) {
        Reference virtualNode = smartStore.virtualize(nodeRef);
        Reference theChild = smartStore.getChildByName(virtualNode, assocTypeQName, childName);
        if (theChild != null) {
            NodeRef childNodeRef = theChild.toNodeRef();
            return childNodeRef;
        }
        if (smartStore.isVirtual(nodeRef)) {
            return null;
        }
    }
    // TODO: add virtualizable enabler
    nodeRef = materializeIfPossible(nodeRef);
    return getTrait().getChildByName(nodeRef, assocTypeQName, childName);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Reference(org.alfresco.repo.virtual.ref.Reference)

Example 50 with Reference

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

the class VirtualCheckOutCheckInServiceExtension method virtualizeOriginalIfNeeded.

private NodeRef virtualizeOriginalIfNeeded(NodeRef workingCopyNodeRef, NodeRef materialOriginalNode) {
    Reference workingCopyReference = Reference.fromNodeRef(workingCopyNodeRef);
    if ((materialOriginalNode != null) && (workingCopyReference != null)) {
        Reference parentReference = workingCopyReference.execute(new GetParentReferenceMethod());
        Reference originalReference = NodeProtocol.newReference(materialOriginalNode, parentReference);
        return originalReference.toNodeRef(materialOriginalNode.getStoreRef());
    } else {
        return materialOriginalNode;
    }
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) Reference(org.alfresco.repo.virtual.ref.Reference)

Aggregations

Reference (org.alfresco.repo.virtual.ref.Reference)81 NodeRef (org.alfresco.service.cmr.repository.NodeRef)59 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)23 VersionServiceTrait (org.alfresco.repo.version.traitextender.VersionServiceTrait)16 LinkedList (java.util.LinkedList)15 VirtualizationIntegrationTest (org.alfresco.repo.virtual.VirtualizationIntegrationTest)15 Test (org.junit.Test)15 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)13 NodeServiceTrait (org.alfresco.repo.node.db.traitextender.NodeServiceTrait)12 QName (org.alfresco.service.namespace.QName)10 Serializable (java.io.Serializable)9 GetParentReferenceMethod (org.alfresco.repo.virtual.ref.GetParentReferenceMethod)9 Version (org.alfresco.service.cmr.version.Version)9 GetActualNodeRefMethod (org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)8 VirtualFolderDefinition (org.alfresco.repo.virtual.template.VirtualFolderDefinition)6 FileInfo (org.alfresco.service.cmr.model.FileInfo)6 PermissionServiceTrait (org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait)5 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4