Revize 21d41302
Přidáno uživatelem Michal Linha před téměř 5 roky(ů)
src/main/java/vldc/aswi/dao/AssemblyRepository.java | ||
---|---|---|
1 |
package vldc.aswi.dao; |
|
2 |
|
|
3 |
import org.springframework.data.repository.CrudRepository; |
|
4 |
import org.springframework.stereotype.Repository; |
|
5 |
import vldc.aswi.domain.Assembly; |
|
6 |
|
|
7 |
/** |
|
8 |
* Repository for domain Assembly. |
|
9 |
*/ |
|
10 |
@Repository |
|
11 |
public interface AssemblyRepository extends CrudRepository<Assembly, Long> { |
|
12 |
|
|
13 |
/** |
|
14 |
* Find Assembly by its ID. |
|
15 |
* @param Id - Assembly Id. |
|
16 |
* @return Assembly if ID is present in database. |
|
17 |
*/ |
|
18 |
Assembly getById(Long Id); |
|
19 |
} |
src/main/java/vldc/aswi/dao/ConfigurationRepository.java | ||
---|---|---|
1 |
package vldc.aswi.dao; |
|
2 |
|
|
3 |
import org.springframework.data.repository.CrudRepository; |
|
4 |
import org.springframework.stereotype.Repository; |
|
5 |
import vldc.aswi.domain.Configuration; |
|
6 |
|
|
7 |
/** |
|
8 |
* Repository for domain Configuration. |
|
9 |
*/ |
|
10 |
@Repository |
|
11 |
public interface ConfigurationRepository extends CrudRepository<Configuration, Long> { |
|
12 |
|
|
13 |
/** |
|
14 |
* Find Configuration by its ID. |
|
15 |
* @param Id - Configuration Id. |
|
16 |
* @return Configuration if ID is present in database. |
|
17 |
*/ |
|
18 |
Configuration getById(Long Id); |
|
19 |
} |
src/main/java/vldc/aswi/dao/FunctionRepository.java | ||
---|---|---|
1 |
package vldc.aswi.dao; |
|
2 |
|
|
3 |
import org.springframework.data.repository.CrudRepository; |
|
4 |
import org.springframework.stereotype.Repository; |
|
5 |
import vldc.aswi.domain.Function; |
|
6 |
|
|
7 |
/** |
|
8 |
* Repository for domain Function. |
|
9 |
*/ |
|
10 |
@Repository |
|
11 |
public interface FunctionRepository extends CrudRepository<Function, Long> { |
|
12 |
|
|
13 |
/** |
|
14 |
* Find Function by its ID. |
|
15 |
* @param Id - Function Id. |
|
16 |
* @return Function if ID is present in database. |
|
17 |
*/ |
|
18 |
Function getById(Long Id); |
|
19 |
} |
src/main/java/vldc/aswi/dao/LocationRepository.java | ||
---|---|---|
1 |
package vldc.aswi.dao; |
|
2 |
|
|
3 |
import org.springframework.data.repository.CrudRepository; |
|
4 |
import org.springframework.stereotype.Repository; |
|
5 |
import vldc.aswi.domain.Location; |
|
6 |
|
|
7 |
/** |
|
8 |
* Repository for domain Location. |
|
9 |
*/ |
|
10 |
@Repository |
|
11 |
public interface LocationRepository extends CrudRepository<Location, Long> { |
|
12 |
|
|
13 |
/** |
|
14 |
* Find Location by its ID. |
|
15 |
* @param Id - Location Id. |
|
16 |
* @return Location if ID is present in database. |
|
17 |
*/ |
|
18 |
Location getById(Long Id); |
|
19 |
} |
src/main/java/vldc/aswi/dao/OperatorRepository.java | ||
---|---|---|
1 |
package vldc.aswi.dao; |
|
2 |
|
|
3 |
import org.springframework.data.repository.CrudRepository; |
|
4 |
import org.springframework.stereotype.Repository; |
|
5 |
import vldc.aswi.domain.Operator; |
|
6 |
|
|
7 |
/** |
|
8 |
* Repository for domain Operator. |
|
9 |
*/ |
|
10 |
@Repository |
|
11 |
public interface OperatorRepository extends CrudRepository<Operator, Long> { |
|
12 |
|
|
13 |
/** |
|
14 |
* Find Operator by its ID. |
|
15 |
* @param Id - Operator Id. |
|
16 |
* @return Operator if ID is present in database. |
|
17 |
*/ |
|
18 |
Operator getById(Long Id); |
|
19 |
} |
src/main/java/vldc/aswi/dao/RoleRepository.java | ||
---|---|---|
1 |
package vldc.aswi.dao; |
|
2 |
|
|
3 |
import org.springframework.data.repository.CrudRepository; |
|
4 |
import org.springframework.stereotype.Repository; |
|
5 |
import vldc.aswi.domain.Role; |
|
6 |
|
|
7 |
/** |
|
8 |
* Repository for domain Role. |
|
9 |
*/ |
|
10 |
@Repository |
|
11 |
public interface RoleRepository extends CrudRepository<Role, Long> { |
|
12 |
|
|
13 |
/** |
|
14 |
* Find Role by name; |
|
15 |
* @param name - name of role. |
|
16 |
* @return Role if name is presented in database. |
|
17 |
*/ |
|
18 |
Role getByName(String name); |
|
19 |
|
|
20 |
/** |
|
21 |
* Find Role by its ID. |
|
22 |
* @param Id - Role Id. |
|
23 |
* @return Role if ID is present in database. |
|
24 |
*/ |
|
25 |
Role getById(Long Id); |
|
26 |
} |
src/main/java/vldc/aswi/dao/UserRepository.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
@Repository |
11 | 11 |
public interface UserRepository extends CrudRepository<User, Long> { |
12 |
|
|
13 |
/** |
|
14 |
* Find User by his ID. |
|
15 |
* @param Id - User Id. |
|
16 |
* @return User if ID is present in database. |
|
17 |
*/ |
|
18 |
User getById(Long Id); |
|
12 | 19 |
} |
src/main/java/vldc/aswi/dao/parameter/ParameterInConfigurationRepository.java | ||
---|---|---|
1 |
package vldc.aswi.dao.parameter; |
|
2 |
|
|
3 |
import org.springframework.data.repository.CrudRepository; |
|
4 |
import org.springframework.stereotype.Repository; |
|
5 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
|
6 |
|
|
7 |
/** |
|
8 |
* Repository for domain ParameterInConfiguration. |
|
9 |
*/ |
|
10 |
@Repository |
|
11 |
public interface ParameterInConfigurationRepository extends CrudRepository<ParameterInConfiguration, Long> { |
|
12 |
|
|
13 |
/** |
|
14 |
* Find ParameterInConfiguration by its ID. |
|
15 |
* @param Id - ParameterInConfiguration Id. |
|
16 |
* @return ParameterInConfiguration if ID is present in database. |
|
17 |
*/ |
|
18 |
ParameterInConfiguration getById(Long Id); |
|
19 |
} |
src/main/java/vldc/aswi/dao/parameter/ParameterRepository.java | ||
---|---|---|
1 |
package vldc.aswi.dao.parameter; |
|
2 |
|
|
3 |
import org.springframework.data.repository.CrudRepository; |
|
4 |
import org.springframework.stereotype.Repository; |
|
5 |
import vldc.aswi.domain.parameter.Parameter; |
|
6 |
|
|
7 |
/** |
|
8 |
* Repository for domain Parameter. |
|
9 |
*/ |
|
10 |
@Repository |
|
11 |
public interface ParameterRepository extends CrudRepository<Parameter, Long> { |
|
12 |
|
|
13 |
/** |
|
14 |
* Find Parameter by its ID. |
|
15 |
* @param Id - Parameter Id. |
|
16 |
* @return Parameter if ID is present in database. |
|
17 |
*/ |
|
18 |
Parameter getById(Long Id); |
|
19 |
} |
src/main/java/vldc/aswi/dao/parameter/ParameterTypeRepository.java | ||
---|---|---|
1 |
package vldc.aswi.dao.parameter; |
|
2 |
|
|
3 |
import org.springframework.data.repository.CrudRepository; |
|
4 |
import org.springframework.stereotype.Repository; |
|
5 |
import vldc.aswi.domain.parameter.ParameterType; |
|
6 |
|
|
7 |
/** |
|
8 |
* Repository for domain ParameterType. |
|
9 |
*/ |
|
10 |
@Repository |
|
11 |
public interface ParameterTypeRepository extends CrudRepository<ParameterType, Long> { |
|
12 |
|
|
13 |
/** |
|
14 |
* Find ParameterType by its ID. |
|
15 |
* @param Id - ParameterType Id. |
|
16 |
* @return ParameterType if ID is present in database. |
|
17 |
*/ |
|
18 |
ParameterType getById(Long Id); |
|
19 |
} |
src/main/java/vldc/aswi/dao/parameter/ParameterValueRepository.java | ||
---|---|---|
1 |
package vldc.aswi.dao.parameter; |
|
2 |
|
|
3 |
import org.springframework.data.repository.CrudRepository; |
|
4 |
import org.springframework.stereotype.Repository; |
|
5 |
import vldc.aswi.domain.parameter.ParameterValue; |
|
6 |
|
|
7 |
/** |
|
8 |
* Repository for domain ParameterValue. |
|
9 |
*/ |
|
10 |
@Repository |
|
11 |
public interface ParameterValueRepository extends CrudRepository<ParameterValue, Long> { |
|
12 |
|
|
13 |
/** |
|
14 |
* Find ParameterValue by its ID. |
|
15 |
* @param Id - ParameterValue Id. |
|
16 |
* @return ParameterValue if ID is present in database. |
|
17 |
*/ |
|
18 |
ParameterValue getById(Long Id); |
|
19 |
} |
src/main/java/vldc/aswi/domain/Assembly.java | ||
---|---|---|
18 | 18 |
public class Assembly extends EntityParent { |
19 | 19 |
|
20 | 20 |
/** Name of Assembly. */ |
21 |
@Column(name = "nazev") |
|
21 | 22 |
private String name; |
22 | 23 |
|
23 | 24 |
/** SQL query which gets data from database. */ |
25 |
@Column(name = "sql_dotaz") |
|
24 | 26 |
private String SQLQuery; |
25 | 27 |
|
26 | 28 |
/** Specific order of assembly in list of assemblies. */ |
29 |
@Column(name = "poradi") |
|
27 | 30 |
private int order; |
28 | 31 |
|
29 | 32 |
/** List of configurations, which using this assembly. */ |
src/main/java/vldc/aswi/domain/Configuration.java | ||
---|---|---|
18 | 18 |
public class Configuration extends EntityParent { |
19 | 19 |
|
20 | 20 |
/** Name of configuration. */ |
21 |
@Column(name = "nazev") |
|
21 | 22 |
private String name; |
22 | 23 |
|
23 | 24 |
/** Name of contingent table. */ |
25 |
@Column(name = "nazev_tabulky") |
|
24 | 26 |
private String tableName; |
25 | 27 |
|
26 | 28 |
/** Specific user, which created this configuration. */ |
src/main/java/vldc/aswi/domain/Function.java | ||
---|---|---|
6 | 6 |
import vldc.aswi.domain.parameter.Parameter; |
7 | 7 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
8 | 8 |
|
9 |
import javax.persistence.Column; |
|
9 | 10 |
import javax.persistence.Entity; |
10 | 11 |
import javax.persistence.ManyToMany; |
11 | 12 |
import java.util.List; |
... | ... | |
20 | 21 |
public class Function extends EntityParent { |
21 | 22 |
|
22 | 23 |
/** Name of function. */ |
24 |
@Column(name = "nazev") |
|
23 | 25 |
private String name; |
24 | 26 |
|
25 | 27 |
/** List of parameters, which defined that this function can be used. */ |
src/main/java/vldc/aswi/domain/Location.java | ||
---|---|---|
5 | 5 |
import lombok.NoArgsConstructor; |
6 | 6 |
import vldc.aswi.domain.parameter.Parameter; |
7 | 7 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
8 |
|
|
9 |
import javax.persistence.Column; |
|
8 | 10 |
import javax.persistence.Entity; |
9 | 11 |
import javax.persistence.ManyToMany; |
10 | 12 |
import javax.persistence.OneToMany; |
... | ... | |
20 | 22 |
public class Location extends EntityParent { |
21 | 23 |
|
22 | 24 |
/** Name of location. */ |
25 |
@Column(name = "nazev") |
|
23 | 26 |
private String name; |
24 | 27 |
|
25 | 28 |
/** List of parameters which allows this location. */ |
src/main/java/vldc/aswi/domain/Operator.java | ||
---|---|---|
5 | 5 |
import lombok.NoArgsConstructor; |
6 | 6 |
import vldc.aswi.domain.parameter.Parameter; |
7 | 7 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
8 |
|
|
9 |
import javax.persistence.Column; |
|
8 | 10 |
import javax.persistence.Entity; |
9 | 11 |
import javax.persistence.ManyToMany; |
10 | 12 |
import javax.persistence.OneToMany; |
... | ... | |
20 | 22 |
public class Operator extends EntityParent { |
21 | 23 |
|
22 | 24 |
/** Name of operator. */ |
25 |
@Column(name = "nazev") |
|
23 | 26 |
private String name; |
24 | 27 |
|
25 | 28 |
/** List of parameters which allowing this operator to be used. */ |
src/main/java/vldc/aswi/domain/Role.java | ||
---|---|---|
3 | 3 |
import lombok.Data; |
4 | 4 |
import lombok.EqualsAndHashCode; |
5 | 5 |
import lombok.NoArgsConstructor; |
6 |
|
|
7 |
import javax.persistence.Column; |
|
6 | 8 |
import javax.persistence.Entity; |
7 | 9 |
import javax.persistence.ManyToMany; |
8 | 10 |
import javax.persistence.OneToMany; |
... | ... | |
18 | 20 |
public class Role extends EntityParent { |
19 | 21 |
|
20 | 22 |
/** Name of role. */ |
23 |
@Column(name = "nazev") |
|
21 | 24 |
private String name; |
22 | 25 |
|
23 | 26 |
/** List of assemblies, which using this role. */ |
src/main/java/vldc/aswi/domain/User.java | ||
---|---|---|
10 | 10 |
import java.util.List; |
11 | 11 |
|
12 | 12 |
/** |
13 |
* Domain entity representing User in application. User is used for loging into application. |
|
13 |
* Domain entity representing User in application. User is used for logging into application.
|
|
14 | 14 |
*/ |
15 | 15 |
@Entity(name = "Uzivatel") |
16 | 16 |
@Data |
... | ... | |
18 | 18 |
@NoArgsConstructor |
19 | 19 |
public class User extends EntityParent { |
20 | 20 |
|
21 |
/** Username of user. */ |
|
22 |
@Column(name = "jmeno") |
|
21 | 23 |
private String username; |
22 | 24 |
|
25 |
/** Password of the user. */ |
|
26 |
@Column(name = "heslo") |
|
23 | 27 |
private String password; |
24 | 28 |
|
29 |
/** Role of user. */ |
|
25 | 30 |
@ManyToOne(fetch=FetchType.LAZY) |
26 | 31 |
@JoinColumn(name = "role_id") |
27 | 32 |
private Role role; |
28 | 33 |
|
34 |
/** List of user configurations. */ |
|
29 | 35 |
@OneToMany(mappedBy = "user") |
30 | 36 |
private List<Configuration> configurations; |
31 | 37 |
|
32 |
|
|
38 |
/** |
|
39 |
* Constructor. |
|
40 |
* @param username username of user |
|
41 |
* @param password password of user |
|
42 |
*/ |
|
33 | 43 |
public User(String username, String password) { |
34 | 44 |
this.setUsername(username); |
35 | 45 |
this.setPassword(password); |
src/main/java/vldc/aswi/domain/parameter/Parameter.java | ||
---|---|---|
17 | 17 |
public class Parameter extends EntityParent { |
18 | 18 |
|
19 | 19 |
/** Name of parameter in SQL query. */ |
20 |
@Column(name = "nazev") |
|
20 | 21 |
private String name; |
21 | 22 |
|
22 | 23 |
/** Admin-defined name of parameter, which will be used in assembly. */ |
24 |
@Column(name = "nazev_select") |
|
23 | 25 |
private String nameOfSelect; |
24 | 26 |
|
25 | 27 |
/** Specific assembly, in which this parameter will be part of. */ |
... | ... | |
28 | 30 |
private Assembly assembly; |
29 | 31 |
|
30 | 32 |
/** Default value of this parameter. */ |
33 |
@Column(name = "default_hodnota") |
|
31 | 34 |
private String defaultValue; |
32 | 35 |
|
33 | 36 |
/** List of parametersInConfiguration, which using this parameter. */ |
src/main/java/vldc/aswi/domain/parameter/ParameterInConfiguration.java | ||
---|---|---|
27 | 27 |
private Parameter parameter; |
28 | 28 |
|
29 | 29 |
/** Value of used operator. */ |
30 |
@Column(name = "hodnota_operatoru") |
|
30 | 31 |
private String operatorValue; |
31 | 32 |
|
32 | 33 |
/** Specific type of parameter, which represents type of entry. */ |
... | ... | |
40 | 41 |
private Location location; |
41 | 42 |
|
42 | 43 |
/** User-defined name of this parameterConfiguration. */ |
44 |
@Column(name = "nazev_sloupce") |
|
43 | 45 |
private String columnName; |
44 | 46 |
|
45 | 47 |
/** Specific operator which will be aplied onto data. */ |
src/main/java/vldc/aswi/domain/parameter/ParameterType.java | ||
---|---|---|
4 | 4 |
import lombok.EqualsAndHashCode; |
5 | 5 |
import lombok.NoArgsConstructor; |
6 | 6 |
import vldc.aswi.domain.EntityParent; |
7 |
|
|
8 |
import javax.persistence.Column; |
|
7 | 9 |
import javax.persistence.Entity; |
8 | 10 |
import javax.persistence.OneToMany; |
9 | 11 |
import java.util.List; |
... | ... | |
18 | 20 |
public class ParameterType extends EntityParent { |
19 | 21 |
|
20 | 22 |
/** Name of parameter. */ |
23 |
@Column(name = "nazev") |
|
21 | 24 |
private String name; |
22 | 25 |
|
23 | 26 |
/** List of parameterInConfigurations, which using this parameter type. */ |
src/main/java/vldc/aswi/domain/parameter/ParameterValue.java | ||
---|---|---|
6 | 6 |
import vldc.aswi.domain.Assembly; |
7 | 7 |
import vldc.aswi.domain.EntityParent; |
8 | 8 |
|
9 |
import javax.persistence.Entity; |
|
10 |
import javax.persistence.FetchType; |
|
11 |
import javax.persistence.JoinColumn; |
|
12 |
import javax.persistence.ManyToOne; |
|
9 |
import javax.persistence.*; |
|
13 | 10 |
|
14 | 11 |
/** |
15 | 12 |
* Domain entity representing Parameter in application. |
... | ... | |
26 | 23 |
private Parameter parameter; |
27 | 24 |
|
28 | 25 |
/** Value that can be used in specific parameter. */ |
26 |
@Column(name = "hodnota") |
|
29 | 27 |
private String value; |
30 | 28 |
|
31 | 29 |
/** |
src/main/java/vldc/aswi/service/AssemblyManager.java | ||
---|---|---|
1 |
package vldc.aswi.service; |
|
2 |
|
|
3 |
import vldc.aswi.domain.Assembly; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
/** |
|
8 |
* Interface for Assembly manager. |
|
9 |
*/ |
|
10 |
public interface AssemblyManager { |
|
11 |
|
|
12 |
/** |
|
13 |
* Get all Assemblies from database. |
|
14 |
* @return List of assemblies. |
|
15 |
*/ |
|
16 |
List<Assembly> getAssemblies(); |
|
17 |
} |
src/main/java/vldc/aswi/service/AssemblyManagerImpl.java | ||
---|---|---|
1 |
package vldc.aswi.service; |
|
2 |
|
|
3 |
import lombok.extern.slf4j.Slf4j; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.context.event.ContextRefreshedEvent; |
|
6 |
import org.springframework.context.event.EventListener; |
|
7 |
import org.springframework.core.annotation.Order; |
|
8 |
import org.springframework.stereotype.Service; |
|
9 |
import vldc.aswi.dao.AssemblyRepository; |
|
10 |
import vldc.aswi.domain.Assembly; |
|
11 |
|
|
12 |
import javax.transaction.Transactional; |
|
13 |
import java.util.LinkedList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
@Service |
|
17 |
@Slf4j |
|
18 |
public class AssemblyManagerImpl implements AssemblyManager { |
|
19 |
|
|
20 |
/** Autowired assembly repository. */ |
|
21 |
@Autowired |
|
22 |
private AssemblyRepository assemblyRepository; |
|
23 |
|
|
24 |
/** |
|
25 |
* Initialization setup for assembly manager. Check if assembly repository contains |
|
26 |
* records and if not, initialize default values. |
|
27 |
*/ |
|
28 |
@EventListener(classes = { |
|
29 |
ContextRefreshedEvent.class |
|
30 |
}) |
|
31 |
@Order(1) |
|
32 |
@Transactional |
|
33 |
public void setup() { |
|
34 |
if (this.assemblyRepository.count() == 0) { |
|
35 |
log.info("No assembly present, creating items."); |
|
36 |
|
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Get all Assemblies from database. |
|
42 |
* @return List of assemblies. |
|
43 |
*/ |
|
44 |
@Override |
|
45 |
public List<Assembly> getAssemblies() { |
|
46 |
List<Assembly> retVal = new LinkedList<>(); |
|
47 |
this.assemblyRepository.findAll().forEach(retVal::add); |
|
48 |
return retVal; |
|
49 |
} |
|
50 |
} |
src/main/java/vldc/aswi/service/ConfigurationManager.java | ||
---|---|---|
1 |
package vldc.aswi.service; |
|
2 |
|
|
3 |
|
|
4 |
import vldc.aswi.domain.Configuration; |
|
5 |
|
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
/** |
|
9 |
* Interface for Configuration manager. |
|
10 |
*/ |
|
11 |
public interface ConfigurationManager { |
|
12 |
|
|
13 |
/** |
|
14 |
* Get all configurations from database. |
|
15 |
* @return List of configurations. |
|
16 |
*/ |
|
17 |
List<Configuration> getConfigurations(); |
|
18 |
} |
src/main/java/vldc/aswi/service/ConfigurationManagerImpl.java | ||
---|---|---|
1 |
package vldc.aswi.service; |
|
2 |
|
|
3 |
import lombok.extern.slf4j.Slf4j; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.context.event.ContextRefreshedEvent; |
|
6 |
import org.springframework.context.event.EventListener; |
|
7 |
import org.springframework.core.annotation.Order; |
|
8 |
import org.springframework.stereotype.Service; |
|
9 |
import vldc.aswi.dao.ConfigurationRepository; |
|
10 |
import vldc.aswi.domain.Configuration; |
|
11 |
|
|
12 |
import javax.transaction.Transactional; |
|
13 |
import java.util.LinkedList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
@Service |
|
17 |
@Slf4j |
|
18 |
public class ConfigurationManagerImpl implements ConfigurationManager { |
|
19 |
|
|
20 |
/** Autowired configuration repository. */ |
|
21 |
@Autowired |
|
22 |
private ConfigurationRepository configurationRepository; |
|
23 |
|
|
24 |
/** |
|
25 |
* Initialization setup for configuration manager. Check if configuration repository contains |
|
26 |
* records and if not, initialize default values. |
|
27 |
*/ |
|
28 |
@EventListener(classes = { |
|
29 |
ContextRefreshedEvent.class |
|
30 |
}) |
|
31 |
@Order(1) |
|
32 |
@Transactional |
|
33 |
public void setup() { |
|
34 |
if (this.configurationRepository.count() == 0) { |
|
35 |
log.info("No configuration present, creating items."); |
|
36 |
|
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Get all configurations from database. |
|
42 |
* @return List of configurations. |
|
43 |
*/ |
|
44 |
@Override |
|
45 |
public List<Configuration> getConfigurations() { |
|
46 |
List<Configuration> retVal = new LinkedList<>(); |
|
47 |
this.configurationRepository.findAll().forEach(retVal::add); |
|
48 |
return retVal; |
|
49 |
} |
|
50 |
} |
src/main/java/vldc/aswi/service/FunctionManager.java | ||
---|---|---|
1 |
package vldc.aswi.service; |
|
2 |
|
|
3 |
import vldc.aswi.domain.Function; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
/** |
|
8 |
* Interface for Function manager. |
|
9 |
*/ |
|
10 |
public interface FunctionManager { |
|
11 |
|
|
12 |
/** |
|
13 |
* Get all functions from database. |
|
14 |
* @return List of functions. |
|
15 |
*/ |
|
16 |
List<Function> getFunctions(); |
|
17 |
} |
src/main/java/vldc/aswi/service/FunctionManagerImpl.java | ||
---|---|---|
1 |
package vldc.aswi.service; |
|
2 |
|
|
3 |
import lombok.extern.slf4j.Slf4j; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.context.event.ContextRefreshedEvent; |
|
6 |
import org.springframework.context.event.EventListener; |
|
7 |
import org.springframework.core.annotation.Order; |
|
8 |
import org.springframework.stereotype.Service; |
|
9 |
import vldc.aswi.dao.FunctionRepository; |
|
10 |
import vldc.aswi.domain.Function; |
|
11 |
|
|
12 |
import javax.transaction.Transactional; |
|
13 |
import java.util.LinkedList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
@Service |
|
17 |
@Slf4j |
|
18 |
public class FunctionManagerImpl implements FunctionManager { |
|
19 |
|
|
20 |
/** Autowired function repository. */ |
|
21 |
@Autowired |
|
22 |
private FunctionRepository functionRepository; |
|
23 |
|
|
24 |
/** |
|
25 |
* Initialization setup for function manager. Check if function repository contains |
|
26 |
* records and if not, initialize default values. |
|
27 |
*/ |
|
28 |
@EventListener(classes = { |
|
29 |
ContextRefreshedEvent.class |
|
30 |
}) |
|
31 |
@Order(1) |
|
32 |
@Transactional |
|
33 |
public void setup() { |
|
34 |
if (this.functionRepository.count() == 0) { |
|
35 |
log.info("No function present, creating items."); |
|
36 |
|
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Get all functions from database. |
|
42 |
* @return List of functions. |
|
43 |
*/ |
|
44 |
@Override |
|
45 |
public List<Function> getFunctions() { |
|
46 |
List<Function> retVal = new LinkedList<>(); |
|
47 |
this.functionRepository.findAll().forEach(retVal::add); |
|
48 |
return retVal; |
|
49 |
} |
|
50 |
} |
src/main/java/vldc/aswi/service/LocationManager.java | ||
---|---|---|
1 |
package vldc.aswi.service; |
|
2 |
|
|
3 |
import vldc.aswi.domain.Location; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
/** |
|
8 |
* Interface for Location manager. |
|
9 |
*/ |
|
10 |
public interface LocationManager { |
|
11 |
|
|
12 |
/** |
|
13 |
* Get all locations from database. |
|
14 |
* @return List of locations. |
|
15 |
*/ |
|
16 |
List<Location> getLocations(); |
|
17 |
} |
src/main/java/vldc/aswi/service/LocationManagerImpl.java | ||
---|---|---|
1 |
package vldc.aswi.service; |
|
2 |
|
|
3 |
import lombok.extern.slf4j.Slf4j; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.context.event.ContextRefreshedEvent; |
|
6 |
import org.springframework.context.event.EventListener; |
|
7 |
import org.springframework.core.annotation.Order; |
|
8 |
import org.springframework.stereotype.Service; |
|
9 |
import vldc.aswi.dao.LocationRepository; |
|
10 |
import vldc.aswi.domain.Location; |
|
11 |
|
|
12 |
import javax.transaction.Transactional; |
|
13 |
import java.util.LinkedList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
@Service |
|
17 |
@Slf4j |
|
18 |
public class LocationManagerImpl implements LocationManager { |
|
19 |
|
|
20 |
/** Autowired location repository. */ |
|
21 |
@Autowired |
|
22 |
private LocationRepository locationRepository; |
|
23 |
|
|
24 |
/** |
|
25 |
* Initialization setup for location manager. Check if location repository contains |
|
26 |
* records and if not, initialize default values. |
|
27 |
*/ |
|
28 |
@EventListener(classes = { |
|
29 |
ContextRefreshedEvent.class |
|
30 |
}) |
|
31 |
@Order(1) |
|
32 |
@Transactional |
|
33 |
public void setup() { |
|
34 |
if (this.locationRepository.count() == 0) { |
|
35 |
log.info("No location present, creating items."); |
|
36 |
|
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Get all locations from database. |
|
42 |
* @return List of locations. |
|
43 |
*/ |
|
44 |
@Override |
|
45 |
public List<Location> getLocations() { |
|
46 |
List<Location> retVal = new LinkedList<>(); |
|
47 |
this.locationRepository.findAll().forEach(retVal::add); |
|
48 |
return retVal; |
|
49 |
} |
|
50 |
} |
src/main/java/vldc/aswi/service/OperatorManager.java | ||
---|---|---|
1 |
package vldc.aswi.service; |
|
2 |
|
|
3 |
import vldc.aswi.domain.Operator; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
/** |
|
8 |
* Interface for Operator manager. |
|
9 |
*/ |
|
10 |
public interface OperatorManager { |
|
11 |
|
|
12 |
/** |
|
13 |
* Get all operators from database. |
|
14 |
* @return List of operators. |
|
15 |
*/ |
|
16 |
List<Operator> getOperators(); |
|
17 |
} |
src/main/java/vldc/aswi/service/OperatorManagerImpl.java | ||
---|---|---|
1 |
package vldc.aswi.service; |
|
2 |
|
|
3 |
import lombok.extern.slf4j.Slf4j; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.context.event.ContextRefreshedEvent; |
|
6 |
import org.springframework.context.event.EventListener; |
|
7 |
import org.springframework.core.annotation.Order; |
|
8 |
import org.springframework.stereotype.Service; |
|
9 |
import vldc.aswi.dao.OperatorRepository; |
|
10 |
import vldc.aswi.domain.Operator; |
|
11 |
|
|
12 |
import javax.transaction.Transactional; |
|
13 |
import java.util.LinkedList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
@Service |
|
17 |
@Slf4j |
|
18 |
public class OperatorManagerImpl implements OperatorManager { |
|
19 |
|
|
20 |
/** Autowired operator repository. */ |
|
21 |
@Autowired |
|
22 |
private OperatorRepository operatorRepository; |
|
23 |
|
|
24 |
/** |
|
25 |
* Initialization setup for operator manager. Check if operator repository contains |
|
26 |
* records and if not, initialize default values. |
|
27 |
*/ |
|
28 |
@EventListener(classes = { |
|
29 |
ContextRefreshedEvent.class |
|
30 |
}) |
|
31 |
@Order(1) |
|
32 |
@Transactional |
|
33 |
public void setup() { |
|
34 |
if (this.operatorRepository.count() == 0) { |
|
35 |
log.info("No operator present, creating items."); |
|
36 |
|
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Get all operators from database. |
|
42 |
* @return List of operators. |
|
43 |
*/ |
|
44 |
@Override |
|
45 |
public List<Operator> getOperators() { |
|
46 |
List<Operator> retVal = new LinkedList<>(); |
|
47 |
this.operatorRepository.findAll().forEach(retVal::add); |
|
48 |
return retVal; |
|
49 |
} |
|
50 |
} |
src/main/java/vldc/aswi/service/RoleManager.java | ||
---|---|---|
1 |
package vldc.aswi.service; |
|
2 |
|
|
3 |
import vldc.aswi.domain.Role; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
/** |
|
8 |
* Interface for Role manager. |
|
9 |
*/ |
|
10 |
public interface RoleManager { |
|
11 |
|
|
12 |
/** |
|
13 |
* Get all roles from database. |
|
14 |
* @return List of roles. |
|
15 |
*/ |
|
16 |
List<Role> getRoles(); |
|
17 |
|
|
18 |
/** |
|
19 |
* Add newly created role into database. |
|
20 |
* @param name Name of role. |
|
21 |
*/ |
|
22 |
void addRole(String name); |
|
23 |
} |
src/main/java/vldc/aswi/service/RoleManagerImpl.java | ||
---|---|---|
1 |
package vldc.aswi.service; |
|
2 |
|
|
3 |
import lombok.extern.slf4j.Slf4j; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.context.event.ContextRefreshedEvent; |
|
6 |
import org.springframework.context.event.EventListener; |
|
7 |
import org.springframework.core.annotation.Order; |
|
8 |
import org.springframework.stereotype.Service; |
|
9 |
import vldc.aswi.dao.RoleRepository; |
|
10 |
import vldc.aswi.domain.Role; |
|
11 |
|
|
12 |
import javax.transaction.Transactional; |
|
13 |
import java.util.LinkedList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
@Service |
|
17 |
@Slf4j |
|
18 |
public class RoleManagerImpl implements RoleManager { |
|
19 |
|
|
20 |
/** Autowired role repository. */ |
|
21 |
@Autowired |
|
22 |
private RoleRepository roleRepository; |
|
23 |
|
|
24 |
/** |
|
25 |
* Initialization setup for role manager. Check if role repository contains records and if not, initialize default values. |
|
26 |
*/ |
|
27 |
/* |
|
28 |
@EventListener(classes = { |
|
29 |
ContextRefreshedEvent.class |
|
30 |
}) |
|
31 |
@Order(1) |
|
32 |
@Transactional |
|
33 |
public void setup() { |
|
34 |
if (this.roleRepository.count() == 0) { |
|
35 |
log.info("No role present, creating 'Admin', 'Studijni referentka', 'Prorektor'."); |
|
36 |
this.addRole("Admin"); |
|
37 |
this.addRole("Studijni referentka"); |
|
38 |
this.addRole("Prorektor"); |
|
39 |
} |
|
40 |
} |
|
41 |
*/ |
|
42 |
|
|
43 |
/** |
|
44 |
* Add newly created role into database. |
|
45 |
* @param name - Name of role. |
|
46 |
*/ |
|
47 |
public void addRole(String name) { |
|
48 |
Role role = new Role(name); |
|
49 |
this.roleRepository.save(role); |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* Get all roles from database. |
|
54 |
* @return List of roles. |
|
55 |
*/ |
|
56 |
@Override |
|
57 |
public List<Role> getRoles() { |
|
58 |
List<Role> retVal = new LinkedList<>(); |
|
59 |
this.roleRepository.findAll().forEach(retVal::add); |
|
60 |
return retVal; |
|
61 |
} |
|
62 |
} |
src/main/java/vldc/aswi/service/UserManager.java | ||
---|---|---|
1 | 1 |
package vldc.aswi.service; |
2 | 2 |
|
3 |
import org.springframework.stereotype.Repository;
|
|
3 |
import vldc.aswi.domain.User;
|
|
4 | 4 |
|
5 |
@Repository |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
/** |
|
8 |
* Interface for User manager. |
|
9 |
*/ |
|
6 | 10 |
public interface UserManager { |
11 |
|
|
12 |
/** |
|
13 |
* Get all users from database. |
|
14 |
* @return List of users. |
|
15 |
*/ |
|
16 |
List<User> getUsers(); |
|
17 |
|
|
18 |
/** |
|
19 |
* Add new user into database. |
|
20 |
* @param username - login username for user. |
|
21 |
* @param password - password for user. |
|
22 |
* @return ID of newly created user. |
|
23 |
*/ |
|
24 |
Long addUser(String username, String password); |
|
7 | 25 |
} |
src/main/java/vldc/aswi/service/UserManagerImpl.java | ||
---|---|---|
1 | 1 |
package vldc.aswi.service; |
2 | 2 |
|
3 | 3 |
import lombok.extern.slf4j.Slf4j; |
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.context.event.ContextRefreshedEvent; |
|
6 |
import org.springframework.context.event.EventListener; |
|
7 |
import org.springframework.core.annotation.Order; |
|
4 | 8 |
import org.springframework.stereotype.Service; |
9 |
import vldc.aswi.dao.RoleRepository; |
|
10 |
import vldc.aswi.dao.UserRepository; |
|
11 |
import vldc.aswi.domain.User; |
|
12 |
|
|
13 |
import javax.transaction.Transactional; |
|
14 |
import java.util.LinkedList; |
|
15 |
import java.util.List; |
|
5 | 16 |
|
6 | 17 |
@Service |
7 | 18 |
@Slf4j |
8 | 19 |
public class UserManagerImpl implements UserManager { |
9 | 20 |
|
21 |
/** Autowired user repository. */ |
|
22 |
@Autowired |
|
23 |
private UserRepository userRepository; |
|
24 |
|
|
25 |
/** Autowired role repository. */ |
|
26 |
@Autowired |
|
27 |
private RoleRepository roleRepository; |
|
28 |
|
|
29 |
/** |
|
30 |
* Initialization setup for user manager. Check if user repository contains records and if not, initialize default values. |
|
31 |
*/ |
|
32 |
/* |
|
33 |
@EventListener(classes = { |
|
34 |
ContextRefreshedEvent.class |
|
35 |
}) |
|
36 |
@Order(1) |
|
37 |
@Transactional |
|
38 |
public void setup() { |
|
39 |
if (this.userRepository.count() == 0) { |
|
40 |
log.info("No user present, creating 'admin', 'referentka', 'prorektor'."); |
|
41 |
Long idAdmin = this.addUser("admin", "admin"); |
|
42 |
Long idReferentka = this.addUser("referentka", "referentka"); |
|
43 |
Long idProrektor = this.addUser("prorektor", "prorektor"); |
|
44 |
|
|
45 |
User admin = this.userRepository.getById(idAdmin); |
|
46 |
User referentka = this.userRepository.getById(idReferentka); |
|
47 |
User prorektor = this.userRepository.getById(idProrektor); |
|
48 |
|
|
49 |
// TODO: set roles for every default user. |
|
50 |
//admin.setRole(); |
|
51 |
} |
|
52 |
} |
|
53 |
*/ |
|
54 |
|
|
55 |
/** |
|
56 |
* Get all users from database. |
|
57 |
* @return List of users. |
|
58 |
*/ |
|
59 |
@Override |
|
60 |
public List<User> getUsers() { |
|
61 |
List<User> retVal = new LinkedList<>(); |
|
62 |
this.userRepository.findAll().forEach(retVal::add); |
|
63 |
return retVal; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Add new user into database. |
|
68 |
* @param username - login username for user. |
|
69 |
* @param password - password for user. |
|
70 |
* @return ID of newly created user. |
|
71 |
*/ |
|
72 |
@Override |
|
73 |
public Long addUser(String username, String password) { |
|
74 |
User user = new User(username, password); |
|
75 |
this.userRepository.save(user); |
|
76 |
return user.getId(); |
|
77 |
} |
|
10 | 78 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterInConfigurationManager.java | ||
---|---|---|
1 |
package vldc.aswi.service.parameter; |
|
2 |
|
|
3 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
/** |
|
8 |
* Interface for ParameterInConfiguration manager. |
|
9 |
*/ |
|
10 |
public interface ParameterInConfigurationManager { |
|
11 |
|
|
12 |
/** |
|
13 |
* Get all parameter in configuration from database. |
|
14 |
* @return List of parameter in configuration. |
|
15 |
*/ |
|
16 |
List<ParameterInConfiguration> getAllParameterInConfiguration(); |
|
17 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterInConfigurationManagerImpl.java | ||
---|---|---|
1 |
package vldc.aswi.service.parameter; |
|
2 |
|
|
3 |
import lombok.extern.slf4j.Slf4j; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.context.event.ContextRefreshedEvent; |
|
6 |
import org.springframework.context.event.EventListener; |
|
7 |
import org.springframework.core.annotation.Order; |
|
8 |
import org.springframework.stereotype.Service; |
|
9 |
import vldc.aswi.dao.parameter.ParameterInConfigurationRepository; |
|
10 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
|
11 |
|
|
12 |
import javax.transaction.Transactional; |
|
13 |
import java.util.LinkedList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
@Service |
|
17 |
@Slf4j |
|
18 |
public class ParameterInConfigurationManagerImpl implements ParameterInConfigurationManager { |
|
19 |
|
|
20 |
/** Autowired parameter in configuration repository. */ |
|
21 |
@Autowired |
|
22 |
private ParameterInConfigurationRepository parameterInConfigurationRepository; |
|
23 |
|
|
24 |
/** |
|
25 |
* Initialization setup for parameter in configuration manager. Check if parameter in configuration repository |
|
26 |
* contains records and if not, initialize default values. |
|
27 |
*/ |
|
28 |
@EventListener(classes = { |
|
29 |
ContextRefreshedEvent.class |
|
30 |
}) |
|
31 |
@Order(1) |
|
32 |
@Transactional |
|
33 |
public void setup() { |
|
34 |
if (this.parameterInConfigurationRepository.count() == 0) { |
|
35 |
log.info("No parameter in configuration present, creating items."); |
|
36 |
|
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Get all parameter in configuration from database. |
|
42 |
* @return List of parameter in configuration. |
|
43 |
*/ |
|
44 |
@Override |
|
45 |
public List<ParameterInConfiguration> getAllParameterInConfiguration() { |
|
46 |
List<ParameterInConfiguration> retVal = new LinkedList<>(); |
|
47 |
this.parameterInConfigurationRepository.findAll().forEach(retVal::add); |
|
48 |
return retVal; |
|
49 |
} |
|
50 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterManager.java | ||
---|---|---|
1 |
package vldc.aswi.service.parameter; |
|
2 |
|
|
3 |
import vldc.aswi.domain.parameter.Parameter; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
/** |
|
8 |
* Interface for Parameter manager. |
|
9 |
*/ |
|
10 |
public interface ParameterManager { |
|
11 |
|
|
12 |
/** |
|
13 |
* Get all parameters from database. |
|
14 |
* @return List of parameters. |
|
15 |
*/ |
|
16 |
List<Parameter> getParameters(); |
|
17 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterManagerImpl.java | ||
---|---|---|
1 |
package vldc.aswi.service.parameter; |
|
2 |
|
|
3 |
import lombok.extern.slf4j.Slf4j; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.context.event.ContextRefreshedEvent; |
|
6 |
import org.springframework.context.event.EventListener; |
|
7 |
import org.springframework.core.annotation.Order; |
|
8 |
import org.springframework.stereotype.Service; |
|
9 |
import vldc.aswi.dao.parameter.ParameterRepository; |
|
10 |
import vldc.aswi.domain.parameter.Parameter; |
|
11 |
|
|
12 |
import javax.transaction.Transactional; |
|
13 |
import java.util.LinkedList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
@Service |
|
17 |
@Slf4j |
|
18 |
public class ParameterManagerImpl implements ParameterManager { |
|
19 |
|
|
20 |
/** Autowired parameter repository. */ |
|
21 |
@Autowired |
|
22 |
private ParameterRepository parameterRepository; |
|
23 |
|
|
24 |
/** |
|
25 |
* Initialization setup for parameter manager. Check if parameter repository contains |
|
26 |
* records and if not, initialize default values. |
|
27 |
*/ |
|
28 |
@EventListener(classes = { |
|
29 |
ContextRefreshedEvent.class |
|
30 |
}) |
|
31 |
@Order(1) |
|
32 |
@Transactional |
|
33 |
public void setup() { |
|
34 |
if (this.parameterRepository.count() == 0) { |
|
35 |
log.info("No parameter present, creating items."); |
|
36 |
|
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Get all parameters from database. |
|
42 |
* @return List of parameters. |
|
43 |
*/ |
|
44 |
@Override |
|
45 |
public List<Parameter> getParameters() { |
|
46 |
List<Parameter> retVal = new LinkedList<>(); |
|
47 |
this.parameterRepository.findAll().forEach(retVal::add); |
|
48 |
return retVal; |
|
49 |
} |
|
50 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterTypeManager.java | ||
---|---|---|
1 |
package vldc.aswi.service.parameter; |
|
2 |
|
|
3 |
import vldc.aswi.domain.parameter.ParameterType; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
/** |
|
8 |
* Interface for ParameterType manager. |
|
9 |
*/ |
|
10 |
public interface ParameterTypeManager { |
|
11 |
|
|
12 |
/** |
|
13 |
* Get all parameter types from database. |
|
14 |
* @return List of parameter types. |
|
15 |
*/ |
|
16 |
List<ParameterType> getParameterTypes(); |
|
17 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterTypeManagerImpl.java | ||
---|---|---|
1 |
package vldc.aswi.service.parameter; |
|
2 |
|
|
3 |
import lombok.extern.slf4j.Slf4j; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.context.event.ContextRefreshedEvent; |
|
6 |
import org.springframework.context.event.EventListener; |
|
7 |
import org.springframework.core.annotation.Order; |
|
8 |
import org.springframework.stereotype.Service; |
|
9 |
import vldc.aswi.dao.parameter.ParameterTypeRepository; |
|
10 |
import vldc.aswi.domain.parameter.ParameterType; |
|
11 |
|
|
12 |
import javax.transaction.Transactional; |
|
13 |
import java.util.LinkedList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
@Service |
|
17 |
@Slf4j |
|
18 |
public class ParameterTypeManagerImpl implements ParameterTypeManager { |
|
19 |
|
|
20 |
/** Autowired parameter type repository. */ |
|
21 |
@Autowired |
|
22 |
private ParameterTypeRepository parameterTypeRepository; |
|
23 |
|
|
24 |
/** |
|
25 |
* Initialization setup for parameter type manager. Check if parameter type repository contains |
|
26 |
* records and if not, initialize default values. |
|
27 |
*/ |
|
28 |
@EventListener(classes = { |
|
29 |
ContextRefreshedEvent.class |
|
30 |
}) |
|
31 |
@Order(1) |
|
32 |
@Transactional |
|
33 |
public void setup() { |
|
34 |
if (this.parameterTypeRepository.count() == 0) { |
|
35 |
log.info("No parameter type present, creating items."); |
|
36 |
|
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Get all parameter types from database. |
|
42 |
* @return List of parameter types. |
|
43 |
*/ |
|
44 |
@Override |
|
45 |
public List<ParameterType> getParameterTypes() { |
|
46 |
List<ParameterType> retVal = new LinkedList<>(); |
|
47 |
this.parameterTypeRepository.findAll().forEach(retVal::add); |
|
48 |
return retVal; |
|
49 |
} |
|
50 |
|
|
51 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterValueManager.java | ||
---|---|---|
1 |
package vldc.aswi.service.parameter; |
|
2 |
|
|
3 |
import vldc.aswi.domain.parameter.ParameterValue; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
/** |
|
8 |
* Interface for ParameterValue manager. |
|
9 |
*/ |
|
10 |
public interface ParameterValueManager { |
|
11 |
|
|
12 |
/** |
|
13 |
* Get all parameter values from database. |
|
14 |
* @return List of parameter values. |
|
15 |
*/ |
|
16 |
List<ParameterValue> getParameterValues(); |
|
17 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterValueManagerImpl.java | ||
---|---|---|
1 |
package vldc.aswi.service.parameter; |
|
2 |
|
|
3 |
import lombok.extern.slf4j.Slf4j; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.context.event.ContextRefreshedEvent; |
|
6 |
import org.springframework.context.event.EventListener; |
|
7 |
import org.springframework.core.annotation.Order; |
|
8 |
import org.springframework.stereotype.Service; |
|
9 |
import vldc.aswi.dao.parameter.ParameterValueRepository; |
|
10 |
import vldc.aswi.domain.parameter.ParameterValue; |
|
11 |
|
|
12 |
import javax.transaction.Transactional; |
|
13 |
import java.util.LinkedList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
@Service |
|
17 |
@Slf4j |
|
18 |
public class ParameterValueManagerImpl implements ParameterValueManager { |
|
19 |
|
|
20 |
/** Autowired parameter value repository. */ |
|
21 |
@Autowired |
|
22 |
private ParameterValueRepository parameterValueRepository; |
|
23 |
|
|
24 |
/** |
|
25 |
* Initialization setup for parameter value manager. Check if parameter value repository contains |
|
26 |
* records and if not, initialize default values. |
|
27 |
*/ |
|
28 |
@EventListener(classes = { |
|
29 |
ContextRefreshedEvent.class |
|
30 |
}) |
|
31 |
@Order(1) |
|
32 |
@Transactional |
|
33 |
public void setup() { |
|
34 |
if (this.parameterValueRepository.count() == 0) { |
|
35 |
log.info("No parameter value present, creating items."); |
|
36 |
|
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Get all parameter values from database. |
|
42 |
* @return List of parameter values. |
|
43 |
*/ |
|
44 |
@Override |
|
45 |
public List<ParameterValue> getParameterValues() { |
|
46 |
List<ParameterValue> retVal = new LinkedList<>(); |
|
47 |
this.parameterValueRepository.findAll().forEach(retVal::add); |
|
48 |
return retVal; |
|
49 |
} |
|
50 |
} |
Také k dispozici: Unified diff
re #7839 Repositories with basic methods created, domain class attributes mapped to names from database, services with basic methods created