use of org.structr.core.entity.MailTemplate in project structr by structr.
the class DeploymentTest method test28MailTemplates.
@Test
public void test28MailTemplates() {
// setup
try (final Tx tx = app.tx()) {
app.create(MailTemplate.class, new NodeAttribute<>(StructrApp.key(MailTemplate.class, "name"), "template1"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "locale"), "de_DE"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "text"), "text1"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "visibleToPublicUsers"), true));
app.create(MailTemplate.class, new NodeAttribute<>(StructrApp.key(MailTemplate.class, "name"), "template2"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "locale"), "en"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "text"), "text2"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "visibleToAuthenticatedUsers"), true));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
// test
doImportExportRoundtrip(true);
// check
try (final Tx tx = app.tx()) {
final MailTemplate template1 = app.nodeQuery(MailTemplate.class).and(MailTemplate.name, "template1").getFirst();
final MailTemplate template2 = app.nodeQuery(MailTemplate.class).and(MailTemplate.name, "template2").getFirst();
Assert.assertNotNull("Invalid deployment result", template1);
Assert.assertNotNull("Invalid deployment result", template2);
Assert.assertEquals("Invalid MailTemplate deployment result", "template1", template1.getProperty(StructrApp.key(MailTemplate.class, "name")));
Assert.assertEquals("Invalid MailTemplate deployment result", "de_DE", template1.getProperty(StructrApp.key(MailTemplate.class, "locale")));
Assert.assertEquals("Invalid MailTemplate deployment result", "text1", template1.getProperty(StructrApp.key(MailTemplate.class, "text")));
Assert.assertEquals("Invalid MailTemplate deployment result", true, template1.getProperty(StructrApp.key(MailTemplate.class, "visibleToPublicUsers")));
Assert.assertEquals("Invalid MailTemplate deployment result", false, template1.getProperty(StructrApp.key(MailTemplate.class, "visibleToAuthenticatedUsers")));
Assert.assertEquals("Invalid MailTemplate deployment result", "template2", template2.getProperty(StructrApp.key(MailTemplate.class, "name")));
Assert.assertEquals("Invalid MailTemplate deployment result", "en", template2.getProperty(StructrApp.key(MailTemplate.class, "locale")));
Assert.assertEquals("Invalid MailTemplate deployment result", "text2", template2.getProperty(StructrApp.key(MailTemplate.class, "text")));
Assert.assertEquals("Invalid MailTemplate deployment result", false, template2.getProperty(StructrApp.key(MailTemplate.class, "visibleToPublicUsers")));
Assert.assertEquals("Invalid MailTemplate deployment result", true, template2.getProperty(StructrApp.key(MailTemplate.class, "visibleToAuthenticatedUsers")));
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
}
use of org.structr.core.entity.MailTemplate in project structr by structr.
the class DeployCommand method exportMailTemplates.
private void exportMailTemplates(final Path target) throws FrameworkException {
logger.info("Exporting mail templates");
final PropertyKey<String> textKey = StructrApp.key(MailTemplate.class, "text");
final PropertyKey<String> localeKey = StructrApp.key(MailTemplate.class, "locale");
final List<Map<String, Object>> mailTemplates = new LinkedList<>();
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx()) {
for (final MailTemplate mailTemplate : app.nodeQuery(MailTemplate.class).sort(MailTemplate.name).getAsList()) {
final Map<String, Object> entry = new TreeMap<>();
mailTemplates.add(entry);
entry.put("name", mailTemplate.getProperty(MailTemplate.name));
entry.put("text", mailTemplate.getProperty(textKey));
entry.put("locale", mailTemplate.getProperty(localeKey));
entry.put("visibleToAuthenticatedUsers", mailTemplate.getProperty(MailTemplate.visibleToAuthenticatedUsers));
entry.put("visibleToPublicUsers", mailTemplate.getProperty(MailTemplate.visibleToPublicUsers));
}
tx.success();
}
try (final Writer fos = new OutputStreamWriter(new FileOutputStream(target.toFile()))) {
getGson().toJson(mailTemplates, fos);
} catch (IOException ioex) {
logger.warn("", ioex);
}
}
use of org.structr.core.entity.MailTemplate in project structr by structr.
the class GraphQLTest method testAdvancedQueries.
@Test
public void testAdvancedQueries() {
final List<MailTemplate> templates = new LinkedList<>();
final List<Principal> team = new LinkedList<>();
Group group = null;
try (final Tx tx = app.tx()) {
final PropertyKey<List> membersKey = StructrApp.key(Group.class, "members");
team.add(app.create(Principal.class, new NodeAttribute<>(Principal.name, "Axel")));
team.add(app.create(Principal.class, new NodeAttribute<>(Principal.name, "Christian")));
team.add(app.create(Principal.class, new NodeAttribute<>(Principal.name, "Christian")));
team.add(app.create(Principal.class, new NodeAttribute<>(Principal.name, "Inès")));
team.add(app.create(Principal.class, new NodeAttribute<>(Principal.name, "Kai")));
team.add(app.create(Principal.class, new NodeAttribute<>(Principal.name, "Lukas")));
team.add(app.create(Principal.class, new NodeAttribute<>(Principal.name, "Michael")));
team.add(app.create(Principal.class, new NodeAttribute<>(Principal.name, "Susanne")));
team.add(app.create(Principal.class, new NodeAttribute<>(Principal.name, "Tobias")));
group = app.create(Group.class, new NodeAttribute<>(Group.name, "Structr Team"), new NodeAttribute<>(membersKey, team));
app.create(Group.class, new NodeAttribute<>(Group.name, "All teams"), new NodeAttribute<>(membersKey, Arrays.asList(group)));
templates.add(app.create(MailTemplate.class, new NodeAttribute<>(StructrApp.key(MailTemplate.class, "text"), "MailTemplate4"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "locale"), "de_DE"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "name"), "zrtsga"), new NodeAttribute<>(AbstractNode.owner, team.get(2))));
templates.add(app.create(MailTemplate.class, new NodeAttribute<>(StructrApp.key(MailTemplate.class, "text"), "MailTemplate2"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "locale"), "de_DE"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "name"), "lertdf"), new NodeAttribute<>(AbstractNode.owner, team.get(0))));
templates.add(app.create(MailTemplate.class, new NodeAttribute<>(StructrApp.key(MailTemplate.class, "text"), "MailTemplate5"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "locale"), "de_DE"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "name"), "tzegsg"), new NodeAttribute<>(AbstractNode.owner, team.get(3))));
templates.add(app.create(MailTemplate.class, new NodeAttribute<>(StructrApp.key(MailTemplate.class, "text"), "MailTemplate3"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "locale"), "de_DE"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "name"), "asgw"), new NodeAttribute<>(AbstractNode.owner, team.get(1))));
templates.add(app.create(MailTemplate.class, new NodeAttribute<>(StructrApp.key(MailTemplate.class, "text"), "MailTemplate6"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "locale"), "de_DE"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "name"), "dfjgr"), new NodeAttribute<>(AbstractNode.owner, team.get(4))));
templates.add(app.create(MailTemplate.class, new NodeAttribute<>(StructrApp.key(MailTemplate.class, "text"), "MailTemplate1"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "locale"), "de_DE"), new NodeAttribute<>(StructrApp.key(MailTemplate.class, "name"), "abcdef"), new NodeAttribute<>(AbstractNode.owner, team.get(0))));
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
}
RestAssured.basePath = "/structr/graphql";
{
final Map<String, Object> result = fetchGraphQL("{ Principal(id: \"" + team.get(0).getUuid() + "\") { id, type, name } }");
assertMapPathValueIs(result, "Principal.#", 1);
assertMapPathValueIs(result, "Principal.0.id", team.get(0).getUuid());
assertMapPathValueIs(result, "Principal.0.type", "Principal");
assertMapPathValueIs(result, "Principal.0.name", "Axel");
}
{
final Map<String, Object> result = fetchGraphQL("{ Principal(name: \"Axel\") { name } }");
assertMapPathValueIs(result, "Principal.#", 1);
assertMapPathValueIs(result, "Principal.0.name", "Axel");
assertMapPathValueIs(result, "Principal.0.type", null);
assertMapPathValueIs(result, "Principal.0.id", null);
}
{
final Map<String, Object> result = fetchGraphQL("{ Principal { name(_equals: \"Axel\") } }");
assertMapPathValueIs(result, "Principal.#", 1);
assertMapPathValueIs(result, "Principal.0.name", "Axel");
assertMapPathValueIs(result, "Principal.0.type", null);
assertMapPathValueIs(result, "Principal.0.id", null);
}
{
final Map<String, Object> result = fetchGraphQL("{ Principal { name(_contains: \"a\", _contains: \"l\", _conj: \"and\") } }");
assertMapPathValueIs(result, "Principal.#", 4);
assertMapPathValueIs(result, "Principal.0.name", "All teams");
assertMapPathValueIs(result, "Principal.1.name", "Axel");
assertMapPathValueIs(result, "Principal.2.name", "Lukas");
assertMapPathValueIs(result, "Principal.3.name", "Michael");
}
{
final Map<String, Object> result = fetchGraphQL("{ Group(_pageSize: 1) { name }, Principal(_pageSize: 2, _page: 2) { name(_contains: \"i\") } }");
assertMapPathValueIs(result, "Group.#", 1);
assertMapPathValueIs(result, "Group.0.name", "All teams");
assertMapPathValueIs(result, "Principal.#", 2);
assertMapPathValueIs(result, "Principal.0.name", "Inès");
assertMapPathValueIs(result, "Principal.1.name", "Kai");
}
{
final Map<String, Object> result = fetchGraphQL("{ Group { name, members(_pageSize: 2, _page: 2) { name }}}");
assertMapPathValueIs(result, "Group.#", 2);
assertMapPathValueIs(result, "Group.0.name", "All teams");
assertMapPathValueIs(result, "Group.0.members", new LinkedList<>());
assertMapPathValueIs(result, "Group.1.name", "Structr Team");
assertMapPathValueIs(result, "Group.1.members.#", 2);
assertMapPathValueIs(result, "Group.1.members.0.name", "Christian");
assertMapPathValueIs(result, "Group.1.members.1.name", "Inès");
}
{
final Map<String, Object> result = fetchGraphQL("{ Group { name, members(_sort: \"name\") { name }}}");
assertMapPathValueIs(result, "Group.#", 2);
assertMapPathValueIs(result, "Group.0.name", "All teams");
assertMapPathValueIs(result, "Group.0.members.#", 1);
assertMapPathValueIs(result, "Group.1.name", "Structr Team");
assertMapPathValueIs(result, "Group.1.members.#", 9);
assertMapPathValueIs(result, "Group.1.members.0.name", "Axel");
assertMapPathValueIs(result, "Group.1.members.1.name", "Christian");
assertMapPathValueIs(result, "Group.1.members.2.name", "Christian");
assertMapPathValueIs(result, "Group.1.members.3.name", "Inès");
assertMapPathValueIs(result, "Group.1.members.4.name", "Kai");
assertMapPathValueIs(result, "Group.1.members.5.name", "Lukas");
assertMapPathValueIs(result, "Group.1.members.6.name", "Michael");
assertMapPathValueIs(result, "Group.1.members.7.name", "Susanne");
assertMapPathValueIs(result, "Group.1.members.8.name", "Tobias");
}
{
final Map<String, Object> result = fetchGraphQL("{ Group { name, members(_sort: \"name\", _desc: true) { name }}}");
assertMapPathValueIs(result, "Group.#", 2);
assertMapPathValueIs(result, "Group.0.name", "All teams");
assertMapPathValueIs(result, "Group.0.members.#", 1);
assertMapPathValueIs(result, "Group.1.name", "Structr Team");
assertMapPathValueIs(result, "Group.1.members.#", 9);
assertMapPathValueIs(result, "Group.1.members.8.name", "Axel");
assertMapPathValueIs(result, "Group.1.members.7.name", "Christian");
assertMapPathValueIs(result, "Group.1.members.6.name", "Christian");
assertMapPathValueIs(result, "Group.1.members.5.name", "Inès");
assertMapPathValueIs(result, "Group.1.members.4.name", "Kai");
assertMapPathValueIs(result, "Group.1.members.3.name", "Lukas");
assertMapPathValueIs(result, "Group.1.members.2.name", "Michael");
assertMapPathValueIs(result, "Group.1.members.1.name", "Susanne");
assertMapPathValueIs(result, "Group.1.members.0.name", "Tobias");
}
{
final Map<String, Object> result = fetchGraphQL("{ Group { members { name(_contains: \"k\", _contains: \"l\", _conj: \"and\") }}}");
assertMapPathValueIs(result, "Group.#", 2);
assertMapPathValueIs(result, "Group.0.name", null);
assertMapPathValueIs(result, "Group.0.members", new LinkedList<>());
assertMapPathValueIs(result, "Group.1.members.0.name", "Lukas");
assertMapPathValueIs(result, "Group.1.members.1", null);
}
{
final Map<String, Object> result = fetchGraphQL("{ Group { members { name(_contains: \"k\", _contains: \"l\", _conj: \"or\") }}}");
assertMapPathValueIs(result, "Group.#", 2);
assertMapPathValueIs(result, "Group.0.name", null);
assertMapPathValueIs(result, "Group.0.members", new LinkedList<>());
assertMapPathValueIs(result, "Group.1.members.#", 4);
assertMapPathValueIs(result, "Group.1.members.0.name", "Axel");
assertMapPathValueIs(result, "Group.1.members.1.name", "Kai");
assertMapPathValueIs(result, "Group.1.members.2.name", "Lukas");
assertMapPathValueIs(result, "Group.1.members.3.name", "Michael");
}
{
final Map<String, Object> result = fetchGraphQL("{ MailTemplate { id, type, text(_contains: \"2\"), owner(_equals: { name: \"Axel\"}) { name } }}");
assertMapPathValueIs(result, "MailTemplate.#", 1);
assertMapPathValueIs(result, "MailTemplate.0.id", templates.get(1).getUuid());
assertMapPathValueIs(result, "MailTemplate.0.type", "MailTemplate");
assertMapPathValueIs(result, "MailTemplate.0.text", "MailTemplate2");
assertMapPathValueIs(result, "MailTemplate.0.name", null);
assertMapPathValueIs(result, "MailTemplate.0.owner.name", "Axel");
}
{
final Map<String, Object> result = fetchGraphQL("{ MailTemplate(_sort: \"owner.name\") { name, owner { name }}}");
assertMapPathValueIs(result, "MailTemplate.#", 6);
assertMapPathValueIs(result, "MailTemplate.0.name", "abcdef");
assertMapPathValueIs(result, "MailTemplate.0.owner.name", "Axel");
assertMapPathValueIs(result, "MailTemplate.1.name", "lertdf");
assertMapPathValueIs(result, "MailTemplate.1.owner.name", "Axel");
assertMapPathValueIs(result, "MailTemplate.2.name", "asgw");
assertMapPathValueIs(result, "MailTemplate.2.owner.name", "Christian");
assertMapPathValueIs(result, "MailTemplate.3.name", "zrtsga");
assertMapPathValueIs(result, "MailTemplate.3.owner.name", "Christian");
assertMapPathValueIs(result, "MailTemplate.4.name", "tzegsg");
assertMapPathValueIs(result, "MailTemplate.4.owner.name", "Inès");
assertMapPathValueIs(result, "MailTemplate.5.name", "dfjgr");
assertMapPathValueIs(result, "MailTemplate.5.owner.name", "Kai");
}
{
final Map<String, Object> result = fetchGraphQL("{ Group { name, members(_sort: \"name\", _desc: true) { name }}}");
assertMapPathValueIs(result, "Group.#", 2);
assertMapPathValueIs(result, "Group.0.name", "All teams");
assertMapPathValueIs(result, "Group.0.members.#", 1);
assertMapPathValueIs(result, "Group.1.name", "Structr Team");
assertMapPathValueIs(result, "Group.1.members.#", 9);
assertMapPathValueIs(result, "Group.1.members.8.name", "Axel");
assertMapPathValueIs(result, "Group.1.members.7.name", "Christian");
assertMapPathValueIs(result, "Group.1.members.6.name", "Christian");
assertMapPathValueIs(result, "Group.1.members.5.name", "Inès");
assertMapPathValueIs(result, "Group.1.members.4.name", "Kai");
assertMapPathValueIs(result, "Group.1.members.3.name", "Lukas");
assertMapPathValueIs(result, "Group.1.members.2.name", "Michael");
assertMapPathValueIs(result, "Group.1.members.1.name", "Susanne");
assertMapPathValueIs(result, "Group.1.members.0.name", "Tobias");
}
}
use of org.structr.core.entity.MailTemplate in project structr by structr.
the class RegistrationResource method getTemplateText.
private String getTemplateText(final TemplateKey key, final String defaultValue, final String localeString) {
try {
final Query<MailTemplate> query = StructrApp.getInstance().nodeQuery(MailTemplate.class).andName(key.name());
if (localeString != null) {
query.and("locale", localeString);
}
MailTemplate template = query.getFirst();
if (template != null) {
final String text = template.getProperty("text");
return text != null ? text : defaultValue;
} else {
return defaultValue;
}
} catch (FrameworkException ex) {
LoggerFactory.getLogger(RegistrationResource.class.getName()).warn("Could not get mail template for key " + key, ex);
}
return null;
}
use of org.structr.core.entity.MailTemplate in project structr by structr.
the class ResetPasswordResource method getTemplateText.
private String getTemplateText(final TemplateKey key, final String defaultValue, final String localeString, final String confKey) {
try {
final Query<MailTemplate> query = StructrApp.getInstance().nodeQuery(MailTemplate.class).andName(key.name());
if (localeString != null) {
query.and("locale", localeString);
}
MailTemplate template = query.getFirst();
if (template != null) {
final String text = template.getProperty("text");
return text != null ? text : defaultValue;
} else {
return defaultValue;
}
} catch (FrameworkException ex) {
LoggerFactory.getLogger(ResetPasswordResource.class.getName()).warn("Could not get mail template for key " + key, ex);
}
return null;
}
Aggregations