Clover icon

sunshower-core

  1. Project Clover database Fri Apr 6 2018 03:27:42 UTC
  2. Package io.sunshower.model.core.auth

File Tenant.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
14% of files have more coverage

Code metrics

8
22
13
1
96
76
17
0.77
1.69
13
1.31

Classes

Class Line # Actions
Tenant 12 22 17
0.7441860474.4%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    package io.sunshower.model.core.auth;
2   
3    import io.sunshower.common.Identifier;
4    import io.sunshower.model.core.Schemata;
5    import io.sunshower.persistence.core.Hierarchical;
6    import java.util.HashSet;
7    import java.util.Set;
8    import javax.persistence.*;
9   
10    @Entity
11    @Table(name = "TENANT", schema = Schemata.SUNSHOWER)
 
12    public class Tenant extends ProtectedDistributableEntity
13    implements Hierarchical<Identifier, Tenant> {
14   
15    @Basic private String name;
16   
17    @ManyToOne private Tenant parent;
18   
19    @OneToOne(mappedBy = "tenant", cascade = CascadeType.ALL)
20    private TenantDetails details;
21   
22    @OneToMany(mappedBy = "tenant", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
23    private Set<User> users;
24   
25    @OneToMany(orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
26    @JoinColumn(name = "parent_id")
27    private Set<Tenant> children;
28   
 
29  4 toggle public Tenant() {}
30   
 
31  0 toggle public String getName() {
32  0 return name;
33    }
34   
 
35  4 toggle public void setName(String name) {
36  4 this.name = name;
37    }
38   
 
39  0 toggle @Override
40    public Tenant getParent() {
41  0 return parent;
42    }
43   
 
44  2 toggle @Override
45    public Set<Tenant> getChildren() {
46  2 return children;
47    }
48   
 
49  2 toggle @Override
50    public boolean addChild(Tenant tenant) {
51  2 setParent(tenant);
52  2 if (tenant != null) {
53  2 return children().add(tenant);
54    }
55  0 return false;
56    }
57   
 
58  2 toggle @Override
59    public void setParent(Tenant tenant) {
60  2 this.parent = tenant;
61    }
62   
 
63  3 toggle public TenantDetails getDetails() {
64  3 return details;
65    }
66   
 
67  4 toggle public void setDetails(TenantDetails details) {
68  4 this.details = details;
69  4 if (details != null) {
70  4 details.setTenant(this);
71    }
72    }
73   
 
74  2 toggle public Set<User> getUsers() {
75  2 return users;
76    }
77   
 
78  0 toggle public void setUsers(Set<User> users) {
79  0 this.users = users;
80    }
81   
 
82  2 toggle public void addUser(User user) {
83  2 if (users == null) {
84  2 users = new HashSet<>();
85    }
86  2 users.add(user);
87  2 user.setTenant(this);
88    }
89   
 
90  2 toggle protected Set<Tenant> children() {
91  2 if (children == null) {
92  2 children = new HashSet<>();
93    }
94  2 return children;
95    }
96    }