Search in sources :

Example 11 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class SchemaMethodsTest method test06InheritedSchemaMethodOnEntityOfBuiltinType.

@Test
public void test06InheritedSchemaMethodOnEntityOfBuiltinType() {
    final String builtinTypeName = "File";
    final String schemaMethodName = "testFileMethod";
    User admin = null;
    try (final Tx tx = app.tx()) {
        admin = createAdminUser();
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        // Add schema method "testFileMethod" to built-in File class
        SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
        final PropertyMap testFileMethodProperties = new PropertyMap();
        testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
        testFileMethodProperties.put(SchemaMethod.source, "()");
        testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
        SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    String id = createEntityAsAdmin("Image", "{'name': 'Test Image'}");
    try (final Tx tx = app.tx()) {
        RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post("/Image/" + id + "/" + schemaMethodName);
        tx.success();
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : SchemaNode(org.structr.core.entity.SchemaNode) User(org.structr.web.entity.User) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) SchemaMethod(org.structr.core.entity.SchemaMethod) FrameworkException(org.structr.common.error.FrameworkException) FrameworkException(org.structr.common.error.FrameworkException) Test(org.junit.Test)

Example 12 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class SchemaMethodsTest method test01SchemaMethodOnBuiltinType.

@Test
public void test01SchemaMethodOnBuiltinType() {
    final String builtinTypeName = "File";
    final String schemaMethodName = "testFileMethod";
    try (final Tx tx = app.tx()) {
        // Add schema method "testFileMethod" to built-in File class
        SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
        final PropertyMap testFileMethodProperties = new PropertyMap();
        testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
        testFileMethodProperties.put(SchemaMethod.source, "()");
        testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
        SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    User admin = null;
    try (final Tx tx = app.tx()) {
        admin = createAdminUser();
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post(builtinTypeName + "/" + schemaMethodName);
        tx.success();
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : SchemaNode(org.structr.core.entity.SchemaNode) PropertyMap(org.structr.core.property.PropertyMap) User(org.structr.web.entity.User) Tx(org.structr.core.graph.Tx) SchemaMethod(org.structr.core.entity.SchemaMethod) FrameworkException(org.structr.common.error.FrameworkException) FrameworkException(org.structr.common.error.FrameworkException) Test(org.junit.Test)

Example 13 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class UiTest method test01AutoRenameThumbnailForImageSubclass.

@Test
public void test01AutoRenameThumbnailForImageSubclass() {
    final Class testImageType = createTestImageType();
    Image subclassTestImage = null;
    final String initialImageName = "initial_image_name.png";
    final String renamedImageName = "image_name_after_rename.png";
    try (final Tx tx = app.tx()) {
        subclassTestImage = (Image) ImageHelper.createFileBase64(securityContext, base64Image, testImageType);
        subclassTestImage.setProperties(subclassTestImage.getSecurityContext(), new PropertyMap(Image.name, initialImageName));
        assertNotNull(subclassTestImage);
        assertTrue(subclassTestImage instanceof Image);
        final Image tnSmall = subclassTestImage.getProperty(StructrApp.key(testImageType, "tnSmall"));
        final Image tnMid = subclassTestImage.getProperty(StructrApp.key(testImageType, "tnMid"));
        final Image tnCustom = subclassTestImage.getProperty(StructrApp.key(testImageType, "thumbnail"));
        assertEquals("Initial small thumbnail name not as expected", ImageHelper.getThumbnailName(initialImageName, tnSmall.getWidth(), tnSmall.getHeight()), tnSmall.getProperty(StructrApp.key(Image.class, "name")));
        assertEquals("Initial mid thumbnail name not as expected", ImageHelper.getThumbnailName(initialImageName, tnMid.getWidth(), tnMid.getHeight()), tnMid.getProperty(StructrApp.key(Image.class, "name")));
        assertEquals("Initial custom thumbnail name not as expected", ImageHelper.getThumbnailName(initialImageName, tnCustom.getWidth(), tnCustom.getHeight()), tnCustom.getProperty(StructrApp.key(Image.class, "name")));
        tx.success();
    } catch (Exception ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
    try (final Tx tx = app.tx()) {
        subclassTestImage.setProperties(subclassTestImage.getSecurityContext(), new PropertyMap(Image.name, renamedImageName));
        tx.success();
    } catch (Exception ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
    try (final Tx tx = app.tx()) {
        final Image tnSmall = subclassTestImage.getProperty(StructrApp.key(testImageType, "tnSmall"));
        final Image tnMid = subclassTestImage.getProperty(StructrApp.key(testImageType, "tnMid"));
        final Image tnCustom = subclassTestImage.getProperty(StructrApp.key(testImageType, "thumbnail"));
        assertEquals("Small Thumbnail name not auto-renamed as expected for image subclass", ImageHelper.getThumbnailName(renamedImageName, tnSmall.getWidth(), tnSmall.getHeight()), tnSmall.getProperty(StructrApp.key(Image.class, "name")));
        assertEquals("Mid Thumbnail name not auto-renamed as expected for image subclass", ImageHelper.getThumbnailName(renamedImageName, tnMid.getWidth(), tnMid.getHeight()), tnMid.getProperty(StructrApp.key(Image.class, "name")));
        assertEquals("Custom Thumbnail name not auto-renamed as expected for image subclass", ImageHelper.getThumbnailName(renamedImageName, tnCustom.getWidth(), tnCustom.getHeight()), tnCustom.getProperty(StructrApp.key(Image.class, "name")));
        tx.success();
    } catch (Exception ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) Image(org.structr.web.entity.Image) FrameworkException(org.structr.common.error.FrameworkException) IOException(java.io.IOException) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 14 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class RenderDataTest method testRenderListFromRestQuery.

@Test
public void testRenderListFromRestQuery() {
    String name = null;
    try (final Tx tx = app.tx()) {
        final Page doc = (Page) getDocument();
        name = doc.getName();
        final List<User> users = createTestNodes(User.class, 3);
        assertEquals(3, users.size());
        User user1 = users.get(0);
        user1.setProperty(AbstractNode.name, "user1");
        User user2 = users.get(1);
        user2.setProperty(AbstractNode.name, "user2");
        User user3 = users.get(2);
        user3.setProperty(AbstractNode.name, "user3");
        final List<File> files = createTestNodes(File.class, 6);
        assertEquals(6, files.size());
        File nodeA = files.get(0);
        nodeA.setProperty(AbstractNode.name, "fileA");
        File nodeB = files.get(1);
        nodeB.setProperty(AbstractNode.name, "fileB");
        File nodeC = files.get(2);
        nodeC.setProperty(AbstractNode.name, "fileC");
        File nodeD = files.get(3);
        nodeD.setProperty(AbstractNode.name, "fileD");
        File nodeE = files.get(4);
        nodeE.setProperty(AbstractNode.name, "fileE");
        File nodeF = files.get(5);
        nodeF.setProperty(AbstractNode.name, "fileF");
        // create dom tree
        Element html = doc.createElement("html");
        Element body = doc.createElement("body");
        Element b = doc.createElement("b");
        final Element p1 = doc.createElement("p");
        final PropertyMap p1Properties = new PropertyMap();
        p1Properties.put(StructrApp.key(DOMElement.class, "restQuery"), "users?sort=name");
        p1Properties.put(StructrApp.key(DOMElement.class, "dataKey"), "user");
        ((DOMElement) p1).setProperties(((DOMElement) p1).getSecurityContext(), p1Properties);
        Content userNameContentNode = (Content) doc.createTextNode("${user.name}");
        p1.appendChild(userNameContentNode);
        Element div = doc.createElement("div");
        final Element p2 = doc.createElement("p");
        final PropertyMap p2Properties = new PropertyMap();
        p2Properties.put(StructrApp.key(DOMElement.class, "restQuery"), "files?sort=name");
        p2Properties.put(StructrApp.key(DOMElement.class, "dataKey"), "file");
        ((DOMElement) p2).setProperties(((DOMElement) p2).getSecurityContext(), p2Properties);
        Content fileNameContentNode = (Content) doc.createTextNode("${file.name}");
        p2.appendChild(fileNameContentNode);
        doc.appendChild(html);
        html.appendChild(body);
        body.appendChild(b);
        body.appendChild(div);
        b.appendChild(p1);
        div.appendChild(p2);
        makePublic(doc, html, body, div, b, p1, p2, fileNameContentNode, userNameContentNode, nodeA, nodeB, nodeC, nodeD, nodeE, nodeF, user1, user2, user3);
        tx.success();
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Unexpected exception");
    }
    try (final Tx tx = app.tx()) {
        Document parsedDocument = Jsoup.connect(baseUri + name).timeout(100000).get();
        System.out.println(parsedDocument.outerHtml());
        assertEquals("user1", parsedDocument.select("html > body > b > p").get(0).ownText());
        assertEquals("user2", parsedDocument.select("html > body > b > p").get(1).ownText());
        assertEquals("user3", parsedDocument.select("html > body > b > p").get(2).ownText());
        assertEquals("fileA", parsedDocument.select("html > body > div > p").get(0).ownText());
        assertEquals("fileB", parsedDocument.select("html > body > div > p").get(1).ownText());
        assertEquals("fileC", parsedDocument.select("html > body > div > p").get(2).ownText());
        assertEquals("fileD", parsedDocument.select("html > body > div > p").get(3).ownText());
        assertEquals("fileE", parsedDocument.select("html > body > div > p").get(4).ownText());
        assertEquals("fileF", parsedDocument.select("html > body > div > p").get(5).ownText());
        tx.success();
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("unexpected exception");
    }
}
Also used : User(org.structr.web.entity.User) Tx(org.structr.core.graph.Tx) Element(org.w3c.dom.Element) Document(org.jsoup.nodes.Document) PropertyMap(org.structr.core.property.PropertyMap) File(org.structr.web.entity.File) DOMTest(org.structr.web.advanced.DOMTest) Test(org.junit.Test)

Example 15 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class SearchCommand method or.

@Override
public <P> org.structr.core.app.Query<T> or(final PropertyMap attributes) {
    for (final Map.Entry<PropertyKey, Object> entry : attributes.entrySet()) {
        final PropertyKey key = entry.getKey();
        final Object value = entry.getValue();
        or(key, value);
    }
    return this;
}
Also used : GraphObject(org.structr.core.GraphObject) LinkedHashMap(java.util.LinkedHashMap) PropertyMap(org.structr.core.property.PropertyMap) Map(java.util.Map) PropertyKey(org.structr.core.property.PropertyKey)

Aggregations

PropertyMap (org.structr.core.property.PropertyMap)233 FrameworkException (org.structr.common.error.FrameworkException)100 Tx (org.structr.core.graph.Tx)93 Test (org.junit.Test)60 App (org.structr.core.app.App)34 StructrApp (org.structr.core.app.StructrApp)34 PropertyKey (org.structr.core.property.PropertyKey)34 LinkedList (java.util.LinkedList)28 NodeInterface (org.structr.core.graph.NodeInterface)25 SchemaProperty (org.structr.core.entity.SchemaProperty)23 SecurityContext (org.structr.common.SecurityContext)22 StructrUiTest (org.structr.web.StructrUiTest)21 GraphObject (org.structr.core.GraphObject)20 Result (org.structr.core.Result)19 File (org.structr.web.entity.File)19 DOMNode (org.structr.web.entity.dom.DOMNode)19 TestOne (org.structr.core.entity.TestOne)17 AbstractNode (org.structr.core.entity.AbstractNode)16 Folder (org.structr.web.entity.Folder)15 Page (org.structr.web.entity.dom.Page)15