/**
* Adds country to all relevant beans and sends it to the EJB. A redirect
- * should happen after successfull creation.
+ * should happen after successful creation.
* <p>
* @return Redirect outcome
* <p>
*/
public String addCountry () {
// Create new country object
- final Country country = new CountryData();
-
- // Add all data
- country.setCountryAbroadDialPrefix(this.getCountryAbroadDialPrefix());
- country.setCountryCode(this.getCountryCode());
- country.setCountryExternalDialPrefix(this.getCountryExternalDialPrefix());
- country.setCountryI18nKey(this.getCountryI18nKey());
- country.setCountryIsLocalPrefixRequired(this.getCountryIsLocalPrefixRequired());
- country.setCountryPhoneCode(this.getCountryPhoneCode());
+ final Country country = new CountryData(
+ this.getCountryAbroadDialPrefix(),
+ this.getCountryCode(),
+ this.getCountryExternalDialPrefix(),
+ this.getCountryI18nKey(),
+ this.getCountryIsLocalPrefixRequired(),
+ this.getCountryPhoneCode()
+ );
// Does it already exist?
if (this.isCountryAdded(country)) {
throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
}
- // All fine, so update list
+ // Set user id again
+ this.setUserId(event.getLinkedUser().getUserId());
+ }
+
+ /**
+ * Event observer for when a bean helper has successfully created a user
+ * instance, means the user exists. If the user does not exist, this event
+ * should not fire but instead a proper exception must be thrown.
+ * <p>
+ * @param event User created event
+ */
+ public void afterCreatedUserEvent (@Observes final ObservableCreatedUserEvent event) {
+ // Is the instance valid?
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getCreatedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.createdUser is null"); //NOI18N
+ } else if (event.getCreatedUser().getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.createdUser.userId is null"); //NOI18N
+ } else if (event.getCreatedUser().getUserId() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("event.createdUser.userId={0} is not valid", event.getCreatedUser().getUserId())); //NOI18N
+ }
+
+ // Get user instance
+ final User user = event.getCreatedUser();
+
+ // Set all fields here
+ this.copyToUser(user);
+ }
+
+ /**
+ * Event observer for logged-in user
+ * <p>
+ * @param event Event instance
+ */
+ public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
+ // Event and contained entity instance should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getLoggedInUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.registeredUser is null"); //NOI18N
+ } else if (event.getLoggedInUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+ } else if (event.getLoggedInUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
+ }
+
+ // "Cache" user instance
+ final User user = event.getLoggedInUser();
+
+ // Copy all data to this bean
+ this.copyToUser(user);
+ }
+
+ /**
+ * Event observer for user password changes
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterUserPasswordChangedEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
+ // Is it valid?
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUserPassword() == null) {
+ // Throw NPE
+ throw new NullPointerException("event.userPassword is null"); //NOI18N
+ } else if (event.getUserPassword().isEmpty()) {
+ // Throw NPE
+ throw new IllegalArgumentException("event.userPassword is empty"); //NOI18N
+ }
+
+ // Set it here
+ this.setUserPassword(event.getUserPassword());
this.updatePasswordHistory(event.getPasswordHistory());
}
+ /**
+ * Event observer for new user registrations
+ * <p>
+ * @param event User registration event
+ */
+ public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
+ // Event and contained entity instance should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getRegisteredUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.registeredUser is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+ }
+
+ // Get user instance
+ final User registeredUser = event.getRegisteredUser();
+
+ // Copy all data from registered->user
+ this.copyToUser(registeredUser);
+
+ // Set user id again
+ this.setUserId(registeredUser.getUserId());
+ }
+
/**
* Logout for administrator area. If a logged-in user instance exists, it is
* being logged-out, too.
private void clear () {
// Clear all fields
this.setUserCurrentPassword(null);
+ this.setUserProfileMode(null);
+ }
+
+ /**
+ * Copies given user into the controller
+ * <p>
+ * @param user User instance
+ */
+ private void copyToUser (final User user) {
+ // Copy all fields:
+ // - base data
+ this.setUserId(user.getUserId());
+ this.setUserName(user.getUserName());
+ this.setUserProfileMode(user.getUserProfileMode());
}
/**