001// Generated by delombok at Mon Oct 12 23:00:28 BST 2020
002/*
003 *  Licensed to the Apache Software Foundation (ASF) under one
004 *  or more contributor license agreements.  See the NOTICE file
005 *  distributed with this work for additional information
006 *  regarding copyright ownership.  The ASF licenses this file
007 *  to you under the Apache License, Version 2.0 (the
008 *  "License"); you may not use this file except in compliance
009 *  with the License.  You may obtain a copy of the License at
010 *
011 *        http://www.apache.org/licenses/LICENSE-2.0
012 *
013 *  Unless required by applicable law or agreed to in writing,
014 *  software distributed under the License is distributed on an
015 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 *  KIND, either express or implied.  See the License for the
017 *  specific language governing permissions and limitations
018 *  under the License.
019 */
020package org.apache.isis.extensions.secman.api.events;
021
022import org.apache.isis.extensions.secman.api.user.AccountType;
023import org.apache.isis.extensions.secman.api.user.ApplicationUser;
024import lombok.NonNull;
025
026/**
027 * SecMan fires this event when a new user entity just got persisted.
028
029 * <p>
030
031 * Users may subscribe to this event in order to apply business 
032
033 * logic to the newly created user. eg. add default roles
034
035 * <p>
036
037 * <pre>
038
039 * &#64;Component
040
041 * public class Listener {
042
043 *     &#64;EventListener(UserCreatedEvent.class)
044
045 *     public void listenOn(UserCreatedEvent<String> event) {
046
047 *         // business logic ...
048
049 *     }
050
051 * }
052
053 *                     
054
055 * </pre>
056
057 * @since Jun 23, 2020
058 */
059public final class UserCreatedEvent {
060    @NonNull
061    private final ApplicationUser user;
062
063    // -- SHORTCUTS
064    public AccountType getAccountType() {
065        return user.getAccountType();
066    }
067
068    public String getUserName() {
069        return user.getUsername();
070    }
071
072    public boolean isDelegated() {
073        return getAccountType() != null && getAccountType().isDelegated();
074    }
075
076    @java.lang.SuppressWarnings("all")
077    private UserCreatedEvent(@NonNull final ApplicationUser user) {
078        if (user == null) {
079            throw new java.lang.NullPointerException("user is marked non-null but is null");
080        }
081        this.user = user;
082    }
083
084    @java.lang.SuppressWarnings("all")
085    public static UserCreatedEvent of(@NonNull final ApplicationUser user) {
086        return new UserCreatedEvent(user);
087    }
088
089    @NonNull
090    @java.lang.SuppressWarnings("all")
091    public ApplicationUser getUser() {
092        return this.user;
093    }
094
095    @java.lang.Override
096    @java.lang.SuppressWarnings("all")
097    public boolean equals(final java.lang.Object o) {
098        if (o == this) return true;
099        if (!(o instanceof UserCreatedEvent)) return false;
100        final UserCreatedEvent other = (UserCreatedEvent) o;
101        final java.lang.Object this$user = this.getUser();
102        final java.lang.Object other$user = other.getUser();
103        if (this$user == null ? other$user != null : !this$user.equals(other$user)) return false;
104        return true;
105    }
106
107    @java.lang.Override
108    @java.lang.SuppressWarnings("all")
109    public int hashCode() {
110        final int PRIME = 59;
111        int result = 1;
112        final java.lang.Object $user = this.getUser();
113        result = result * PRIME + ($user == null ? 43 : $user.hashCode());
114        return result;
115    }
116
117    @java.lang.Override
118    @java.lang.SuppressWarnings("all")
119    public java.lang.String toString() {
120        return "UserCreatedEvent(user=" + this.getUser() + ")";
121    }
122}