Search in sources :

Example 1 with UserProfileDTO

use of org.activityinfo.legacy.shared.model.UserProfileDTO in project activityinfo by bedatadriven.

the class GetUserProfileHandler method execute.

@Override
public void execute(final GetUserProfile command, ExecutionContext context, final AsyncCallback<UserProfileDTO> callback) {
    final int userId = command.getUserId();
    SqlQuery.select().appendColumn("u.name", "name").appendColumn("u.email", "email").appendColumn("u.organization", "organization").appendColumn("u.jobtitle", "jobtitle").appendColumn("u.locale", "locale").appendColumn("u.emailNotification", "emailNotification").from("userlogin", "u").where("u.userid").equalTo(userId).execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            SqlResultSetRowList list = results.getRows();
            if (list.isEmpty()) {
                callback.onFailure(new IllegalArgumentException("user " + userId + " not found"));
            }
            SqlResultSetRow row = list.get(0);
            UserProfileDTO dto = new UserProfileDTO(userId);
            dto.setName(row.getString("name"));
            dto.setEmail(row.getString("email"));
            dto.setOrganization(row.getString("organization"));
            dto.setJobtitle(row.getString("jobtitle"));
            dto.setLocale(row.getString("locale"));
            dto.setEmailNotification(row.getBoolean("emailNotification"));
            callback.onSuccess(dto);
        }
    });
}
Also used : UserProfileDTO(org.activityinfo.legacy.shared.model.UserProfileDTO)

Example 2 with UserProfileDTO

use of org.activityinfo.legacy.shared.model.UserProfileDTO in project activityinfo by bedatadriven.

the class UpdateUserProfileHandler method execute.

@Override
public void execute(final UpdateUserProfile command, ExecutionContext context, final AsyncCallback<VoidResult> callback) {
    // Users can ONLY update their own profile
    int userId = context.getUser().getId();
    UserProfileDTO model = command.getModel();
    SqlUpdate.update("userlogin").where("userId", userId).value("name", model.getName()).value("organization", model.getOrganization()).value("jobtitle", model.getJobtitle()).value("locale", validateLocale(model.getLocale())).value("emailNotification", model.isEmailNotification()).execute(context.getTransaction());
    callback.onSuccess(new VoidResult());
}
Also used : VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult) UserProfileDTO(org.activityinfo.legacy.shared.model.UserProfileDTO)

Example 3 with UserProfileDTO

use of org.activityinfo.legacy.shared.model.UserProfileDTO in project activityinfo by bedatadriven.

the class UserProfilePage method bindProfile.

private void bindProfile() {
    userProfile = new UserProfileDTO();
    AuthenticatedUser user = new ClientSideAuthProvider().get();
    dispatcher.execute(new GetUserProfile(user.getUserId()), new AsyncCallback<UserProfileDTO>() {

        @Override
        public void onFailure(Throwable caught) {
            Log.error("error binding profile", caught);
            MessageBox.alert(I18N.CONSTANTS.serverError(), caught.getMessage(), null);
        }

        @Override
        public void onSuccess(UserProfileDTO userProfileDTO) {
            userProfile = userProfileDTO;
            binding.bind(userProfile);
            UserProfilePage.this.show();
            maybeShowSwitchLocaleLink();
        }
    });
}
Also used : ClientSideAuthProvider(org.activityinfo.ui.client.inject.ClientSideAuthProvider) GetUserProfile(org.activityinfo.legacy.shared.command.GetUserProfile) UserProfileDTO(org.activityinfo.legacy.shared.model.UserProfileDTO) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser)

Aggregations

UserProfileDTO (org.activityinfo.legacy.shared.model.UserProfileDTO)3 AuthenticatedUser (org.activityinfo.legacy.shared.AuthenticatedUser)1 GetUserProfile (org.activityinfo.legacy.shared.command.GetUserProfile)1 VoidResult (org.activityinfo.legacy.shared.command.result.VoidResult)1 ClientSideAuthProvider (org.activityinfo.ui.client.inject.ClientSideAuthProvider)1