diff --git a/core/pom.xml b/core/pom.xml
index 6d57345a..48b8b678 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -102,6 +102,11 @@
${objenesis.version}
test
+
+
+ org.springframework.boot
+ spring-boot-starter-amqp
+
diff --git a/core/src/main/java/com/arturjarosz/task/Main.java b/core/src/main/java/com/arturjarosz/task/Main.java
index 71de38d4..8e5d3cde 100644
--- a/core/src/main/java/com/arturjarosz/task/Main.java
+++ b/core/src/main/java/com/arturjarosz/task/Main.java
@@ -5,6 +5,8 @@
@SpringBootApplication
public class Main {
+
+
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
diff --git a/core/src/main/java/com/arturjarosz/task/architect/application/impl/ArchitectApplicationServiceImpl.java b/core/src/main/java/com/arturjarosz/task/architect/application/impl/ArchitectApplicationServiceImpl.java
index ca851978..d85e0e3f 100644
--- a/core/src/main/java/com/arturjarosz/task/architect/application/impl/ArchitectApplicationServiceImpl.java
+++ b/core/src/main/java/com/arturjarosz/task/architect/application/impl/ArchitectApplicationServiceImpl.java
@@ -10,8 +10,10 @@
import com.arturjarosz.task.sharedkernel.annotations.ApplicationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.support.TransactionSynchronizationManager;
-import javax.transaction.Transactional;
import java.util.List;
import java.util.stream.Collectors;
@@ -33,11 +35,15 @@ public ArchitectApplicationServiceImpl(ArchitectRepository architectRepository,
this.architectValidator = architectValidator;
}
- @Transactional
+ @Transactional(propagation = Propagation.REQUIRED)
@Override
public ArchitectDto createArchitect(ArchitectBasicDto architectBasicDto) {
LOG.debug("creating architect");
-
+ if (TransactionSynchronizationManager.isActualTransactionActive()) {
+ System.out.printf(" *** TRANSACTION %s in class %s%n",
+ TransactionSynchronizationManager.getCurrentTransactionName(), this.getClass()
+ .getName());
+ }
validateBasicArchitectDto(architectBasicDto);
Architect architect = ArchitectDtoMapper.INSTANCE.architectBasicDtoToArchitect(architectBasicDto);
architect = this.architectRepository.save(architect);
@@ -84,7 +90,8 @@ public ArchitectDto updateArchitect(Long architectId, ArchitectDto architectDto)
@Override
public List getBasicArchitects() {
- return this.architectRepository.loadAll().stream()
+ return this.architectRepository.loadAll()
+ .stream()
.map(ArchitectDtoMapper.INSTANCE::architectToArchitectBasicDto)
.collect(Collectors.toList());
}
diff --git a/core/src/main/java/com/arturjarosz/task/client/application/impl/ClientApplicationServiceImpl.java b/core/src/main/java/com/arturjarosz/task/client/application/impl/ClientApplicationServiceImpl.java
index 096fc940..50799525 100644
--- a/core/src/main/java/com/arturjarosz/task/client/application/impl/ClientApplicationServiceImpl.java
+++ b/core/src/main/java/com/arturjarosz/task/client/application/impl/ClientApplicationServiceImpl.java
@@ -10,8 +10,8 @@
import com.arturjarosz.task.sharedkernel.annotations.ApplicationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Transactional;
-import javax.transaction.Transactional;
import java.util.List;
import java.util.stream.Collectors;
@@ -38,8 +38,7 @@ public ClientDto createClient(ClientDto clientDto) {
if (clientType.equals(ClientType.CORPORATE)) {
client = Client.createCorporateClient(clientDto.getCompanyName());
} else {
- client = Client.createPrivateClient(clientDto.getFirstName(),
- clientDto.getLastName());
+ client = Client.createPrivateClient(clientDto.getFirstName(), clientDto.getLastName());
}
client = this.clientRepository.save(client);
@@ -86,17 +85,22 @@ public ClientDto updateClient(Long clientId, ClientDto clientDto) {
client.updateCompanyName(clientDto.getCompanyName());
}
if (clientDto.getContact() != null) {
- if (clientDto.getContact().getAddress() != null) {
- client.updateAddress(
- ClientDtoMapper.INSTANCE.addressDtoToAddress(clientDto.getContact().getAddress()));
+ if (clientDto.getContact()
+ .getAddress() != null) {
+ client.updateAddress(ClientDtoMapper.INSTANCE.addressDtoToAddress(clientDto.getContact()
+ .getAddress()));
}
- if (clientDto.getContact().getEmail() != null) {
- client.updateEmail(clientDto.getContact().getEmail());
+ if (clientDto.getContact()
+ .getEmail() != null) {
+ client.updateEmail(clientDto.getContact()
+ .getEmail());
}
- client.updateTelephone(clientDto.getContact().getTelephone());
+ client.updateTelephone(clientDto.getContact()
+ .getTelephone());
}
if (clientDto.getAdditionalData() != null) {
- client.updateNote(clientDto.getAdditionalData().getNote());
+ client.updateNote(clientDto.getAdditionalData()
+ .getNote());
}
this.clientRepository.save(client);
diff --git a/core/src/main/java/com/arturjarosz/task/configuration/RabbitConfiguration.java b/core/src/main/java/com/arturjarosz/task/configuration/RabbitConfiguration.java
new file mode 100644
index 00000000..52c4ad4e
--- /dev/null
+++ b/core/src/main/java/com/arturjarosz/task/configuration/RabbitConfiguration.java
@@ -0,0 +1,109 @@
+package com.arturjarosz.task.configuration;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.amqp.core.AmqpAdmin;
+import org.springframework.amqp.core.AmqpTemplate;
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.core.TopicExchange;
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
+import org.springframework.amqp.rabbit.connection.Connection;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+@Configuration
+public class RabbitConfiguration {
+ private static final Logger LOG = LoggerFactory.getLogger(RabbitConfiguration.class);
+ private static final String TEST_EXCHANGE = "test.exchange";
+ private static final String TEST_EXCHANGE_2 = "test.exchange2";
+ private static final String TEST_QUEUE = "test.queue";
+ private static final String TEST_QUEUE_2 = "test.queue";
+ private static final String LOGIN = "guest";
+ private static final String PASSWORD = "guest";
+ private static final String HOST = "localhost";
+ private static final String VIRTUAL_HOST = "/";
+ private static final String ROUTING_KEY = "#";
+ private static final String ADDRESSES = "127.0.0.1:30000,127.0.0.1:30002,127.0.0.1:30004";
+
+ private final CachingConnectionFactory connectionFactory;
+ private final Connection connection;
+ private RabbitAdmin admin;
+ private AmqpTemplate amqpTemplate;
+
+ private int counter = 0;
+
+ @Autowired
+ public RabbitConfiguration() {
+ LOG.info("Creating rabbit configuration.");
+ com.rabbitmq.client.ConnectionFactory rabbitFactory = new com.rabbitmq.client.ConnectionFactory();
+ rabbitFactory.setUsername(LOGIN);
+ rabbitFactory.setPassword(PASSWORD);
+ //rabbitFactory.setHost(HOST);
+ //rabbitFactory.setVirtualHost(VIRTUAL_HOST);
+ rabbitFactory.setAutomaticRecoveryEnabled(true);
+
+ this.connectionFactory = new CachingConnectionFactory(rabbitFactory);
+ this.connectionFactory.setAddresses(ADDRESSES);
+ this.connection = this.connectionFactory.createConnection();
+ this.amqpTemplate = new RabbitTemplate(this.connectionFactory);
+ this.publishMessages(this.amqpTemplate);
+ }
+
+ @Bean
+ public AmqpAdmin admin() {
+ this.admin = new RabbitAdmin(this.connectionFactory);
+ return this.admin;
+ }
+
+ @Bean
+ public Queue queue() {
+ Queue queue = new Queue(TEST_QUEUE + "2", true);
+ //queue.setAdminsThatShouldDeclare(this.admin);
+ return queue;
+ }
+
+ @Bean
+ public Queue queue2() {
+ return new Queue(TEST_QUEUE_2, true);
+ }
+
+ @Bean
+ public TopicExchange topicExchange2() {
+ return new TopicExchange(TEST_EXCHANGE_2);
+ }
+
+ @Bean
+ public Binding binding() {
+ return BindingBuilder.bind(this.queue2()).to(this.topicExchange2()).with(ROUTING_KEY);
+ }
+
+ public void publishMessages(AmqpTemplate amqpTemplate) {
+ LOG.info("** Publish message **");
+ Runnable newRunnable = new Runnable() {
+
+ public void publishMessage() {
+ LOG.info("*** Publishing next message: " + RabbitConfiguration.this.counter + " ***");
+ amqpTemplate.convertAndSend(TEST_EXCHANGE_2, ROUTING_KEY,
+ "Event number: " + RabbitConfiguration.this.counter);
+ RabbitConfiguration.this.counter++;
+ }
+
+ @Override
+ public void run() {
+ this.publishMessage();
+ }
+ };
+ ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
+ executor.scheduleAtFixedRate(newRunnable, 0, 10, TimeUnit.SECONDS);
+ }
+
+}
diff --git a/core/src/main/java/com/arturjarosz/task/cooperator/application/impl/ContractorApplicationServiceImpl.java b/core/src/main/java/com/arturjarosz/task/cooperator/application/impl/ContractorApplicationServiceImpl.java
index 975e5e13..f8144ee2 100644
--- a/core/src/main/java/com/arturjarosz/task/cooperator/application/impl/ContractorApplicationServiceImpl.java
+++ b/core/src/main/java/com/arturjarosz/task/cooperator/application/impl/ContractorApplicationServiceImpl.java
@@ -11,8 +11,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
-import javax.transaction.Transactional;
import java.util.List;
import java.util.stream.Collectors;
@@ -50,8 +50,9 @@ public void updateContractor(Long contractorId, ContractorDto contractorDto) {
this.contractorValidator.validateContractorExistence(contractorId);
ContractorValidator.validateUpdateContractorDto(contractorDto);
Cooperator cooperator = this.cooperatorRepository.load(contractorId);
- cooperator.update(contractorDto.getName(), contractorDto.getCategory().asCooperatorCategory(),
- contractorDto.getEmail(), contractorDto.getTelephone(), contractorDto.getNote());
+ cooperator.update(contractorDto.getName(), contractorDto.getCategory()
+ .asCooperatorCategory(), contractorDto.getEmail(), contractorDto.getTelephone(),
+ contractorDto.getNote());
this.cooperatorRepository.save(cooperator);
LOG.debug("Contractor with id {} updated", contractorId);
}
@@ -79,7 +80,8 @@ public ContractorDto getContractor(Long contractorId) {
@Override
public List getBasicContractors() {
LOG.debug("Loading Contractors list");
- return this.cooperatorRepository.loadAll().stream()
+ return this.cooperatorRepository.loadAll()
+ .stream()
.map(ContractorDtoMapper.INSTANCE::cooperatorToBasicContractor)
.collect(Collectors.toList());
}
diff --git a/core/src/main/java/com/arturjarosz/task/cooperator/application/impl/SupplierApplicationServiceImpl.java b/core/src/main/java/com/arturjarosz/task/cooperator/application/impl/SupplierApplicationServiceImpl.java
index c4fcaf08..d2db33dd 100644
--- a/core/src/main/java/com/arturjarosz/task/cooperator/application/impl/SupplierApplicationServiceImpl.java
+++ b/core/src/main/java/com/arturjarosz/task/cooperator/application/impl/SupplierApplicationServiceImpl.java
@@ -10,8 +10,8 @@
import com.arturjarosz.task.sharedkernel.model.CreatedEntityDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Transactional;
-import javax.transaction.Transactional;
import java.util.List;
import java.util.stream.Collectors;
@@ -46,8 +46,8 @@ public void updateSupplier(Long supplierId, SupplierDto supplierDto) {
this.supplierValidator.validateSupplierExistence(supplierId);
SupplierValidator.validateUpdateSupplierDto(supplierDto);
Cooperator cooperator = this.cooperatorRepository.load(supplierId);
- cooperator.update(supplierDto.getName(), supplierDto.getCategory().asCooperatorCategory(),
- supplierDto.getEmail(), supplierDto.getTelephone(), supplierDto.getNote());
+ cooperator.update(supplierDto.getName(), supplierDto.getCategory()
+ .asCooperatorCategory(), supplierDto.getEmail(), supplierDto.getTelephone(), supplierDto.getNote());
this.cooperatorRepository.save(cooperator);
LOG.debug("Supplier with id {} updated.", supplierId);
}
@@ -75,7 +75,8 @@ public SupplierDto getSupplier(Long supplierId) {
@Override
public List getBasicSuppliers() {
LOG.debug("Loading Suppliers list");
- return this.cooperatorRepository.loadAll().stream()
+ return this.cooperatorRepository.loadAll()
+ .stream()
.map(SupplierDtoMapper.INSTANCE::cooperatorToBasicSupplier)
.collect(Collectors.toList());
}
diff --git a/core/src/main/java/com/arturjarosz/task/project/application/impl/ContractorJobApplicationServiceImpl.java b/core/src/main/java/com/arturjarosz/task/project/application/impl/ContractorJobApplicationServiceImpl.java
index fd640300..72d1a59c 100644
--- a/core/src/main/java/com/arturjarosz/task/project/application/impl/ContractorJobApplicationServiceImpl.java
+++ b/core/src/main/java/com/arturjarosz/task/project/application/impl/ContractorJobApplicationServiceImpl.java
@@ -14,8 +14,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-
-import javax.transaction.Transactional;
+import org.springframework.transaction.annotation.Transactional;
@ApplicationService
public class ContractorJobApplicationServiceImpl implements ContractorJobApplicationService {
@@ -54,7 +53,8 @@ public ContractorJobDto createContractorJob(Long projectId, ContractorJobDto con
LOG.debug("ContractorJob for Project with id {} created", projectId);
ContractorJobDto createdContractorJobDto = ContractorJobDtoMapper.INSTANCE.contractorJobToContractorJobDto(
contractorJob, projectId);
- createdContractorJobDto.setId(this.getCreatedContractorJob(project, contractorJob).getId());
+ createdContractorJobDto.setId(this.getCreatedContractorJob(project, contractorJob)
+ .getId());
return createdContractorJobDto;
}
@@ -98,8 +98,10 @@ public void deleteContractorJob(Long projectId, Long contractorJobId) {
}
private ContractorJob getCreatedContractorJob(Project project, ContractorJob contractorJob) {
- return project.getContractorJobs().stream()
- .filter(contractorJobOnProject -> contractorJobOnProject.equals(contractorJob)).findFirst()
+ return project.getContractorJobs()
+ .stream()
+ .filter(contractorJobOnProject -> contractorJobOnProject.equals(contractorJob))
+ .findFirst()
.orElse(null);
}
}
diff --git a/core/src/main/java/com/arturjarosz/task/project/application/impl/CostApplicationServiceImpl.java b/core/src/main/java/com/arturjarosz/task/project/application/impl/CostApplicationServiceImpl.java
index e2d65825..e1c47e2c 100644
--- a/core/src/main/java/com/arturjarosz/task/project/application/impl/CostApplicationServiceImpl.java
+++ b/core/src/main/java/com/arturjarosz/task/project/application/impl/CostApplicationServiceImpl.java
@@ -13,8 +13,8 @@
import com.arturjarosz.task.sharedkernel.annotations.ApplicationService;
import com.arturjarosz.task.sharedkernel.model.AbstractEntity;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
-import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -62,9 +62,8 @@ public CostDto updateCost(Long projectId, Long costId, CostDto costDto) {
this.costValidator.validateCostExistence(costId);
this.costValidator.validateUpdateCostDto(costDto);
Project project = this.projectRepository.load(projectId);
- Cost cost = project
- .updateCost(costId, costDto.getName(), costDto.getDate(), costDto.getValue(), costDto.getCategory(),
- costDto.getNote());
+ Cost cost = project.updateCost(costId, costDto.getName(), costDto.getDate(), costDto.getValue(),
+ costDto.getCategory(), costDto.getNote());
this.projectRepository.save(project);
this.projectFinanceAwareObjectService.onUpdate(projectId);
return CostDtoMapper.INSTANCE.costToCostDto(cost);
@@ -84,8 +83,7 @@ public List getCosts(Long projectId) {
Set costs = project.getCosts();
return new ArrayList<>(costs.stream()
.map(CostDtoMapper.INSTANCE::costToCostDto)
- .collect(Collectors.toList())
- );
+ .collect(Collectors.toList()));
}
@Transactional
@@ -100,10 +98,12 @@ public void deleteCost(Long projectId, Long costId) {
}
private Long getIdForCreatedCost(Project project, Cost cost) {
- return project.getCosts().stream()
+ return project.getCosts()
+ .stream()
.filter(costOnProject -> costOnProject.equals(cost))
.map(AbstractEntity::getId)
- .findFirst().orElse(null);
+ .findFirst()
+ .orElse(null);
}
}
diff --git a/core/src/main/java/com/arturjarosz/task/project/application/impl/InstallmentApplicationServiceImpl.java b/core/src/main/java/com/arturjarosz/task/project/application/impl/InstallmentApplicationServiceImpl.java
index 44d35c9f..15645447 100644
--- a/core/src/main/java/com/arturjarosz/task/project/application/impl/InstallmentApplicationServiceImpl.java
+++ b/core/src/main/java/com/arturjarosz/task/project/application/impl/InstallmentApplicationServiceImpl.java
@@ -15,8 +15,8 @@
import com.arturjarosz.task.sharedkernel.annotations.ApplicationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Transactional;
-import javax.transaction.Transactional;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -57,8 +57,8 @@ public InstallmentDto createInstallment(Long projectId, Long stageId, Installmen
project = this.projectRepository.save(project);
LOG.debug("installment for stage with id {} created", stageId);
- return InstallmentDtoMapper.INSTANCE
- .installmentToInstallmentDto(this.getNewInstallmentWithId(project, stageId));
+ return InstallmentDtoMapper.INSTANCE.installmentToInstallmentDto(
+ this.getNewInstallmentWithId(project, stageId));
}
@Transactional
@@ -114,7 +114,8 @@ public List getInstallmentList(Long projectId) {
this.projectValidator.validateProjectExistence(projectId);
Project project = this.projectRepository.load(projectId);
- return project.getStages().stream()
+ return project.getStages()
+ .stream()
.map(Stage::getInstallment)
.filter(Objects::nonNull)
.map(InstallmentDtoMapper.INSTANCE::installmentToInstallmentDto)
@@ -133,8 +134,12 @@ public InstallmentDto getInstallment(Long projectId, Long stageId) {
}
private Installment getNewInstallmentWithId(Project project, Long stageId) {
- return project.getStages().stream()
- .filter(stageOnProject -> stageOnProject.getId().equals(stageId)).map(Stage::getInstallment)
- .findFirst().orElse(null);
+ return project.getStages()
+ .stream()
+ .filter(stageOnProject -> stageOnProject.getId()
+ .equals(stageId))
+ .map(Stage::getInstallment)
+ .findFirst()
+ .orElse(null);
}
}
diff --git a/core/src/main/java/com/arturjarosz/task/project/application/impl/ProjectApplicationServiceImpl.java b/core/src/main/java/com/arturjarosz/task/project/application/impl/ProjectApplicationServiceImpl.java
index 6a58e214..02483a68 100644
--- a/core/src/main/java/com/arturjarosz/task/project/application/impl/ProjectApplicationServiceImpl.java
+++ b/core/src/main/java/com/arturjarosz/task/project/application/impl/ProjectApplicationServiceImpl.java
@@ -21,8 +21,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
-import javax.transaction.Transactional;
import java.util.List;
import java.util.stream.Collectors;
@@ -43,10 +43,8 @@ public class ProjectApplicationServiceImpl implements ProjectApplicationService
public ProjectApplicationServiceImpl(ClientApplicationService clientApplicationService,
ClientValidator clientValidator,
ArchitectApplicationService architectApplicationService,
- ArchitectValidator architectValidator,
- ProjectRepository projectRepository,
- ProjectDomainService projectDomainService,
- ProjectValidator projectValidator,
+ ArchitectValidator architectValidator, ProjectRepository projectRepository,
+ ProjectDomainService projectDomainService, ProjectValidator projectValidator,
ProjectFinancialDataService projectFinancialDataService) {
this.clientApplicationService = clientApplicationService;
this.clientValidator = clientValidator;
@@ -134,12 +132,14 @@ public ProjectDto finishProject(Long projectId, ProjectContractDto projectContra
@Override
public List getProjects() {
LOG.debug("Loading list of projects.");
- return this.projectRepository.loadAll().stream().map(project -> {
- ClientDto clientDto = this.clientApplicationService.getClientBasicData(project.getClientId());
- ArchitectDto architectDto = this.architectApplicationService.getArchitect(project.getArchitectId());
- return ProjectDtoMapper.INSTANCE
- .projectToBasicProjectDto(clientDto, architectDto, project);
- }).collect(Collectors.toList());
+ return this.projectRepository.loadAll()
+ .stream()
+ .map(project -> {
+ ClientDto clientDto = this.clientApplicationService.getClientBasicData(project.getClientId());
+ ArchitectDto architectDto = this.architectApplicationService.getArchitect(project.getArchitectId());
+ return ProjectDtoMapper.INSTANCE.projectToBasicProjectDto(clientDto, architectDto, project);
+ })
+ .collect(Collectors.toList());
}
@Transactional
diff --git a/core/src/main/java/com/arturjarosz/task/project/application/impl/StageApplicationServiceImpl.java b/core/src/main/java/com/arturjarosz/task/project/application/impl/StageApplicationServiceImpl.java
index 62f35793..5c3a2c8a 100644
--- a/core/src/main/java/com/arturjarosz/task/project/application/impl/StageApplicationServiceImpl.java
+++ b/core/src/main/java/com/arturjarosz/task/project/application/impl/StageApplicationServiceImpl.java
@@ -14,8 +14,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
-import javax.transaction.Transactional;
import java.util.List;
@ApplicationService
@@ -29,9 +29,8 @@ public class StageApplicationServiceImpl implements StageApplicationService {
private final StageValidator stageValidator;
@Autowired
- public StageApplicationServiceImpl(ProjectQueryService projectQueryService,
- ProjectValidator projectValidator, ProjectRepository projectRepository,
- StageDomainService stageDomainService,
+ public StageApplicationServiceImpl(ProjectQueryService projectQueryService, ProjectValidator projectValidator,
+ ProjectRepository projectRepository, StageDomainService stageDomainService,
StageValidator stageValidator) {
this.projectQueryService = projectQueryService;
this.projectValidator = projectValidator;
@@ -121,12 +120,19 @@ public StageDto reopenStage(Long projectId, Long stageId) {
}
private Stage getCreatedStageWithId(Project project, Stage stage) {
- return project.getStages().stream().filter(stageOnProject -> stageOnProject.equals(stage)).findFirst()
+ return project.getStages()
+ .stream()
+ .filter(stageOnProject -> stageOnProject.equals(stage))
+ .findFirst()
.orElse(null);
}
private Stage getStageById(Project project, Long stageId) {
- return project.getStages().stream().filter(stageOnProject -> stageOnProject.getId().equals(stageId)).findFirst()
+ return project.getStages()
+ .stream()
+ .filter(stageOnProject -> stageOnProject.getId()
+ .equals(stageId))
+ .findFirst()
.orElse(null);
}
diff --git a/core/src/main/java/com/arturjarosz/task/project/application/impl/SupplyApplicationServiceImpl.java b/core/src/main/java/com/arturjarosz/task/project/application/impl/SupplyApplicationServiceImpl.java
index c776596d..124a3838 100644
--- a/core/src/main/java/com/arturjarosz/task/project/application/impl/SupplyApplicationServiceImpl.java
+++ b/core/src/main/java/com/arturjarosz/task/project/application/impl/SupplyApplicationServiceImpl.java
@@ -14,8 +14,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-
-import javax.transaction.Transactional;
+import org.springframework.transaction.annotation.Transactional;
@ApplicationService
public class SupplyApplicationServiceImpl implements SupplyApplicationService {
@@ -53,7 +52,8 @@ public SupplyDto createSupply(Long projectId, SupplyDto supplyDto) {
this.projectFinanceAwareObjectService.onCreate(projectId);
LOG.debug("Supply for Project with id {} created", projectId);
SupplyDto createdSupplyDto = SupplyDtoMapper.INSTANCE.supplyToSupplyDto(supply, projectId);
- createdSupplyDto.setId(this.getCreatedSupply(project, supply).getId());
+ createdSupplyDto.setId(this.getCreatedSupply(project, supply)
+ .getId());
return createdSupplyDto;
}
@@ -95,8 +95,10 @@ public void deleteSupply(Long projectId, Long supplyId) {
}
private Supply getCreatedSupply(Project project, Supply supply) {
- return project.getSupplies().stream()
- .filter(supplyOnProject -> (supplyOnProject).equals(supply)).findFirst()
+ return project.getSupplies()
+ .stream()
+ .filter(supplyOnProject -> (supplyOnProject).equals(supply))
+ .findFirst()
.orElse(null);
}
}
diff --git a/core/src/main/java/com/arturjarosz/task/project/application/impl/TaskApplicationServiceImpl.java b/core/src/main/java/com/arturjarosz/task/project/application/impl/TaskApplicationServiceImpl.java
index 7b8549d8..a7d83b0c 100644
--- a/core/src/main/java/com/arturjarosz/task/project/application/impl/TaskApplicationServiceImpl.java
+++ b/core/src/main/java/com/arturjarosz/task/project/application/impl/TaskApplicationServiceImpl.java
@@ -16,8 +16,8 @@
import com.arturjarosz.task.sharedkernel.annotations.ApplicationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Transactional;
-import javax.transaction.Transactional;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -34,11 +34,9 @@ public class TaskApplicationServiceImpl implements TaskApplicationService {
private final TaskDomainService taskDomainService;
private final TaskValidator taskValidator;
- public TaskApplicationServiceImpl(ProjectQueryService projectQueryService,
- ProjectRepository projectRepository, ProjectValidator projectValidator,
- StageValidator stageValidator,
- TaskDomainService taskDomainService,
- TaskValidator taskValidator) {
+ public TaskApplicationServiceImpl(ProjectQueryService projectQueryService, ProjectRepository projectRepository,
+ ProjectValidator projectValidator, StageValidator stageValidator,
+ TaskDomainService taskDomainService, TaskValidator taskValidator) {
this.projectQueryService = projectQueryService;
this.projectRepository = projectRepository;
this.projectValidator = projectValidator;
@@ -119,9 +117,12 @@ public List getTaskList(Long projectId, Long stageId) {
this.projectValidator.validateProjectExistence(projectId);
this.stageValidator.validateExistenceOfStageInProject(projectId, stageId);
Project project = this.projectRepository.load(projectId);
- return project.getStages().stream()
- .filter(stageOnProject -> stageOnProject.getId().equals(stageId))
- .flatMap(stageOnProject -> stageOnProject.getTasks().stream())
+ return project.getStages()
+ .stream()
+ .filter(stageOnProject -> stageOnProject.getId()
+ .equals(stageId))
+ .flatMap(stageOnProject -> stageOnProject.getTasks()
+ .stream())
.map(TaskDtoMapper.INSTANCE::taskToTaskBasicDto)
.collect(Collectors.toList());
@@ -154,22 +155,31 @@ public TaskDto reopenTask(Long projectId, Long stageId, Long taskId) {
}
private Task getNewTaskWithId(Project project, Long stageId, Task task) {
- Predicate stagePredicate = stage -> stage.getId().equals(stageId);
+ Predicate stagePredicate = stage -> stage.getId()
+ .equals(stageId);
Predicate taskPredicate = taskOnStage -> taskOnStage.equals(task);
- return project.getStages().stream()
+ return project.getStages()
+ .stream()
.filter(stagePredicate)
- .flatMap(stage -> stage.getTasks().stream())
+ .flatMap(stage -> stage.getTasks()
+ .stream())
.filter(taskPredicate)
- .findFirst().orElse(null);
+ .findFirst()
+ .orElse(null);
}
private Task getTaskById(Project project, Long stageId, Long taskId) {
- Predicate stagePredicate = stage -> stage.getId().equals(stageId);
- Predicate taskPredicate = taskOnStage -> taskOnStage.getId().equals(taskId);
- return project.getStages().stream()
+ Predicate stagePredicate = stage -> stage.getId()
+ .equals(stageId);
+ Predicate taskPredicate = taskOnStage -> taskOnStage.getId()
+ .equals(taskId);
+ return project.getStages()
+ .stream()
.filter(stagePredicate)
- .flatMap(stage -> stage.getTasks().stream())
+ .flatMap(stage -> stage.getTasks()
+ .stream())
.filter(taskPredicate)
- .findFirst().orElse(null);
+ .findFirst()
+ .orElse(null);
}
}
diff --git a/core/src/main/java/com/arturjarosz/task/project/query/ProjectQueryService.java b/core/src/main/java/com/arturjarosz/task/project/query/ProjectQueryService.java
index bead1d4a..51c4c3d1 100644
--- a/core/src/main/java/com/arturjarosz/task/project/query/ProjectQueryService.java
+++ b/core/src/main/java/com/arturjarosz/task/project/query/ProjectQueryService.java
@@ -14,66 +14,41 @@ public interface ProjectQueryService {
/**
* Load Cost by given costId.
- *
- * @param costId
- * @return
*/
Cost getCostById(Long costId);
/**
* Load Stage by given stageId.
- *
- * @param stageId
- * @return
*/
Stage getStageById(Long stageId);
/**
* Load list of Project for given Client with clientId.
- *
- * @param clientId
- * @return
*/
List getProjectsForClientId(Long clientId);
/**
* Load list of Project for given Architect with architectId.
- *
- * @param architectId
- * @return
*/
List getProjectsForArchitect(Long architectId);
/**
* Retrieve Task as TaskDto of given TaskId.
- *
- * @return
*/
TaskDto getTaskByTaskId(Long taskId);
/**
* Return List of Stages as StageDto for Project of given projectId.
- *
- * @param projectId
- * @return
*/
List getStagesForProjectById(Long projectId);
/**
* Returns Supply with supplyId for Project with projectId.
- *
- * @param supplyId
- * @param projectId
- * @return
*/
SupplyDto getSupplyForProject(long supplyId, long projectId);
/**
* Returns ContractorJob with contractorJobId for Project with projectId.
- *
- * @param contractorJobId
- * @param projectId
- * @return
*/
ContractorJobDto getContractorJobForProject(long contractorJobId, long projectId);
}
diff --git a/core/src/main/java/com/arturjarosz/task/supervision/application/impl/SupervisionApplicationServiceImpl.java b/core/src/main/java/com/arturjarosz/task/supervision/application/impl/SupervisionApplicationServiceImpl.java
index 984638ce..8f092175 100644
--- a/core/src/main/java/com/arturjarosz/task/supervision/application/impl/SupervisionApplicationServiceImpl.java
+++ b/core/src/main/java/com/arturjarosz/task/supervision/application/impl/SupervisionApplicationServiceImpl.java
@@ -18,8 +18,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-
-import javax.transaction.Transactional;
+import org.springframework.transaction.annotation.Transactional;
@ApplicationService
public class SupervisionApplicationServiceImpl implements SupervisionApplicationService {
@@ -70,8 +69,8 @@ public SupervisionDto updateSupervision(Long supervisionId, SupervisionDto super
this.supervisionValidator.validateUpdateSupervision(supervisionDto);
Supervision supervision = this.supervisionRepository.load(supervisionId);
supervision.update(supervisionDto);
- this.projectFinancialDataApplicationService.recalculateSupervision(supervisionId,
- supervision.getFinancialData().getId());
+ this.projectFinancialDataApplicationService.recalculateSupervision(supervisionId, supervision.getFinancialData()
+ .getId());
this.supervisionRepository.save(supervision);
LOG.debug("Supervision with id {} updated.", supervisionId);
@@ -107,11 +106,11 @@ public SupervisionVisitDto createSupervisionVisit(Long supervisionId, Supervisio
SupervisionVisit supervisionVisit = new SupervisionVisit(supervisionVisitDto.getDateOfVisit(),
supervisionVisitDto.getHoursCount(), supervisionVisitDto.getPayable());
supervision.addSupervisionVisit(supervisionVisit);
- SupervisionVisitDto createdSupervisionVisitDto = SupervisionVisitDtoMapper.INSTANCE
- .supervisionVisitToSupervisionVisionDto(supervisionVisit);
+ SupervisionVisitDto createdSupervisionVisitDto = SupervisionVisitDtoMapper.INSTANCE.supervisionVisitToSupervisionVisionDto(
+ supervisionVisit);
this.updateSupervisionHoursCount(supervision);
- this.projectFinancialDataApplicationService.recalculateSupervision(supervisionId,
- supervision.getFinancialData().getId());
+ this.projectFinancialDataApplicationService.recalculateSupervision(supervisionId, supervision.getFinancialData()
+ .getId());
this.supervisionRepository.save(supervision);
createdSupervisionVisitDto.setId(this.getIdForCreatedSupervisionVisit(supervision, supervisionVisit));
createdSupervisionVisitDto.setSupervisionId(supervisionId);
@@ -132,8 +131,8 @@ public SupervisionVisitDto updateSupervisionVisit(Long supervisionId, Long super
Supervision supervision = this.supervisionRepository.load(supervisionId);
supervision.updateSupervisionVisit(supervisionVisitId, supervisionVisitDto);
this.updateSupervisionHoursCount(supervision);
- this.projectFinancialDataApplicationService.recalculateSupervision(supervisionId,
- supervision.getFinancialData().getId());
+ this.projectFinancialDataApplicationService.recalculateSupervision(supervisionId, supervision.getFinancialData()
+ .getId());
this.supervisionRepository.save(supervision);
LOG.debug("Supervision visit with id {} updated.", supervisionVisitId);
@@ -160,23 +159,28 @@ public void deleteSupervisionVisit(Long supervisionId, Long supervisionVisitId)
Supervision supervision = this.supervisionRepository.load(supervisionId);
supervision.removeSupervisionVisit(supervisionVisitId);
this.updateSupervisionHoursCount(supervision);
- this.projectFinancialDataApplicationService.recalculateSupervision(supervisionId,
- supervision.getFinancialData().getId());
+ this.projectFinancialDataApplicationService.recalculateSupervision(supervisionId, supervision.getFinancialData()
+ .getId());
this.supervisionRepository.save(supervision);
LOG.debug("Supervision visit with id {} removed.", supervisionVisitId);
}
private void updateSupervisionHoursCount(Supervision supervision) {
- int hoursCount = supervision.getSupervisionVisits().stream().mapToInt(SupervisionVisit::getHoursCount).sum();
+ int hoursCount = supervision.getSupervisionVisits()
+ .stream()
+ .mapToInt(SupervisionVisit::getHoursCount)
+ .sum();
supervision.setHoursCount(hoursCount);
}
private Long getIdForCreatedSupervisionVisit(Supervision supervision, SupervisionVisit supervisionVisit) {
- return supervision.getSupervisionVisits().stream()
+ return supervision.getSupervisionVisits()
+ .stream()
.filter(visit -> visit.equals(supervisionVisit))
.map(AbstractEntity::getId)
- .findFirst().orElse(null);
+ .findFirst()
+ .orElse(null);
}
}
diff --git a/core/src/main/java/com/arturjarosz/task/systemparameter/application/SystemParameterService.java b/core/src/main/java/com/arturjarosz/task/systemparameter/application/SystemParameterService.java
new file mode 100644
index 00000000..a1c05973
--- /dev/null
+++ b/core/src/main/java/com/arturjarosz/task/systemparameter/application/SystemParameterService.java
@@ -0,0 +1,19 @@
+package com.arturjarosz.task.systemparameter.application;
+
+import com.arturjarosz.task.systemparameter.domain.dto.SystemParameterDto;
+import com.arturjarosz.task.systemparameter.model.SystemParameter;
+
+import java.util.List;
+
+public interface SystemParameterService {
+
+ SystemParameterDto createSystemParameter(SystemParameterDto systemParameterDto, SystemParameter systemParameter);
+
+ SystemParameterDto updateSystemParameter(Long systemParameterId, SystemParameterDto systemParameterDto);
+
+ void removeSystemParameter(Long systemParameterId);
+
+ SystemParameterDto getSystemParameter(Long systemParameterId);
+
+ List getSystemParameters();
+}
diff --git a/core/src/main/java/com/arturjarosz/task/systemparameter/application/impl/SystemParameterServiceImpl.java b/core/src/main/java/com/arturjarosz/task/systemparameter/application/impl/SystemParameterServiceImpl.java
new file mode 100644
index 00000000..737cc876
--- /dev/null
+++ b/core/src/main/java/com/arturjarosz/task/systemparameter/application/impl/SystemParameterServiceImpl.java
@@ -0,0 +1,53 @@
+package com.arturjarosz.task.systemparameter.application.impl;
+
+import com.arturjarosz.task.sharedkernel.annotations.ApplicationService;
+import com.arturjarosz.task.systemparameter.application.SystemParameterService;
+import com.arturjarosz.task.systemparameter.domain.dto.SystemParameterDto;
+import com.arturjarosz.task.systemparameter.infrastructure.repository.SystemParameterRepository;
+import com.arturjarosz.task.systemparameter.model.SystemParameter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+@ApplicationService
+public class SystemParameterServiceImpl implements SystemParameterService {
+
+ private final SystemParameterRepository systemParameterRepository;
+
+ @Autowired
+ public SystemParameterServiceImpl(SystemParameterRepository systemParameterRepository) {
+ this.systemParameterRepository = systemParameterRepository;
+ }
+
+ @Transactional
+ @Override
+ public SystemParameterDto createSystemParameter(SystemParameterDto systemParameterDto,
+ SystemParameter systemParameter) {
+ //TODO: validate system parameter dto
+ //TODO: create new system parameter
+ //TODO: add system parameter
+ this.systemParameterRepository.save(systemParameter);
+ return null;
+ }
+
+ @Override
+ public SystemParameterDto updateSystemParameter(Long systemParameterId, SystemParameterDto systemParameterDto) {
+ return null;
+ }
+
+ @Override
+ public void removeSystemParameter(Long systemParameterId) {
+
+ }
+
+ @Override
+ public SystemParameterDto getSystemParameter(Long systemParameterId) {
+ return null;
+ }
+
+ @Override
+ public List getSystemParameters() {
+ return null;
+ }
+}
diff --git a/core/src/main/java/com/arturjarosz/task/systemparameter/domain/SystemParameterValidator.java b/core/src/main/java/com/arturjarosz/task/systemparameter/domain/SystemParameterValidator.java
new file mode 100644
index 00000000..25780d3c
--- /dev/null
+++ b/core/src/main/java/com/arturjarosz/task/systemparameter/domain/SystemParameterValidator.java
@@ -0,0 +1,9 @@
+package com.arturjarosz.task.systemparameter.domain;
+
+public interface SystemParameterValidator {
+
+ /**
+ * Validates system parameter with given name.
+ */
+ void validate(String name);
+}
diff --git a/core/src/main/java/com/arturjarosz/task/systemparameter/domain/dto/SystemParameterDto.java b/core/src/main/java/com/arturjarosz/task/systemparameter/domain/dto/SystemParameterDto.java
new file mode 100644
index 00000000..191bca1d
--- /dev/null
+++ b/core/src/main/java/com/arturjarosz/task/systemparameter/domain/dto/SystemParameterDto.java
@@ -0,0 +1,62 @@
+package com.arturjarosz.task.systemparameter.domain.dto;
+
+public class SystemParameterDto {
+
+ private Long id;
+ private String name;
+ private String type;
+ private String value;
+ private String defaultValue;
+ private Boolean singleValue;
+
+ public SystemParameterDto() {
+ }
+
+ public Long getId() {
+ return this.id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getDefaultValue() {
+ return this.defaultValue;
+ }
+
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ public Boolean getSingleValue() {
+ return this.singleValue;
+ }
+
+ public void setSingleValue(Boolean singleValue) {
+ this.singleValue = singleValue;
+ }
+}
diff --git a/core/src/main/java/com/arturjarosz/task/systemparameter/infrastructure/repository/SystemParameterRepository.java b/core/src/main/java/com/arturjarosz/task/systemparameter/infrastructure/repository/SystemParameterRepository.java
new file mode 100644
index 00000000..cd86e58c
--- /dev/null
+++ b/core/src/main/java/com/arturjarosz/task/systemparameter/infrastructure/repository/SystemParameterRepository.java
@@ -0,0 +1,7 @@
+package com.arturjarosz.task.systemparameter.infrastructure.repository;
+
+import com.arturjarosz.task.sharedkernel.infrastructure.AbstractBaseRepository;
+import com.arturjarosz.task.systemparameter.model.SystemParameter;
+
+public interface SystemParameterRepository extends AbstractBaseRepository {
+}
diff --git a/core/src/main/java/com/arturjarosz/task/systemparameter/infrastructure/repository/impl/SystemParameterRepositoryImpl.java b/core/src/main/java/com/arturjarosz/task/systemparameter/infrastructure/repository/impl/SystemParameterRepositoryImpl.java
new file mode 100644
index 00000000..c1673716
--- /dev/null
+++ b/core/src/main/java/com/arturjarosz/task/systemparameter/infrastructure/repository/impl/SystemParameterRepositoryImpl.java
@@ -0,0 +1,20 @@
+package com.arturjarosz.task.systemparameter.infrastructure.repository.impl;
+
+import com.arturjarosz.task.sharedkernel.infrastructure.impl.GenericJpaRepositoryImpl;
+import com.arturjarosz.task.systemparameter.infrastructure.repository.SystemParameterRepository;
+import com.arturjarosz.task.systemparameter.model.QSystemParameter;
+import com.arturjarosz.task.systemparameter.model.SystemParameter;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+@Repository
+@Transactional
+public class SystemParameterRepositoryImpl extends GenericJpaRepositoryImpl implements SystemParameterRepository {
+
+ public static final QSystemParameter SYSTEM_PARAMETER = QSystemParameter.systemParameter;
+
+ public SystemParameterRepositoryImpl() {
+ super(SYSTEM_PARAMETER);
+ }
+
+}
diff --git a/core/src/main/java/com/arturjarosz/task/systemparameter/model/SystemParameter.java b/core/src/main/java/com/arturjarosz/task/systemparameter/model/SystemParameter.java
new file mode 100644
index 00000000..120c98ad
--- /dev/null
+++ b/core/src/main/java/com/arturjarosz/task/systemparameter/model/SystemParameter.java
@@ -0,0 +1,48 @@
+package com.arturjarosz.task.systemparameter.model;
+
+import com.arturjarosz.task.sharedkernel.model.AbstractAggregateRoot;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+@Entity
+@SequenceGenerator(name = "sequence_generator", sequenceName = "system_parameter_sequence", allocationSize = 1)
+@Table(name = "SYSTEM_PARAMETER")
+public class SystemParameter extends AbstractAggregateRoot {
+ private static final long serialVersionUID = 9194763340793223514L;
+
+ @Column(name = "NAME")
+ private String name;
+
+ @Enumerated(EnumType.STRING)
+ @Column(name = "TYPE")
+ private SystemParameterType type;
+
+ @Column(name = "VALUE")
+ private String value;
+
+ @Column(name = "DEFAULT_VALUE")
+ private String defaultValue;
+
+ @Column(name = "SINGLE_VALUE")
+ private boolean singleValue;
+
+ protected SystemParameter() {
+ //needed by Hibernate
+ }
+
+ public SystemParameter(String name, String value, String defaultValue, SystemParameterType type,
+ boolean singleValue) {
+ this.name = name;
+ this.value = value;
+ this.defaultValue = defaultValue;
+ this.type = type;
+ this.singleValue = singleValue;
+ }
+
+
+}
diff --git a/core/src/main/java/com/arturjarosz/task/systemparameter/model/SystemParameterType.java b/core/src/main/java/com/arturjarosz/task/systemparameter/model/SystemParameterType.java
new file mode 100644
index 00000000..58766fee
--- /dev/null
+++ b/core/src/main/java/com/arturjarosz/task/systemparameter/model/SystemParameterType.java
@@ -0,0 +1,5 @@
+package com.arturjarosz.task.systemparameter.model;
+
+public enum SystemParameterType {
+ TEXT, NUMBER, DECIMAL_NUMBER
+}
diff --git a/core/src/main/java/com/arturjarosz/task/systemparameter/query/SystemParameterQueryService.java b/core/src/main/java/com/arturjarosz/task/systemparameter/query/SystemParameterQueryService.java
new file mode 100644
index 00000000..ed21d486
--- /dev/null
+++ b/core/src/main/java/com/arturjarosz/task/systemparameter/query/SystemParameterQueryService.java
@@ -0,0 +1,14 @@
+package com.arturjarosz.task.systemparameter.query;
+
+import com.arturjarosz.task.systemparameter.domain.dto.SystemParameterDto;
+
+public interface SystemParameterQueryService {
+
+ /**
+ * Loads SystemPropertyDto by name.
+ */
+ SystemParameterDto getSystemPropertyByName(String name);
+
+}
+
+
diff --git a/core/src/main/java/com/arturjarosz/task/systemparameter/query/impl/SystemParameterQueryServiceImpl.java b/core/src/main/java/com/arturjarosz/task/systemparameter/query/impl/SystemParameterQueryServiceImpl.java
new file mode 100644
index 00000000..c4d5a3b5
--- /dev/null
+++ b/core/src/main/java/com/arturjarosz/task/systemparameter/query/impl/SystemParameterQueryServiceImpl.java
@@ -0,0 +1,28 @@
+package com.arturjarosz.task.systemparameter.query.impl;
+
+import com.arturjarosz.task.sharedkernel.annotations.Finder;
+import com.arturjarosz.task.sharedkernel.infrastructure.AbstractQueryService;
+import com.arturjarosz.task.systemparameter.domain.dto.SystemParameterDto;
+import com.arturjarosz.task.systemparameter.model.QSystemParameter;
+import com.arturjarosz.task.systemparameter.query.SystemParameterQueryService;
+import com.querydsl.core.types.Projections;
+
+@Finder
+public class SystemParameterQueryServiceImpl extends AbstractQueryService implements SystemParameterQueryService {
+
+ private final static QSystemParameter SYSTEM_PARAMETER = QSystemParameter.systemParameter;
+
+ public SystemParameterQueryServiceImpl() {
+ super(SYSTEM_PARAMETER);
+ }
+
+ @Override
+ public SystemParameterDto getSystemPropertyByName(String name) {
+ return this.queryFromAggregate()
+ .where(SYSTEM_PARAMETER.name.eq(name))
+ .select(Projections.bean(SystemParameterDto.class, SYSTEM_PARAMETER.id, SYSTEM_PARAMETER.name,
+ SYSTEM_PARAMETER.type, SYSTEM_PARAMETER.value, SYSTEM_PARAMETER.defaultValue,
+ SYSTEM_PARAMETER.singleValue))
+ .fetchOne();
+ }
+}
diff --git a/core/src/main/resources/application.yaml b/core/src/main/resources/application.yaml
index 1d580aea..4ccf1e63 100644
--- a/core/src/main/resources/application.yaml
+++ b/core/src/main/resources/application.yaml
@@ -26,6 +26,14 @@ spring:
banner-mode: off
jackson:
default-property-inclusion: non_null
+ rabbitmq:
+ port: 5672
+ password: guest
+ username: guest
+ host: localhost
+ cache:
+ connection:
+ mode: channel
server:
port: 8099
task:
diff --git a/database/src/main/resources/database/changelogs/v1.0.0/architect/create-architect-sequence.yml b/database/src/main/resources/database/changelogs/v1.0.0/architect/create-architect-sequence.yml
index 816d44b0..3a7f9765 100644
--- a/database/src/main/resources/database/changelogs/v1.0.0/architect/create-architect-sequence.yml
+++ b/database/src/main/resources/database/changelogs/v1.0.0/architect/create-architect-sequence.yml
@@ -2,9 +2,9 @@ databaseChangeLog:
- changeSet:
author: "liquibase"
id: "create-architect-sequence"
- changes:
- - createSequence:
- sequenceName: "architect_sequence"
- startValue: 100
- cacheSize: 10
- incrementBy: 1
+ changes:
+ - createSequence:
+ sequenceName: "architect_sequence"
+ startValue: 100
+ cacheSize: 10
+ incrementBy: 1
diff --git a/database/src/main/resources/database/changelogs/v1.0.0/changelog-v1.0.0.yml b/database/src/main/resources/database/changelogs/v1.0.0/changelog-v1.0.0.yml
index 01381794..01f407d2 100644
--- a/database/src/main/resources/database/changelogs/v1.0.0/changelog-v1.0.0.yml
+++ b/database/src/main/resources/database/changelogs/v1.0.0/changelog-v1.0.0.yml
@@ -23,6 +23,9 @@ databaseChangeLog:
- include:
file: "supervision/supervision-tables.xml"
relativeToChangelogFile: true
+ - include:
+ file: "system-parameter/system-parameter-tables.yml"
+ relativeToChangelogFile: true
- changeSet:
author: "liquibase"
id: "tag-version_1.0.0"
diff --git a/database/src/main/resources/database/changelogs/v1.0.0/system-property/create-system-property-sequence.yml b/database/src/main/resources/database/changelogs/v1.0.0/system-parameter/create-system-parameter-sequence.yml
similarity index 62%
rename from database/src/main/resources/database/changelogs/v1.0.0/system-property/create-system-property-sequence.yml
rename to database/src/main/resources/database/changelogs/v1.0.0/system-parameter/create-system-parameter-sequence.yml
index b10b021d..825dd965 100644
--- a/database/src/main/resources/database/changelogs/v1.0.0/system-property/create-system-property-sequence.yml
+++ b/database/src/main/resources/database/changelogs/v1.0.0/system-parameter/create-system-parameter-sequence.yml
@@ -1,10 +1,10 @@
databaseChangeLog:
- changeSet:
author: "liquibase"
- id: "create-system-property-sequence"
+ id: "create-system-parameter-sequence"
changes:
- createSequence:
- sequenceName: "system_property_sequence"
+ sequenceName: "system_parameter_sequence"
startValue: 100
cacheSize: 10
incrementBy: 1
diff --git a/database/src/main/resources/database/changelogs/v1.0.0/system-property/create-system-property-table.yml b/database/src/main/resources/database/changelogs/v1.0.0/system-parameter/create-system-parameter-table.yml
similarity index 67%
rename from database/src/main/resources/database/changelogs/v1.0.0/system-property/create-system-property-table.yml
rename to database/src/main/resources/database/changelogs/v1.0.0/system-parameter/create-system-parameter-table.yml
index 559cc5a5..291e3813 100644
--- a/database/src/main/resources/database/changelogs/v1.0.0/system-property/create-system-property-table.yml
+++ b/database/src/main/resources/database/changelogs/v1.0.0/system-parameter/create-system-parameter-table.yml
@@ -1,16 +1,21 @@
databaseChangeLog:
- changeSet:
- id: "create-system-property-table"
+ id: "create-system-parameter-table"
author: "liquibase"
changes:
- createTable:
- tableName: "SYSTEM_PROPERTY"
+ tableName: "SYSTEM_PARAMETER"
columns:
- column:
name: "ID"
type: "${long.type}"
constraints:
nullable: false
+ - column:
+ name: "UUID"
+ type: "${uuid.type}"
+ constraints:
+ nullable: false
- column:
name: "NAME"
type: "VARCHAR2(60 ${char.unit})"
@@ -35,6 +40,10 @@ databaseChangeLog:
constraints:
nullable: false
- addPrimaryKey:
- tableName: "SYSTEM_PROPERTY"
+ tableName: "SYSTEM_PARAMETER"
columnNames: "ID"
- constraintName: "PK_SYSTEM_PROPERTY"
+ constraintName: "PK_SYSTEM_PARAMETER"
+ - addUniqueConstraint:
+ tableName: "SYSTEM_PARAMETER"
+ columnNames: "NAME"
+ constraintName: "UNIQ_SYSTEM_PARAMETER_NAME"
diff --git a/database/src/main/resources/database/changelogs/v1.0.0/system-property/system-property-tables.yml b/database/src/main/resources/database/changelogs/v1.0.0/system-parameter/system-parameter-tables.yml
similarity index 52%
rename from database/src/main/resources/database/changelogs/v1.0.0/system-property/system-property-tables.yml
rename to database/src/main/resources/database/changelogs/v1.0.0/system-parameter/system-parameter-tables.yml
index 2ac1be43..2861de70 100644
--- a/database/src/main/resources/database/changelogs/v1.0.0/system-property/system-property-tables.yml
+++ b/database/src/main/resources/database/changelogs/v1.0.0/system-parameter/system-parameter-tables.yml
@@ -1,7 +1,7 @@
databaseChangeLog:
- include:
- file: "create-system-property-sequence.yml"
+ file: "create-system-parameter-sequence.yml"
relativeToChangelogFile: true
- include:
- file: "create-system-property-table.yml"
+ file: "create-system-parameter-table.yml"
relativeToChangelogFile: true
diff --git a/pom.xml b/pom.xml
index c202c125..e344efe8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,6 +9,7 @@
database
sample-data
sharedkernel
+ testRabbit
org.springframework.boot
diff --git a/sample-data/src/main/java/com/arturjarosz/task/data/ArchitectsInitializer.java b/sample-data/src/main/java/com/arturjarosz/task/data/ArchitectsInitializer.java
index 100b1fc6..90b8b871 100644
--- a/sample-data/src/main/java/com/arturjarosz/task/data/ArchitectsInitializer.java
+++ b/sample-data/src/main/java/com/arturjarosz/task/data/ArchitectsInitializer.java
@@ -10,15 +10,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import javax.transaction.Transactional;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.List;
@Component
-public class ArchitectsInitializer {
-
+public class ArchitectsInitializer implements DataInitializer {
private static final Logger LOG = LogManager.getLogger(ArchitectsInitializer.class);
private final ArchitectApplicationService architectApplicationService;
@@ -28,8 +26,8 @@ public ArchitectsInitializer(ArchitectApplicationService architectApplicationSer
this.architectApplicationService = architectApplicationService;
}
- @Transactional
- void run() {
+ @Override
+ public void initializeData() {
LOG.info("Starting importing architects.");
this.importArchitectsFromFile();
LOG.info("Architects added to the database.");
@@ -43,7 +41,8 @@ private void importArchitectsFromFile() {
private List prepareArchitects(String filename) {
ObjectMapper mapper = new ObjectMapper();
BaseValidator.assertNotEmpty(filename, "File name cannot be empty.");
- try (InputStream inputStream = ArchitectsInitializer.class.getClassLoader().getResourceAsStream(filename)) {
+ try (InputStream inputStream = ArchitectsInitializer.class.getClassLoader()
+ .getResourceAsStream(filename)) {
return mapper.readValue(inputStream, new TypeReference>() {
});
} catch (IOException e) {
diff --git a/sample-data/src/main/java/com/arturjarosz/task/data/ClientInitializer.java b/sample-data/src/main/java/com/arturjarosz/task/data/ClientInitializer.java
index 1fc7b20a..e2061fe4 100644
--- a/sample-data/src/main/java/com/arturjarosz/task/data/ClientInitializer.java
+++ b/sample-data/src/main/java/com/arturjarosz/task/data/ClientInitializer.java
@@ -16,7 +16,7 @@
import java.util.List;
@Component
-public class ClientInitializer {
+public class ClientInitializer implements DataInitializer {
private static final Logger LOG = LogManager.getLogger(ClientInitializer.class);
@@ -27,7 +27,8 @@ public ClientInitializer(ClientApplicationService clientApplicationService) {
this.clientApplicationService = clientApplicationService;
}
- void run() {
+ @Override
+ public void initializeData() {
LOG.info("Starting importing clients.");
this.importClientsFromFile();
LOG.info("Clients added to the database.");
@@ -41,7 +42,8 @@ private void importClientsFromFile() {
private List prepareClients(String filename) {
ObjectMapper mapper = new ObjectMapper();
BaseValidator.assertNotEmpty(filename, "File name cannot be empty.");
- try (InputStream inputStream = ClientInitializer.class.getClassLoader().getResourceAsStream(filename)) {
+ try (InputStream inputStream = ClientInitializer.class.getClassLoader()
+ .getResourceAsStream(filename)) {
return mapper.readValue(inputStream, new TypeReference>() {
});
} catch (IOException e) {
diff --git a/sample-data/src/main/java/com/arturjarosz/task/data/DataInitializer.java b/sample-data/src/main/java/com/arturjarosz/task/data/DataInitializer.java
new file mode 100644
index 00000000..85d76165
--- /dev/null
+++ b/sample-data/src/main/java/com/arturjarosz/task/data/DataInitializer.java
@@ -0,0 +1,6 @@
+package com.arturjarosz.task.data;
+
+public interface DataInitializer {
+ void initializeData();
+
+}
diff --git a/sample-data/src/main/java/com/arturjarosz/task/data/InitData.java b/sample-data/src/main/java/com/arturjarosz/task/data/InitData.java
index c2fd585a..0c9da683 100644
--- a/sample-data/src/main/java/com/arturjarosz/task/data/InitData.java
+++ b/sample-data/src/main/java/com/arturjarosz/task/data/InitData.java
@@ -2,17 +2,18 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
+import org.springframework.context.annotation.AdviceMode;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+@EnableTransactionManagement(mode = AdviceMode.PROXY)
@SpringBootApplication(scanBasePackages = "com.arturjarosz.task", exclude = {LiquibaseAutoConfiguration.class, GsonAutoConfiguration.class})
-@EntityScan(basePackages = "com.arturjarosz.task")
-
public class InitData {
public static void main(String[] args) {
- SpringApplication.run(InitData.class, args).close();
+ SpringApplication.run(InitData.class, args)
+ .close();
}
}
diff --git a/sample-data/src/main/java/com/arturjarosz/task/data/SampleDataInitializer.java b/sample-data/src/main/java/com/arturjarosz/task/data/SampleDataInitializer.java
index 23745282..50e6c690 100644
--- a/sample-data/src/main/java/com/arturjarosz/task/data/SampleDataInitializer.java
+++ b/sample-data/src/main/java/com/arturjarosz/task/data/SampleDataInitializer.java
@@ -1,33 +1,45 @@
package com.arturjarosz.task.data;
+import com.arturjarosz.task.sharedkernel.annotations.ApplicationService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.springframework.stereotype.Component;
+import org.springframework.beans.factory.annotation.Autowired;
-import javax.transaction.Transactional;
+import java.util.List;
-@Component
+
+@ApplicationService
public class SampleDataInitializer extends AbstractDataInitializer {
private static final Logger LOG = LogManager.getLogger(SampleDataInitializer.class);
+ private final List dataInitializers;
+ private final TransactionHandler transactionHandler;
- private final ArchitectsInitializer architectsInitializer;
- private final ClientInitializer clientInitializer;
-
- public SampleDataInitializer(ArchitectsInitializer architectsInitializer, ClientInitializer clientInitializer) {
- this.architectsInitializer = architectsInitializer;
- this.clientInitializer = clientInitializer;
+ @Autowired
+ public SampleDataInitializer(List dataInitializers, TransactionHandler transactionHandler) {
+ this.dataInitializers = dataInitializers;
+ this.transactionHandler = transactionHandler;
}
/**
* Loading all sample data.
*/
+
@Override
- @Transactional
protected void loadData() {
LOG.info("Loading sample data.");
- this.architectsInitializer.run();
- this.clientInitializer.run();
+
+ for (DataInitializer dataInitializer : this.dataInitializers) {
+ try {
+ this.transactionHandler.runInTransaction(transactionStatus -> {
+ dataInitializer.initializeData();
+ return null;
+ });
+ } catch (Exception e) {
+ throw new RuntimeException(":(");
+ }
+ }
+
LOG.info("All sample data loaded.");
}
}
diff --git a/sample-data/src/main/java/com/arturjarosz/task/data/SystemParametersInitializer.java b/sample-data/src/main/java/com/arturjarosz/task/data/SystemParametersInitializer.java
new file mode 100644
index 00000000..25153121
--- /dev/null
+++ b/sample-data/src/main/java/com/arturjarosz/task/data/SystemParametersInitializer.java
@@ -0,0 +1,72 @@
+package com.arturjarosz.task.data;
+
+import com.arturjarosz.task.sharedkernel.exceptions.BaseValidator;
+import com.arturjarosz.task.systemparameter.application.SystemParameterService;
+import com.arturjarosz.task.systemparameter.infrastructure.repository.SystemParameterRepository;
+import com.arturjarosz.task.systemparameter.model.SystemParameter;
+import com.arturjarosz.task.systemparameter.model.SystemParameterType;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.List;
+
+@Component
+public class SystemParametersInitializer implements DataInitializer {
+ private static final Logger LOGGER = LogManager.getLogger(SystemParametersInitializer.class);
+ private static final String SYSTEM_PARAMETERS_PATH = "systemParameters.json";
+
+ private final SystemParameterService systemParameterService;
+ private final SystemParameterRepository systemParameterRepository;
+
+ @Autowired
+ public SystemParametersInitializer(SystemParameterService systemParameterService,
+ SystemParameterRepository systemParameterRepository) {
+ this.systemParameterService = systemParameterService;
+ this.systemParameterRepository = systemParameterRepository;
+ }
+
+ @Override
+ public void initializeData() {
+ LOGGER.info("Start importing system parameters.");
+ this.importSystemParametersFromFile();
+ LOGGER.info("System parameters added to the database.");
+ }
+
+ private void importSystemParametersFromFile() {
+ List systemParameters = this.prepareSystemParameters(SYSTEM_PARAMETERS_PATH);
+ systemParameters.forEach(this.systemParameterRepository::save);
+ }
+
+ private List prepareSystemParameters(String filename) {
+ ObjectMapper mapper = new ObjectMapper();
+ BaseValidator.assertNotEmpty(filename, "File name cannot be empty.");
+ try (InputStream inputStream = SystemParametersInitializer.class.getClassLoader()
+ .getResourceAsStream(filename)) {
+ JsonNode jsonNode = mapper.readTree(inputStream);
+ ArrayNode systemParametersNodes = (ArrayNode) jsonNode;
+ List systemParameters = new ArrayList<>();
+ systemParametersNodes.forEach(systemParameterNode -> {
+ SystemParameter systemParameter = new SystemParameter(systemParameterNode.get("name")
+ .asText(), systemParameterNode.get("value")
+ .asText(), systemParameterNode.get("defaultValue")
+ .asText(), SystemParameterType.valueOf(systemParameterNode.get("type")
+ .asText()), systemParameterNode.get("singleValue")
+ .booleanValue());
+ systemParameters.add(systemParameter);
+ });
+ return systemParameters;
+ } catch (IOException e) {
+ throw new UncheckedIOException(
+ String.format("There was a problem with adding system parameter from %1$s file", filename), e);
+ }
+ }
+}
diff --git a/sample-data/src/main/java/com/arturjarosz/task/data/TransactionHandler.java b/sample-data/src/main/java/com/arturjarosz/task/data/TransactionHandler.java
new file mode 100644
index 00000000..836433dc
--- /dev/null
+++ b/sample-data/src/main/java/com/arturjarosz/task/data/TransactionHandler.java
@@ -0,0 +1,25 @@
+package com.arturjarosz.task.data;
+
+import com.arturjarosz.task.sharedkernel.annotations.DomainService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
+
+@DomainService
+public class TransactionHandler {
+ private final PlatformTransactionManager transactionManager;
+
+ @Autowired
+ public TransactionHandler(PlatformTransactionManager transactionManager) {
+ this.transactionManager = transactionManager;
+ }
+
+ @Transactional(propagation = Propagation.REQUIRED)
+ public void runInTransaction(TransactionCallback transaction) {
+ TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);
+ transactionTemplate.execute(transaction);
+ }
+}
diff --git a/sample-data/src/main/resources/systemParameters.json b/sample-data/src/main/resources/systemParameters.json
new file mode 100644
index 00000000..a1f055dc
--- /dev/null
+++ b/sample-data/src/main/resources/systemParameters.json
@@ -0,0 +1,9 @@
+[
+ {
+ "name": "Vat tax",
+ "type": "NUMBER",
+ "value": "0.23",
+ "defaultValue": "0.23",
+ "singleValue": true
+ }
+]
diff --git a/sharedkernel/src/main/java/com/arturjarosz/task/sharedkernel/infrastructure/impl/GenericJpaRepositoryImpl.java b/sharedkernel/src/main/java/com/arturjarosz/task/sharedkernel/infrastructure/impl/GenericJpaRepositoryImpl.java
index ab33e9a4..2318fbc3 100644
--- a/sharedkernel/src/main/java/com/arturjarosz/task/sharedkernel/infrastructure/impl/GenericJpaRepositoryImpl.java
+++ b/sharedkernel/src/main/java/com/arturjarosz/task/sharedkernel/infrastructure/impl/GenericJpaRepositoryImpl.java
@@ -24,10 +24,9 @@
* @param
*/
-@Transactional(propagation = Propagation.SUPPORTS)
+@Transactional
@Repository
-public abstract class GenericJpaRepositoryImpl>
- implements AbstractBaseRepository {
+public abstract class GenericJpaRepositoryImpl> implements AbstractBaseRepository {
private AutowireCapableBeanFactory spring;
@PersistenceContext
@@ -64,7 +63,9 @@ public JPAQuery queryFromAggregateRoot() {
*/
@Override
public T load(Long id) {
- return this.queryFromAggregateRoot().where(this.qAbstractAggregateRoot.id.eq(id)).fetchOne();
+ return this.queryFromAggregateRoot()
+ .where(this.qAbstractAggregateRoot.id.eq(id))
+ .fetchOne();
}
/**
@@ -74,7 +75,8 @@ public T load(Long id) {
*/
@Override
public List loadAll() {
- List aggregates = this.queryFromAggregateRoot().fetch();
+ List aggregates = this.queryFromAggregateRoot()
+ .fetch();
this.autowire(aggregates);
return aggregates;
}
@@ -85,6 +87,7 @@ public List loadAll() {
* @param aggregate
*/
@Override
+ @Transactional(propagation = Propagation.MANDATORY)
public T save(T aggregate) {
if (!this.entityManager.contains(aggregate)) {
this.entityManager.persist(aggregate);
diff --git a/testRabbit/pom.xml b/testRabbit/pom.xml
new file mode 100644
index 00000000..3435c609
--- /dev/null
+++ b/testRabbit/pom.xml
@@ -0,0 +1,64 @@
+
+
+
+ task-parent
+ com.arturjarosz
+ 1.0.0-SNAPSHOT
+
+ 4.0.0
+
+ testRabbit
+
+
+ 15
+ 15
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-log4j2
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.5
+
+
+ org.slf4j
+ slf4j-log4j12
+ 1.7.5
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ compile
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-amqp
+
+
+
+
diff --git a/testRabbit/src/main/java/com/test/Main.java b/testRabbit/src/main/java/com/test/Main.java
new file mode 100644
index 00000000..e64bf364
--- /dev/null
+++ b/testRabbit/src/main/java/com/test/Main.java
@@ -0,0 +1,12 @@
+package com.test;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+
+@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
+public class Main {
+ public static void main(String[] args) {
+ SpringApplication.run(Main.class, args);
+ }
+}
diff --git a/testRabbit/src/main/java/com/test/RabbitConfiguration.java b/testRabbit/src/main/java/com/test/RabbitConfiguration.java
new file mode 100644
index 00000000..3343a5b0
--- /dev/null
+++ b/testRabbit/src/main/java/com/test/RabbitConfiguration.java
@@ -0,0 +1,64 @@
+package com.test;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.amqp.core.AmqpAdmin;
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
+import org.springframework.amqp.rabbit.connection.Connection;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.amqp.rabbit.listener.MessageListenerContainer;
+import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class RabbitConfiguration {
+ private static final Logger LOG = LoggerFactory.getLogger(RabbitConfiguration.class);
+ private static final String TEST_EXCHANGE = "test.exchange";
+ private static final String TEST_EXCHANGE_2 = "test.exchange2";
+ private static final String TEST_QUEUE = "test.queue";
+ private static final String TEST_QUEUE_2 = "test.queue";
+ private static final String LOGIN = "guest";
+ private static final String PASSWORD = "guest";
+ private static final String HOST = "localhost";
+ private static final String VIRTUAL_HOST = "/";
+ private static final String ROUTING_KEY = "#";
+ private static final String ADDRESSES = "127.0.0.1:30000,127.0.0.1:30002,127.0.0.1:30004";
+
+ private final CachingConnectionFactory connectionFactory;
+ private final Connection connection;
+ private RabbitAdmin admin;
+
+ @Autowired
+ public RabbitConfiguration() {
+ LOG.info("Creating rabbit configuration.");
+ com.rabbitmq.client.ConnectionFactory rabbitFactory = new com.rabbitmq.client.ConnectionFactory();
+ rabbitFactory.setUsername(LOGIN);
+ rabbitFactory.setPassword(PASSWORD);
+ //rabbitFactory.setHost(HOST);
+ //rabbitFactory.setVirtualHost(VIRTUAL_HOST);
+ rabbitFactory.setAutomaticRecoveryEnabled(true);
+
+ this.connectionFactory = new CachingConnectionFactory(rabbitFactory);
+ this.connectionFactory.setAddresses(ADDRESSES);
+ this.connection = this.connectionFactory.createConnection();
+ }
+
+ @Bean
+ public AmqpAdmin admin() {
+ this.admin = new RabbitAdmin(this.connectionFactory);
+ return this.admin;
+ }
+
+ @Bean
+ MessageListenerContainer messageListenerContainer() {
+ SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer();
+ simpleMessageListenerContainer.setConnectionFactory(this.connectionFactory);
+ simpleMessageListenerContainer.setQueueNames(TEST_QUEUE_2);
+ simpleMessageListenerContainer.setMessageListener(new Receiver());
+ return simpleMessageListenerContainer;
+ }
+
+
+}
diff --git a/testRabbit/src/main/java/com/test/Receiver.java b/testRabbit/src/main/java/com/test/Receiver.java
new file mode 100644
index 00000000..2bf00f9a
--- /dev/null
+++ b/testRabbit/src/main/java/com/test/Receiver.java
@@ -0,0 +1,35 @@
+package com.test;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.amqp.core.AcknowledgeMode;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.core.MessageListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class Receiver implements MessageListener {
+ private static final Logger LOG = LoggerFactory.getLogger(Receiver.class);
+
+ @Autowired
+ public Receiver() {
+ }
+
+ @Override
+ public void onMessage(Message message) {
+ LOG.info("-- Receiving message: " + new String(message.getBody()));
+ }
+
+ @Override
+ public void containerAckMode(AcknowledgeMode mode) {
+ MessageListener.super.containerAckMode(mode);
+ }
+
+ @Override
+ public void onMessageBatch(List messages) {
+ MessageListener.super.onMessageBatch(messages);
+ }
+}
diff --git a/testRabbit/src/main/resources/application.yaml b/testRabbit/src/main/resources/application.yaml
new file mode 100644
index 00000000..fd57a530
--- /dev/null
+++ b/testRabbit/src/main/resources/application.yaml
@@ -0,0 +1,15 @@
+spring:
+ jpa:
+ openInView: false
+ show_sql: false
+ generate-ddl: false
+ main:
+ log-startup-info: false
+ banner-mode: off
+ jackson:
+ default-property-inclusion: non_null
+server:
+ port: 8100
+task:
+ language: en
+ encoding: UTF-8
diff --git a/testRabbit/src/main/resources/log4j2.xml b/testRabbit/src/main/resources/log4j2.xml
new file mode 100644
index 00000000..d1a9d459
--- /dev/null
+++ b/testRabbit/src/main/resources/log4j2.xml
@@ -0,0 +1,35 @@
+
+
+
+
+ archive
+ [%d{ISO8601}] %5p [%t]%x - %C{1}.%M(%F:%L) - %m%n
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+