Search in sources :

Example 71 with Reference

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

the class VirtualStoreImpl method getChildByName.

@Override
public Reference getChildByName(Reference reference, QName assocTypeQName, String childName) throws VirtualizationException {
    VirtualFolderDefinition structure = resolveVirtualFolderDefinition(reference);
    VirtualFolderDefinition theChild = structure.findChildByName(childName);
    if (theChild != null) {
        return reference.execute(new GetChildByIdMethod(theChild.getId()));
    } else {
        final VirtualQuery query = structure.getQuery();
        if (query != null) {
            PropertyValueConstraint constraint = new PropertyValueConstraint(new FilesFoldersConstraint(BasicConstraint.INSTANCE, true, true), ContentModel.PROP_NAME, childName, environment.getNamespacePrefixResolver());
            PagingResults<Reference> result = query.perform(environment, constraint, null, reference);
            List<Reference> page = result.getPage();
            return page == null || page.isEmpty() ? null : page.get(0);
        } else {
            return null;
        }
    }
}
Also used : VirtualQuery(org.alfresco.repo.virtual.template.VirtualQuery) FilesFoldersConstraint(org.alfresco.repo.virtual.template.FilesFoldersConstraint) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) NamePatternPropertyValueConstraint(org.alfresco.repo.virtual.template.NamePatternPropertyValueConstraint) PropertyValueConstraint(org.alfresco.repo.virtual.template.PropertyValueConstraint) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition) GetChildByIdMethod(org.alfresco.repo.virtual.ref.GetChildByIdMethod)

Example 72 with Reference

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

the class VirtualStoreImpl method getPath.

@Override
public Path getPath(Reference reference) throws VirtualizationException {
    Reference virtualPathElement = reference;
    Reference virtualPathParent = reference.execute(new GetParentReferenceMethod());
    Path virtualPath = new Path();
    while (virtualPathElement != null && virtualPathParent != null) {
        NodeRef parentNodeRef;
        parentNodeRef = virtualPathParent.toNodeRef();
        NodeRef parent = parentNodeRef;
        NodeRef virtualPathNodeRef = virtualPathElement.toNodeRef();
        // TODO: extract node reference name into protocol method in order
        // to enforce path processing code reuse and consistency
        String templatePath = virtualPathElement.execute(new GetTemplatePathMethod()).trim();
        final String pathSeparator = "/";
        if (pathSeparator.equals(templatePath)) {
            // found root
            break;
        } else if (templatePath.endsWith(pathSeparator)) {
            templatePath = templatePath.substring(0, templatePath.length() - 1);
        }
        int lastSeparator = templatePath.lastIndexOf(pathSeparator);
        String childId = templatePath.substring(lastSeparator + 1);
        VirtualFolderDefinition structure = resolveVirtualFolderDefinition(virtualPathParent);
        VirtualFolderDefinition child = structure.findChildById(childId);
        if (child == null) {
            throw new VirtualizationException("Invalid reference: " + reference.encode());
        }
        String childName = child.getName();
        QName childQName = QName.createQName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, childName);
        ChildAssociationRef assocRef = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, parent, childQName, virtualPathNodeRef, true, -1);
        ChildAssocElement assocRefElement = new ChildAssocElement(assocRef);
        virtualPath.prepend(assocRefElement);
        virtualPathElement = virtualPathParent;
        virtualPathParent = virtualPathParent.execute(new GetParentReferenceMethod());
    }
    return virtualPath;
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) Path(org.alfresco.service.cmr.repository.Path) NodeRef(org.alfresco.service.cmr.repository.NodeRef) GetTemplatePathMethod(org.alfresco.repo.virtual.ref.GetTemplatePathMethod) ChildAssocElement(org.alfresco.service.cmr.repository.Path.ChildAssocElement) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NamePatternPropertyValueConstraint(org.alfresco.repo.virtual.template.NamePatternPropertyValueConstraint) PropertyValueConstraint(org.alfresco.repo.virtual.template.PropertyValueConstraint) FilesFoldersConstraint(org.alfresco.repo.virtual.template.FilesFoldersConstraint) VirtualQueryConstraint(org.alfresco.repo.virtual.template.VirtualQueryConstraint) BasicConstraint(org.alfresco.repo.virtual.template.BasicConstraint) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Example 73 with Reference

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

the class ApplyTemplateMethodTest method testExecute_vanillaISO9075ActualPath.

