1
|
package vldc.aswi.domain;
|
2
|
|
3
|
import lombok.Data;
|
4
|
import lombok.EqualsAndHashCode;
|
5
|
import lombok.NoArgsConstructor;
|
6
|
import vldc.aswi.domain.parameter.Parameter;
|
7
|
|
8
|
import javax.persistence.*;
|
9
|
import java.util.Collection;
|
10
|
import java.util.Collections;
|
11
|
import java.util.List;
|
12
|
|
13
|
/**
|
14
|
* Domain entity representing Assembly in application.
|
15
|
*/
|
16
|
@Entity(name = "Sestava")
|
17
|
@Data
|
18
|
@EqualsAndHashCode(callSuper = true)
|
19
|
@NoArgsConstructor
|
20
|
public class Assembly extends EntityParent {
|
21
|
|
22
|
/** Name of Assembly. */
|
23
|
@Column(name = "nazev")
|
24
|
private String name;
|
25
|
|
26
|
/** SQL query which gets data from database. */
|
27
|
@Column(name = "sql_dotaz")
|
28
|
private String SQLQuery;
|
29
|
|
30
|
/** Specific order of assembly in list of assemblies. */
|
31
|
@Column(name = "poradi")
|
32
|
private int assemblyOrder;
|
33
|
|
34
|
@Column(name = "verejny")
|
35
|
private int isPublic;
|
36
|
|
37
|
/** List of configurations, which using this assembly. */
|
38
|
@OneToMany(mappedBy = "assembly")
|
39
|
private List<Configuration> configurations;
|
40
|
|
41
|
/** List of parameters, which using this assembly. */
|
42
|
@OneToMany(mappedBy = "assembly", fetch = FetchType.EAGER, orphanRemoval = true)
|
43
|
private List<Parameter> parameters;
|
44
|
|
45
|
/**
|
46
|
* Creating new table with M:N relationship between Assembly and Role.
|
47
|
*/
|
48
|
@ManyToMany
|
49
|
@JoinTable(
|
50
|
name = "Sestava_ma_Role",
|
51
|
joinColumns = @JoinColumn(name = "sestava_id"),
|
52
|
inverseJoinColumns = @JoinColumn(name = "role_id")
|
53
|
)
|
54
|
private List<Role> roles;
|
55
|
|
56
|
/**
|
57
|
* Constructor.
|
58
|
* @param name - Name of Assembly.
|
59
|
* @param SQLQuery - SQL query which gets data from database.
|
60
|
* @param assemblyOrder - Specific order of assembly in list of assemblies.
|
61
|
*/
|
62
|
public Assembly(String name, String SQLQuery, int assemblyOrder, int isPublic) {
|
63
|
this.setName(name);
|
64
|
this.setSQLQuery(SQLQuery);
|
65
|
this.setAssemblyOrder(assemblyOrder);
|
66
|
this.setIsPublic(isPublic);
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* Equal method for comparing two objects.
|
71
|
* @param obj - Comparing object.
|
72
|
* @return true if objects are same.
|
73
|
*/
|
74
|
@Override
|
75
|
public boolean equals(Object obj) {
|
76
|
return super.equals(obj);
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* Overriding toString method to prevent StackOverflowError.
|
81
|
* @return Object with zero parameters.
|
82
|
*/
|
83
|
@Override
|
84
|
public String toString() {
|
85
|
return "Assembly[]";
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* Remove role from assembly in 'Sestava_ma_Role' table.
|
90
|
* @param role - Role to be removed.
|
91
|
*/
|
92
|
public void removeRole(Role role) {
|
93
|
roles.remove(role);
|
94
|
role.getAssemblies().remove(this);
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* Sort parameter list by parameterOrder.
|
99
|
*/
|
100
|
public void sortParameterList() {
|
101
|
Collections.sort(parameters);
|
102
|
}
|
103
|
}
|