Search in sources :

Example 1 with EzySimpleUserAccessedAppEvent

use of com.tvd12.ezyfoxserver.event.EzySimpleUserAccessedAppEvent in project ezyfox-server by youngmonkeys.

the class EzySimpleUserAccessedAppEventTest method test.

@Test
public void test() {
    // given
    EzyUser user = newUser();
    EzySimpleUserAccessedAppEvent underTest = new EzySimpleUserAccessedAppEvent(user);
    // when
    EzyUser actual = underTest.getUser();
    // then
    Asserts.assertEquals(actual, user);
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzySimpleUserAccessedAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessedAppEvent) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 2 with EzySimpleUserAccessedAppEvent

use of com.tvd12.ezyfoxserver.event.EzySimpleUserAccessedAppEvent in project ezyfox-server by youngmonkeys.

the class EzyAccessAppController method doHandle.

protected void doHandle(EzyServerContext ctx, EzyAccessAppRequest request) {
    EzyUser user = request.getUser();
    int zoneId = user.getZoneId();
    EzyAccessAppParams params = request.getParams();
    EzyZoneContext zoneContext = ctx.getZoneContext(zoneId);
    EzyAppContext appContext = zoneContext.getAppContext(params.getAppName());
    EzyApplication app = appContext.getApp();
    EzyAppSetting appSetting = app.getSetting();
    EzyAppUserManager appUserManger = app.getUserManager();
    EzySession session = request.getSession();
    String username = user.getName();
    Lock lock = appUserManger.getLock(username);
    lock.lock();
    try {
        boolean hasNotAccessed = !appUserManger.containsUser(user);
        if (hasNotAccessed) {
            checkAppUserMangerAvailable(appUserManger);
        }
        EzyUserAccessAppEvent accessAppEvent = new EzySimpleUserAccessAppEvent(user);
        appContext.handleEvent(EzyEventType.USER_ACCESS_APP, accessAppEvent);
        if (hasNotAccessed) {
            addUser(appUserManger, user, appSetting);
            EzyUserAccessedAppEvent accessedAppEvent = new EzySimpleUserAccessedAppEvent(user);
            appContext.handleEvent(EzyEventType.USER_ACCESSED_APP, accessedAppEvent);
        }
        EzyArray output = accessAppEvent.getOutput();
        EzyResponse accessAppResponse = newAccessAppResponse(appSetting, output);
        ctx.send(accessAppResponse, session, false);
    } finally {
        lock.unlock();
        appUserManger.removeLock(username);
    }
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyAccessAppParams(com.tvd12.ezyfoxserver.request.EzyAccessAppParams) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzySimpleUserAccessedAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessedAppEvent) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Lock(java.util.concurrent.locks.Lock) EzyAppSetting(com.tvd12.ezyfoxserver.setting.EzyAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyUserAccessedAppEvent(com.tvd12.ezyfoxserver.event.EzyUserAccessedAppEvent) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzyUserAccessAppEvent) EzySimpleUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent)

Aggregations

EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)2 EzySimpleUserAccessedAppEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserAccessedAppEvent)2 EzyArray (com.tvd12.ezyfox.entity.EzyArray)1 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)1 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)1 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)1 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)1 EzySimpleUserAccessAppEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent)1 EzyUserAccessAppEvent (com.tvd12.ezyfoxserver.event.EzyUserAccessAppEvent)1 EzyUserAccessedAppEvent (com.tvd12.ezyfoxserver.event.EzyUserAccessedAppEvent)1 EzyAccessAppParams (com.tvd12.ezyfoxserver.request.EzyAccessAppParams)1 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)1 EzyAppSetting (com.tvd12.ezyfoxserver.setting.EzyAppSetting)1 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)1 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)1 Lock (java.util.concurrent.locks.Lock)1 Test (org.testng.annotations.Test)1