@Category(RedundantTests.class)
@Test
public void testExecute_vanillaISO9075ActualPath() throws Exception {
    ChildAssociationRef iso9075FolderAssoc = createFolder(testRootFolder.getNodeRef(), "Acutal ISO9075 Node");
    NodeRef iso9075Folder = iso9075FolderAssoc.getChildRef();
    NewVirtualReferenceMethod newVirtualReferenceMethod = new NewVirtualReferenceMethod(TEST_TEMPLATE_5_JSON_SYS_PATH, "/", iso9075Folder, VANILLA_PROCESSOR_JS_CLASSPATH);
    ApplyTemplateMethod applyTemplateMethod = new ApplyTemplateMethod(environment);
    Reference ref = Protocols.VANILLA.protocol.dispatch(newVirtualReferenceMethod, null);
    VirtualFolderDefinition structure = ref.execute(applyTemplateMethod);
    VirtualFolderDefinition sfp5 = structure.findChildByName("SpecialFilingPath5");
    VirtualQuery query = sfp5.getQuery();
    assertEquals("(PATH:'/app:company_home/cm:TestFolder/cm:Acutal_x0020_ISO9075_x0020_Node/cm:Space_x0020_Sub_x0020_Folder/*')  and =cm:description:'SpecialFilingPath_5'", query.getQueryString());
    ChildAssociationRef iso9075SubFolderAssoc = createFolder(iso9075Folder, "Space Sub Folder");
    ChildAssociationRef someContentAssoc = createContent(iso9075SubFolderAssoc.getChildRef(), "someContent");
    nodeService.setProperty(someContentAssoc.getChildRef(), ContentModel.PROP_DESCRIPTION, "SpecialFilingPath_5");
    // check query for validity
    SearchParameters searchParameters = new SearchParameters();
    searchParameters.setQuery(query.getQueryString());
    searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    searchParameters.setLanguage(query.getLanguage());
/* Code commented out as part of REPO-2028
         * If this test needs to be reactivated, please refactor this to use the prepareMocks/resetMocks methods
         */
// ResultSet qresult = searchService.query(searchParameters);
// assertEquals(1, qresult.getNumberFound());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Reference(org.alfresco.repo.virtual.ref.Reference) NewVirtualReferenceMethod(org.alfresco.repo.virtual.ref.NewVirtualReferenceMethod) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) VirtualizationIntegrationTest(org.alfresco.repo.virtual.VirtualizationIntegrationTest)

Example 74 with Reference

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

the class ApplyTemplateMethodTest method testExecute_vanillaRepositoryJSON.

@Test
public void testExecute_vanillaRepositoryJSON() throws Exception {
    ChildAssociationRef templateAssoc = createContent(testRootFolder.getNodeRef(), "template1.json", ApplyTemplateMethodTest.class.getResourceAsStream(TEST_TEMPLATE_1_JSON_NAME), MimetypeMap.MIMETYPE_JSON, StandardCharsets.UTF_8.name());
    ApplyTemplateMethod applyTemplateMethod = new ApplyTemplateMethod(environment);
    NewVirtualReferenceMethod newVirtualReferenceMethod = new NewVirtualReferenceMethod(templateAssoc.getChildRef(), "/", virtualFolder1NodeRef, VANILLA_PROCESSOR_JS_CLASSPATH);
    Reference ref = Protocols.VANILLA.protocol.dispatch(newVirtualReferenceMethod, null);
    VirtualFolderDefinition structure = ref.execute(applyTemplateMethod);
    String templateName = structure.getName();
    assertEquals("Test", templateName);
    List<VirtualFolderDefinition> children = structure.getChildren();
    assertEquals(2, children.size());
    VirtualFolderDefinition child1 = structure.findChildByName("Node1");
    assertTrue(child1 != null);
    VirtualFolderDefinition child2 = structure.findChildByName("Node2");
    assertTrue(child2 != null);
}
Also used : Reference(org.alfresco.repo.virtual.ref.Reference) NewVirtualReferenceMethod(org.alfresco.repo.virtual.ref.NewVirtualReferenceMethod) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Test(org.junit.Test) VirtualizationIntegrationTest(org.alfresco.repo.virtual.VirtualizationIntegrationTest)

Example 75 with Reference

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

the class TypeVirtualizationMethodIntegrationTest method virtualize.

private void virtualize(NodeRef expectedTemplateNodeRef, QName fodlerType, QName... aspects) throws Exception {
    ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(), "TypeVirtualized", fodlerType);
    NodeRef typeNode = typedNodeAssocRef.getChildRef();
    for (QName aspect : aspects) {
        nodeService.addAspect(typeNode, aspect, Collections.<QName, Serializable>emptyMap());
    }
    assertTrue(typeVirtualizationMethod.canVirtualize(environment, typeNode));
    Reference theVirtualizedNode = typeVirtualizationMethod.virtualize(environment, typeNode);
    assertEquals(Protocols.VANILLA.protocol, theVirtualizedNode.getProtocol());
    List<Parameter> parameters = theVirtualizedNode.getParameters();
    ResourceParameter vanillaResourceParameter = (ResourceParameter) parameters.get(VanillaProtocol.VANILLA_TEMPLATE_PARAM_INDEX);
    Resource vanillaResource = vanillaResourceParameter.getValue();
    NodeRef resourceNodeRef = vanillaResource.processWith(new ResourceProcessor<NodeRef>() {

        @Override
        public NodeRef process(Resource resource) throws ResourceProcessingError {
            fail("Inavlid resource type");
            return null;
        }

        @Override
        public NodeRef process(ClasspathResource classpath) throws ResourceProcessingError {
            fail("Inavlid resource type");
            return null;
        }

        @Override
        public NodeRef process(RepositoryResource repository) throws ResourceProcessingError {
            RepositoryLocation location = repository.getLocation();
            return location.asNodeRef(environment);
        }
    });
    assertEquals(expectedTemplateNodeRef, resourceNodeRef);
}
Also used : QName(org.alfresco.service.namespace.QName) Reference(org.alfresco.repo.virtual.ref.Reference) Resource(org.alfresco.repo.virtual.ref.Resource) ClasspathResource(org.alfresco.repo.virtual.ref.ClasspathResource) RepositoryResource(org.alfresco.repo.virtual.ref.RepositoryResource) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RepositoryLocation(org.alfresco.repo.virtual.ref.RepositoryLocation) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResourceProcessingError(org.alfresco.repo.virtual.ref.ResourceProcessingError) ClasspathResource(org.alfresco.repo.virtual.ref.ClasspathResource) ResourceParameter(org.alfresco.repo.virtual.ref.ResourceParameter) RepositoryResource(org.alfresco.repo.virtual.ref.RepositoryResource) ResourceParameter(org.alfresco.repo.virtual.ref.ResourceParameter) Parameter(org.alfresco.repo.virtual.ref.Parameter)

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