Search in sources :

Example 11 with Image

use of org.structr.web.entity.Image in project structr by structr.

the class GetByTypeCommand method processMessage.

@Override
public void processMessage(final WebSocketMessage webSocketData) {
    final SecurityContext securityContext = getWebSocket().getSecurityContext();
    final String rawType = (String) webSocketData.getNodeData().get("type");
    final String properties = (String) webSocketData.getNodeData().get("properties");
    final boolean includeDeletedAndHidden = (Boolean) webSocketData.getNodeData().get("includeDeletedAndHidden");
    final Class type = SchemaHelper.getEntityClassForRawType(rawType);
    if (type == null) {
        getWebSocket().send(MessageBuilder.status().code(404).message("Type " + rawType + " not found").build(), true);
        return;
    }
    if (properties != null) {
        securityContext.setCustomView(StringUtils.split(properties, ","));
    }
    final String sortOrder = webSocketData.getSortOrder();
    final String sortKey = webSocketData.getSortKey();
    final int pageSize = webSocketData.getPageSize();
    final int page = webSocketData.getPage();
    final Query query = StructrApp.getInstance(securityContext).nodeQuery(type).includeDeletedAndHidden(includeDeletedAndHidden);
    if (sortKey != null) {
        final PropertyKey sortProperty = StructrApp.key(type, sortKey);
        if (sortProperty != null) {
            query.sort(sortProperty).order("desc".equals(sortOrder));
        }
    }
    // for image lists, suppress thumbnails
    if (type.equals(Image.class)) {
        query.and(StructrApp.key(Image.class, "isThumbnail"), false);
    }
    try {
        // do search
        Result result = query.getResult();
        // save raw result count
        int resultCountBeforePaging = result.size();
        // set full result list
        webSocketData.setResult(PagingHelper.subList(result.getResults(), pageSize, page));
        webSocketData.setRawResultCount(resultCountBeforePaging);
        // send only over local connection
        getWebSocket().send(webSocketData, true);
    } catch (FrameworkException fex) {
        logger.warn("Exception occured", fex);
        getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
    }
}
Also used : Query(org.structr.core.app.Query) FrameworkException(org.structr.common.error.FrameworkException) SecurityContext(org.structr.common.SecurityContext) Image(org.structr.web.entity.Image) PropertyKey(org.structr.core.property.PropertyKey) Result(org.structr.core.Result)

Example 12 with Image

use of org.structr.web.entity.Image in project structr by structr.

the class FilesystemTest method test01ImageUploadBase64.

@Test
public void test01ImageUploadBase64() {
    try (final Tx tx = app.tx()) {
        app.create(Image.class, new NodeAttribute<>(Image.name, "test01.png"), new NodeAttribute<>(StructrApp.key(Image.class, "imageData"), Base64ImageData));
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final List<Image> images = app.nodeQuery(Image.class).getAsList();
        assertEquals("There should be exactly one image", 1, images.size());
        final Image image = images.get(0);
        assertEquals("File size of the image does not match", Long.valueOf(1707), image.getProperty(StructrApp.key(Image.class, "size")));
        assertEquals("Width of the image does not match", Integer.valueOf(100), image.getProperty(StructrApp.key(Image.class, "width")));
        assertEquals("Height of the image does not match", Integer.valueOf(59), image.getProperty(StructrApp.key(Image.class, "height")));
        assertEquals("Content type of the image does not match", "image/png", image.getProperty(StructrApp.key(Image.class, "contentType")));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Image(org.structr.web.entity.Image) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 13 with Image

use of org.structr.web.entity.Image in project structr by structr.

the class FilesystemTest method test02ImageUploadBase64WithContentType.

@Test
public void test02ImageUploadBase64WithContentType() {
    try (final Tx tx = app.tx()) {
        app.create(Image.class, new NodeAttribute<>(Image.name, "test01.png"), new NodeAttribute<>(StructrApp.key(Image.class, "imageData"), "data:image/jpeg;base64," + Base64ImageData));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final List<Image> images = app.nodeQuery(Image.class).getAsList();
        assertEquals("There should be exactly one image", 1, images.size());
        final Image image = images.get(0);
        assertEquals("File size of the image does not match", Long.valueOf(1707), image.getProperty(StructrApp.key(Image.class, "size")));
        assertEquals("Width of the image does not match", Integer.valueOf(100), image.getProperty(StructrApp.key(Image.class, "width")));
        assertEquals("Height of the image does not match", Integer.valueOf(59), image.getProperty(StructrApp.key(Image.class, "height")));
        assertEquals("Content type of the image does not match", "image/jpeg", image.getProperty(StructrApp.key(Image.class, "contentType")));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Image(org.structr.web.entity.Image) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 14 with Image

use of org.structr.web.entity.Image in project structr by structr.

the class ImageUploadTest method test02ImageUploadBase64WithContentType.

@Test
public void test02ImageUploadBase64WithContentType() {
    try (final Tx tx = app.tx()) {
        app.create(Image.class, new NodeAttribute<>(StructrApp.key(Image.class, "name"), "test01.png"), new NodeAttribute<>(StructrApp.key(Image.class, "imageData"), "data:image/jpeg;base64," + Base64ImageData));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final List<Image> images = app.nodeQuery(Image.class).getAsList();
        assertEquals("There should be exactly one image", 1, images.size());
        final Image image = images.get(0);
        assertEquals("File size of the image does not match", Long.valueOf(1707), image.getSize());
        assertEquals("Width of the image does not match", Integer.valueOf(100), image.getWidth());
        assertEquals("Height of the image does not match", Integer.valueOf(59), image.getHeight());
        assertEquals("Content type of the image does not match", "image/jpeg", image.getContentType());
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Image(org.structr.web.entity.Image) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 15 with Image

use of org.structr.web.entity.Image in project structr by structr.

the class ImageUploadTest method test01ImageUploadBase64.

@Test
public void test01ImageUploadBase64() {
    try (final Tx tx = app.tx()) {
        app.create(Image.class, new NodeAttribute<>(StructrApp.key(Image.class, "name"), "test01.png"), new NodeAttribute<>(StructrApp.key(Image.class, "imageData"), Base64ImageData));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final List<Image> images = app.nodeQuery(Image.class).getAsList();
        assertEquals("There should be exactly one image", 1, images.size());
        final Image image = images.get(0);
        assertEquals("File size of the image does not match", Long.valueOf(1707), image.getSize());
        assertEquals("Width of the image does not match", Integer.valueOf(100), image.getWidth());
        assertEquals("Height of the image does not match", Integer.valueOf(59), image.getHeight());
        assertEquals("Content type of the image does not match", "image/png", image.getContentType());
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Image(org.structr.web.entity.Image) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

Image (org.structr.web.entity.Image)26 FrameworkException (org.structr.common.error.FrameworkException)18 Tx (org.structr.core.graph.Tx)12 PropertyMap (org.structr.core.property.PropertyMap)12 Test (org.junit.Test)9 StructrUiTest (org.structr.web.StructrUiTest)9 BufferedImage (java.awt.image.BufferedImage)8 IOException (java.io.IOException)7 File (org.structr.web.entity.File)6 AbstractFile (org.structr.web.entity.AbstractFile)5 App (org.structr.core.app.App)4 StructrApp (org.structr.core.app.StructrApp)4 SecurityContext (org.structr.common.SecurityContext)3 Relation (org.structr.core.entity.Relation)3 PropertyKey (org.structr.core.property.PropertyKey)3 Folder (org.structr.web.entity.Folder)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ImageInputStream (javax.imageio.stream.ImageInputStream)2 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)2