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 vldc.aswi.validators.operator.value.OperatorValueConstraint;
|
8
|
|
9
|
import javax.persistence.*;
|
10
|
import java.util.List;
|
11
|
|
12
|
/**
|
13
|
* Domain entity representing ParameterInConfiguration in application.
|
14
|
*/
|
15
|
@Entity(name = "Parametr_konfigurace")
|
16
|
@Data
|
17
|
@EqualsAndHashCode(callSuper = true)
|
18
|
@NoArgsConstructor
|
19
|
public class ParameterInConfiguration extends EntityParent implements Comparable<ParameterInConfiguration> {
|
20
|
|
21
|
/** Specific configuration in which is this parameterConfiguration presented. */
|
22
|
@ManyToOne(fetch = FetchType.LAZY)
|
23
|
@JoinColumn(name = "konfigurace_id")
|
24
|
private Configuration configuration;
|
25
|
|
26
|
/** Specific parameter of configuration, which is used as template. */
|
27
|
@ManyToOne(fetch=FetchType.EAGER)
|
28
|
@JoinColumn(name = "parametr_id")
|
29
|
private Parameter parameter;
|
30
|
|
31
|
/** Value of used operator. */
|
32
|
@Column(name = "hodnota_operatoru")
|
33
|
private String operatorValue;
|
34
|
|
35
|
/** Order of parameter. */
|
36
|
@Column(name = "poradi")
|
37
|
private int parameterOrder;
|
38
|
|
39
|
/** Specific location in which this parameterConfiguration will be used. */
|
40
|
@ManyToOne(fetch=FetchType.EAGER)
|
41
|
@JoinColumn(name = "umisteni_id")
|
42
|
private Location location;
|
43
|
|
44
|
/** User-defined name of this parameterConfiguration. */
|
45
|
@Column(name = "nazev_sloupce")
|
46
|
private String columnName;
|
47
|
|
48
|
/** Specific operator which will be aplied onto data. */
|
49
|
@ManyToOne(fetch=FetchType.LAZY)
|
50
|
@JoinColumn(name = "operator_id")
|
51
|
private Operator operator;
|
52
|
|
53
|
/**
|
54
|
* Creating new table with M:N relationship between Parameter_Hodnota and Parametr_Konfigurace.
|
55
|
* Specify which functions can be used for parameter.
|
56
|
*/
|
57
|
@ManyToMany
|
58
|
@JoinTable(
|
59
|
name = "P_konfigurace_ma_Hodnoty",
|
60
|
joinColumns = @JoinColumn(name = "parametr_konfigurace_id"),
|
61
|
inverseJoinColumns = @JoinColumn(name = "parametr_hodnota_id")
|
62
|
)
|
63
|
private List<ParameterValue> selectedParameterValues;
|
64
|
|
65
|
/**
|
66
|
* Creating new table with M:N relationship between ParameterInConfiguration and Function.
|
67
|
* On every ParameterInConfiguration can be applied 0 - every function.
|
68
|
*/
|
69
|
@ManyToMany(cascade = CascadeType.PERSIST)
|
70
|
@JoinTable(
|
71
|
name = "Parametr_konfigurace_ma_Funkce",
|
72
|
joinColumns = @JoinColumn(name = "parametr_konfigurace_id"),
|
73
|
inverseJoinColumns = @JoinColumn(name = "funkce_id")
|
74
|
)
|
75
|
private List<Function> functions;
|
76
|
|
77
|
/**
|
78
|
* Constructor.
|
79
|
* @param operatorValue - Value of used operator.
|
80
|
* @param columnName - User-defined name of this parameterConfiguration.
|
81
|
*/
|
82
|
public ParameterInConfiguration(String operatorValue, String columnName) {
|
83
|
this.setOperatorValue(operatorValue);
|
84
|
this.setColumnName(columnName);
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* Equal method for comparing two objects.
|
89
|
* @param obj - Comparing object.
|
90
|
* @return true if objects are same.
|
91
|
*/
|
92
|
@Override
|
93
|
public boolean equals(Object obj) {
|
94
|
return super.equals(obj);
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* Overriding toString method to prevent StackOverflowError.
|
99
|
* @return Object with zero parameters.
|
100
|
*/
|
101
|
@Override
|
102
|
public String toString() {
|
103
|
return "ParameterInConfiguration[]";
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* Remove function from parameter in 'Parametr_Konfigurace_ma_Funkce' table.
|
108
|
* @param function - Function to be removed.
|
109
|
*/
|
110
|
public void removeFunction(Function function) {
|
111
|
functions.remove(function);
|
112
|
function.getParametersInConfigurations().remove(this);
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* Compare two parameters in configuration by parameterOrder from 0 to X.
|
117
|
* @param parameterInConfiguration - Compared parameter in configuration.
|
118
|
* @return difference between orders
|
119
|
*/
|
120
|
@Override
|
121
|
public int compareTo(ParameterInConfiguration parameterInConfiguration) {
|
122
|
return (this.getParameterOrder() - parameterInConfiguration.getParameterOrder());
|
123
|
}
|
124
|
}
|