Skip to content

Commit

Permalink
Fixes transaction invalidation bug, fixes DeployCommand export for ye…
Browse files Browse the repository at this point in the history
…t another

special way of using a template in a page.
  • Loading branch information
cmorgner committed Sep 29, 2016
1 parent 76c6307 commit b72132f
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 6 deletions.
Expand Up @@ -82,11 +82,19 @@ public void close() {

if (!success) {

// we need to invalidate all existing references because we cannot
// be sure that they contain the correct values after a rollback
// We need to invalidate all existing references because we cannot
// be sure that they contain the correct values after a rollback.
for (final EntityWrapper entity : modifiedEntities) {
entity.stale();
}

} else {

// Invalidate all nodes that are modified in this transaction
// so that the relationship caches are rebuilt.
for (final EntityWrapper entity : modifiedEntities) {
entity.invalidate();
}
}

// mark this transaction as closed BEFORE trying to actually close it
Expand Down
Expand Up @@ -46,7 +46,7 @@ public EntityWrapper(final BoltDatabaseService db, final T entity) {
}

protected abstract String getQueryPrefix();
protected abstract void invalidate();
public abstract void invalidate();

@Override
public long getId() {
Expand Down
Expand Up @@ -813,7 +813,7 @@ public void testSearchWithOwnerAndEnum() {
}

uuid = users.get(0).getUuid();

tx.success();
}

Expand Down Expand Up @@ -1068,4 +1068,130 @@ public void testSearchWithOwnerAndEnumOnDynamicNodes() {

}
}

/* disabled, failing test
public void testQueriesOnFunctionProperties() {
String customerId = null;
try (final Tx tx = app.tx()) {
// setup test schema
final SchemaNode customerType = app.create(SchemaNode.class, "Customer");
final SchemaNode projectType = app.create(SchemaNode.class, "Project");
app.create(SchemaRelationshipNode.class,
new NodeAttribute<>(SchemaRelationshipNode.sourceNode, customerType),
new NodeAttribute<>(SchemaRelationshipNode.targetNode, projectType),
new NodeAttribute<>(SchemaRelationshipNode.relationshipType, "has"),
new NodeAttribute<>(SchemaRelationshipNode.sourceMultiplicity, "1"),
new NodeAttribute<>(SchemaRelationshipNode.targetMultiplicity, "*"),
new NodeAttribute<>(SchemaRelationshipNode.sourceJsonName, "customer"),
new NodeAttribute<>(SchemaRelationshipNode.targetJsonName, "projects")
);
customerType.setProperty(new StringProperty("_projectCount"), "Function(size(this.projects))");
customerType.setProperty(new StringProperty("_hasProjects"), "Function(gt(this.projectCount, 0))");
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
final Class customerType = StructrApp.getConfiguration().getNodeEntityClass("Customer");
final Class projectType = StructrApp.getConfiguration().getNodeEntityClass("Project");
final PropertyKey projects = StructrApp.getConfiguration().getPropertyKeyForJSONName(customerType, "projects");
final List<NodeInterface> projectList = new LinkedList<>();
projectList.add(app.create(projectType, "Project 1"));
projectList.add(app.create(projectType, "Project 2"));
// create a customer with the two projects
customerId = app.create(customerType,
new NodeAttribute<>(AbstractNode.name, "Customer 1"),
new NodeAttribute<>(projects, projectList)
).getUuid();
// create a second customer without projects
app.create(customerType, "Customer 2");
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
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))
.expect()
.statusCode(200)
.body("result", hasSize(2))
.body("result_count", equalTo(2))
.when()
.get(concat("/Customer/ui"));
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))
.expect()
.statusCode(200)
.body("result", hasSize(1))
.body("result_count", equalTo(1))
.body("result[0].id", equalTo(customerId))
.when()
.get(concat("/Customer?hasProjects=true"));
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))
.expect()
.statusCode(200)
.body("result", hasSize(1))
.body("result_count", equalTo(1))
.body("result[0].id", equalTo(customerId))
.when()
.get(concat("/Customer?projectCount=2"));
}
*/
}
Expand Up @@ -296,7 +296,7 @@ public void renderContent(final RenderContext renderContext, final int depth) th
if (EditMode.DEPLOYMENT.equals(edit)) {

// EditMode "deployment" means "output raw content, do not interpret in any way
renderContext.getBuffer().append(getProperty(Content.content));
renderContext.getBuffer().append(escapeForHtmlAttributes(getProperty(Content.content)));

return;
}
Expand Down
10 changes: 10 additions & 0 deletions structr-ui/src/main/java/org/structr/web/entity/dom/DOMNode.java
Expand Up @@ -608,6 +608,16 @@ protected void renderCustomAttributes(final AsyncBuffer out, final SecurityConte

if (EditMode.DEPLOYMENT.equals(editMode) || EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode)) {

if (EditMode.DEPLOYMENT.equals(editMode)) {

// export name property if set
final String name = getProperty(AbstractNode.name);
if (name != null) {

out.append(" data-structr-meta-name=\"").append(escapeForHtmlAttributes(name)).append("\"");
}
}

for (final Property p : rawProps) {

String htmlName = "data-structr-meta-" + CaseHelper.toUnderscore(p.jsonName(), false).replaceAll("_", "-");
Expand Down
Expand Up @@ -140,7 +140,6 @@ protected void setUp(final Map<String, Object> additionalConfig) {
config.setProperty(Services.UDP_PORT, (System.getProperty("udpPort") != null ? System.getProperty("udpPort") : "13466"));
config.setProperty(Services.SUPERUSER_USERNAME, "superadmin");
config.setProperty(Services.SUPERUSER_PASSWORD, "sehrgeheim");
config.setProperty(Structr.LOG_CYPHER_DEBUG, "true");

// configure servlets
config.setProperty(HttpService.APPLICATION_TITLE, "structr unit test app" + timestamp);
Expand Down

0 comments on commit b72132f

Please sign in to comment.