| package org.eclipse.osbp.authentication.account.entities; |
| |
| import java.util.ArrayList; |
| import java.util.Collections; |
| import java.util.List; |
| import javax.persistence.Column; |
| import javax.persistence.DiscriminatorValue; |
| import javax.persistence.Entity; |
| import javax.persistence.Id; |
| import javax.persistence.Index; |
| import javax.persistence.JoinColumn; |
| import javax.persistence.OneToMany; |
| import javax.persistence.PreRemove; |
| import javax.persistence.PreUpdate; |
| import javax.persistence.Table; |
| import javax.persistence.Transient; |
| import javax.validation.constraints.Pattern; |
| import org.eclipse.osbp.authentication.account.entities.UserAccountFilter; |
| import org.eclipse.osbp.dsl.common.datatypes.IEntity; |
| import org.eclipse.osbp.runtime.common.annotations.Dispose; |
| import org.eclipse.osbp.runtime.common.annotations.Properties; |
| import org.eclipse.osbp.runtime.common.annotations.Property; |
| import org.eclipse.osbp.runtime.jsr303.validation.common.ErrorSeverity; |
| import org.eclipse.persistence.annotations.Noncacheable; |
| |
| @Entity |
| @Table(name = "USER_ACCOUNT", indexes = @Index(name = "INDEX_USER_NAME", unique = true, columnList = "USER_NAME")) |
| @DiscriminatorValue(value = "USER_ACCOUNT") |
| @SuppressWarnings("all") |
| public class UserAccount implements IEntity { |
| @Transient |
| @Dispose |
| private boolean disposed; |
| |
| @Id |
| private String id = java.util.UUID.randomUUID().toString(); |
| |
| @Column(name = "EMAIL") |
| private String email; |
| |
| @Column(name = "USER_NAME", nullable = false) |
| private String userName; |
| |
| @Column(name = "PASSWORD") |
| private String password; |
| |
| @Column(name = "EXTRA_PASSWORD") |
| @Pattern(regexp = "[0-9]*", payload = ErrorSeverity.class) |
| private String extraPassword; |
| |
| @Column(name = "PASSWORD_RESET") |
| private boolean passwordReset; |
| |
| @Column(name = "POSITION") |
| @Properties(properties = @Property(key = "organization", value = "")) |
| private String position; |
| |
| @Column(name = "DEFAULT_PERSPECTIVE") |
| @Properties(properties = @Property(key = "perspective", value = "")) |
| private String defaultPerspective; |
| |
| @Column(name = "ENABLED") |
| private boolean enabled; |
| |
| @Column(name = "LOCKED") |
| private boolean locked; |
| |
| @Column(name = "SUPERUSER") |
| private boolean superuser; |
| |
| @Column(name = "SUPERVISOR") |
| private boolean supervisor; |
| |
| @Column(name = "FORCE_PWD_CHANGE") |
| private boolean forcePwdChange; |
| |
| @Column(name = "NOT_REGISTERED") |
| private boolean notRegistered; |
| |
| @Column(name = "FAILED_ATTEMPT") |
| private int failedAttempt; |
| |
| @Column(name = "SUCCESSFUL_ATTEMPT") |
| private int successfulAttempt; |
| |
| @Column(name = "COOKIE_HASH_CODE") |
| private int cookieHashCode; |
| |
| @Column(name = "LOCALE_TAG") |
| private String localeTag; |
| |
| @Column(name = "PROFILEIMAGE") |
| @Properties(properties = @Property(key = "Blob", value = "2")) |
| private String profileimage; |
| |
| @Column(name = "LAYOUTING_STRATEGY") |
| private String layoutingStrategy; |
| |
| @Column(name = "FOCUSING_STRATEGY") |
| private String focusingStrategy; |
| |
| @Column(name = "THEME") |
| @Properties(properties = @Property(key = "theme", value = "")) |
| private String theme; |
| |
| @Column(name = "PRINT_SERVICE") |
| @Properties(properties = @Property(key = "printservice", value = "")) |
| private String printService; |
| |
| @JoinColumn(name = "USER_ACCOUNT_FILTER_ID") |
| @OneToMany(mappedBy = "userAccount") |
| @Noncacheable |
| private List<UserAccountFilter> userAccountFilter; |
| |
| /** |
| * @return true, if the object is disposed. |
| * Disposed means, that it is prepared for garbage collection and may not be used anymore. |
| * Accessing objects that are already disposed will cause runtime exceptions. |
| * |
| */ |
| @Dispose |
| public boolean isDisposed() { |
| return this.disposed; |
| } |
| |
| /** |
| * Checks whether the object is disposed. |
| * @throws RuntimeException if the object is disposed. |
| */ |
| private void checkDisposed() { |
| if (isDisposed()) { |
| throw new RuntimeException("Object already disposed: " + this); |
| } |
| } |
| |
| /** |
| * Calling dispose will destroy that instance. The internal state will be |
| * set to 'disposed' and methods of that object must not be used anymore. |
| * Each call will result in runtime exceptions.<br> |
| * If this object keeps composition containments, these will be disposed too. |
| * So the whole composition containment tree will be disposed on calling this method. |
| */ |
| @Dispose |
| public void dispose() { |
| if (isDisposed()) { |
| return; |
| } |
| disposed = true; |
| } |
| |
| /** |
| * @return Returns the id property or <code>null</code> if not present. |
| */ |
| public String getId() { |
| checkDisposed(); |
| return this.id; |
| } |
| |
| /** |
| * Sets the id property to this instance. |
| */ |
| public void setId(final String id) { |
| checkDisposed(); |
| this.id = id; |
| } |
| |
| /** |
| * @return Returns the email property or <code>null</code> if not present. |
| */ |
| public String getEmail() { |
| checkDisposed(); |
| return this.email; |
| } |
| |
| /** |
| * Sets the email property to this instance. |
| */ |
| public void setEmail(final String email) { |
| checkDisposed(); |
| this.email = email; |
| } |
| |
| /** |
| * @return Returns the <em>required</em> userName property. |
| */ |
| public String getUserName() { |
| checkDisposed(); |
| return this.userName; |
| } |
| |
| /** |
| * Sets the userName property to this instance. |
| */ |
| public void setUserName(final String userName) { |
| checkDisposed(); |
| this.userName = userName; |
| } |
| |
| /** |
| * @return Returns the password property or <code>null</code> if not present. |
| */ |
| public String getPassword() { |
| checkDisposed(); |
| return this.password; |
| } |
| |
| /** |
| * Sets the password property to this instance. |
| */ |
| public void setPassword(final String password) { |
| checkDisposed(); |
| this.password = password; |
| } |
| |
| /** |
| * @return Returns the extraPassword property or <code>null</code> if not present. |
| */ |
| public String getExtraPassword() { |
| checkDisposed(); |
| return this.extraPassword; |
| } |
| |
| /** |
| * Sets the extraPassword property to this instance. |
| */ |
| public void setExtraPassword(final String extraPassword) { |
| checkDisposed(); |
| this.extraPassword = extraPassword; |
| } |
| |
| /** |
| * @return Returns the passwordReset property or <code>null</code> if not present. |
| */ |
| public boolean getPasswordReset() { |
| checkDisposed(); |
| return this.passwordReset; |
| } |
| |
| /** |
| * Sets the passwordReset property to this instance. |
| */ |
| public void setPasswordReset(final boolean passwordReset) { |
| checkDisposed(); |
| this.passwordReset = passwordReset; |
| } |
| |
| /** |
| * @return Returns the position property or <code>null</code> if not present. |
| */ |
| public String getPosition() { |
| checkDisposed(); |
| return this.position; |
| } |
| |
| /** |
| * Sets the position property to this instance. |
| */ |
| public void setPosition(final String position) { |
| checkDisposed(); |
| this.position = position; |
| } |
| |
| /** |
| * @return Returns the defaultPerspective property or <code>null</code> if not present. |
| */ |
| public String getDefaultPerspective() { |
| checkDisposed(); |
| return this.defaultPerspective; |
| } |
| |
| /** |
| * Sets the defaultPerspective property to this instance. |
| */ |
| public void setDefaultPerspective(final String defaultPerspective) { |
| checkDisposed(); |
| this.defaultPerspective = defaultPerspective; |
| } |
| |
| /** |
| * @return Returns the enabled property or <code>null</code> if not present. |
| */ |
| public boolean getEnabled() { |
| checkDisposed(); |
| return this.enabled; |
| } |
| |
| /** |
| * Sets the enabled property to this instance. |
| */ |
| public void setEnabled(final boolean enabled) { |
| checkDisposed(); |
| this.enabled = enabled; |
| } |
| |
| /** |
| * @return Returns the locked property or <code>null</code> if not present. |
| */ |
| public boolean getLocked() { |
| checkDisposed(); |
| return this.locked; |
| } |
| |
| /** |
| * Sets the locked property to this instance. |
| */ |
| public void setLocked(final boolean locked) { |
| checkDisposed(); |
| this.locked = locked; |
| } |
| |
| /** |
| * @return Returns the superuser property or <code>null</code> if not present. |
| */ |
| public boolean getSuperuser() { |
| checkDisposed(); |
| return this.superuser; |
| } |
| |
| /** |
| * Sets the superuser property to this instance. |
| */ |
| public void setSuperuser(final boolean superuser) { |
| checkDisposed(); |
| this.superuser = superuser; |
| } |
| |
| /** |
| * @return Returns the supervisor property or <code>null</code> if not present. |
| */ |
| public boolean getSupervisor() { |
| checkDisposed(); |
| return this.supervisor; |
| } |
| |
| /** |
| * Sets the supervisor property to this instance. |
| */ |
| public void setSupervisor(final boolean supervisor) { |
| checkDisposed(); |
| this.supervisor = supervisor; |
| } |
| |
| /** |
| * @return Returns the forcePwdChange property or <code>null</code> if not present. |
| */ |
| public boolean getForcePwdChange() { |
| checkDisposed(); |
| return this.forcePwdChange; |
| } |
| |
| /** |
| * Sets the forcePwdChange property to this instance. |
| */ |
| public void setForcePwdChange(final boolean forcePwdChange) { |
| checkDisposed(); |
| this.forcePwdChange = forcePwdChange; |
| } |
| |
| /** |
| * @return Returns the notRegistered property or <code>null</code> if not present. |
| */ |
| public boolean getNotRegistered() { |
| checkDisposed(); |
| return this.notRegistered; |
| } |
| |
| /** |
| * Sets the notRegistered property to this instance. |
| */ |
| public void setNotRegistered(final boolean notRegistered) { |
| checkDisposed(); |
| this.notRegistered = notRegistered; |
| } |
| |
| /** |
| * @return Returns the failedAttempt property or <code>null</code> if not present. |
| */ |
| public int getFailedAttempt() { |
| checkDisposed(); |
| return this.failedAttempt; |
| } |
| |
| /** |
| * Sets the failedAttempt property to this instance. |
| */ |
| public void setFailedAttempt(final int failedAttempt) { |
| checkDisposed(); |
| this.failedAttempt = failedAttempt; |
| } |
| |
| /** |
| * @return Returns the successfulAttempt property or <code>null</code> if not present. |
| */ |
| public int getSuccessfulAttempt() { |
| checkDisposed(); |
| return this.successfulAttempt; |
| } |
| |
| /** |
| * Sets the successfulAttempt property to this instance. |
| */ |
| public void setSuccessfulAttempt(final int successfulAttempt) { |
| checkDisposed(); |
| this.successfulAttempt = successfulAttempt; |
| } |
| |
| /** |
| * @return Returns the cookieHashCode property or <code>null</code> if not present. |
| */ |
| public int getCookieHashCode() { |
| checkDisposed(); |
| return this.cookieHashCode; |
| } |
| |
| /** |
| * Sets the cookieHashCode property to this instance. |
| */ |
| public void setCookieHashCode(final int cookieHashCode) { |
| checkDisposed(); |
| this.cookieHashCode = cookieHashCode; |
| } |
| |
| /** |
| * @return Returns the localeTag property or <code>null</code> if not present. |
| */ |
| public String getLocaleTag() { |
| checkDisposed(); |
| return this.localeTag; |
| } |
| |
| /** |
| * Sets the localeTag property to this instance. |
| */ |
| public void setLocaleTag(final String localeTag) { |
| checkDisposed(); |
| this.localeTag = localeTag; |
| } |
| |
| /** |
| * @return Returns the profileimage property or <code>null</code> if not present. |
| */ |
| public String getProfileimage() { |
| checkDisposed(); |
| return this.profileimage; |
| } |
| |
| /** |
| * Sets the profileimage property to this instance. |
| */ |
| public void setProfileimage(final String profileimage) { |
| checkDisposed(); |
| this.profileimage = profileimage; |
| } |
| |
| /** |
| * @return Returns the layoutingStrategy property or <code>null</code> if not present. |
| */ |
| public String getLayoutingStrategy() { |
| checkDisposed(); |
| return this.layoutingStrategy; |
| } |
| |
| /** |
| * Sets the layoutingStrategy property to this instance. |
| */ |
| public void setLayoutingStrategy(final String layoutingStrategy) { |
| checkDisposed(); |
| this.layoutingStrategy = layoutingStrategy; |
| } |
| |
| /** |
| * @return Returns the focusingStrategy property or <code>null</code> if not present. |
| */ |
| public String getFocusingStrategy() { |
| checkDisposed(); |
| return this.focusingStrategy; |
| } |
| |
| /** |
| * Sets the focusingStrategy property to this instance. |
| */ |
| public void setFocusingStrategy(final String focusingStrategy) { |
| checkDisposed(); |
| this.focusingStrategy = focusingStrategy; |
| } |
| |
| /** |
| * @return Returns the theme property or <code>null</code> if not present. |
| */ |
| public String getTheme() { |
| checkDisposed(); |
| return this.theme; |
| } |
| |
| /** |
| * Sets the theme property to this instance. |
| */ |
| public void setTheme(final String theme) { |
| checkDisposed(); |
| this.theme = theme; |
| } |
| |
| /** |
| * @return Returns the printService property or <code>null</code> if not present. |
| */ |
| public String getPrintService() { |
| checkDisposed(); |
| return this.printService; |
| } |
| |
| /** |
| * Sets the printService property to this instance. |
| */ |
| public void setPrintService(final String printService) { |
| checkDisposed(); |
| this.printService = printService; |
| } |
| |
| /** |
| * @return Returns an unmodifiable list of userAccountFilter. |
| */ |
| public List<UserAccountFilter> getUserAccountFilter() { |
| checkDisposed(); |
| return Collections.unmodifiableList(internalGetUserAccountFilter()); |
| } |
| |
| /** |
| * Sets the given userAccountFilter to the object. Currently contained userAccountFilter instances will be removed. |
| * |
| * @param userAccountFilter the list of new instances |
| */ |
| public void setUserAccountFilter(final List<UserAccountFilter> userAccountFilter) { |
| // remove the old userAccountFilter |
| for(UserAccountFilter oldElement : new ArrayList<UserAccountFilter>(this.internalGetUserAccountFilter())){ |
| removeFromUserAccountFilter(oldElement); |
| } |
| |
| // add the new userAccountFilter |
| for(UserAccountFilter newElement : userAccountFilter){ |
| addToUserAccountFilter(newElement); |
| } |
| } |
| |
| /** |
| * For internal use only! Returns the list of <code>UserAccountFilter</code>s thereby lazy initializing it. |
| */ |
| public List<UserAccountFilter> internalGetUserAccountFilter() { |
| if (this.userAccountFilter == null) { |
| this.userAccountFilter = new ArrayList<UserAccountFilter>(); |
| } |
| return this.userAccountFilter; |
| } |
| |
| /** |
| * Adds the given userAccountFilter to this object. <p> |
| * Since the reference is a composition reference, the opposite reference (UserAccountFilter.userAccount) |
| * of the userAccountFilter will be handled automatically and no further coding is required to keep them in sync. |
| * See {@link UserAccountFilter#setUserAccount(UserAccountFilter)}. |
| * |
| */ |
| public void addToUserAccountFilter(final UserAccountFilter userAccountFilter) { |
| checkDisposed(); |
| userAccountFilter.setUserAccount(this); |
| } |
| |
| /** |
| * Removes the given userAccountFilter from this object. <p> |
| * |
| */ |
| public void removeFromUserAccountFilter(final UserAccountFilter userAccountFilter) { |
| checkDisposed(); |
| userAccountFilter.setUserAccount(null); |
| } |
| |
| /** |
| * For internal use only! |
| */ |
| public void internalAddToUserAccountFilter(final UserAccountFilter userAccountFilter) { |
| if(userAccountFilter == null) { |
| return; |
| } |
| |
| if(!internalGetUserAccountFilter().contains(userAccountFilter)) { |
| internalGetUserAccountFilter().add(userAccountFilter); |
| } |
| } |
| |
| /** |
| * For internal use only! |
| */ |
| public void internalRemoveFromUserAccountFilter(final UserAccountFilter userAccountFilter) { |
| internalGetUserAccountFilter().remove(userAccountFilter); |
| } |
| |
| @PreUpdate |
| public void preUpdate() { |
| if ((this.locked && (!this.enabled))) { |
| this.locked = false; |
| this.failedAttempt = 00; |
| } |
| } |
| |
| public boolean equalVersions(final Object obj) { |
| if (this == obj) |
| return true; |
| if (obj == null) |
| return false; |
| if (getClass() != obj.getClass()) |
| return false; |
| UserAccount other = (UserAccount) obj; |
| if (this.id == null) { |
| if (other.id != null) |
| return false; |
| } else if (!this.id.equals(other.id)) |
| return false; |
| return true; |
| } |
| |
| @Override |
| public boolean equals(final Object obj) { |
| return equalVersions(obj); |
| } |
| |
| @Override |
| public int hashCode() { |
| int prime = 31; |
| int result = 1; |
| result = prime * result + ((this.id== null) ? 0 : this.id.hashCode()); |
| return result; |
| } |
| |
| /** |
| * Iterates all cross references and removes them from the parent to avoid ConstraintViolationException |
| */ |
| @PreRemove |
| protected void preRemove() { |
| // remove the userAccountFilter |
| for(UserAccountFilter oldElement : new ArrayList<UserAccountFilter>(this.internalGetUserAccountFilter())){ |
| removeFromUserAccountFilter(oldElement); |
| } |
| } |
| } |