package org.synyx.urlaubsverwaltung.person;

import org.synyx.urlaubsverwaltung.security.Role;
import org.synyx.urlaubsverwaltung.application.domain.Application;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.springframework.data.jpa.domain.AbstractPersistable;

import javax.persistence.*;
import java.util.Collection;
import java.util.List;


/**
 * @author  Johannes Reuter
 * @author  Aljona Murygina
 */

@Entity
public class Person extends AbstractPersistable<Integer> {

    private static final long serialVersionUID = 765672310978437L;

    private String loginName;

    private String lastName;

    private String firstName;

    private String email;

    // private key of person - RSA
    // private key has to be saved as byte[] in database
    // when retrieved from database, byte[] have to be transformed back to private key
    @Column(columnDefinition = "longblob")
    private byte[] privateKey;

    // public key of person
    // saving like private key
    @Column(columnDefinition = "longblob")
    private byte[] publicKey;

    private Role role;

    @ElementCollection
    @LazyCollection(LazyCollectionOption.FALSE)
    @Enumerated(EnumType.STRING)
    private Collection<Role> permissions;

    @OneToMany
    private List<Application> applications;

    private boolean active;

    public boolean isActive() {

        return active;
    }


    public void setActive(boolean active) {

        this.active = active;
    }


    public List<Application> getApplications() {

        return applications;
    }


    public void setApplications(List<Application> applications) {

        this.applications = applications;
    }


    public String getEmail() {

        return email;
    }


    public void setEmail(String email) {

        this.email = email;
    }


    public String getFirstName() {

        return firstName;
    }


    public void setFirstName(String firstName) {

        this.firstName = firstName;
    }


    public String getLastName() {

        return lastName;
    }


    public void setLastName(String lastName) {

        this.lastName = lastName;
    }


    public String getLoginName() {

        return loginName;
    }


    public void setLoginName(String loginName) {

        this.loginName = loginName;
    }


    public byte[] getPrivateKey() {

        return privateKey;
    }


    public void setPrivateKey(byte[] privateKey) {

        this.privateKey = privateKey;
    }


    public byte[] getPublicKey() {

        return publicKey;
    }


    public void setPublicKey(byte[] publicKey) {

        this.publicKey = publicKey;
    }


    public Role getRole() {

        return role;
    }


    public void setRole(Role role) {

        this.role = role;
    }

    public void setPermissions(Collection<Role> permissions) {

        this.permissions = permissions;
    }


    public Collection<Role> getPermissions() {

        return permissions;
    }
    
    public boolean hasRole(Role role) {
        
        for(Role r : getPermissions()) {
            if(r.equals(role)) {
                return true;
            }
        }
        
        return false;
        
    }
}

@@ -1117,32 +1117,8 @@
 y;%0A%0A
-    private Role role;%0A%0A
     
@@ -1136,16 +1136,16 @@
 lection%0A
+
     @Laz
@@ -1264,68 +1264,8 @@
 s;%0A%0A
-    @OneToMany%0A    private List%3CApplication%3E applications;%0A%0A
     
@@ -1432,220 +1432,15 @@
 ve;%0A
+
     %7D%0A%0A
-%0A    public List%3CApplication%3E getApplications() %7B%0A%0A        return applications;%0A    %7D%0A%0A%0A    public void setApplications(List%3CApplication%3E applications) %7B%0A%0A        this.applications = applications;%0A    %7D%0A%0A%0A
     
@@ -2399,137 +2399,8 @@
 %7D%0A%0A%0A
-    public Role getRole() %7B%0A%0A        return role;%0A    %7D%0A%0A%0A    public void setRole(Role role) %7B%0A%0A        this.role = role;%0A    %7D%0A%0A
     

Remove unused fields role and applications