Revize b439853d
Přidáno uživatelem Michal Linha před téměř 5 roky(ů)
src/main/java/vldc/aswi/dao/FunctionRepository.java | ||
---|---|---|
16 | 16 |
* @return Function if ID is present in database. |
17 | 17 |
*/ |
18 | 18 |
Function getById(Long Id); |
19 |
|
|
20 |
/** |
|
21 |
* Find function by its name. |
|
22 |
* @param name - function name. |
|
23 |
* @return function if name is present in database. |
|
24 |
*/ |
|
25 |
Function getByName(String name); |
|
19 | 26 |
} |
src/main/java/vldc/aswi/dao/LocationRepository.java | ||
---|---|---|
16 | 16 |
* @return Location if ID is present in database. |
17 | 17 |
*/ |
18 | 18 |
Location getById(Long Id); |
19 |
|
|
20 |
/** |
|
21 |
* Find Location by its name. |
|
22 |
* @param name - Location name. |
|
23 |
* @return Location if name is present in database. |
|
24 |
*/ |
|
25 |
Location getByName(String name); |
|
19 | 26 |
} |
src/main/java/vldc/aswi/dao/OperatorRepository.java | ||
---|---|---|
16 | 16 |
* @return Operator if ID is present in database. |
17 | 17 |
*/ |
18 | 18 |
Operator getById(Long Id); |
19 |
|
|
20 |
/** |
|
21 |
* Find Operator by its name. |
|
22 |
* @param name - Operator name. |
|
23 |
* @return Operator if name is present in database. |
|
24 |
*/ |
|
25 |
Operator getByName(String name); |
|
19 | 26 |
} |
src/main/java/vldc/aswi/dao/parameter/ParameterTypeRepository.java | ||
---|---|---|
16 | 16 |
* @return ParameterType if ID is present in database. |
17 | 17 |
*/ |
18 | 18 |
ParameterType getById(Long Id); |
19 |
|
|
20 |
/** |
|
21 |
* Find ParameterType by its name. |
|
22 |
* @param name - ParameterType name. |
|
23 |
* @return ParameterType if name is present in database. |
|
24 |
*/ |
|
25 |
ParameterType getByName(String name); |
|
19 | 26 |
} |
src/main/java/vldc/aswi/domain/Configuration.java | ||
---|---|---|
4 | 4 |
import lombok.EqualsAndHashCode; |
5 | 5 |
import lombok.NoArgsConstructor; |
6 | 6 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
7 |
import vldc.aswi.utils.validator.OperatorValueConstraint; |
|
7 | 8 |
|
8 | 9 |
import javax.persistence.*; |
10 |
import javax.validation.Valid; |
|
11 |
import javax.validation.constraints.NotNull; |
|
9 | 12 |
import java.util.List; |
10 | 13 |
|
11 | 14 |
/** |
... | ... | |
37 | 40 |
|
38 | 41 |
/** List of parametersInConfiguration, which is part of this configuration. */ |
39 | 42 |
@OneToMany(mappedBy = "configuration") |
43 |
@Valid |
|
40 | 44 |
private List<ParameterInConfiguration> parametersInConfiguration; |
41 | 45 |
|
42 | 46 |
/** |
src/main/java/vldc/aswi/domain/EntityParent.java | ||
---|---|---|
16 | 16 |
|
17 | 17 |
/** Specific identificator for every table. */ |
18 | 18 |
@Id |
19 |
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
19 |
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
20 | 20 |
private Long id; |
21 | 21 |
} |
src/main/java/vldc/aswi/domain/parameter/Parameter.java | ||
---|---|---|
33 | 33 |
@Column(name = "default_hodnota") |
34 | 34 |
private String defaultValue; |
35 | 35 |
|
36 |
/** Specific type of parameter, which represents type of entry. */ |
|
37 |
@ManyToOne(fetch=FetchType.LAZY) |
|
38 |
@JoinColumn(name = "parametr_typ_id") |
|
39 |
private ParameterType parameterType; |
|
40 |
|
|
36 | 41 |
/** List of parametersInConfiguration, which using this parameter. */ |
37 | 42 |
@OneToMany(mappedBy = "parameter") |
38 | 43 |
private List<ParameterInConfiguration> parametersInConfiguration; |
src/main/java/vldc/aswi/domain/parameter/ParameterInConfiguration.java | ||
---|---|---|
4 | 4 |
import lombok.EqualsAndHashCode; |
5 | 5 |
import lombok.NoArgsConstructor; |
6 | 6 |
import vldc.aswi.domain.*; |
7 |
import vldc.aswi.utils.validator.OperatorValueConstraint; |
|
8 |
|
|
7 | 9 |
import javax.persistence.*; |
8 | 10 |
import java.util.List; |
9 | 11 |
|
... | ... | |
14 | 16 |
@Data |
15 | 17 |
@EqualsAndHashCode(callSuper = true) |
16 | 18 |
@NoArgsConstructor |
19 |
@OperatorValueConstraint |
|
17 | 20 |
public class ParameterInConfiguration extends EntityParent { |
18 | 21 |
|
19 | 22 |
/** Specific configuration in which is this parameterConfiguration presented. */ |
... | ... | |
30 | 33 |
@Column(name = "hodnota_operatoru") |
31 | 34 |
private String operatorValue; |
32 | 35 |
|
33 |
/** Specific type of parameter, which represents type of entry. */ |
|
34 |
@ManyToOne(fetch=FetchType.LAZY) |
|
35 |
@JoinColumn(name = "parametr_typ_id") |
|
36 |
private ParameterType parameterType; |
|
37 |
|
|
38 | 36 |
/** Specific location in which this parameterConfiguration will be used. */ |
39 | 37 |
@ManyToOne(fetch=FetchType.LAZY) |
40 | 38 |
@JoinColumn(name = "umisteni_id") |
src/main/java/vldc/aswi/domain/parameter/ParameterType.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
/** List of parameterInConfigurations, which using this parameter type. */ |
27 | 27 |
@OneToMany(mappedBy = "parameterType") |
28 |
private List<ParameterInConfiguration> parametersInConfiguration;
|
|
28 |
private List<Parameter> parameters;
|
|
29 | 29 |
|
30 | 30 |
/** |
31 | 31 |
* Constructor. |
src/main/java/vldc/aswi/domain/parameter/ParameterValue.java | ||
---|---|---|
3 | 3 |
import lombok.Data; |
4 | 4 |
import lombok.EqualsAndHashCode; |
5 | 5 |
import lombok.NoArgsConstructor; |
6 |
import vldc.aswi.domain.Assembly; |
|
7 | 6 |
import vldc.aswi.domain.EntityParent; |
8 | 7 |
|
9 | 8 |
import javax.persistence.*; |
src/main/java/vldc/aswi/service/ConfigurationManager.java | ||
---|---|---|
16 | 16 |
*/ |
17 | 17 |
List<Configuration> getConfigurations(); |
18 | 18 |
|
19 |
/** |
|
20 |
* Gets configuration according to its ID |
|
21 |
* @param id ID of configuration |
|
22 |
* @return configuration by ID |
|
23 |
*/ |
|
19 | 24 |
Configuration getConfigurationById(Long id); |
25 |
|
|
26 |
/** |
|
27 |
* Saves configuration and its contents into database |
|
28 |
* @param newConfiguration configuration to save |
|
29 |
* @param id id of configuration, if not empty configuration is updated |
|
30 |
* @return saved configuration |
|
31 |
*/ |
|
32 |
Configuration saveConfiguration(Configuration newConfiguration, String id); |
|
20 | 33 |
} |
src/main/java/vldc/aswi/service/ConfigurationManagerImpl.java | ||
---|---|---|
6 | 6 |
import org.springframework.context.event.EventListener; |
7 | 7 |
import org.springframework.core.annotation.Order; |
8 | 8 |
import org.springframework.stereotype.Service; |
9 |
import vldc.aswi.dao.ConfigurationRepository; |
|
9 |
import vldc.aswi.dao.*; |
|
10 |
import vldc.aswi.dao.parameter.ParameterInConfigurationRepository; |
|
11 |
import vldc.aswi.dao.parameter.ParameterTypeRepository; |
|
10 | 12 |
import vldc.aswi.domain.Assembly; |
11 | 13 |
import vldc.aswi.domain.Configuration; |
14 |
import vldc.aswi.domain.Function; |
|
15 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
|
12 | 16 |
|
13 | 17 |
import javax.transaction.Transactional; |
18 |
import java.util.ArrayList; |
|
14 | 19 |
import java.util.LinkedList; |
15 | 20 |
import java.util.List; |
16 | 21 |
|
... | ... | |
22 | 27 |
@Autowired |
23 | 28 |
private ConfigurationRepository configurationRepository; |
24 | 29 |
|
30 |
/** Autowired assembly repository. */ |
|
31 |
@Autowired |
|
32 |
private AssemblyRepository assemblyRepository; |
|
33 |
|
|
34 |
/** Autowired parameterInConfiguration repository. */ |
|
35 |
@Autowired |
|
36 |
private ParameterInConfigurationRepository parameterInConfigurationRepository; |
|
37 |
|
|
38 |
/** Autowired operator repository. */ |
|
39 |
@Autowired |
|
40 |
private OperatorRepository operatorRepository; |
|
41 |
|
|
42 |
/** Autowired location repository. */ |
|
43 |
@Autowired |
|
44 |
private LocationRepository locationRepository; |
|
45 |
|
|
46 |
/** Autowired parameter type repository. */ |
|
47 |
@Autowired |
|
48 |
private ParameterTypeRepository parameterTypeRepository; |
|
49 |
|
|
50 |
/** Autowired function repository. */ |
|
51 |
@Autowired |
|
52 |
private FunctionRepository functionRepository; |
|
53 |
|
|
54 |
/** Autowired user repository. */ |
|
55 |
@Autowired |
|
56 |
private UserRepository userRepository; |
|
57 |
|
|
25 | 58 |
/** |
26 | 59 |
* Initialization setup for configuration manager. Check if configuration repository contains |
27 | 60 |
* records and if not, initialize default values. |
... | ... | |
49 | 82 |
return retVal; |
50 | 83 |
} |
51 | 84 |
|
85 |
/** |
|
86 |
* Gets configuration according to its ID |
|
87 |
* @param id ID of configuration |
|
88 |
* @return configuration by ID |
|
89 |
*/ |
|
52 | 90 |
@Override |
53 | 91 |
public Configuration getConfigurationById(Long id) { |
54 | 92 |
return configurationRepository.getById(id); |
55 | 93 |
} |
94 |
|
|
95 |
/** |
|
96 |
* Saves configuration and its contents into database |
|
97 |
* @param newConfiguration configuration to save |
|
98 |
* @param id id of configuration, if not empty configuration is updated |
|
99 |
* @return saved configuration |
|
100 |
*/ |
|
101 |
@Override |
|
102 |
public Configuration saveConfiguration(Configuration newConfiguration, String id) { |
|
103 |
if(id.equals("")) { |
|
104 |
return addConfiguration(newConfiguration); |
|
105 |
} |
|
106 |
else { |
|
107 |
return editConfiguration(newConfiguration, Long.valueOf(id)); |
|
108 |
} |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Saves new configuration into database |
|
113 |
* @param newConfiguration container with data for a new configuration |
|
114 |
* @return saved configuration |
|
115 |
*/ |
|
116 |
private Configuration addConfiguration(Configuration newConfiguration) { |
|
117 |
Configuration configuration = new Configuration(); |
|
118 |
Assembly assembly = assemblyRepository.getById(newConfiguration.getAssembly().getId()); |
|
119 |
configuration.setAssembly(assembly); |
|
120 |
configuration.setName(newConfiguration.getName()); |
|
121 |
configuration.setTableName(newConfiguration.getTableName()); |
|
122 |
configuration.setUser(userRepository.getById((long) 1)); |
|
123 |
Configuration savedConfiguration = configurationRepository.save(configuration); |
|
124 |
|
|
125 |
savedConfiguration.setParametersInConfiguration(new ArrayList<>()); |
|
126 |
for(int i = 0; i < newConfiguration.getParametersInConfiguration().size(); i++) { |
|
127 |
ParameterInConfiguration parameterInConfiguration = new ParameterInConfiguration(); |
|
128 |
parameterInConfiguration.setParameter(assembly.getParameters().get(i)); |
|
129 |
parameterInConfiguration.setColumnName(newConfiguration.getParametersInConfiguration().get(i).getColumnName()); |
|
130 |
parameterInConfiguration.setConfiguration(savedConfiguration); |
|
131 |
parameterInConfiguration.setOperatorValue(newConfiguration.getParametersInConfiguration().get(i).getOperatorValue()); |
|
132 |
parameterInConfiguration.setColumnName(assembly.getParameters().get(i).getName()); |
|
133 |
if(newConfiguration.getParametersInConfiguration().get(i).getLocation() != null) { |
|
134 |
parameterInConfiguration.setLocation(locationRepository.getByName( |
|
135 |
newConfiguration.getParametersInConfiguration().get(i).getLocation().getName())); |
|
136 |
} |
|
137 |
if(newConfiguration.getParametersInConfiguration().get(i).getOperator() != null) { |
|
138 |
parameterInConfiguration.setOperator(operatorRepository.getByName( |
|
139 |
newConfiguration.getParametersInConfiguration().get(i).getOperator().getName())); |
|
140 |
} |
|
141 |
if(newConfiguration.getParametersInConfiguration().get(i).getFunctions() != null) { |
|
142 |
parameterInConfiguration.setFunctions(new ArrayList<>()); |
|
143 |
for (Function function : newConfiguration.getParametersInConfiguration().get(i).getFunctions()) { |
|
144 |
parameterInConfiguration.getFunctions().add(functionRepository.getByName(function.getName())); |
|
145 |
} |
|
146 |
} |
|
147 |
ParameterInConfiguration savedParameterInConfiguration = parameterInConfigurationRepository.save( |
|
148 |
parameterInConfiguration); |
|
149 |
savedConfiguration.getParametersInConfiguration().add(savedParameterInConfiguration); |
|
150 |
} |
|
151 |
savedConfiguration = configurationRepository.save(savedConfiguration); |
|
152 |
|
|
153 |
return savedConfiguration; |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* Saves edited configuration with given ID |
|
158 |
* @param newConfiguration container with data for edited configuration |
|
159 |
* @param id ID of edited configuration |
|
160 |
* @return saved configuration |
|
161 |
*/ |
|
162 |
private Configuration editConfiguration(Configuration newConfiguration, Long id) { |
|
163 |
Configuration configuration = configurationRepository.getById(id); |
|
164 |
configuration.setName(newConfiguration.getName()); |
|
165 |
configuration.setTableName(newConfiguration.getTableName()); |
|
166 |
|
|
167 |
for(int i = 0; i < configuration.getParametersInConfiguration().size(); i++) { |
|
168 |
ParameterInConfiguration parameterInConfiguration = configuration.getParametersInConfiguration().get(i); |
|
169 |
parameterInConfiguration.setOperatorValue(newConfiguration.getParametersInConfiguration().get(i).getOperatorValue()); |
|
170 |
if(newConfiguration.getParametersInConfiguration().get(i).getColumnName() != null) { |
|
171 |
parameterInConfiguration.setColumnName(newConfiguration.getParametersInConfiguration().get(i).getColumnName()); |
|
172 |
} |
|
173 |
if(newConfiguration.getParametersInConfiguration().get(i).getLocation() != null) { |
|
174 |
parameterInConfiguration.setLocation(locationRepository.getByName( |
|
175 |
newConfiguration.getParametersInConfiguration().get(i).getLocation().getName())); |
|
176 |
} |
|
177 |
if(newConfiguration.getParametersInConfiguration().get(i).getOperator() != null) { |
|
178 |
parameterInConfiguration.setOperator(operatorRepository.getByName( |
|
179 |
newConfiguration.getParametersInConfiguration().get(i).getOperator().getName())); |
|
180 |
} |
|
181 |
if(newConfiguration.getParametersInConfiguration().get(i).getFunctions() != null) { |
|
182 |
parameterInConfiguration.setFunctions(new ArrayList<>()); |
|
183 |
for (Function function : newConfiguration.getParametersInConfiguration().get(i).getFunctions()) { |
|
184 |
parameterInConfiguration.getFunctions().add(functionRepository.getByName(function.getName())); |
|
185 |
} |
|
186 |
} |
|
187 |
parameterInConfigurationRepository.save(parameterInConfiguration); |
|
188 |
} |
|
189 |
|
|
190 |
return configurationRepository.save(configuration); |
|
191 |
} |
|
56 | 192 |
} |
src/main/java/vldc/aswi/utils/validator/OperatorValueConstraint.java | ||
---|---|---|
1 |
package vldc.aswi.utils.validator; |
|
2 |
|
|
3 |
import javax.validation.Constraint; |
|
4 |
import javax.validation.Payload; |
|
5 |
import java.lang.annotation.*; |
|
6 |
|
|
7 |
/** |
|
8 |
* Annotation used for validation of operator value |
|
9 |
*/ |
|
10 |
@Documented |
|
11 |
@Constraint(validatedBy = OperatorValueValidator.class) |
|
12 |
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) |
|
13 |
@Retention(RetentionPolicy.RUNTIME) |
|
14 |
public @interface OperatorValueConstraint { |
|
15 |
|
|
16 |
/** |
|
17 |
* Message of operator value is invalid |
|
18 |
* @return error message |
|
19 |
*/ |
|
20 |
String message() default "Neplatná hodnota filtru!"; |
|
21 |
|
|
22 |
/** |
|
23 |
* Array of classes |
|
24 |
* @return array of classes |
|
25 |
*/ |
|
26 |
Class<?>[] groups() default {}; |
|
27 |
|
|
28 |
/** |
|
29 |
* Class payload |
|
30 |
* @return class payload |
|
31 |
*/ |
|
32 |
Class<? extends Payload>[] payload() default {}; |
|
33 |
} |
src/main/java/vldc/aswi/utils/validator/OperatorValueValidator.java | ||
---|---|---|
1 |
package vldc.aswi.utils.validator; |
|
2 |
|
|
3 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
|
4 |
|
|
5 |
import javax.validation.ConstraintValidator; |
|
6 |
import javax.validation.ConstraintValidatorContext; |
|
7 |
|
|
8 |
/** |
|
9 |
* Validator class for validation operator value according to used operator |
|
10 |
*/ |
|
11 |
public class OperatorValueValidator implements |
|
12 |
ConstraintValidator<OperatorValueConstraint, Object> { |
|
13 |
|
|
14 |
/** |
|
15 |
* Initialize validator |
|
16 |
* @param operatorValue operator value |
|
17 |
*/ |
|
18 |
@Override |
|
19 |
public void initialize(OperatorValueConstraint operatorValue) { |
|
20 |
} |
|
21 |
|
|
22 |
/** |
|
23 |
* Validation process of operator value |
|
24 |
* @param o object to be validated |
|
25 |
* @param constraintValidatorContext context |
|
26 |
* @return true if operator value is valid |
|
27 |
*/ |
|
28 |
@Override |
|
29 |
public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) { |
|
30 |
ParameterInConfiguration parameterInConfiguration = (ParameterInConfiguration) o; |
|
31 |
if (parameterInConfiguration.getOperator() != null && parameterInConfiguration.getOperator().getName().equals("BETWEEN")) { |
|
32 |
return parameterInConfiguration.getOperatorValue().matches(".;."); |
|
33 |
} |
|
34 |
|
|
35 |
return true; |
|
36 |
} |
|
37 |
} |
src/main/java/vldc/aswi/web/controller/AssemblyController.java | ||
---|---|---|
7 | 7 |
import org.springframework.web.bind.annotation.GetMapping; |
8 | 8 |
import org.springframework.web.bind.annotation.ModelAttribute; |
9 | 9 |
import org.springframework.web.bind.annotation.PostMapping; |
10 |
import org.springframework.web.bind.annotation.RequestParam; |
|
10 | 11 |
import org.springframework.web.servlet.ModelAndView; |
11 | 12 |
import org.springframework.web.servlet.mvc.support.RedirectAttributes; |
12 | 13 |
import vldc.aswi.domain.Assembly; |
13 | 14 |
import vldc.aswi.domain.Configuration; |
15 |
import vldc.aswi.domain.Location; |
|
16 |
import vldc.aswi.domain.Operator; |
|
17 |
import vldc.aswi.domain.parameter.Parameter; |
|
18 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
|
14 | 19 |
import vldc.aswi.service.AssemblyManager; |
15 | 20 |
import vldc.aswi.service.ConfigurationManager; |
16 | 21 |
import vldc.aswi.service.SqlQueryManager; |
17 | 22 |
|
18 | 23 |
import javax.validation.Valid; |
24 |
import java.util.ArrayList; |
|
19 | 25 |
|
26 |
/** |
|
27 |
* Controller for assemblies and configurations |
|
28 |
*/ |
|
20 | 29 |
@Controller |
21 | 30 |
public class AssemblyController { |
22 | 31 |
|
32 |
/** |
|
33 |
* Autowired SQL query manager |
|
34 |
*/ |
|
23 | 35 |
@Autowired |
24 | 36 |
private SqlQueryManager sqlQueryManager; |
25 | 37 |
|
38 |
/** |
|
39 |
* Autowired assembly manager |
|
40 |
*/ |
|
26 | 41 |
@Autowired |
27 | 42 |
private AssemblyManager assemblyManager; |
28 | 43 |
|
44 |
/** |
|
45 |
* Autowired configuration manager |
|
46 |
*/ |
|
29 | 47 |
@Autowired |
30 | 48 |
private ConfigurationManager configurationManager; |
31 | 49 |
|
50 |
/** |
|
51 |
* Opens an configuration page after assembly name was clicked |
|
52 |
* @param id ID of assembly |
|
53 |
* @return modelAndView of page to be shown |
|
54 |
*/ |
|
32 | 55 |
@GetMapping("/assembly") |
33 | 56 |
public ModelAndView assemblyIndex(@Valid @ModelAttribute("assemblyID") String id) { |
34 | 57 |
ModelAndView modelAndView = new ModelAndView("assembly"); |
... | ... | |
40 | 63 |
Configuration configuration = new Configuration(); |
41 | 64 |
|
42 | 65 |
configuration.setAssembly(assembly); |
66 |
configuration.setParametersInConfiguration(new ArrayList<>()); |
|
67 |
for(Parameter parameter : assembly.getParameters()) { |
|
68 |
ParameterInConfiguration parameterInConfiguration = new ParameterInConfiguration(); |
|
69 |
parameterInConfiguration.setParameter(parameter); |
|
70 |
parameterInConfiguration.setConfiguration(configuration); |
|
71 |
parameterInConfiguration.setOperator(new Operator()); |
|
72 |
parameterInConfiguration.setLocation(new Location()); |
|
73 |
configuration.getParametersInConfiguration().add(parameterInConfiguration); |
|
74 |
} |
|
43 | 75 |
|
44 | 76 |
modelMap.addAttribute("configuration", configuration); |
45 |
modelMap.addAttribute("assemblyID", id);
|
|
77 |
modelMap.addAttribute("isAssembly", false);
|
|
46 | 78 |
|
47 | 79 |
return modelAndView; |
48 | 80 |
} |
49 | 81 |
|
50 |
@GetMapping("/assembly") |
|
51 |
public ModelAndView configurationIndex(@Valid @ModelAttribute("assemblyID") String id) { |
|
82 |
/** |
|
83 |
* Opens an configuration page after configuration name was clicked |
|
84 |
* @param id ID of configuration |
|
85 |
* @return modelAndView of page to be shown |
|
86 |
*/ |
|
87 |
@GetMapping("/configuration") |
|
88 |
public ModelAndView configurationIndex(@Valid @ModelAttribute("configurationID") String id) { |
|
52 | 89 |
ModelAndView modelAndView = new ModelAndView("assembly"); |
53 | 90 |
|
54 | 91 |
ModelMap modelMap = modelAndView.getModelMap(); |
55 | 92 |
|
56 | 93 |
Configuration configuration = configurationManager.getConfigurationById(Long.parseLong(id)); |
57 | 94 |
|
95 |
for(ParameterInConfiguration parameterInConfiguration : configuration.getParametersInConfiguration()) { |
|
96 |
if(parameterInConfiguration.getLocation() == null) { |
|
97 |
parameterInConfiguration.setLocation(new Location()); |
|
98 |
} |
|
99 |
if(parameterInConfiguration.getOperator() == null) { |
|
100 |
parameterInConfiguration.setOperator(new Operator()); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
58 | 104 |
modelMap.addAttribute("configuration", configuration); |
59 |
modelMap.addAttribute("assemblyID", configuration.getAssembly().getId());
|
|
105 |
modelMap.addAttribute("isAssembly", "0");
|
|
60 | 106 |
|
61 | 107 |
return modelAndView; |
62 | 108 |
} |
63 | 109 |
|
110 |
/** |
|
111 |
* Saves or edits configuration and redirects to the page with configuration |
|
112 |
* @param newConfiguration contained with configuration data |
|
113 |
* @param id ID of configuration, if empty new configuration is created |
|
114 |
* @param bindingResult binding result |
|
115 |
* @return modelAndView with redirection |
|
116 |
*/ |
|
117 |
@PostMapping("/configuration") |
|
118 |
public ModelAndView saveConfiguration(@Valid Configuration newConfiguration, BindingResult bindingResult, |
|
119 |
@RequestParam("configurationID") String id) { |
|
120 |
ModelAndView modelAndView = new ModelAndView(); |
|
121 |
|
|
122 |
if (bindingResult.hasErrors()) { |
|
123 |
modelAndView.setViewName("redirect:/"); |
|
124 |
|
|
125 |
return modelAndView; |
|
126 |
} |
|
127 |
|
|
128 |
Configuration configuration = configurationManager.saveConfiguration(newConfiguration, id); |
|
129 |
|
|
130 |
for(ParameterInConfiguration parameterInConfiguration : configuration.getParametersInConfiguration()) { |
|
131 |
if(parameterInConfiguration.getLocation() == null) { |
|
132 |
parameterInConfiguration.setLocation(new Location()); |
|
133 |
} |
|
134 |
if(parameterInConfiguration.getOperator() == null) { |
|
135 |
parameterInConfiguration.setOperator(new Operator()); |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
modelAndView.setViewName("redirect:/configuration?configurationID=" + configuration.getId()); |
|
140 |
|
|
141 |
return modelAndView; |
|
142 |
} |
|
143 |
|
|
144 |
|
|
64 | 145 |
@PostMapping("/assembly") |
65 | 146 |
public ModelAndView indexPost(@Valid Assembly assembly, BindingResult bindingResult, RedirectAttributes atts) { |
66 | 147 |
ModelAndView modelAndView = new ModelAndView(); |
... | ... | |
68 | 149 |
ModelMap modelMap = modelAndView.getModelMap(); |
69 | 150 |
|
70 | 151 |
long assemblyID = assembly.getId(); |
71 |
System.out.println(assemblyID); |
|
152 |
System.out.println(assemblyID);
|
|
72 | 153 |
Assembly assembly2 = assemblyManager.getAssemblyById(assemblyID); |
73 | 154 |
|
74 | 155 |
|
src/main/java/vldc/aswi/web/controller/IndexController.java | ||
---|---|---|
7 | 7 |
import org.springframework.web.bind.annotation.ModelAttribute; |
8 | 8 |
import org.springframework.web.bind.annotation.PostMapping; |
9 | 9 |
import org.springframework.web.servlet.ModelAndView; |
10 |
import vldc.aswi.database.DatabaseInterface; |
|
11 | 10 |
import vldc.aswi.domain.Assembly; |
12 | 11 |
import vldc.aswi.domain.parameter.Parameter; |
13 |
import vldc.aswi.model.table.TableColumn; |
|
14 |
import vldc.aswi.model.table.contingencyTable.ContingencyTableRow; |
|
15 |
import vldc.aswi.model.table.contingencyTable.ContingencyTableRowCell; |
|
16 | 12 |
import vldc.aswi.service.AssemblyManager; |
13 |
import vldc.aswi.service.ConfigurationManager; |
|
17 | 14 |
import vldc.aswi.service.SqlQueryManager; |
18 |
import vldc.aswi.utils.Converter; |
|
19 | 15 |
|
20 |
import javax.sql.DataSource; |
|
21 | 16 |
import javax.validation.Valid; |
22 | 17 |
import java.util.ArrayList; |
23 | 18 |
import java.util.List; |
24 |
import java.util.Map; |
|
25 | 19 |
|
20 |
/** |
|
21 |
* Controller for index page |
|
22 |
*/ |
|
26 | 23 |
@Controller |
27 | 24 |
public class IndexController { |
28 | 25 |
|
26 |
/** |
|
27 |
* Length when attribute string generation stops after its exceeded |
|
28 |
*/ |
|
29 |
private static final int ATTRIBUTES_LENGTH = 50; |
|
30 |
|
|
31 |
/** |
|
32 |
* Autowired SQL query manager |
|
33 |
*/ |
|
29 | 34 |
@Autowired |
30 | 35 |
private SqlQueryManager sqlQueryManager; |
31 | 36 |
|
37 |
/** |
|
38 |
* Autowired assembly manager |
|
39 |
*/ |
|
32 | 40 |
@Autowired |
33 | 41 |
private AssemblyManager assemblyManager; |
34 | 42 |
|
43 |
/** |
|
44 |
* Autowired configuration manager |
|
45 |
*/ |
|
46 |
@Autowired |
|
47 |
private ConfigurationManager configurationManager; |
|
48 |
|
|
49 |
/** |
|
50 |
* Shows index page |
|
51 |
* @return modelAndView with index page |
|
52 |
*/ |
|
35 | 53 |
@GetMapping("/") |
36 | 54 |
public ModelAndView index() { |
37 | 55 |
ModelAndView modelAndView = new ModelAndView("index"); |
... | ... | |
40 | 58 |
|
41 | 59 |
List<Assembly> assemblies = assemblyManager.getAssemblies(); |
42 | 60 |
|
61 |
|
|
62 |
modelMap.addAttribute("assemblies", assemblies); |
|
63 |
modelMap.addAttribute("attributes", createAttributesString(assemblies)); |
|
64 |
modelMap.addAttribute("configurations", configurationManager.getConfigurations()); |
|
65 |
|
|
66 |
return modelAndView; |
|
67 |
} |
|
68 |
|
|
69 |
@PostMapping("/") |
|
70 |
public ModelAndView indexPost(@Valid @ModelAttribute("assemblyID") String id) { |
|
71 |
ModelAndView modelAndView = new ModelAndView(); |
|
72 |
modelAndView.setViewName("redirect:/assembly"); |
|
73 |
|
|
74 |
return modelAndView; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Generates list of strings with attributes for each assembly |
|
79 |
* @param assemblies list of assemblies |
|
80 |
* @return list of strings with attributes |
|
81 |
*/ |
|
82 |
private List<String> createAttributesString(List<Assembly> assemblies) { |
|
43 | 83 |
List<String> attributes = new ArrayList<>(); |
44 | 84 |
for(Assembly assembly : assemblies) { |
45 | 85 |
int i = 0; |
46 |
StringBuilder stringBuilder = new StringBuilder("");
|
|
86 |
StringBuilder stringBuilder = new StringBuilder(); |
|
47 | 87 |
for(Parameter parameter : assembly.getParameters()) { |
48 | 88 |
stringBuilder.append(parameter.getName()); |
49 | 89 |
i++; |
50 |
if(i == 3) { |
|
51 |
stringBuilder.append(",..."); |
|
90 |
if (i == assembly.getParameters().size()) { |
|
52 | 91 |
break; |
53 | 92 |
} |
54 |
else if(i == assembly.getParameters().size()) { |
|
93 |
else if (stringBuilder.toString().length() > ATTRIBUTES_LENGTH) { |
|
94 |
stringBuilder.append(",..."); |
|
55 | 95 |
break; |
56 | 96 |
} |
57 | 97 |
else { |
... | ... | |
61 | 101 |
attributes.add(stringBuilder.toString()); |
62 | 102 |
} |
63 | 103 |
|
64 |
modelMap.addAttribute("assemblies", assemblies); |
|
65 |
modelMap.addAttribute("attributes", attributes); |
|
66 |
|
|
67 |
return modelAndView; |
|
104 |
return attributes; |
|
68 | 105 |
} |
69 |
|
|
70 |
@PostMapping("/") |
|
71 |
public ModelAndView indexPost(@Valid @ModelAttribute("assemblyID") String id) { |
|
72 |
ModelAndView modelAndView = new ModelAndView(); |
|
73 |
modelAndView.setViewName("redirect:/assembly"); |
|
74 |
|
|
75 |
return modelAndView; |
|
76 |
} |
|
77 |
|
|
78 | 106 |
} |
src/main/resources/application.properties | ||
---|---|---|
1 | 1 |
# Tell hibernate to use oracle dialect. |
2 |
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
|
|
2 |
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
|
|
3 | 3 |
|
4 | 4 |
# TNS format of connection to ORACLE 12c database. |
5 | 5 |
oracle.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=atreus-v.zcu.cz)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=DEMO_SERVICE))) |
src/main/webapp/WEB-INF/templates/assembly.html | ||
---|---|---|
29 | 29 |
</h1> |
30 | 30 |
</div> |
31 | 31 |
|
32 |
<form th:object="${configuration}" method="post" th:action="@{/assembly(assemblyID=${assemblyID})}">
|
|
33 |
<input type="hidden" th:field="*{id}" th:value="${assembly?.getId()}" />
|
|
32 |
<form th:object="${configuration}" method="post" th:action="@{/configuration(configurationID=${configuration.id})}">
|
|
33 |
<input type="hidden" th:field="*{assembly.id}" th:value="${configuration.assembly?.getId()}" />
|
|
34 | 34 |
<div class="container box"> |
35 | 35 |
<div class="col-md-12"> |
36 | 36 |
<div class="col-md-12 form-group row"> |
37 | 37 |
<label for="exampleFormControlSelect1" class="name-input-label">Titulek tabulky:</label> |
38 |
<input type="text" class="form-control name-input" th:field="*{name}" th:value="${assembly?.name}">
|
|
38 |
<input type="text" class="form-control name-input" th:field="*{tableName}" th:value="${configuration?.tableName}">
|
|
39 | 39 |
</div> |
40 | 40 |
|
41 | 41 |
<span>Parametry:</span> |
... | ... | |
49 | 49 |
</tr> |
50 | 50 |
</thead> |
51 | 51 |
<tbody> |
52 |
<tr th:each="parameter, itemStat : ${configuration.parametersInConfiguration}"> |
|
53 |
|
|
54 |
</tr> |
|
55 |
<tr> |
|
56 |
<td><span class="select-text-padding">Akademický rok</span></td> |
|
52 |
<tr th:each="parameterInConfiguration, itemStat : ${configuration.parametersInConfiguration}"> |
|
57 | 53 |
<td> |
58 |
<span class="select-action-padding select-action-button select-input-action-margin-collapse"> |
|
54 |
<span class="select-text-padding" th:text="${parameterInConfiguration.parameter.name}"></span> |
|
55 |
</td> |
|
56 |
<td> |
|
57 |
<optional th:each="location : ${parameterInConfiguration.parameter.locations}"> |
|
58 |
<span th:if="${location.name.equals('Sloupec')}" th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].location.name}" class="select-action-padding select-action-button select-input-action-margin-collapse"> |
|
59 | 59 |
<i class="fas fa-align-justify"></i> |
60 | 60 |
</span> |
61 |
<span class="select-action-padding select-action-button select-input-action-margin-collapse">
|
|
61 |
<span th:if="${location.name.equals('Řádek')}" th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].location.name}" class="select-action-padding select-action-button select-input-action-margin-collapse">
|
|
62 | 62 |
<i class="fas fa-align-justify transform"></i> |
63 | 63 |
</span> |
64 |
<span th:if="${location.name.equals('Hodnota')}" th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].location.name}" class="select-action-padding select-action-button select-input-action-margin-collapse"> |
|
65 |
<i class="fas fa-heading"></i> |
|
66 |
</span> |
|
67 |
</optional> |
|
64 | 68 |
</td> |
65 | 69 |
<td class="s"> |
66 | 70 |
<div class="col select-filter"> |
67 |
<select class="form-control" style="{width:60px;}" id="exampleFormControlSelect1"> |
|
68 |
<option>IN</option> |
|
69 |
<option>GREATER</option> |
|
70 |
<option>LESS</option> |
|
71 |
<option>EQUAL</option> |
|
72 |
</select> |
|
73 |
<input type="text" class="form-control select-filter-input" id="name"> |
|
74 |
</div> |
|
75 |
</td> |
|
76 |
</tr> |
|
77 |
<tr> |
|
78 |
<td><span class="select-text-padding">Fakulta</span></td> |
|
79 |
<td> |
|
80 |
<span class="select-action-padding select-action-button select-input-action-margin-collapse select-action-headlight"> |
|
81 |
<i class="fas fa-align-justify"></i> |
|
82 |
</span> |
|
83 |
<span class="select-action-padding select-action-button select-input-action-margin-collapse "> |
|
84 |
<i class="fas fa-align-justify transform"></i> |
|
85 |
</span> |
|
86 |
</td> |
|
87 |
<td class="s"> |
|
88 |
<div class="col select-filter"> |
|
89 |
<select class="form-control" style="{width:60px;}" id="exampleFormControlSelect1"> |
|
90 |
<option>IN</option> |
|
91 |
<option>GREATER</option> |
|
92 |
<option>LESS</option> |
|
93 |
<option>EQUAL</option> |
|
94 |
</select> |
|
95 |
<input type="text" class="form-control select-filter-input" id="name"> |
|
96 |
</div> |
|
97 |
</td> |
|
98 |
</tr> |
|
99 |
<tr> |
|
100 |
<td><span class="select-text-padding">Ročník</span></td> |
|
101 |
<td> |
|
102 |
<span class="select-action-padding select-action-button select-input-action-margin-collapse"> |
|
103 |
<i class="fas fa-align-justify"></i> |
|
104 |
</span> |
|
105 |
<span class="select-action-padding select-action-button select-input-action-margin-collapse select-action-headlight"> |
|
106 |
<i class="fas fa-align-justify transform"></i> |
|
107 |
</span> |
|
108 |
</td> |
|
109 |
<td class="s"> |
|
110 |
<div class="col select-filter"> |
|
111 |
<select class="form-control" style="{width:60px;}" id="exampleFormControlSelect1"> |
|
112 |
<option>IN</option> |
|
113 |
<option>GREATER</option> |
|
114 |
<option>LESS</option> |
|
115 |
<option>EQUAL</option> |
|
116 |
</select> |
|
117 |
<input type="text" class="form-control select-filter-input" id="name"> |
|
118 |
</div> |
|
119 |
</td> |
|
120 |
</tr> |
|
121 |
<tr> |
|
122 |
<td><span class="select-text-padding">Typ strudia</span></td> |
|
123 |
<td> |
|
124 |
<span class="select-action-padding select-action-button select-input-action-margin-collapse select-action-headlight"> |
|
125 |
<i class="fas fa-align-justify"></i> |
|
126 |
</span> |
|
127 |
<span class="select-action-padding select-action-button select-input-action-margin-collapse"> |
|
128 |
<i class="fas fa-align-justify transform"></i> |
|
129 |
</span> |
|
130 |
<span class="select-action-padding select-action-button select-input-action-margin-collapse"> |
|
131 |
<i class="fas fa-heading"></i> |
|
132 |
</span> |
|
133 |
</td> |
|
134 |
<td class="s"> |
|
135 |
<div class="col select-filter"> |
|
136 |
<select class="form-control" style="{width:60px;}" id="exampleFormControlSelect1"> |
|
137 |
<option>IN</option> |
|
138 |
<option>GREATER</option> |
|
139 |
<option>LESS</option> |
|
140 |
<option>EQUAL</option> |
|
141 |
</select> |
|
142 |
<input type="text" class="form-control select-filter-input" id="name"> |
|
143 |
</div> |
|
144 |
</td> |
|
145 |
</tr> |
|
146 |
<tr> |
|
147 |
<td><span class="select-text-padding">Počet</span></td> |
|
148 |
<td> |
|
149 |
<span class="select-action-padding select-action-button select-input-action-margin-collapse select-action-headlight"> |
|
150 |
<i class="fas fa-heading"></i> |
|
151 |
</span> |
|
152 |
</td> |
|
153 |
<td class="s"> |
|
154 |
<div class="col select-filter"> |
|
155 |
<select class="form-control" style="{width:60px;}" id="exampleFormControlSelect1"> |
|
156 |
<option>IN</option> |
|
157 |
<option>GREATER</option> |
|
158 |
<option>LESS</option> |
|
159 |
<option>EQUAL</option> |
|
71 |
<select class="form-control" style="{width:60px;}" id="exampleFormControlSelect1" th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].operator.name}"> |
|
72 |
<option th:value="zadny" selected value> -- Zvolte operátor -- </option> |
|
73 |
<option th:each="operator : ${parameterInConfiguration.parameter.operators}" th:text="${operator.name}" th:value="${operator.name}"></option> |
|
160 | 74 |
</select> |
161 |
<input type="text" class="form-control select-filter-input" id="name"> |
|
75 |
<input type="text" class="form-control select-filter-input" id="name" th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].operatorValue}">
|
|
162 | 76 |
</div> |
163 | 77 |
</td> |
164 | 78 |
</tr> |
... | ... | |
271 | 185 |
<div class="col-md-12 form-group row template-input"> |
272 | 186 |
<label for="exampleFormControlSelect1" class="template-input-label">Vlastní název šablony:</label> |
273 | 187 |
<div class=""> |
274 |
<input type="text" class="form-control select-filter-input" id="name">
|
|
188 |
<input type="text" required="required" class="form-control select-filter-input" id="name" th:field="${configuration.name}">
|
|
275 | 189 |
</div> |
276 | 190 |
|
277 | 191 |
<button type="submit" class="btn btn-success mb-2 template-input-submit">Uložit šablonu</button> |
src/main/webapp/WEB-INF/templates/index.html | ||
---|---|---|
31 | 31 |
</div> |
32 | 32 |
<table class="table table-bordered table-striped"> |
33 | 33 |
<tbody> |
34 |
<tr> |
|
35 |
<td><a href=#>Vlastní šablona 1</a></td> |
|
36 |
<td class="center-cell"> |
|
37 |
<span class="action-button"> |
|
38 |
<a href=# class="action-link far fa-trash-alt"></a> |
|
39 |
</span> |
|
40 |
</td> |
|
41 |
</tr> |
|
42 |
<tr> |
|
43 |
<td><a href=#>Vlastní šablona 2, Vlastní šablona 2, Vlastní šablona 2, Vlastní šablona 2</a></td> |
|
34 |
<tr th:each="iconfiguration : ${configurations}"> |
|
35 |
<td><a th:href="@{/configuration(configurationID=${iconfiguration.id})}"><span th:text="${iconfiguration.name}"></span></a></td> |
|
44 | 36 |
<td class="center-cell"> |
45 | 37 |
<span class="action-button"> |
46 | 38 |
<a href=# class="action-link far fa-trash-alt"></a> |
Také k dispozici: Unified diff
re #7881 ability to create or edit a user configuration and set or edit its basic attributes, operator value and configuration name are validated, if operator value is wrong user is redirected to main page, auto increment functionality changed to IDENTITY