001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.causeway.viewer.commons.applib.services.userprof; 020 021import java.io.Serializable; 022import java.net.URL; 023import java.util.Optional; 024 025import org.apache.causeway.applib.services.user.UserMemento; 026import org.apache.causeway.applib.services.user.UserService; 027 028import lombok.AllArgsConstructor; 029import lombok.Data; 030import lombok.NoArgsConstructor; 031 032/** 033 * Represents the currently logged in user (or, possibly, the user being 034 * impersonated). 035 * 036 * @since 2.0 {@index} 037 */ 038@Data 039@AllArgsConstructor(staticName = "of") 040@NoArgsConstructor 041public class UserProfileUiModel implements Serializable { 042 043 private static final long serialVersionUID = 1L; 044 045 /** 046 * Returns an alternate name for the current user, typically for use on the 047 * viewer's menu bar to identify the currently logged in user. 048 * 049 * <p> 050 * For example, In the Wicket viewer, used as the menu name of the 051 * {@link org.apache.causeway.applib.annotation.DomainServiceLayout.MenuBar#TERTIARY tertiary} 052 * "Me" menu bar. 053 * </p> 054 * 055 * <p> 056 * If returns <tt>null</tt>, then the current user name is used instead. 057 * </p> 058 */ 059 private String userProfileName; 060 061 /** 062 * The {@link UserMemento}, as provided by {@link UserService#currentUser()}. 063 * 064 * <p> 065 * Will return null if anonymous. 066 * </p> 067 */ 068 private UserMemento userMemento; 069 070 public Optional<UserMemento> userMemento() { 071 return Optional.ofNullable(getUserMemento()); 072 } 073 public Optional<URL> avatarUrl() { 074 return userMemento().map(UserMemento::getAvatarUrl); 075 } 076}