Search in sources :

Example 6 with UnlicensedException

use of org.structr.common.error.UnlicensedException in project structr by structr.

the class LocalizationTest method testLocalizationWithoutDomain.

@Test
public void testLocalizationWithoutDomain() {
    final PropertyKey<String> localizedName = StructrApp.key(Localization.class, "localizedName");
    final PropertyKey<String> domain = StructrApp.key(Localization.class, "domain");
    final PropertyKey<String> locale = StructrApp.key(Localization.class, "locale");
    // create
    try (final Tx tx = app.tx()) {
        app.create(Localization.class, new NodeAttribute<>(Localization.name, "test1"), new NodeAttribute<>(locale, "de"), new NodeAttribute<>(localizedName, "test1-de-no_domain"));
        app.create(Localization.class, new NodeAttribute<>(Localization.name, "test2"), new NodeAttribute<>(locale, "de"), new NodeAttribute<>(domain, "ExistingDomain"), new NodeAttribute<>(localizedName, "test2-de-ExistingDomain"));
        app.create(Localization.class, new NodeAttribute<>(Localization.name, "test3"), new NodeAttribute<>(locale, "de_DE"), new NodeAttribute<>(localizedName, "test3-de_DE-no_domain"));
        app.create(Localization.class, new NodeAttribute<>(Localization.name, "test4"), new NodeAttribute<>(locale, "de_DE"), new NodeAttribute<>(domain, "ExistingDomain"), new NodeAttribute<>(localizedName, "test4-de_DE-ExistingDomain"));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final ActionContext ctx = new ActionContext(securityContext);
        ctx.setLocale(new Locale("de"));
        assertEquals("Invalid localization result", "test1-de-no_domain", Scripting.evaluate(ctx, null, "${localize('test1', 'ExistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test1-de-no_domain", Scripting.evaluate(ctx, null, "${localize('test1', 'NonexistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test1-de-no_domain", Scripting.evaluate(ctx, null, "${localize('test1')}", "test"));
        assertEquals("Invalid localization result", "test2-de-ExistingDomain", Scripting.evaluate(ctx, null, "${localize('test2', 'ExistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test2", Scripting.evaluate(ctx, null, "${localize('test2', 'NonexistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test2", Scripting.evaluate(ctx, null, "${localize('test2')}", "test"));
        assertEquals("Invalid localization result", "test3", Scripting.evaluate(ctx, null, "${localize('test3', 'ExistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test3", Scripting.evaluate(ctx, null, "${localize('test3', 'NonexistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test3", Scripting.evaluate(ctx, null, "${localize('test3')}", "test"));
        assertEquals("Invalid localization result", "test4", Scripting.evaluate(ctx, null, "${localize('test4', 'ExistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test4", Scripting.evaluate(ctx, null, "${localize('test4', 'NonexistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test4", Scripting.evaluate(ctx, null, "${localize('test4')}", "test"));
        tx.success();
    } catch (UnlicensedException | FrameworkException fex) {
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final ActionContext ctx = new ActionContext(securityContext);
        ctx.setLocale(new Locale("de", "DE"));
        assertEquals("Invalid localization result", "test1-de-no_domain", Scripting.evaluate(ctx, null, "${localize('test1', 'ExistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test1-de-no_domain", Scripting.evaluate(ctx, null, "${localize('test1', 'NonexistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test1-de-no_domain", Scripting.evaluate(ctx, null, "${localize('test1')}", "test"));
        assertEquals("Invalid localization result", "test2-de-ExistingDomain", Scripting.evaluate(ctx, null, "${localize('test2', 'ExistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test2", Scripting.evaluate(ctx, null, "${localize('test2', 'NonexistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test2", Scripting.evaluate(ctx, null, "${localize('test2')}", "test"));
        assertEquals("Invalid localization result", "test3-de_DE-no_domain", Scripting.evaluate(ctx, null, "${localize('test3', 'ExistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test3-de_DE-no_domain", Scripting.evaluate(ctx, null, "${localize('test3', 'NonexistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test3-de_DE-no_domain", Scripting.evaluate(ctx, null, "${localize('test3')}", "test"));
        assertEquals("Invalid localization result", "test4-de_DE-ExistingDomain", Scripting.evaluate(ctx, null, "${localize('test4', 'ExistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test4", Scripting.evaluate(ctx, null, "${localize('test4', 'NonexistingDomain')}", "test"));
        assertEquals("Invalid localization result", "test4", Scripting.evaluate(ctx, null, "${localize('test4')}", "test"));
        tx.success();
    } catch (UnlicensedException | FrameworkException fex) {
        fail("Unexpected exception.");
    }
}
Also used : Locale(java.util.Locale) UnlicensedException(org.structr.common.error.UnlicensedException) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ActionContext(org.structr.schema.action.ActionContext) Test(org.junit.Test) StructrTest(org.structr.common.StructrTest)

Example 7 with UnlicensedException

use of org.structr.common.error.UnlicensedException in project structr by structr.

the class AuthHelper method doLogin.

public static void doLogin(final HttpServletRequest request, final Principal user) throws FrameworkException {
    HttpSession session = request.getSession(false);
    if (session == null) {
        session = SessionHelper.newSession(request);
    }
    SessionHelper.clearInvalidSessions(user);
    // We need a session to login a user
    if (session != null) {
        SessionHelper.clearSession(session.getId());
        user.addSessionId(session.getId());
        try {
            Actions.call(Actions.NOTIFICATION_LOGIN, user);
        } catch (UnlicensedException ex) {
            ex.log(logger);
        }
    }
}
Also used : UnlicensedException(org.structr.common.error.UnlicensedException) HttpSession(javax.servlet.http.HttpSession)

Example 8 with UnlicensedException

use of org.structr.common.error.UnlicensedException in project structr by structr.

the class ScriptingTest method testEnumPropertyGet.

@Test
public void testEnumPropertyGet() {
    // setup phase
    try (final Tx tx = app.tx()) {
        final ActionContext actionContext = new ActionContext(securityContext);
        final TestOne context = app.create(TestOne.class);
        Scripting.evaluate(actionContext, context, "${{ var e = Structr.get('this'); e.anEnum = 'One'; }}", "test");
        assertEquals("Invalid enum get result", "One", Scripting.evaluate(actionContext, context, "${{ var e = Structr.get('this'); return e.anEnum; }}", "test"));
        assertEquals("Invaliid Javascript enum comparison result", true, Scripting.evaluate(actionContext, context, "${{ var e = Structr.get('this'); return e.anEnum == 'One'; }}", "test"));
        tx.success();
    } catch (UnlicensedException | FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
}
Also used : UnlicensedException(org.structr.common.error.UnlicensedException) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) ActionContext(org.structr.schema.action.ActionContext) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 9 with UnlicensedException

use of org.structr.common.error.UnlicensedException in project structr by structr.

the class ScriptingTest method testWrappingUnwrapping.

@Test
public void testWrappingUnwrapping() {
    // setup phase
    try (final Tx tx = app.tx()) {
        final ActionContext actionContext = new ActionContext(securityContext);
        final TestOne context = app.create(TestOne.class);
        Scripting.evaluate(actionContext, context, "${{ Structr.create('Group', { name: 'Group1' } ); }}", "test");
        Scripting.evaluate(actionContext, context, "${{ Structr.create('Group', 'name', 'Group2'); }}", "test");
        assertEquals("Invalid unwrapping result", 2, app.nodeQuery(Group.class).getAsList().size());
        tx.success();
    } catch (UnlicensedException | FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
}
Also used : Group(org.structr.core.entity.Group) UnlicensedException(org.structr.common.error.UnlicensedException) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) ActionContext(org.structr.schema.action.ActionContext) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 10 with UnlicensedException

use of org.structr.common.error.UnlicensedException in project structr by structr.

the class ScriptingTest method testQuotes.

@Test
public void testQuotes() {
    try (final Tx tx = app.tx()) {
        final ActionContext actionContext = new ActionContext(securityContext);
        Scripting.evaluate(actionContext, app.create(TestOne.class), "${{\n // \"test\n}}", "test");
        tx.success();
    } catch (UnlicensedException | FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
}
Also used : UnlicensedException(org.structr.common.error.UnlicensedException) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) ActionContext(org.structr.schema.action.ActionContext) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Aggregations

UnlicensedException (org.structr.common.error.UnlicensedException)17 FrameworkException (org.structr.common.error.FrameworkException)13 Tx (org.structr.core.graph.Tx)11 ActionContext (org.structr.schema.action.ActionContext)11 Test (org.junit.Test)10 StructrTest (org.structr.common.StructrTest)10 TestOne (org.structr.core.entity.TestOne)7 GraphObject (org.structr.core.GraphObject)6 LinkedList (java.util.LinkedList)3 Principal (org.structr.core.entity.Principal)3 NodeInterface (org.structr.core.graph.NodeInterface)3 Date (java.util.Date)2 List (java.util.List)2 Locale (java.util.Locale)2 Group (org.structr.core.entity.Group)2 TestFour (org.structr.core.entity.TestFour)2 TestSix (org.structr.core.entity.TestSix)2 TestThree (org.structr.core.entity.TestThree)2 TestTwo (org.structr.core.entity.TestTwo)2 PropertyMap (org.structr.core.property.PropertyMap)2