1
|
package vldc.aswi.domain.parameter;
|
2
|
|
3
|
import lombok.Data;
|
4
|
import lombok.EqualsAndHashCode;
|
5
|
import lombok.NoArgsConstructor;
|
6
|
import vldc.aswi.domain.*;
|
7
|
import javax.persistence.*;
|
8
|
import java.util.List;
|
9
|
|
10
|
/**
|
11
|
* Domain entity representing Parameter in application.
|
12
|
*/
|
13
|
@Entity(name = "Parametr")
|
14
|
@Data
|
15
|
@EqualsAndHashCode(callSuper = true)
|
16
|
@NoArgsConstructor
|
17
|
public class Parameter extends EntityParent implements Comparable<Parameter> {
|
18
|
|
19
|
/** Name of parameter in SQL query. */
|
20
|
@Column(name = "nazev")
|
21
|
private String name;
|
22
|
|
23
|
/** Admin-defined name of parameter, which will be used in assembly. */
|
24
|
@Column(name = "nazev_select")
|
25
|
private String nameOfSelect;
|
26
|
|
27
|
/** Specific assembly, in which this parameter will be part of. */
|
28
|
@ManyToOne(fetch = FetchType.EAGER)
|
29
|
@JoinColumn(name = "sestava_id")
|
30
|
private Assembly assembly;
|
31
|
|
32
|
/** Specific type of parameter, which represents type of entry. */
|
33
|
@ManyToOne(fetch=FetchType.EAGER)
|
34
|
@JoinColumn(name = "parametr_typ_id")
|
35
|
private ParameterType parameterType;
|
36
|
|
37
|
/** Default value of this parameter. */
|
38
|
@Column(name = "default_hodnota")
|
39
|
private String defaultValue;
|
40
|
|
41
|
/** Order of parameter. */
|
42
|
@Column(name = "poradi")
|
43
|
private int parameterOrder;
|
44
|
|
45
|
/** List of parametersInConfiguration, which using this parameter. */
|
46
|
@OneToMany(mappedBy = "parameter")
|
47
|
private List<ParameterInConfiguration> parametersInConfiguration;
|
48
|
|
49
|
/** List of parametersInConfiguration, which using this parameter. */
|
50
|
@OneToMany(mappedBy = "parameter", fetch = FetchType.EAGER)
|
51
|
private List<ParameterValue> parameterValues;
|
52
|
|
53
|
/**
|
54
|
* Creating new table with M:N relationship between Parameter and Location.
|
55
|
* Specify which locations can be used for parameter.
|
56
|
*/
|
57
|
@ManyToMany
|
58
|
@JoinTable(
|
59
|
name = "Parametr_ma_Umisteni",
|
60
|
joinColumns = @JoinColumn(name = "parametr_id"),
|
61
|
inverseJoinColumns = @JoinColumn(name = "umisteni_id")
|
62
|
)
|
63
|
private List<Location> locations;
|
64
|
|
65
|
/**
|
66
|
* Creating new table with M:N relationship between Parameter and Function.
|
67
|
* Specify which functions can be used for parameter.
|
68
|
*/
|
69
|
@ManyToMany
|
70
|
@JoinTable(
|
71
|
name = "Parametr_ma_Funkce",
|
72
|
joinColumns = @JoinColumn(name = "parametr_id"),
|
73
|
inverseJoinColumns = @JoinColumn(name = "funkce_id")
|
74
|
)
|
75
|
private List<Function> functions;
|
76
|
|
77
|
/**
|
78
|
* Creating new table with M:N relationship between Parameter and Operator.
|
79
|
* Specify which operators can be used for parameter.
|
80
|
*/
|
81
|
@ManyToMany
|
82
|
@JoinTable(
|
83
|
name = "Parametr_ma_Operator",
|
84
|
joinColumns = @JoinColumn(name = "parametr_id"),
|
85
|
inverseJoinColumns = @JoinColumn(name = "operator_id")
|
86
|
)
|
87
|
private List<Operator> operators;
|
88
|
|
89
|
/**
|
90
|
* Constructor.
|
91
|
* @param name - Name of parameter in SQL query.
|
92
|
* @param nameOfSelect - Admin-defined name of parameter, which will be used in assembly.
|
93
|
* @param defaultValue - Default value of this parameter.
|
94
|
*/
|
95
|
public Parameter(String name, String nameOfSelect, String defaultValue) {
|
96
|
this.setName(name);
|
97
|
this.setNameOfSelect(nameOfSelect);
|
98
|
this.setDefaultValue(defaultValue);
|
99
|
}
|
100
|
|
101
|
/**
|
102
|
* Overriding toString method to prevent StackOverflowError.
|
103
|
* @return Object with zero parameters.
|
104
|
*/
|
105
|
@Override
|
106
|
public String toString() {
|
107
|
return "Parameter[]";
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Equal method for comparing two objects.
|
112
|
* @param obj - Comparing object.
|
113
|
* @return true if objects are same.
|
114
|
*/
|
115
|
@Override
|
116
|
public boolean equals(Object obj) {
|
117
|
return super.equals(obj);
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* Remove function from parameter in 'Parametr_ma_Funkce' table.
|
122
|
* @param function - Function to be removed.
|
123
|
*/
|
124
|
public void removeFunction(Function function) {
|
125
|
functions.remove(function);
|
126
|
function.getParameters().remove(this);
|
127
|
}
|
128
|
|
129
|
/**
|
130
|
* Remove operator from parameter in 'Parametr_ma_Operator' table.
|
131
|
* @param operator - Operator to be removed.
|
132
|
*/
|
133
|
public void removeOperator(Operator operator) {
|
134
|
operators.remove(operator);
|
135
|
operator.getParameters().remove(this);
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* Remove location from parameter in 'Parametr_ma_Umisteni' table.
|
140
|
* @param location - Location to be removed.
|
141
|
*/
|
142
|
public void removeLocation(Location location) {
|
143
|
locations.remove(location);
|
144
|
location.getParameters().remove(this);
|
145
|
}
|
146
|
|
147
|
/**
|
148
|
* Compare two parameters by parameterOrder from 0 to X.
|
149
|
* @param parameter - Compared parameter.
|
150
|
* @return 1 if current parameter is higher, -1 if lower.
|
151
|
*/
|
152
|
@Override
|
153
|
public int compareTo(Parameter parameter) {
|
154
|
if (this.getParameterOrder() > parameter.getParameterOrder()) {
|
155
|
return 1;
|
156
|
}
|
157
|
else {
|
158
|
return -1;
|
159
|
}
|
160
|
}
|
161
|
}
|