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);
}
}
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.");
}
}
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.");
}
}
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.");
}
}
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.");
}
}
Aggregations