- @Override
- public User addUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("addUser: user={0} - CALLED!", user)); //NOI18N
-
- // user should not be null
- if (null == user) {
- // Abort here
- throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserId() != null) {
- // Not allowed here
- throw new IllegalStateException(MessageFormat.format("user.userId must be null, is: {0}", user.getUserId())); //NOI18N
- }
-
- // Check if user is registered
- if (this.registerBean.isUserNameRegistered(user)) {
- // Abort here
- throw new UserNameAlreadyRegisteredException(user);
- } else if (this.registerBean.isEmailAddressRegistered(user)) {
- // Abort here
- throw new EmailAddressAlreadyRegisteredException(user);
- }
-
- // Set created timestamp
- user.setUserCreated(new GregorianCalendar());
- user.getUserContact().setContactCreated(new GregorianCalendar());
-
- // Get all phone instances
- DialableLandLineNumber landLineNumber = user.getUserContact().getContactLandLineNumber();
- DialableFaxNumber faxNumber = user.getUserContact().getContactFaxNumber();
- DialableCellphoneNumber cellphoneNumber = user.getUserContact().getContactCellphoneNumber();
-
- // Is a phone number instance set?
- if (landLineNumber instanceof DialableLandLineNumber) {
- // Set created timestamp
- landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
- }
-
- // Is a fax number instance set?
- if (faxNumber instanceof DialableFaxNumber) {
- // Set created timestamp
- faxNumber.setPhoneEntryCreated(new GregorianCalendar());
- }
-
- // Is a mobile number instance set?
- if (cellphoneNumber instanceof DialableCellphoneNumber) {
- // Set created timestamp
- cellphoneNumber.setPhoneEntryCreated(new GregorianCalendar());
- }
-
- // Persist it
- this.getEntityManager().persist(user);
-
- // Flush to get id back
- this.getEntityManager().flush();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("addUser: user={0},user.id={1} - EXIT!", user, user.getUserId())); //NOI18N
-
- // Return it
- return user;
- }
-