All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.knightsoftnet.validators.client.GwtpSpringSession Maven / Gradle / Ivy

Go to download

The GWT Bean Validators is a collection of JSR-303/JSR-349/JSR 380 bean validators. It can be used on server and with the help of GWT even on client side. This packages contains rest services and validator for phone numbers based on gwtp-rest dispatcher and spring to reduce client side code.

There is a newer version: 2.3.2
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package de.knightsoftnet.validators.client;

import de.knightsoftnet.navigation.client.session.AbstractSession;
import de.knightsoftnet.navigation.shared.models.User;
import de.knightsoftnet.validators.client.services.UserRestServiceTemplate;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.dispatch.rest.client.RestDispatch;

import org.apache.commons.lang3.BooleanUtils;

/**
 * Session handler using spring rest service.
 * 
 * @author Manfred Tremmel
 *
 * @param  user data implementation
 */
public class GwtpSpringSession extends AbstractSession {
  private final RestDispatch dispatcher;
  private final UserRestServiceTemplate userService;

  /**
   * constructor with injected parameters.
   *
   * @param peventBus event bus
   */
  public GwtpSpringSession(final EventBus peventBus, final RestDispatch pdispatcher,
      final UserRestServiceTemplate puserService) {
    super(peventBus);
    this.dispatcher = pdispatcher;
    this.userService = puserService;
  }

  /**
   * read session data.
   */
  @Override
  public void readSessionData() {
    this.dispatcher.execute(this.userService.isCurrentUserLoggedIn(), new AsyncCallback() {

      @Override
      public void onFailure(final Throwable pcaught) {
        GWT.log("Error checking if user is logged in", pcaught);
      }

      @Override
      public void onSuccess(final Boolean presult) {
        if (BooleanUtils.isTrue(presult)) {
          // we do have a logged in user, read it
          GwtpSpringSession.this.dispatcher
              .execute(GwtpSpringSession.this.userService.getCurrentUser(), new AsyncCallback() {
                @Override
                public void onFailure(final Throwable pcaught) {
                  GWT.log("Error reading session user", pcaught);
                }

                @Override
                public void onSuccess(final T presult) {
                  GwtpSpringSession.this.setUser(presult);
                }
              });
        } else {
          GwtpSpringSession.this.setUser(null);
        }
      }

    });
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy