Search in sources :

Example 1 with MailTemplate

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.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) MailTemplate(org.structr.core.entity.MailTemplate) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 2 with MailTemplate

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);
    }
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) Tx(org.structr.core.graph.Tx) IOException(java.io.IOException) TreeMap(java.util.TreeMap) LinkedList(java.util.LinkedList) FileOutputStream(java.io.FileOutputStream) MailTemplate(org.structr.core.entity.MailTemplate) OutputStreamWriter(java.io.OutputStreamWriter) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PropertyMap(org.structr.core.property.PropertyMap) TreeMap(java.util.TreeMap) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) FileWriter(java.io.FileWriter)

Example 3 with MailTemplate

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");
    }
}
Also used : Group(org.structr.core.entity.Group) NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) LinkedList(java.util.LinkedList) MailTemplate(org.structr.core.entity.MailTemplate) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) Principal(org.structr.core.entity.Principal) Test(org.junit.Test) StructrGraphQLTest(org.structr.rest.common.StructrGraphQLTest)

Example 4 with MailTemplate

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;
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) MailTemplate(org.structr.core.entity.MailTemplate)

Example 5 with MailTemplate

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;
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) MailTemplate(org.structr.core.entity.MailTemplate)

Aggregations

MailTemplate (org.structr.core.entity.MailTemplate)5 FrameworkException (org.structr.common.error.FrameworkException)4 Tx (org.structr.core.graph.Tx)3 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 Test (org.junit.Test)2 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 Group (org.structr.core.entity.Group)1 Principal (org.structr.core.entity.Principal)1 NodeAttribute (org.structr.core.graph.NodeAttribute)1