Revize ba8b306a
Přidáno uživatelem Vojtěch Danišík před téměř 5 roky(ů)
src/main/java/vldc/aswi/AswiJpa.java | ||
---|---|---|
7 | 7 |
import vldc.aswi.configuration.AppConfig; |
8 | 8 |
import vldc.aswi.configuration.DbConfig; |
9 | 9 |
|
10 |
/** |
|
11 |
* Main class. |
|
12 |
*/ |
|
10 | 13 |
@SpringBootApplication |
11 | 14 |
@Import({ |
12 | 15 |
AppConfig.class, |
... | ... | |
14 | 17 |
}) |
15 | 18 |
public class AswiJpa { |
16 | 19 |
|
20 |
/** |
|
21 |
* Main method. |
|
22 |
* @param args - Input arguments. |
|
23 |
*/ |
|
17 | 24 |
public static void main(String[] args) { |
18 | 25 |
SpringApplication.run(AswiJpa.class, args); |
19 | 26 |
} |
src/main/java/vldc/aswi/configuration/AppConfig.java | ||
---|---|---|
6 | 6 |
import org.springframework.context.annotation.Bean; |
7 | 7 |
import org.springframework.context.annotation.ComponentScan; |
8 | 8 |
import org.springframework.context.annotation.Configuration; |
9 |
import org.springframework.http.HttpMethod; |
|
10 | 9 |
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; |
11 | 10 |
import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
12 | 11 |
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
... | ... | |
14 | 13 |
import org.springframework.security.core.userdetails.UserDetailsService; |
15 | 14 |
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
16 | 15 |
import org.springframework.security.crypto.password.PasswordEncoder; |
17 |
import org.springframework.security.web.util.matcher.RegexRequestMatcher; |
|
18 | 16 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc; |
19 | 17 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
20 | 18 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
... | ... | |
24 | 22 |
import org.thymeleaf.spring5.view.ThymeleafViewResolver; |
25 | 23 |
import org.thymeleaf.templatemode.TemplateMode; |
26 | 24 |
|
25 |
/** |
|
26 |
* Application configuration. |
|
27 |
*/ |
|
27 | 28 |
@Configuration |
28 | 29 |
@ComponentScan |
29 | 30 |
@EnableWebMvc |
src/main/java/vldc/aswi/configuration/DbConfig.java | ||
---|---|---|
5 | 5 |
import com.sun.istack.NotNull; |
6 | 6 |
import oracle.jdbc.pool.OracleDataSource; |
7 | 7 |
import org.springframework.boot.context.properties.ConfigurationProperties; |
8 |
import org.springframework.boot.jdbc.DataSourceBuilder; |
|
9 | 8 |
import org.springframework.context.annotation.Bean; |
10 | 9 |
import org.springframework.context.annotation.Configuration; |
11 | 10 |
import org.springframework.transaction.annotation.EnableTransactionManagement; |
12 | 11 |
|
13 | 12 |
import java.sql.SQLException; |
14 | 13 |
|
14 |
/** |
|
15 |
* Connection configuration for database. |
|
16 |
*/ |
|
15 | 17 |
@Configuration |
16 | 18 |
@EnableTransactionManagement |
17 | 19 |
@ConfigurationProperties(prefix = "oracle") |
18 | 20 |
public class DbConfig { |
19 | 21 |
|
22 |
/** Username of logging user. */ |
|
20 | 23 |
@NotNull |
21 | 24 |
private String username; |
22 | 25 |
|
26 |
/** Password of logging user. */ |
|
23 | 27 |
@NotNull |
24 | 28 |
private String password; |
25 | 29 |
|
30 |
/** TNS url for connection into database. */ |
|
26 | 31 |
@NotNull |
27 | 32 |
private String url; |
28 | 33 |
|
34 |
/** |
|
35 |
* Set new username. |
|
36 |
* @param username - User's name. |
|
37 |
*/ |
|
29 | 38 |
public void setUsername(String username) { |
30 | 39 |
this.username = username; |
31 | 40 |
} |
32 | 41 |
|
42 |
/** |
|
43 |
* Set new password. |
|
44 |
* @param password - User's password. |
|
45 |
*/ |
|
33 | 46 |
public void setPassword(String password) { |
34 | 47 |
this.password = password; |
35 | 48 |
} |
36 | 49 |
|
50 |
/** |
|
51 |
* Set new url. |
|
52 |
* @param url - TNS url for connection into database. |
|
53 |
*/ |
|
37 | 54 |
public void setUrl(String url) { |
38 | 55 |
this.url = url; |
39 | 56 |
} |
40 | 57 |
|
58 |
/** |
|
59 |
* Create new datasource. |
|
60 |
* @return new Datasource of currently logged database. |
|
61 |
* @throws SQLException |
|
62 |
*/ |
|
41 | 63 |
@Bean |
42 | 64 |
DataSource dataSource() throws SQLException { |
43 | 65 |
OracleDataSource dataSource = new OracleDataSource(); |
src/main/java/vldc/aswi/dao/AssemblyRepository.java | ||
---|---|---|
1 | 1 |
package vldc.aswi.dao; |
2 | 2 |
|
3 |
import org.springframework.data.jpa.repository.JpaRepository; |
|
4 | 3 |
import org.springframework.data.repository.CrudRepository; |
5 | 4 |
import org.springframework.stereotype.Repository; |
6 | 5 |
import vldc.aswi.domain.Assembly; |
... | ... | |
18 | 17 |
*/ |
19 | 18 |
Assembly getById(Long Id); |
20 | 19 |
|
21 |
// TODO |
|
20 |
|
|
21 |
/** |
|
22 |
* Find record with highest order. |
|
23 |
* @return Assembly with highest order. |
|
24 |
*/ |
|
25 |
// TODO: test it. |
|
22 | 26 |
Assembly findFirst1ByOrderByAssemblyOrder(); |
23 | 27 |
} |
src/main/java/vldc/aswi/dao/parameter/ParameterTypeRepository.java | ||
---|---|---|
17 | 17 |
*/ |
18 | 18 |
ParameterType getById(Long Id); |
19 | 19 |
|
20 |
/** |
|
21 |
* Find ParameterType by its name. |
|
22 |
* @param name - ParameterType name |
|
23 |
* @return ParameterType if name is present in database. |
|
24 |
*/ |
|
20 | 25 |
ParameterType findByName(String name); |
21 | 26 |
} |
src/main/java/vldc/aswi/database/DatabaseInterface.java | ||
---|---|---|
1 | 1 |
package vldc.aswi.database; |
2 | 2 |
|
3 |
import org.springframework.context.annotation.Bean; |
|
4 | 3 |
import org.springframework.dao.DataAccessException; |
5 | 4 |
import org.springframework.jdbc.core.JdbcTemplate; |
6 | 5 |
import org.springframework.jdbc.core.ResultSetExtractor; |
7 |
import org.springframework.jdbc.core.RowMapper; |
|
8 | 6 |
import org.springframework.stereotype.Component; |
9 | 7 |
import vldc.aswi.model.table.TableColumn; |
10 | 8 |
|
... | ... | |
16 | 14 |
import java.util.List; |
17 | 15 |
import java.util.Map; |
18 | 16 |
|
17 |
/** |
|
18 |
* Class for manipulating (selecting, updating, creating, ...) database data. |
|
19 |
*/ |
|
19 | 20 |
@Component |
20 | 21 |
public class DatabaseInterface { |
21 | 22 |
|
23 |
/** JdbcTemplate for executing queries. */ |
|
22 | 24 |
private JdbcTemplate jdbcTemplate = null; |
23 | 25 |
|
26 |
/** |
|
27 |
* Constructor. |
|
28 |
* @param jdbcTemplate - JdbcTemplate for executing queries. |
|
29 |
*/ |
|
24 | 30 |
public DatabaseInterface(JdbcTemplate jdbcTemplate) { |
25 | 31 |
this.jdbcTemplate = jdbcTemplate; |
26 | 32 |
} |
27 | 33 |
|
34 |
/** |
|
35 |
* Validate given SQLQuery. |
|
36 |
* @param sqlQuery - Tested SQL Query. |
|
37 |
* @return true if SQL query is valid, false if not. |
|
38 |
*/ |
|
39 |
public boolean validateSQLQuery(String sqlQuery) { |
|
40 |
try |
|
41 |
{ |
|
42 |
jdbcTemplate.execute("EXPLAIN PLAN FOR " + sqlQuery); |
|
43 |
return true; |
|
44 |
} |
|
45 |
catch (DataAccessException e) |
|
46 |
{ |
|
47 |
return false; |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* Execute given SQL Query and return results as list of TableColumn class. |
|
53 |
* @param sqlQuery - SQL query. |
|
54 |
* @return List of results saved as TableColumn. |
|
55 |
*/ |
|
28 | 56 |
public Map<String, TableColumn> executeQueryAndReturnTableColumns(String sqlQuery) { |
29 | 57 |
return jdbcTemplate.query( |
30 | 58 |
sqlQuery, |
src/main/java/vldc/aswi/domain/Assembly.java | ||
---|---|---|
65 | 65 |
this.setIsPublic(isPublic); |
66 | 66 |
} |
67 | 67 |
|
68 |
/** |
|
69 |
* Equal method for comparing two objects. |
|
70 |
* @param obj - Comparing object. |
|
71 |
* @return true if objects are same. |
|
72 |
*/ |
|
68 | 73 |
@Override |
69 | 74 |
public boolean equals(Object obj) { |
70 | 75 |
return super.equals(obj); |
src/main/java/vldc/aswi/domain/Configuration.java | ||
---|---|---|
49 | 49 |
this.setTableName(tableName); |
50 | 50 |
} |
51 | 51 |
|
52 |
/** |
|
53 |
* Equal method for comparing two objects. |
|
54 |
* @param obj - Comparing object. |
|
55 |
* @return true if objects are same. |
|
56 |
*/ |
|
52 | 57 |
@Override |
53 | 58 |
public boolean equals(Object obj) { |
54 | 59 |
return super.equals(obj); |
src/main/java/vldc/aswi/domain/EntityParent.java | ||
---|---|---|
3 | 3 |
import javax.persistence.*; |
4 | 4 |
|
5 | 5 |
import lombok.Data; |
6 |
import org.apache.poi.ss.formula.functions.T; |
|
7 |
import vldc.aswi.domain.parameter.Parameter; |
|
8 |
|
|
9 |
import java.util.LinkedList; |
|
10 |
import java.util.List; |
|
11 | 6 |
|
12 | 7 |
/** |
13 | 8 |
* Class which is extended for all domain entities containing common attributes. |
... | ... | |
22 | 17 |
@GeneratedValue(strategy=GenerationType.IDENTITY) |
23 | 18 |
private Long id; |
24 | 19 |
|
20 |
/** |
|
21 |
* Equal method for comparing two objects. |
|
22 |
* @param obj - Comparing object. |
|
23 |
* @return true if objects are same. |
|
24 |
*/ |
|
25 | 25 |
@Override |
26 | 26 |
public boolean equals(Object obj) |
27 | 27 |
{ |
src/main/java/vldc/aswi/domain/Function.java | ||
---|---|---|
41 | 41 |
this.setName(name); |
42 | 42 |
} |
43 | 43 |
|
44 |
/** |
|
45 |
* Equal method for comparing two objects. |
|
46 |
* @param obj - Comparing object. |
|
47 |
* @return true if objects are same. |
|
48 |
*/ |
|
44 | 49 |
@Override |
45 | 50 |
public boolean equals(Object obj) { |
46 | 51 |
return super.equals(obj); |
src/main/java/vldc/aswi/domain/Location.java | ||
---|---|---|
38 | 38 |
this.setName(name); |
39 | 39 |
} |
40 | 40 |
|
41 |
/** |
|
42 |
* Equal method for comparing two objects. |
|
43 |
* @param obj - Comparing object. |
|
44 |
* @return true if objects are same. |
|
45 |
*/ |
|
41 | 46 |
@Override |
42 | 47 |
public boolean equals(Object obj) { |
43 | 48 |
return super.equals(obj); |
src/main/java/vldc/aswi/domain/Operator.java | ||
---|---|---|
38 | 38 |
this.setName(name); |
39 | 39 |
} |
40 | 40 |
|
41 |
/** |
|
42 |
* Equal method for comparing two objects. |
|
43 |
* @param obj - Comparing object. |
|
44 |
* @return true if objects are same. |
|
45 |
*/ |
|
41 | 46 |
@Override |
42 | 47 |
public boolean equals(Object obj) { |
43 | 48 |
return super.equals(obj); |
src/main/java/vldc/aswi/domain/Role.java | ||
---|---|---|
36 | 36 |
this.setName(name); |
37 | 37 |
} |
38 | 38 |
|
39 |
/** |
|
40 |
* Equal method for comparing two objects. |
|
41 |
* @param obj - Comparing object. |
|
42 |
* @return true if objects are same. |
|
43 |
*/ |
|
39 | 44 |
@Override |
40 | 45 |
public boolean equals(Object obj) { |
41 | 46 |
return super.equals(obj); |
src/main/java/vldc/aswi/domain/User.java | ||
---|---|---|
45 | 45 |
this.setPassword(password); |
46 | 46 |
} |
47 | 47 |
|
48 |
/** |
|
49 |
* Equal method for comparing two objects. |
|
50 |
* @param obj - Comparing object. |
|
51 |
* @return true if objects are same. |
|
52 |
*/ |
|
48 | 53 |
@Override |
49 | 54 |
public boolean equals(Object obj) { |
50 | 55 |
return super.equals(obj); |
src/main/java/vldc/aswi/domain/parameter/Parameter.java | ||
---|---|---|
1 | 1 |
package vldc.aswi.domain.parameter; |
2 | 2 |
|
3 |
import com.fasterxml.jackson.annotation.JsonBackReference; |
|
4 |
import com.fasterxml.jackson.annotation.JsonIdentityInfo; |
|
5 |
import com.fasterxml.jackson.annotation.JsonManagedReference; |
|
6 |
import com.fasterxml.jackson.annotation.ObjectIdGenerators; |
|
7 | 3 |
import lombok.Data; |
8 | 4 |
import lombok.EqualsAndHashCode; |
9 | 5 |
import lombok.NoArgsConstructor; |
10 |
import lombok.ToString; |
|
11 | 6 |
import vldc.aswi.domain.*; |
12 | 7 |
import javax.persistence.*; |
13 | 8 |
import java.util.List; |
... | ... | |
99 | 94 |
this.setDefaultValue(defaultValue); |
100 | 95 |
} |
101 | 96 |
|
97 |
/** |
|
98 |
* Overriding toString method to prevent StackOverflowError when parsing values from assembly form. |
|
99 |
* @return Parameter info. |
|
100 |
*/ |
|
102 | 101 |
@Override |
103 | 102 |
public String toString() { |
104 | 103 |
return "Parameter[name=" + name + ", nameOfSelect=" + nameOfSelect + ", defaultHodnota=" + defaultValue + "]"; |
105 | 104 |
} |
106 | 105 |
|
106 |
/** |
|
107 |
* Equal method for comparing two objects. |
|
108 |
* @param obj - Comparing object. |
|
109 |
* @return true if objects are same. |
|
110 |
*/ |
|
107 | 111 |
@Override |
108 | 112 |
public boolean equals(Object obj) { |
109 | 113 |
return super.equals(obj); |
src/main/java/vldc/aswi/domain/parameter/ParameterInConfiguration.java | ||
---|---|---|
66 | 66 |
this.setColumnName(columnName); |
67 | 67 |
} |
68 | 68 |
|
69 |
/** |
|
70 |
* Equal method for comparing two objects. |
|
71 |
* @param obj - Comparing object. |
|
72 |
* @return true if objects are same. |
|
73 |
*/ |
|
69 | 74 |
@Override |
70 | 75 |
public boolean equals(Object obj) { |
71 | 76 |
return super.equals(obj); |
src/main/java/vldc/aswi/domain/parameter/ParameterType.java | ||
---|---|---|
36 | 36 |
this.setName(name); |
37 | 37 |
} |
38 | 38 |
|
39 |
/** |
|
40 |
* Equal method for comparing two objects. |
|
41 |
* @param obj - Comparing object. |
|
42 |
* @return true if objects are same. |
|
43 |
*/ |
|
39 | 44 |
@Override |
40 | 45 |
public boolean equals(Object obj) { |
41 | 46 |
return super.equals(obj); |
src/main/java/vldc/aswi/domain/parameter/ParameterValue.java | ||
---|---|---|
34 | 34 |
this.setValue(value); |
35 | 35 |
} |
36 | 36 |
|
37 |
/** |
|
38 |
* Equal method for comparing two objects. |
|
39 |
* @param obj - Comparing object. |
|
40 |
* @return true if objects are same. |
|
41 |
*/ |
|
37 | 42 |
@Override |
38 | 43 |
public boolean equals(Object obj) { |
39 | 44 |
return super.equals(obj); |
src/main/java/vldc/aswi/model/table/TableColumn.java | ||
---|---|---|
3 | 3 |
import java.util.ArrayList; |
4 | 4 |
import java.util.List; |
5 | 5 |
|
6 |
/** |
|
7 |
* Class representing one table column. |
|
8 |
*/ |
|
6 | 9 |
public class TableColumn { |
7 | 10 |
|
11 |
/** Name of table column. */ |
|
8 | 12 |
private String name; |
9 | 13 |
|
14 |
/** List of values in current column. */ |
|
10 | 15 |
private List<String> values; |
11 | 16 |
|
17 |
/** |
|
18 |
* Constructor. |
|
19 |
* @param name - Name of table column. |
|
20 |
*/ |
|
12 | 21 |
public TableColumn(String name) { |
13 | 22 |
this.name = name; |
14 | 23 |
values = new ArrayList<>(); |
15 | 24 |
} |
16 | 25 |
|
26 |
/** |
|
27 |
* Add new value into list of values. |
|
28 |
* @param value - New value. |
|
29 |
*/ |
|
17 | 30 |
public void addValue(String value) { |
18 | 31 |
values.add(value); |
19 | 32 |
} |
20 | 33 |
|
34 |
/** |
|
35 |
* Get name of table column. |
|
36 |
* @return Name of table column. |
|
37 |
*/ |
|
21 | 38 |
public String getName() { |
22 | 39 |
return name; |
23 | 40 |
} |
24 | 41 |
|
42 |
/** |
|
43 |
* Get all values in current table column. |
|
44 |
* @return List of all values. |
|
45 |
*/ |
|
25 | 46 |
public List<String> getValues() { |
26 | 47 |
return values; |
27 | 48 |
} |
src/main/java/vldc/aswi/model/table/contingencyTable/ContingencyTableRow.java | ||
---|---|---|
3 | 3 |
import java.util.ArrayList; |
4 | 4 |
import java.util.List; |
5 | 5 |
|
6 |
/** |
|
7 |
* Class representing one row in Contingency table. Rows are represented as tree with given level. |
|
8 |
*/ |
|
6 | 9 |
public class ContingencyTableRow { |
7 | 10 |
|
11 |
/** True if current row is header, false if not. */ |
|
8 | 12 |
private boolean isHeader; |
9 | 13 |
|
14 |
/** Level of current row. */ |
|
10 | 15 |
private int level; |
11 | 16 |
|
17 |
/** List of cells in current row. */ |
|
12 | 18 |
private List<ContingencyTableRowCell> cells; |
13 | 19 |
|
20 |
/** |
|
21 |
* Constructor. |
|
22 |
* @param isHeader - True if current row is header, false if not. |
|
23 |
* @param level - Level of current row. |
|
24 |
*/ |
|
14 | 25 |
public ContingencyTableRow(boolean isHeader, int level) { |
15 | 26 |
this.isHeader = isHeader; |
16 | 27 |
this.level = level; |
... | ... | |
18 | 29 |
cells = new ArrayList<>(); |
19 | 30 |
} |
20 | 31 |
|
32 |
/** |
|
33 |
* Add new cell into current row. |
|
34 |
* @param cell - New cell. |
|
35 |
*/ |
|
21 | 36 |
public void addTableRowCell(ContingencyTableRowCell cell) { |
22 | 37 |
cells.add(cell); |
23 | 38 |
} |
24 | 39 |
|
40 |
/** |
|
41 |
* Check if current row is header or not. |
|
42 |
* @return True if current row is header, false if not. |
|
43 |
*/ |
|
25 | 44 |
public boolean isHeader() { |
26 | 45 |
return isHeader; |
27 | 46 |
} |
28 | 47 |
|
48 |
/** |
|
49 |
* Get level of current cell. |
|
50 |
* @return |
|
51 |
*/ |
|
29 | 52 |
public int getLevel() { |
30 | 53 |
return level; |
31 | 54 |
} |
32 | 55 |
|
56 |
/** |
|
57 |
* Get all cells in current row. |
|
58 |
* @return List of cells. |
|
59 |
*/ |
|
33 | 60 |
public List<ContingencyTableRowCell> getCells() { |
34 | 61 |
return cells; |
35 | 62 |
} |
36 | 63 |
|
64 |
/** |
|
65 |
* Overriding toString method for debugging. |
|
66 |
* @return String. |
|
67 |
*/ |
|
37 | 68 |
@Override |
38 | 69 |
public String toString() { |
39 | 70 |
String str = ""; |
src/main/java/vldc/aswi/model/table/contingencyTable/ContingencyTableRowCell.java | ||
---|---|---|
1 | 1 |
package vldc.aswi.model.table.contingencyTable; |
2 | 2 |
|
3 |
/** |
|
4 |
* Class representing one cell in Contingency table row. |
|
5 |
*/ |
|
3 | 6 |
public class ContingencyTableRowCell { |
4 | 7 |
|
8 |
/** Colspan of current cell. */ |
|
5 | 9 |
private int colSpan; |
6 | 10 |
|
11 |
/** Value in current cell. */ |
|
7 | 12 |
private String value; |
8 | 13 |
|
14 |
/** |
|
15 |
* Constructor. |
|
16 |
* @param value - Value in current cell. |
|
17 |
* @param colSpan - Colspan of current cell. |
|
18 |
*/ |
|
9 | 19 |
public ContingencyTableRowCell(String value, int colSpan) { |
10 | 20 |
this.value = value; |
11 | 21 |
this.colSpan = colSpan; |
12 | 22 |
} |
13 | 23 |
|
24 |
/** |
|
25 |
* Get value of current cell. |
|
26 |
* @return Value of cell. |
|
27 |
*/ |
|
14 | 28 |
public String getValue() { |
15 | 29 |
return value; |
16 | 30 |
} |
17 | 31 |
|
32 |
/** |
|
33 |
* Get colspan of current cell. |
|
34 |
* @return Colspan of cell. |
|
35 |
*/ |
|
18 | 36 |
public int getColSpan() { |
19 | 37 |
return colSpan; |
20 | 38 |
} |
21 | 39 |
|
40 |
/** |
|
41 |
* Overrided toString method for debugging. |
|
42 |
* @return String. |
|
43 |
*/ |
|
22 | 44 |
@Override |
23 | 45 |
public String toString() { |
24 | 46 |
return "(" + value + ", " + colSpan + ")"; |
src/main/java/vldc/aswi/service/AssemblyManager.java | ||
---|---|---|
17 | 17 |
*/ |
18 | 18 |
List<Assembly> getAssemblies(); |
19 | 19 |
|
20 |
/** |
|
21 |
* Get assembly by id. |
|
22 |
* @param id - ID of assembly. |
|
23 |
* @return Assembly. |
|
24 |
*/ |
|
20 | 25 |
Assembly getAssemblyById(Long id); |
21 | 26 |
|
27 |
/** |
|
28 |
* Update assembly. |
|
29 |
* @param updatedAssemblyValues - Assembly values. |
|
30 |
* @return ID of assembly. |
|
31 |
*/ |
|
22 | 32 |
Long updateAssembly(Assembly updatedAssemblyValues); |
23 | 33 |
|
34 |
/** |
|
35 |
* Update assembly's order. |
|
36 |
* @param id - ID of assembly. |
|
37 |
* @param order - Assembly's order. |
|
38 |
*/ |
|
24 | 39 |
void updateAssemblyOrder(Long id, int order); |
25 | 40 |
|
41 |
/** |
|
42 |
* Create new assembly. |
|
43 |
* @param assemblyValues - Assembly values. |
|
44 |
* @return ID of assembly. |
|
45 |
*/ |
|
26 | 46 |
Long createAssembly(Assembly assemblyValues); |
27 | 47 |
} |
src/main/java/vldc/aswi/service/AssemblyManagerImpl.java | ||
---|---|---|
15 | 15 |
import java.util.LinkedList; |
16 | 16 |
import java.util.List; |
17 | 17 |
|
18 |
/** |
|
19 |
* Manager for Assembly. |
|
20 |
*/ |
|
18 | 21 |
@Service |
19 | 22 |
@Slf4j |
20 | 23 |
public class AssemblyManagerImpl implements AssemblyManager { |
... | ... | |
53 | 56 |
return retVal; |
54 | 57 |
} |
55 | 58 |
|
59 |
/** |
|
60 |
* Get assembly by id. |
|
61 |
* @param id - ID of assembly. |
|
62 |
* @return Assembly. |
|
63 |
*/ |
|
56 | 64 |
@Override |
57 | 65 |
public Assembly getAssemblyById(Long id) { |
58 | 66 |
return assemblyRepository.getById(id); |
59 | 67 |
} |
60 | 68 |
|
69 |
/** |
|
70 |
* Update assembly's order. |
|
71 |
* @param id - ID of assembly. |
|
72 |
* @param order - Assembly's order. |
|
73 |
*/ |
|
61 | 74 |
@Override |
62 | 75 |
public void updateAssemblyOrder(Long id, int order) { |
63 | 76 |
Assembly assembly = getAssemblyById(id); |
... | ... | |
65 | 78 |
this.assemblyRepository.save(assembly); |
66 | 79 |
} |
67 | 80 |
|
81 |
/** |
|
82 |
* Update assembly. |
|
83 |
* @param updatedAssemblyValues - Assembly values. |
|
84 |
* @return ID of assembly. |
|
85 |
*/ |
|
68 | 86 |
@Override |
69 | 87 |
public Long updateAssembly(Assembly updatedAssemblyValues) { |
70 | 88 |
// TODO: test it. |
... | ... | |
80 | 98 |
return assembly.getId(); |
81 | 99 |
} |
82 | 100 |
|
101 |
/** |
|
102 |
* Update assembly's roles. |
|
103 |
* @param id - ID of assembly. |
|
104 |
* @param updatedRoles - List of roles. |
|
105 |
*/ |
|
83 | 106 |
private void updateAssemblyRoles(Long id, List<Role> updatedRoles) { |
84 | 107 |
// TODO: test it. |
85 | 108 |
Assembly assembly = getAssemblyById(id); |
... | ... | |
108 | 131 |
this.assemblyRepository.save(assembly); |
109 | 132 |
} |
110 | 133 |
|
134 |
/** |
|
135 |
* Create new assembly. |
|
136 |
* @param assemblyValues - Assembly values. |
|
137 |
* @return ID of assembly. |
|
138 |
*/ |
|
111 | 139 |
@Override |
112 | 140 |
public Long createAssembly(Assembly assemblyValues) { |
113 | 141 |
// TODO: test it. |
142 |
// Create new assembly and assign values. |
|
114 | 143 |
Assembly assembly = new Assembly(); |
115 | 144 |
assembly.setName(assemblyValues.getName()); |
116 | 145 |
assembly.setSQLQuery(assemblyValues.getSQLQuery()); |
... | ... | |
118 | 147 |
assembly.setIsPublic(assemblyValues.getIsPublic()); |
119 | 148 |
List<Role> roles = new LinkedList<>(); |
120 | 149 |
|
150 |
// Add access for roles. |
|
121 | 151 |
if (assemblyValues.getRoles() != null && assemblyValues.getRoles().size() > 0) { |
122 | 152 |
for (Role newRole : assemblyValues.getRoles()) { |
123 | 153 |
roles.add(this.roleRepository.getById(newRole.getId())); |
... | ... | |
125 | 155 |
} |
126 | 156 |
|
127 | 157 |
assembly.setRoles(roles); |
158 |
|
|
159 |
// Create new record in database. |
|
128 | 160 |
this.assemblyRepository.save(assembly); |
129 | 161 |
|
130 | 162 |
return assembly.getId(); |
src/main/java/vldc/aswi/service/FunctionManagerImpl.java | ||
---|---|---|
13 | 13 |
import java.util.LinkedList; |
14 | 14 |
import java.util.List; |
15 | 15 |
|
16 |
/** |
|
17 |
* Manager for Function. |
|
18 |
*/ |
|
16 | 19 |
@Service |
17 | 20 |
@Slf4j |
18 | 21 |
public class FunctionManagerImpl implements FunctionManager { |
src/main/java/vldc/aswi/service/LocationManagerImpl.java | ||
---|---|---|
13 | 13 |
import java.util.LinkedList; |
14 | 14 |
import java.util.List; |
15 | 15 |
|
16 |
/** |
|
17 |
* Manager for Location. |
|
18 |
*/ |
|
16 | 19 |
@Service |
17 | 20 |
@Slf4j |
18 | 21 |
public class LocationManagerImpl implements LocationManager { |
src/main/java/vldc/aswi/service/OperatorManagerImpl.java | ||
---|---|---|
13 | 13 |
import java.util.LinkedList; |
14 | 14 |
import java.util.List; |
15 | 15 |
|
16 |
/** |
|
17 |
* Manager for Operator. |
|
18 |
*/ |
|
16 | 19 |
@Service |
17 | 20 |
@Slf4j |
18 | 21 |
public class OperatorManagerImpl implements OperatorManager { |
src/main/java/vldc/aswi/service/RoleManagerImpl.java | ||
---|---|---|
13 | 13 |
import java.util.LinkedList; |
14 | 14 |
import java.util.List; |
15 | 15 |
|
16 |
/** |
|
17 |
* Manager for Role. |
|
18 |
*/ |
|
16 | 19 |
@Service |
17 | 20 |
@Slf4j |
18 | 21 |
public class RoleManagerImpl implements RoleManager { |
src/main/java/vldc/aswi/service/SqlQueryManager.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import java.util.List; |
6 | 6 |
|
7 |
/** |
|
8 |
* Interface for SqlQuery manager. |
|
9 |
*/ |
|
7 | 10 |
public interface SqlQueryManager { |
8 | 11 |
|
9 |
List<ContingencyTableRow> getContingencyTableRow(String sql); |
|
12 |
/** |
|
13 |
* Get list of contingencyTableRow. |
|
14 |
* @param sqlQuery - SQL query. |
|
15 |
* @return List of contingencyTableRow. |
|
16 |
*/ |
|
17 |
List<ContingencyTableRow> getContingencyTableRow(String sqlQuery); |
|
18 |
|
|
19 |
/** |
|
20 |
* Validate given SQL query. |
|
21 |
* @param sqlQuery - Validated SQL query. |
|
22 |
* @return true if SQL query is ok, false if not. |
|
23 |
*/ |
|
24 |
boolean validateSQLQuery(String sqlQuery); |
|
10 | 25 |
} |
src/main/java/vldc/aswi/service/SqlQueryManagerImpl.java | ||
---|---|---|
12 | 12 |
import java.util.List; |
13 | 13 |
import java.util.Map; |
14 | 14 |
|
15 |
/** |
|
16 |
* Manager for SqlQuery. |
|
17 |
*/ |
|
15 | 18 |
@Service |
16 | 19 |
@Slf4j |
17 | 20 |
public class SqlQueryManagerImpl implements SqlQueryManager{ |
18 | 21 |
|
19 |
@Autowired |
|
20 |
private DataSource dataSource; |
|
21 |
|
|
22 |
/** Autowired databaseInterface component. */ |
|
22 | 23 |
@Autowired |
23 | 24 |
private DatabaseInterface databaseInterface; |
24 | 25 |
|
26 |
/** |
|
27 |
* Get list of contingencyTableRow. |
|
28 |
* @param sqlQuery - SQL query. |
|
29 |
* @return List of contingencyTableRow. |
|
30 |
*/ |
|
25 | 31 |
@Override |
26 | 32 |
public List<ContingencyTableRow> getContingencyTableRow(String sqlQuery) { |
27 | 33 |
Map<String, TableColumn> tableColumns = databaseInterface.executeQueryAndReturnTableColumns(sqlQuery); |
28 | 34 |
return Converter.convertTableColumnsToContingencyTableRows(tableColumns); |
29 | 35 |
} |
36 |
|
|
37 |
/** |
|
38 |
* Validate given SQL query. |
|
39 |
* @param sqlQuery - Validated SQL query. |
|
40 |
* @return true if SQL query is ok, false if not. |
|
41 |
*/ |
|
42 |
@Override |
|
43 |
public boolean validateSQLQuery(String sqlQuery) { |
|
44 |
return databaseInterface.validateSQLQuery(sqlQuery); |
|
45 |
} |
|
30 | 46 |
} |
src/main/java/vldc/aswi/service/UserManagerImpl.java | ||
---|---|---|
14 | 14 |
import java.util.LinkedList; |
15 | 15 |
import java.util.List; |
16 | 16 |
|
17 |
/** |
|
18 |
* Manager for User. |
|
19 |
*/ |
|
17 | 20 |
@Service |
18 | 21 |
@Slf4j |
19 | 22 |
public class UserManagerImpl implements UserManager { |
... | ... | |
46 | 49 |
User referentka = this.userRepository.getById(idReferentka); |
47 | 50 |
User prorektor = this.userRepository.getById(idProrektor); |
48 | 51 |
|
49 |
// TODO: set roles for every default user. |
|
50 | 52 |
//admin.setRole(); |
51 | 53 |
} |
52 | 54 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterInConfigurationManagerImpl.java | ||
---|---|---|
13 | 13 |
import java.util.LinkedList; |
14 | 14 |
import java.util.List; |
15 | 15 |
|
16 |
/** |
|
17 |
* Manager for ParameterInConfiguration. |
|
18 |
*/ |
|
16 | 19 |
@Service |
17 | 20 |
@Slf4j |
18 | 21 |
public class ParameterInConfigurationManagerImpl implements ParameterInConfigurationManager { |
src/main/java/vldc/aswi/service/parameter/ParameterManager.java | ||
---|---|---|
15 | 15 |
*/ |
16 | 16 |
List<Parameter> getParameters(); |
17 | 17 |
|
18 |
/** |
|
19 |
* Add new parameter into database. |
|
20 |
* @param assemblyId - Assembly in which parameter is presented. |
|
21 |
* @param parameterValuesList - Parameter values. |
|
22 |
*/ |
|
18 | 23 |
void addParameters(Long assemblyId, List<Parameter> parameterValuesList); |
19 | 24 |
|
25 |
/** |
|
26 |
* Update parameter with given values. |
|
27 |
* @param assemblyId - Assembly in which parameter is presented. |
|
28 |
* @param newAssemblyParameters - List of parameters. |
|
29 |
*/ |
|
20 | 30 |
void updateParameters(Long assemblyId, List<Parameter> newAssemblyParameters); |
21 | 31 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterManagerImpl.java | ||
---|---|---|
15 | 15 |
import vldc.aswi.dao.parameter.ParameterValueRepository; |
16 | 16 |
import vldc.aswi.domain.*; |
17 | 17 |
import vldc.aswi.domain.parameter.Parameter; |
18 |
import vldc.aswi.domain.parameter.ParameterType; |
|
19 | 18 |
import vldc.aswi.domain.parameter.ParameterValue; |
20 |
import vldc.aswi.service.FunctionManager; |
|
21 |
import vldc.aswi.service.LocationManager; |
|
22 |
import vldc.aswi.service.OperatorManager; |
|
23 | 19 |
|
24 | 20 |
import javax.transaction.Transactional; |
25 |
import java.util.ArrayList; |
|
26 | 21 |
import java.util.LinkedList; |
27 | 22 |
import java.util.List; |
28 | 23 |
|
24 |
/** |
|
25 |
* Manager for Parameter. |
|
26 |
*/ |
|
29 | 27 |
@Service |
30 | 28 |
@Slf4j |
31 | 29 |
public class ParameterManagerImpl implements ParameterManager { |
... | ... | |
34 | 32 |
@Autowired |
35 | 33 |
private ParameterRepository parameterRepository; |
36 | 34 |
|
35 |
/** Autowired assembly repository. */ |
|
37 | 36 |
@Autowired |
38 | 37 |
private AssemblyRepository assemblyRepository; |
39 | 38 |
|
39 |
/** Autowired parameterType repository. */ |
|
40 | 40 |
@Autowired |
41 | 41 |
private ParameterTypeRepository parameterTypeRepository; |
42 | 42 |
|
43 |
/** Autowired location repository. */ |
|
43 | 44 |
@Autowired |
44 | 45 |
private LocationRepository locationRepository; |
45 | 46 |
|
47 |
/** Autowired function repository. */ |
|
46 | 48 |
@Autowired |
47 | 49 |
private FunctionRepository functionRepository; |
48 | 50 |
|
51 |
/** Autowired operator repository. */ |
|
49 | 52 |
@Autowired |
50 | 53 |
private OperatorRepository operatorRepository; |
51 | 54 |
|
55 |
/** Autowired parameterValue repository. */ |
|
52 | 56 |
@Autowired |
53 | 57 |
private ParameterValueRepository parameterValueRepository; |
54 | 58 |
|
... | ... | |
79 | 83 |
return retVal; |
80 | 84 |
} |
81 | 85 |
|
86 |
/** |
|
87 |
* Add new parameter into database. |
|
88 |
* @param assemblyId - Assembly in which parameter is presented. |
|
89 |
* @param parameterValuesList - Parameter values. |
|
90 |
*/ |
|
82 | 91 |
@Override |
83 | 92 |
public void addParameters(Long assemblyId, List<Parameter> parameterValuesList) { |
84 | 93 |
Assembly assembly = this.assemblyRepository.getById(assemblyId); |
... | ... | |
86 | 95 |
if (parameterValuesList == null) return; |
87 | 96 |
|
88 | 97 |
for (Parameter parameterValues : parameterValuesList) { |
98 |
// Create new parameter and assign him all values. |
|
89 | 99 |
Parameter parameter = new Parameter(); |
90 | 100 |
parameter.setName(parameterValues.getNameOfSelect()); |
91 | 101 |
parameter.setNameOfSelect(parameterValues.getNameOfSelect()); |
... | ... | |
97 | 107 |
List<Function> functionList = new LinkedList<>(); |
98 | 108 |
List<Operator> operatorList = new LinkedList<>(); |
99 | 109 |
|
110 |
// Try to put all locations into list. |
|
100 | 111 |
if (parameterValues.getLocations() != null && parameterValues.getLocations().size() > 0) { |
101 | 112 |
for (Location location : parameterValues.getLocations()) { |
102 | 113 |
locationList.add(this.locationRepository.getById(location.getId())); |
103 | 114 |
} |
104 | 115 |
} |
105 | 116 |
|
117 |
// Try to put all functions into list. |
|
106 | 118 |
if (parameterValues.getFunctions() != null && parameterValues.getFunctions().size() > 0) { |
107 | 119 |
for (Function function : parameterValues.getFunctions()) { |
108 | 120 |
functionList.add(this.functionRepository.getById(function.getId())); |
109 | 121 |
} |
110 | 122 |
} |
111 | 123 |
|
124 |
// Try to put all operators into list. |
|
112 | 125 |
if (parameterValues.getOperators() != null && parameterValues.getOperators().size() > 0) { |
113 | 126 |
for (Operator operator : parameterValues.getOperators()) { |
114 | 127 |
operatorList.add(this.operatorRepository.getById(operator.getId())); |
115 | 128 |
} |
116 | 129 |
} |
117 | 130 |
|
131 |
// Set lists of values into parameter. |
|
118 | 132 |
parameter.setLocations(locationList); |
119 | 133 |
parameter.setFunctions(functionList); |
120 | 134 |
parameter.setOperators(operatorList); |
121 | 135 |
|
136 |
// Insert parameter into database. |
|
122 | 137 |
this.parameterRepository.save(parameter); |
123 | 138 |
} |
124 | 139 |
} |
125 | 140 |
|
141 |
/** |
|
142 |
* Update parameter - remove deleted parameters, add new parameters, update updated parameters. |
|
143 |
* @param assemblyId - Assembly in which parameter is presented. |
|
144 |
* @param newAssemblyParameters - List of parameters. |
|
145 |
*/ |
|
126 | 146 |
@Override |
127 | 147 |
public void updateParameters(Long assemblyId, List<Parameter> newAssemblyParameters) { |
128 | 148 |
// TODO: test it. |
129 | 149 |
Assembly assembly = this.assemblyRepository.getById(assemblyId); |
130 | 150 |
List<Parameter> currentAssemblyParameters = assembly.getParameters(); |
131 | 151 |
|
132 |
// Find new parameters;
|
|
152 |
// Find new parameters.
|
|
133 | 153 |
List<Parameter> currentAssemblyParametersNew = new LinkedList<>(currentAssemblyParameters); |
134 | 154 |
List<Parameter> newAssemblyParametersNew = new LinkedList<>(newAssemblyParameters); |
135 | 155 |
newAssemblyParametersNew.removeAll(currentAssemblyParametersNew); |
136 | 156 |
|
137 |
// Find deleted parameters |
|
157 |
// Find deleted parameters.
|
|
138 | 158 |
List<Parameter> currentAssemblyParametersDeleted = new LinkedList<>(currentAssemblyParameters); |
139 | 159 |
List<Parameter> newAssemblyParametersDeleted = new LinkedList<>(newAssemblyParameters); |
140 | 160 |
currentAssemblyParametersDeleted.removeAll(newAssemblyParametersDeleted); |
... | ... | |
150 | 170 |
// Remove deleted parameters. |
151 | 171 |
for (Parameter parameter : currentAssemblyParametersDeleted) { |
152 | 172 |
for (ParameterValue parameterValue : parameter.getParameterValues()) { |
173 |
// Remove parameters values. |
|
153 | 174 |
this.parameterValueRepository.delete(parameterValue); |
154 | 175 |
} |
155 | 176 |
|
177 |
// Remove parameter. |
|
156 | 178 |
this.parameterRepository.delete(parameter); |
157 | 179 |
} |
158 | 180 |
|
... | ... | |
163 | 185 |
addParameters(assemblyId, newAssemblyParametersNew); |
164 | 186 |
} |
165 | 187 |
|
188 |
/** |
|
189 |
* Update updated parameters. |
|
190 |
* @param parameterValuesList - List of updated parameters. |
|
191 |
*/ |
|
166 | 192 |
private void updateParameters(List<Parameter> parameterValuesList) { |
167 | 193 |
// TODO: test it. |
168 | 194 |
for (Parameter parameterValues : parameterValuesList) { |
195 |
// Get current parameter from database. |
|
169 | 196 |
Parameter parameter = this.parameterRepository.getById(parameterValues.getId()); |
197 |
// Update current parameter values. |
|
170 | 198 |
parameter.setName(parameterValues.getName()); |
171 | 199 |
parameter.setNameOfSelect(parameterValues.getNameOfSelect()); |
172 | 200 |
parameter.setAssembly(this.assemblyRepository.getById(parameterValues.getAssembly().getId())); |
173 | 201 |
parameter.setParameterType(this.parameterTypeRepository.getById(parameterValues.getParameterType().getId())); |
174 | 202 |
parameter.setDefaultValue(parameterValues.getDefaultValue()); |
203 |
|
|
204 |
// Insert changes into database. |
|
175 | 205 |
this.parameterRepository.save(parameter); |
176 | 206 |
|
207 |
// Update parameter values, locations, functions and operators. |
|
177 | 208 |
updateParameterValues(parameterValues.getId(), parameterValues.getParameterValues()); |
178 | 209 |
updateParameterLocations(parameterValues.getId(), parameterValues.getLocations()); |
179 | 210 |
updateParameterFunctions(parameterValues.getId(), parameterValues.getFunctions()); |
... | ... | |
181 | 212 |
} |
182 | 213 |
} |
183 | 214 |
|
215 |
/** |
|
216 |
* Update current parameter locations. |
|
217 |
* @param id - Id of parameter. |
|
218 |
* @param updatedLocations - List of locations. |
|
219 |
*/ |
|
184 | 220 |
private void updateParameterLocations(Long id, List<Location> updatedLocations) { |
185 | 221 |
// TODO: test it. |
186 | 222 |
Parameter parameter = this.parameterRepository.getById(id); |
187 | 223 |
List<Location> currentLocations = parameter.getLocations(); |
188 | 224 |
|
225 |
// Get new locations. |
|
189 | 226 |
List<Location> currentLocationsNew = new LinkedList<>(currentLocations); |
190 | 227 |
List<Location> updatedLocationsNew = new LinkedList<>(updatedLocations); |
191 | 228 |
updatedLocationsNew.removeAll(currentLocationsNew); |
192 | 229 |
|
230 |
// Get deleted locations. |
|
193 | 231 |
List<Location> currentLocationsDeleted = new LinkedList<>(currentLocations); |
194 | 232 |
List<Location> updatedLocationsDeleted = new LinkedList<>(updatedLocations); |
195 | 233 |
currentLocationsDeleted.removeAll(updatedLocationsDeleted); |
196 | 234 |
|
235 |
// If there is no change, do not update. |
|
197 | 236 |
if (updatedLocationsNew.size() == 0 && currentLocationsDeleted.size() == 0) return; |
198 | 237 |
|
238 |
// Add new locations. |
|
199 | 239 |
for (Location newLocation : updatedLocationsNew) { |
200 | 240 |
currentLocations.add(this.locationRepository.getById(newLocation.getId())); |
201 | 241 |
} |
242 |
|
|
243 |
// Remove deleted locations. |
|
202 | 244 |
currentLocations.removeAll(currentLocationsDeleted); |
203 | 245 |
|
246 |
// Insert changes into database. |
|
204 | 247 |
this.parameterRepository.save(parameter); |
205 | 248 |
} |
206 | 249 |
|
250 |
/** |
|
251 |
* Update current parameter functions. |
|
252 |
* @param id - Id of parameter. |
|
253 |
* @param updatedFunctions - List of functions. |
|
254 |
*/ |
|
207 | 255 |
private void updateParameterFunctions(Long id, List<Function> updatedFunctions) { |
208 | 256 |
// TODO: test it. |
209 | 257 |
Parameter parameter = this.parameterRepository.getById(id); |
210 | 258 |
List<Function> currentFunctions = parameter.getFunctions(); |
211 | 259 |
|
260 |
// Get new functions. |
|
212 | 261 |
List<Function> currentFunctionsNew = new LinkedList<>(currentFunctions); |
213 | 262 |
List<Function> updatedFunctionsNew = new LinkedList<>(updatedFunctions); |
214 | 263 |
updatedFunctionsNew.removeAll(currentFunctionsNew); |
215 | 264 |
|
265 |
// Get deleted functions. |
|
216 | 266 |
List<Function> currentFunctionsDeleted = new LinkedList<>(currentFunctions); |
217 | 267 |
List<Function> updatedFunctionsDeleted = new LinkedList<>(updatedFunctions); |
218 | 268 |
currentFunctionsDeleted.removeAll(updatedFunctionsDeleted); |
219 | 269 |
|
270 |
// If there is no change, do not update. |
|
220 | 271 |
if (updatedFunctionsNew.size() == 0 && currentFunctionsDeleted.size() == 0) return; |
221 | 272 |
|
273 |
// Add new functions. |
|
222 | 274 |
for (Function newFunction : updatedFunctionsNew) { |
223 | 275 |
currentFunctions.add(this.functionRepository.getById(newFunction.getId())); |
224 | 276 |
} |
277 |
|
|
278 |
// Delete removed functions. |
|
225 | 279 |
currentFunctions.removeAll(currentFunctionsDeleted); |
226 | 280 |
|
281 |
// Insert changes into database. |
|
227 | 282 |
this.parameterRepository.save(parameter); |
228 | 283 |
} |
229 | 284 |
|
285 |
/** |
|
286 |
* Update current parameter operators. |
|
287 |
* @param id - Id of parameter. |
|
288 |
* @param updatedOperators - List of operators. |
|
289 |
*/ |
|
230 | 290 |
private void updateParameterOperators(Long id, List<Operator> updatedOperators) { |
231 | 291 |
// TODO: test it. |
232 | 292 |
Parameter parameter = this.parameterRepository.getById(id); |
233 | 293 |
List<Operator> currentOperators = parameter.getOperators(); |
234 | 294 |
|
295 |
// Get new operators. |
|
235 | 296 |
List<Operator> currentOperatorsNew = new LinkedList<>(currentOperators); |
236 | 297 |
List<Operator> updatedOperatorsNew = new LinkedList<>(updatedOperators); |
237 | 298 |
updatedOperatorsNew.removeAll(currentOperatorsNew); |
238 | 299 |
|
300 |
// Get deleted operators. |
|
239 | 301 |
List<Operator> currentOperatorsDeleted = new LinkedList<>(currentOperators); |
240 | 302 |
List<Operator> updatedOperatorsDeleted = new LinkedList<>(updatedOperators); |
241 | 303 |
currentOperatorsDeleted.removeAll(updatedOperatorsDeleted); |
242 | 304 |
|
305 |
// If there is no changes, do not update. |
|
243 | 306 |
if (updatedOperatorsNew.size() == 0 && currentOperatorsDeleted.size() == 0) return; |
244 | 307 |
|
308 |
// Insert new operators. |
|
245 | 309 |
for (Operator newOperator : updatedOperatorsNew) { |
246 | 310 |
currentOperators.add(this.operatorRepository.getById(newOperator.getId())); |
247 | 311 |
} |
312 |
|
|
313 |
// Delete removed operators. |
|
248 | 314 |
currentOperators.removeAll(currentOperatorsDeleted); |
249 | 315 |
|
316 |
// Insert changes into database. |
|
250 | 317 |
this.parameterRepository.save(parameter); |
251 | 318 |
} |
252 | 319 |
|
320 |
/** |
|
321 |
* Update current parameter values. |
|
322 |
* @param parameterId - ID of parameter. |
|
323 |
* @param newParameterValues - List of parameter values. |
|
324 |
*/ |
|
253 | 325 |
private void updateParameterValues(Long parameterId, List<ParameterValue> newParameterValues) { |
254 | 326 |
// TODO: test it. |
255 | 327 |
Parameter parameter = this.parameterRepository.getById(parameterId); |
256 | 328 |
List<ParameterValue> currentParameterValues = parameter.getParameterValues(); |
257 | 329 |
|
330 |
// Get new parameter values. |
|
258 | 331 |
List<ParameterValue> currentParameterValuesNew = new LinkedList<>(currentParameterValues); |
259 | 332 |
List<ParameterValue> newParameterValuesNew = new LinkedList<>(newParameterValues); |
260 | 333 |
newParameterValuesNew.removeAll(currentParameterValuesNew); |
261 | 334 |
|
335 |
// Get deleted parameter values. |
|
262 | 336 |
List<ParameterValue> currentParameterValuesDeleted = new LinkedList<>(currentParameterValues); |
263 | 337 |
List<ParameterValue> newParameterValuesDeleted = new LinkedList<>(newParameterValues); |
264 | 338 |
currentParameterValuesDeleted.removeAll(newParameterValuesDeleted); |
265 | 339 |
|
340 |
// Get updated parameter values. |
|
266 | 341 |
List<ParameterValue> currentParameterValuesUpdated = new LinkedList<>(currentParameterValues); |
267 | 342 |
List<ParameterValue> newParameterValuesUpdated = new LinkedList<>(newParameterValues); |
268 | 343 |
newParameterValuesUpdated.retainAll(currentParameterValuesUpdated); |
269 | 344 |
|
345 |
// If there is no changes, do not update. |
|
270 | 346 |
if (newParameterValuesNew.size() == 0 && currentParameterValuesDeleted.size() == 0 && newParameterValuesUpdated.size() == currentParameterValues.size()) return; |
271 | 347 |
|
348 |
// Delete removed parameter values. |
|
272 | 349 |
for (ParameterValue parameterValue : currentParameterValuesDeleted) { |
273 | 350 |
this.parameterValueRepository.delete(parameterValue); |
274 | 351 |
} |
275 | 352 |
|
353 |
// Update parameter values. |
|
276 | 354 |
updateParameterValueValues(newParameterValuesUpdated); |
277 | 355 |
|
356 |
// Add new parameter values. |
|
278 | 357 |
addParameterValueValues(parameterId, newParameterValuesNew); |
279 | 358 |
} |
280 | 359 |
|
360 |
/** |
|
361 |
* Update all updated parameter values. |
|
362 |
* @param updatedParameterValuesList - List of all updated parameter values. |
|
363 |
*/ |
|
281 | 364 |
private void updateParameterValueValues(List<ParameterValue> updatedParameterValuesList) { |
282 | 365 |
// TODO: test it. |
283 | 366 |
for (ParameterValue parameterValueValues : updatedParameterValuesList) { |
284 | 367 |
ParameterValue parameterValue = this.parameterValueRepository.getById(parameterValueValues.getId()); |
285 | 368 |
parameterValue.setValue(parameterValueValues.getValue()); |
286 | 369 |
|
370 |
// Insert changes into database. |
|
287 | 371 |
this.parameterValueRepository.save(parameterValue); |
288 | 372 |
} |
289 | 373 |
} |
290 | 374 |
|
375 |
/** |
|
376 |
* Add new parameter values. |
|
377 |
* @param parameterId - ID of parameter. |
|
378 |
* @param newParameterValuesNew - List of new parameter values. |
|
379 |
*/ |
|
291 | 380 |
private void addParameterValueValues(Long parameterId, List<ParameterValue> newParameterValuesNew) { |
292 | 381 |
// TODO: test it. |
293 | 382 |
Parameter parameter = this.parameterRepository.getById(parameterId); |
... | ... | |
297 | 386 |
parameterValue.setValue(parameterValueValues.getValue()); |
298 | 387 |
parameterValue.setParameter(parameter); |
299 | 388 |
|
389 |
// Insert new parameterValue into database. |
|
300 | 390 |
this.parameterValueRepository.save(parameterValue); |
301 | 391 |
} |
302 | 392 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterTypeManagerImpl.java | ||
---|---|---|
13 | 13 |
import java.util.LinkedList; |
14 | 14 |
import java.util.List; |
15 | 15 |
|
16 |
/** |
|
17 |
* Manager for ParameterType. |
|
18 |
*/ |
|
16 | 19 |
@Service |
17 | 20 |
@Slf4j |
18 | 21 |
public class ParameterTypeManagerImpl implements ParameterTypeManager { |
src/main/java/vldc/aswi/service/parameter/ParameterValueManager.java | ||
---|---|---|
14 | 14 |
* @return List of parameter values. |
15 | 15 |
*/ |
16 | 16 |
List<ParameterValue> getParameterValues(); |
17 |
|
|
18 |
void createParameterValues(Long parameterId, List<ParameterValue> parameterValues); |
|
19 |
|
|
20 |
void updateParameterValues(Long parameterId, List<ParameterValue> parameterValues); |
|
21 |
|
|
22 |
void addParameterValues(Long parameterId, List<ParameterValue> newParameterValuesNew); |
|
23 | 17 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterValueManagerImpl.java | ||
---|---|---|
15 | 15 |
import java.util.LinkedList; |
16 | 16 |
import java.util.List; |
17 | 17 |
|
18 |
/** |
|
19 |
* Manager for ParameterValue. |
|
20 |
*/ |
|
18 | 21 |
@Service |
19 | 22 |
@Slf4j |
20 | 23 |
public class ParameterValueManagerImpl implements ParameterValueManager { |
... | ... | |
52 | 55 |
this.parameterValueRepository.findAll().forEach(retVal::add); |
53 | 56 |
return retVal; |
54 | 57 |
} |
55 |
|
|
56 |
|
|
57 |
@Override |
|
58 |
public void createParameterValues(Long parameterId, List<ParameterValue> parameterValues) { |
|
59 |
Parameter parameter = this.parameterRepository.getById(parameterId); |
|
60 |
|
|
61 |
for (ParameterValue newParameterValue : parameterValues) { |
|
62 |
ParameterValue parameterValue = new ParameterValue(); |
|
63 |
parameterValue.setValue(newParameterValue.getValue()); |
|
64 |
parameterValue.setParameter(parameter); |
|
65 |
|
|
66 |
this.parameterValueRepository.save(parameterValue); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public void updateParameterValues(Long parameterId, List<ParameterValue> newParameterValues) { |
|
72 |
Parameter parameter = this.parameterRepository.getById(parameterId); |
|
73 |
List<ParameterValue> currentParameterValues = parameter.getParameterValues(); |
|
74 |
|
|
75 |
List<ParameterValue> currentParameterValuesNew = new LinkedList<>(currentParameterValues); |
|
76 |
List<ParameterValue> newParameterValuesNew = new LinkedList<>(newParameterValues); |
|
77 |
newParameterValuesNew.removeAll(currentParameterValuesNew); |
|
78 |
|
|
79 |
List<ParameterValue> currentParameterValuesDeleted = new LinkedList<>(currentParameterValues); |
|
80 |
List<ParameterValue> newParameterValuesDeleted = new LinkedList<>(newParameterValues); |
|
81 |
currentParameterValuesDeleted.removeAll(newParameterValuesDeleted); |
|
82 |
|
|
83 |
List<ParameterValue> currentParameterValuesUpdated = new LinkedList<>(currentParameterValues); |
|
84 |
List<ParameterValue> newParameterValuesUpdated = new LinkedList<>(newParameterValues); |
|
85 |
newParameterValuesUpdated.retainAll(currentParameterValuesUpdated); |
|
86 |
|
|
87 |
if (newParameterValuesNew.size() == 0 && currentParameterValuesDeleted.size() == 0 && newParameterValuesUpdated.size() == currentParameterValues.size()) return; |
|
88 |
|
|
89 |
for (ParameterValue parameterValue : currentParameterValuesDeleted) { |
|
90 |
this.parameterValueRepository.delete(parameterValue); |
|
91 |
} |
|
92 |
|
|
93 |
updateParameterValues(newParameterValuesUpdated); |
|
94 |
|
|
95 |
addParameterValues(parameterId, newParameterValuesNew); |
|
96 |
} |
|
97 |
|
|
98 |
private void updateParameterValues(List<ParameterValue> updatedParameterValuesList) { |
|
99 |
for (ParameterValue parameterValueValues : updatedParameterValuesList) { |
|
100 |
ParameterValue parameterValue = this.parameterValueRepository.getById(parameterValueValues.getId()); |
|
101 |
parameterValue.setValue(parameterValueValues.getValue()); |
|
102 |
|
|
103 |
this.parameterValueRepository.save(parameterValue); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public void addParameterValues(Long parameterId, List<ParameterValue> newParameterValuesNew) { |
|
109 |
Parameter parameter = this.parameterRepository.getById(parameterId); |
|
110 |
|
|
111 |
for (ParameterValue parameterValueValues : newParameterValuesNew) { |
|
112 |
ParameterValue parameterValue = new ParameterValue(); |
|
113 |
parameterValue.setValue(parameterValueValues.getValue()); |
|
114 |
parameterValue.setParameter(parameter); |
|
115 |
|
|
116 |
this.parameterValueRepository.save(parameterValue); |
|
117 |
} |
|
118 |
} |
|
119 |
|
|
120 | 58 |
} |
src/main/java/vldc/aswi/utils/Converter.java | ||
---|---|---|
8 | 8 |
import java.util.List; |
9 | 9 |
import java.util.Map; |
10 | 10 |
|
11 |
/** |
|
12 |
* Class for converting classes. |
|
13 |
*/ |
|
11 | 14 |
public class Converter { |
12 | 15 |
|
16 |
/** |
|
17 |
* Convert Map of TableColumns into list of ContingencyTableRow. |
|
18 |
* @param tableColumns - Map of TableColumn. |
|
19 |
* @return List of ContingencyTableRow. |
|
20 |
*/ |
|
13 | 21 |
public static List<ContingencyTableRow> convertTableColumnsToContingencyTableRows(Map<String, TableColumn> tableColumns) { |
14 | 22 |
List<ContingencyTableRow> contingencyTableRows = new ArrayList<>(); |
15 | 23 |
|
24 |
// Create header row with column names. |
|
16 | 25 |
ContingencyTableRow contingencyTableRowHeader = new ContingencyTableRow(true, 0); |
17 | 26 |
for (String columnName : tableColumns.keySet()) { |
18 | 27 |
contingencyTableRowHeader.addTableRowCell(new ContingencyTableRowCell(columnName, 0)); |
... | ... | |
21 | 30 |
|
22 | 31 |
boolean listExpanded = false; |
23 | 32 |
|
33 |
// Create contingency table row. |
|
24 | 34 |
for (TableColumn tableColumn : tableColumns.values()) { |
25 | 35 |
List<String> values = tableColumn.getValues(); |
26 | 36 |
|
37 |
// If list is not created, then create it. |
|
27 | 38 |
if (!listExpanded) { |
28 | 39 |
for (int j = 0; j < values.size(); j++) { |
29 | 40 |
ContingencyTableRow contingencyTableRow = new ContingencyTableRow(false, 0); |
... | ... | |
32 | 43 |
listExpanded = true; |
33 | 44 |
} |
34 | 45 |
|
46 |
// Iterate through all values and assign one value per one row. |
|
35 | 47 |
for (int j = 0; j < values.size(); j++) { |
36 | 48 |
ContingencyTableRowCell contingencyTableRowCell = new ContingencyTableRowCell(values.get(j), 0); |
37 | 49 |
contingencyTableRows.get(j + 1).addTableRowCell(contingencyTableRowCell); |
src/main/java/vldc/aswi/validators/AssemblyValidator.java | ||
---|---|---|
1 |
package vldc.aswi.validators; |
|
2 |
|
|
3 |
import org.springframework.beans.factory.annotation.Autowired; |
|
4 |
import org.springframework.stereotype.Component; |
|
5 |
import org.springframework.validation.Errors; |
|
6 |
import org.springframework.validation.Validator; |
|
7 |
import vldc.aswi.domain.Assembly; |
|
8 |
import vldc.aswi.domain.parameter.Parameter; |
|
9 |
import vldc.aswi.service.SqlQueryManager; |
|
10 |
|
|
11 |
/** |
|
12 |
* Validator for assembly. |
|
13 |
*/ |
|
14 |
@Component |
|
15 |
public class AssemblyValidator implements Validator { |
|
16 |
|
|
17 |
/** Autowired sql query manager. */ |
|
18 |
@Autowired |
|
19 |
private SqlQueryManager sqlQueryManager; |
|
20 |
|
|
21 |
/** |
|
22 |
* Validator for supporting this class. |
|
23 |
* @param aClass - Class. |
|
24 |
* @return true if sent class match Assembly class. |
|
25 |
*/ |
|
26 |
@Override |
|
27 |
public boolean supports(Class<?> aClass) { |
|
28 |
return Assembly.class.equals(aClass); |
|
29 |
} |
|
30 |
|
|
31 |
/** |
|
32 |
* Validate assembly values. |
|
33 |
* @param obj - Validated object. |
|
34 |
* @param errors - Errors sended to output. |
|
35 |
*/ |
|
36 |
@Override |
|
37 |
public void validate(Object obj, Errors errors) { |
|
38 |
// TODO: VALIDATING - https://docs.spring.io/spring/docs/4.1.x/spring-framework-reference/html/validation.html |
|
39 |
// TODO: ERROR STYLES - https://mkyong.com/spring-mvc/spring-mvc-form-errors-tag-example/ |
|
40 |
|
|
41 |
// Get assembly values. |
|
42 |
Assembly assembly = (Assembly) obj; |
Také k dispozici: Unified diff
re #7886 Assembly validator in progress (validating assembly SQLQuery + locations for existing assembly, not tested for new assembly).
Added comments.
Removing unused imports.