Package org.jahia.ajax.gwt.helper

Examples of org.jahia.ajax.gwt.helper.NavigationHelper


                assertNotNull(providerRoot + " : Reference node is null", refProperty.getNode());
                assertEquals(providerRoot + " : Reference identifier is invalid !", testFile1.getIdentifier(), refProperty.getNode().getIdentifier());
            }
            assertEquals(providerRoot + " : Invalid number of file references !", 1, resultCount);

            NavigationHelper navigationHelper = (NavigationHelper) SpringContextSingleton.getInstance().getContext().getBean("NavigationHelper");
            List<String> paths = new ArrayList<String>();
            paths.add(testFile1.getPath());
            List<GWTJahiaNodeUsage> usages = navigationHelper.getUsages(paths, session);
            assertEquals(providerRoot + " : Invalid number of file usages !", 1, usages.size());
            GWTJahiaNodeUsage firstUsage = usages.iterator().next();
            assertEquals(providerRoot + " : Expected path for node pointing to file is invalid !", refNode.getPath(), firstUsage.getPath());

            // now let's test property removal, to check if it works.
            refProperty = refNode.getProperty(SIMPLE_REFERENCE_PROPERTY_NAME);
            refProperty.remove();
            session.save();

            assertFalse(providerRoot + " : Property should no longer be present since it was removed !", refNode.hasProperty(SIMPLE_REFERENCE_PROPERTY_NAME));

            refNode.setProperty(SIMPLE_REFERENCE_PROPERTY_NAME, testFile1);
            ValueFactory valueFactory = session.getValueFactory();
            Value[] multipleRefValues = new Value[]{valueFactory.createValue(testFile1), valueFactory.createValue(testFile2)};
            refNode.setProperty(MULTIPLE_I18N_REFERENCE_PROPERTY_NAME, multipleRefValues);
            session.save();

            Value[] resultingMultipleRefValues = refNode.getProperty(MULTIPLE_I18N_REFERENCE_PROPERTY_NAME).getValues();
            assertEquals(providerRoot + " : Read count of multiple reference values is not equal to set values", multipleRefValues.length, resultingMultipleRefValues.length);
            for (int i = 0; i < resultingMultipleRefValues.length; i++) {
                Value resultingMultipleRefValue = resultingMultipleRefValues[i];
                Value multipleRefValue = multipleRefValues[i];
                assertTrue(providerRoot + " : Read multiple reference values not equal to set values",
                        multipleRefValue.getString().equals(resultingMultipleRefValue.getString()));
            }

            // now we remove one of the two references.
            Value[] singleRefValues = new Value[]{valueFactory.createValue(testFile2)};
            refNode.setProperty(MULTIPLE_I18N_REFERENCE_PROPERTY_NAME, singleRefValues);
            session.save();

            Value[] resultingSingleRefValues = refNode.getProperty(MULTIPLE_I18N_REFERENCE_PROPERTY_NAME).getValues();
            assertEquals(providerRoot + " : Read count of single reference values is not equal to set values", singleRefValues.length, resultingSingleRefValues.length);
            for (int i = 0; i < resultingSingleRefValues.length; i++) {
                Value resultingSingleRefValue = resultingSingleRefValues[i];
                Value singleRefValue = singleRefValues[i];
                assertTrue(providerRoot + " : Read single reference values not equal to set values", singleRefValue.getString().equals(resultingSingleRefValue.getString()));
            }

            // now let's remove everything and make sure that it looks ok.
            Property singleRefProperty = refNode.getProperty(SIMPLE_REFERENCE_PROPERTY_NAME);
            singleRefProperty.remove();
            Property multipleI18NRefProperty = refNode.getProperty(MULTIPLE_I18N_REFERENCE_PROPERTY_NAME);
            multipleI18NRefProperty.remove();
            session.save();

            paths.clear();
            paths.add(testFile1.getPath());
            paths.add(testFile2.getPath());
            usages = navigationHelper.getUsages(paths, session);
            assertEquals(providerRoot + " : Usages should be empty but they are not !" + usages, 0, usages.size());
            assertFalse(providerRoot + " : single reference property should no longer exist !", refNode.hasProperty(SIMPLE_REFERENCE_PROPERTY_NAME));
            assertFalse(providerRoot + " : multiple reference property should no longer exist !", refNode.hasProperty(MULTIPLE_I18N_REFERENCE_PROPERTY_NAME));
            assertFalse(providerRoot + " : node should no longer have the jmix:externalReference node mixin node type", refNode.isNodeType(Constants.JAHIAMIX_EXTERNALREFERENCE));
View Full Code Here


        }

        JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession();
        try {
            JCRSiteNode siteNode = (JCRSiteNode) session.getNode(SITECONTENT_ROOT_NODE);
            NavigationHelper navigationHelper = (NavigationHelper) SpringContextSingleton.getInstance().getContext().getBean("NavigationHelper");
            List<String> paths = new ArrayList<String>();
            paths.add("/mounts");
            List<GWTJahiaNode> rootNodes = navigationHelper.retrieveRoot(paths, null, null, null, null,
                    null, null, siteNode, session, Locale.ENGLISH);
            List<String> nodeTypes = new ArrayList<String>();
            nodeTypes.add("nt:file");
            nodeTypes.add("nt:folder");
            nodeTypes.add("jnt:mountPoints");
            List<String> fields = new ArrayList<String>();
            fields.add("providerKey");
            fields.add("icon");
            fields.add("name");
            fields.add("locked");
            fields.add("size");
            fields.add("jcr:lastModified");
            for (GWTJahiaNode rootNode : rootNodes) {
                assertGWTJahiaNode(rootNode, "/mounts");
                List<GWTJahiaNode> childNodes = navigationHelper.ls(rootNode, nodeTypes, new ArrayList<String>(), new ArrayList<String>(), fields, session);
                assertEquals("Mounted providers in /mounts does not to correspond to expected amount", mountLocations.size(), childNodes.size());
                for (GWTJahiaNode childNode : childNodes) {
                    assertTrue("Path to mount location does not correspond ! Path=" + childNode.getPath(), mountLocations.contains(childNode.getPath()));
                    assertGWTJahiaNode(childNode, "/mounts/" + childNode.getName());
                    List<GWTJahiaNode> childChildNodes = navigationHelper.ls(childNode, nodeTypes, new ArrayList<String>(), new ArrayList<String>(), fields, session);
                    for (GWTJahiaNode childChildNode : childChildNodes) {
                        assertGWTJahiaNode(childChildNode, "/mounts/" + childNode.getName() + "/" + childChildNode.getName());
                    }
                }
            }
View Full Code Here

        }
    }

    private void assertRootNavigation(JCRSessionWrapper session) throws RepositoryException, GWTJahiaServiceException {
        JCRSiteNode siteNode = (JCRSiteNode) session.getNode(SITECONTENT_ROOT_NODE);
        NavigationHelper navigationHelper = (NavigationHelper) SpringContextSingleton.getInstance().getContext().getBean("NavigationHelper");
        Locale locale = LanguageCodeConverters.languageCodeToLocale("en");
        List<String> paths = new ArrayList<String>();
        paths.add("/mounts");
        List<GWTJahiaNode> rootNodes = navigationHelper.retrieveRoot(paths, null,null,null,null,
                            null,null,siteNode, session, locale);
        List<String> nodeTypes = new ArrayList<String>();
        nodeTypes.add("nt:file");
        nodeTypes.add("nt:folder");
        nodeTypes.add("jnt:mountPoints");
        List<String> fields = new ArrayList<String>();
        fields.add("providerKey");
        fields.add("icon");
        fields.add("name");
        fields.add("locked");
        fields.add("size");
        fields.add("jcr:lastModified");
        for (GWTJahiaNode rootNode : rootNodes) {
            assertGWTJahiaNode(rootNode, "/mounts");
            List<GWTJahiaNode> childNodes = navigationHelper.ls(rootNode, nodeTypes, new ArrayList<String>(), new ArrayList<String>(), fields, session);
            for (GWTJahiaNode childNode : childNodes) {
                assertGWTJahiaNode(childNode, "/mounts/" + childNode.getName());
                List<GWTJahiaNode> childChildNodes = navigationHelper.ls(childNode, nodeTypes, new ArrayList<String>(), new ArrayList<String>(), fields, session);               
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.jahia.ajax.gwt.helper.NavigationHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.