Search in sources :

Example 11 with NodeAttribute

use of org.structr.core.graph.NodeAttribute in project structr by structr.

the class UiScriptingTest method testSingleRequestParameters.

@Test
public void testSingleRequestParameters() {
    try (final Tx tx = app.tx()) {
        Page page = (Page) app.create(Page.class, new NodeAttribute(Page.name, "test"), new NodeAttribute(Page.visibleToPublicUsers, true));
        Template template = (Template) app.create(Template.class, new NodeAttribute(Page.visibleToPublicUsers, true));
        template.setContent("${request.param}");
        page.appendChild(template);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception");
    }
    try (final Tx tx = app.tx()) {
        RestAssured.given().filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body(equalTo("a")).when().get("http://localhost:8875/test?param=a");
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception");
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Page(org.structr.web.entity.dom.Page) Template(org.structr.web.entity.dom.Template) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 12 with NodeAttribute

use of org.structr.core.graph.NodeAttribute in project structr by structr.

the class UiScriptingTest method testGroupFunctions.

@Test
public void testGroupFunctions() {
    Group group = null;
    User tester = null;
    try (final Tx tx = app.tx()) {
        // create test user
        tester = createTestNode(User.class, new NodeAttribute<>(StructrApp.key(User.class, "name"), "tester"), new NodeAttribute<>(StructrApp.key(User.class, "password"), "test"));
        // create test group
        group = createTestNode(Group.class, new NodeAttribute<>(StructrApp.key(Group.class, "name"), "test"));
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
        fail("Unexpected exception.");
    }
    final RenderContext renderContext = new RenderContext(securityContext, new RequestMockUp(), new ResponseMockUp(), RenderContext.EditMode.NONE);
    try (final Tx tx = app.tx()) {
        // check that the user is not in the group at first
        assertFalse("User should not be in the test group before testing", group.getMembers().contains(tester));
        // check that is_in_group returns the correct result
        assertEquals("Function is_in_group should return false.", false, Scripting.evaluate(renderContext, null, "${is_in_group(first(find('Group')), first(find('User')))}", "test"));
        // add user to group
        Scripting.evaluate(renderContext, null, "${add_to_group(first(find('Group')), first(find('User')))}", "test");
        // check that the user is in the group after the call to add_to_group
        final List<Principal> members = group.getMembers();
        assertTrue("User should be in the test group now", members.contains(tester));
        // check that is_in_group returns the correct result
        assertEquals("Function is_in_group should return true.", true, Scripting.evaluate(renderContext, null, "${is_in_group(first(find('Group')), first(find('User')))}", "test"));
        // remove user from group
        Scripting.evaluate(renderContext, null, "${remove_from_group(first(find('Group')), first(find('User')))}", "test");
        // check that the user is not in the group any more after the call to remove_from_group
        assertFalse("User should not be in the test group before testing", group.getMembers().contains(tester));
        // check that is_in_group returns the correct result
        assertEquals("Function is_in_group should return false.", false, Scripting.evaluate(renderContext, null, "${is_in_group(first(find('Group')), first(find('User')))}", "test"));
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
        fail("Unexpected exception.");
    }
}
Also used : Group(org.structr.core.entity.Group) NodeAttribute(org.structr.core.graph.NodeAttribute) RenderContext(org.structr.web.common.RenderContext) User(org.structr.web.entity.User) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Principal(org.structr.core.entity.Principal) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 13 with NodeAttribute

use of org.structr.core.graph.NodeAttribute in project structr by structr.

the class UiTest method testAutoRenameFileWithIdenticalPathInSubFolder.

@Test
public void testAutoRenameFileWithIdenticalPathInSubFolder() {
    Settings.UniquePaths.setValue(Boolean.TRUE);
    Folder folder = null;
    File file1 = null;
    File file2 = null;
    try (final Tx tx = app.tx()) {
        folder = FileHelper.createFolderPath(SecurityContext.getSuperUserInstance(), "/my/test/folder");
        assertNotNull(folder);
        assertEquals(folder.getPath(), "/my/test/folder");
        tx.success();
    } catch (FrameworkException ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        file1 = app.create(File.class, new NodeAttribute<>(AbstractNode.name, "test.txt"), new NodeAttribute<>(StructrApp.key(AbstractFile.class, "parent"), folder));
        assertNotNull(file1);
        assertEquals("Testfolder should have exactly one child", 1, Iterables.count(folder.getChildren()));
        tx.success();
    } catch (FrameworkException ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        file2 = app.create(File.class, new NodeAttribute<>(AbstractNode.name, "test.txt"), new NodeAttribute<>(StructrApp.key(AbstractFile.class, "parent"), folder));
        assertNotNull(file2);
        assertEquals("Testfolder should have exactly two children", 2, Iterables.count(folder.getChildren()));
        tx.success();
    } catch (FrameworkException ex) {
        logger.error("", ex);
    }
    assertNotEquals(file1.getName(), file2.getName());
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Folder(org.structr.web.entity.Folder) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 14 with NodeAttribute

use of org.structr.core.graph.NodeAttribute in project structr by structr.

the class StructrLDAPWrapper method getRoot.

private LDAPNode getRoot() throws FrameworkException {
    final Class type = StructrApp.getConfiguration().getNodeEntityClass("LDAPNode");
    final App app = app();
    LDAPNode root = (LDAPNode) app.nodeQuery(type).andName(partitionId).getFirst();
    if (root == null) {
        root = app.create(type, new NodeAttribute<>(StructrApp.key(LDAPNode.class, "name"), partitionId), new NodeAttribute<>(StructrApp.key(LDAPNode.class, "isRoot"), true));
    }
    return root;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) LDAPNode(org.structr.ldap.entity.LDAPNode) NodeAttribute(org.structr.core.graph.NodeAttribute)

Example 15 with NodeAttribute

use of org.structr.core.graph.NodeAttribute in project structr by structr.

the class LDAPService method synchronizeUserEntry.

// ----- private methods -----
private String synchronizeUserEntry(final LdapConnection connection, final Entry entry) {
    final PropertyKey<String> dnKey = StructrApp.key(LDAPUser.class, "distinguishedName");
    final App app = StructrApp.getInstance();
    final Dn dn = entry.getDn();
    final String dnString = dn.toString();
    try (final Tx tx = app.tx()) {
        LDAPUser user = app.nodeQuery(LDAPUser.class).and(dnKey, dnString).getFirst();
        if (user == null) {
            user = app.create(LDAPUser.class, new NodeAttribute(dnKey, dnString));
            user.initializeFrom(entry);
            final String uuid = user.getUuid();
            if (user.getEntryUuid() == null) {
                try {
                    // try to set "our" UUID in the remote database
                    final Modification addUuid = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, "entryUUID", normalizeUUID(uuid));
                    connection.modify(dn, addUuid);
                } catch (LdapException ex) {
                    logger.warn("Unable to set entryUUID: {}", ex.getMessage());
                }
            }
        }
        tx.success();
        return user.getUuid();
    } catch (FrameworkException | LdapInvalidAttributeValueException fex) {
        logger.warn("Unable to update LDAP information", fex);
    }
    return null;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) NodeAttribute(org.structr.core.graph.NodeAttribute) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Aggregations

NodeAttribute (org.structr.core.graph.NodeAttribute)73 Tx (org.structr.core.graph.Tx)55 FrameworkException (org.structr.common.error.FrameworkException)54 Test (org.junit.Test)45 App (org.structr.core.app.App)23 StructrApp (org.structr.core.app.StructrApp)23 StructrUiTest (org.structr.web.StructrUiTest)21 LinkedList (java.util.LinkedList)19 PropertyKey (org.structr.core.property.PropertyKey)17 SchemaNode (org.structr.core.entity.SchemaNode)14 NodeInterface (org.structr.core.graph.NodeInterface)13 Principal (org.structr.core.entity.Principal)12 PropertyMap (org.structr.core.property.PropertyMap)12 StringProperty (org.structr.core.property.StringProperty)10 ConfigurationProvider (org.structr.schema.ConfigurationProvider)10 File (org.structr.web.entity.File)10 Folder (org.structr.web.entity.Folder)9 AbstractFile (org.structr.web.entity.AbstractFile)8 List (java.util.List)7 StructrTest (org.structr.common.StructrTest)7