use of org.structr.core.entity.AbstractNode in project structr by structr.
the class SearchAndSortingTest method test08SearchByStaticMethod02.
@Test
public void test08SearchByStaticMethod02() {
try {
PropertyMap props = new PropertyMap();
final PropertyKey key = AbstractNode.name;
final String name = "89w3hkl sdfghsdkljth";
props.put(key, name);
final AbstractNode node = createTestNode(TestOne.class, props);
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(TestOne.class).andName(name).includeDeletedAndHidden().getResult();
assertTrue(result.size() == 1);
assertTrue(result.get(0).equals(node));
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class SearchAndSortingTest method test10SearchByEmptyDateField.
@Test
public void test10SearchByEmptyDateField() {
try {
PropertyMap props = new PropertyMap();
AbstractNode node = createTestNode(TestOne.class, props);
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(TestOne.class).and(TestOne.aDate, null).includeDeletedAndHidden().getResult();
assertTrue(result.size() == 1);
assertTrue(result.get(0).equals(node));
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class SearchAndSortingTest method test13SearchByEmptyDoubleField.
@Test
public void test13SearchByEmptyDoubleField() {
try {
PropertyMap props = new PropertyMap();
AbstractNode node = createTestNode(TestOne.class, props);
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(TestOne.class).and(TestOne.aDouble, null).includeDeletedAndHidden().getResult();
assertTrue(result.size() == 1);
assertTrue(result.get(0).equals(node));
tx.success();
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class EntityResolverResource method doPost.
@Override
public RestMethodResult doPost(final Map<String, Object> propertySet) throws FrameworkException {
// TODO: fetch nodes with superuser security context, collect forbidden nodes and return
// in error response
RestMethodResult result = new RestMethodResult(200);
for (Object o : propertySet.values()) {
if (o instanceof String) {
String id = (String) o;
AbstractNode node = (AbstractNode) StructrApp.getInstance().getNodeById(id);
if (node != null) {
result.addContent(node);
}
}
}
return result;
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class UpdateCommand method processMessage.
// ~--- methods --------------------------------------------------------
@Override
public void processMessage(final WebSocketMessage webSocketData) throws FrameworkException {
final App app = StructrApp.getInstance(getWebSocket().getSecurityContext());
final Boolean recValue = (Boolean) webSocketData.getNodeData().get("recursive");
final String nodeId = (String) webSocketData.getNodeData().get("nodeId");
final boolean rec = recValue != null ? recValue : false;
final GraphObject obj = getGraphObject(webSocketData.getId(), nodeId);
if (obj == null) {
logger.warn("Graph object with uuid {} not found.", webSocketData.getId());
getWebSocket().send(MessageBuilder.status().code(404).build(), true);
return;
}
webSocketData.getNodeData().remove("recursive");
// If it's a node, check permissions
try (final Tx tx = app.tx()) {
if (obj instanceof AbstractNode) {
final AbstractNode node = (AbstractNode) obj;
if (!node.isGranted(Permission.write, getWebSocket().getSecurityContext())) {
getWebSocket().send(MessageBuilder.status().message("No write permission").code(400).build(), true);
logger.warn("No write permission for {} on {}", new Object[] { getWebSocket().getCurrentUser().toString(), obj.toString() });
tx.success();
return;
}
tx.success();
}
}
final Set<GraphObject> entities = new LinkedHashSet<>();
PropertyMap properties = null;
try (final Tx tx = app.tx()) {
collectEntities(entities, obj, null, rec);
properties = PropertyMap.inputTypeToJavaType(this.getWebSocket().getSecurityContext(), obj.getClass(), webSocketData.getNodeData());
tx.success();
}
final Iterator<GraphObject> iterator = entities.iterator();
while (iterator.hasNext()) {
count = 0;
try (final Tx tx = app.tx()) {
while (iterator.hasNext() && count++ < 100) {
setProperties(iterator.next(), properties, true);
}
// commit and close transaction
tx.success();
}
}
}
Aggregations