Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
<version>${objenesis.version}</version>
<scope>test</scope>
</dependency>
<!-- RabbitMQ -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/com/arturjarosz/task/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

@SpringBootApplication
public class Main {


public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -84,7 +90,8 @@ public ArchitectDto updateArchitect(Long architectId, ArchitectDto architectDto)

@Override
public List<ArchitectBasicDto> getBasicArchitects() {
return this.architectRepository.loadAll().stream()
return this.architectRepository.loadAll()
.stream()
.map(ArchitectDtoMapper.INSTANCE::architectToArchitectBasicDto)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -79,7 +80,8 @@ public ContractorDto getContractor(Long contractorId) {
@Override
public List<ContractorDto> getBasicContractors() {
LOG.debug("Loading Contractors list");
return this.cooperatorRepository.loadAll().stream()
return this.cooperatorRepository.loadAll()
.stream()
.map(ContractorDtoMapper.INSTANCE::cooperatorToBasicContractor)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -75,7 +75,8 @@ public SupplierDto getSupplier(Long supplierId) {
@Override
public List<SupplierDto> getBasicSuppliers() {
LOG.debug("Loading Suppliers list");
return this.cooperatorRepository.loadAll().stream()
return this.cooperatorRepository.loadAll()
.stream()
.map(SupplierDtoMapper.INSTANCE::cooperatorToBasicSupplier)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -84,8 +83,7 @@ public List<CostDto> getCosts(Long projectId) {
Set<Cost> costs = project.getCosts();
return new ArrayList<>(costs.stream()
.map(CostDtoMapper.INSTANCE::costToCostDto)
.collect(Collectors.toList())
);
.collect(Collectors.toList()));
}

@Transactional
Expand All @@ -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);
}

}
Loading