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