Skip to content

Commit

Permalink
Merge pull request #22 from anasabbal/day1
Browse files Browse the repository at this point in the history
begin carrier service with a lot of extends
  • Loading branch information
anasabbal authored Jan 15, 2023
2 parents 65f051d + 3abb6bd commit 453be64
Show file tree
Hide file tree
Showing 36 changed files with 301 additions and 45 deletions.
27 changes: 27 additions & 0 deletions carrier-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,31 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>com.nas</groupId>
<artifactId>core-comm</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.nas.carrier.command;


import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ApplicationSubmitCommand {

private String fullName;
private String email;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nas.carrier.command;


import lombok.Getter;
import lombok.Setter;

import java.util.Set;

@Getter
@Setter
public class JobCommand {
private String description;
private Set<ApplicationSubmitCommand> applicationSubmitCommands;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.nas.carrier.model;


import com.nas.carrier.command.ApplicationSubmitCommand;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class ApplicationSubmit extends BaseEntity{


@Column(name = "FULL_NAME")
private String fullName;

@Column(name = "EMAIL")
private String email;


@ManyToOne
private Job job;


public static ApplicationSubmit create(final ApplicationSubmitCommand applicationSubmitCommand){
final ApplicationSubmit applicationSubmit = new ApplicationSubmit();

applicationSubmit.fullName = applicationSubmitCommand.getFullName();
applicationSubmit.email = applicationSubmitCommand.getEmail();

return applicationSubmit;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.nas.carrier.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDateTime;

@Getter
@Setter
@MappedSuperclass
@EntityListeners(value = AuditingEntityListener.class)
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public abstract class BaseEntity {
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "ID")
@EqualsAndHashCode.Include
protected String id;

@Version
@Column(name = "VERSION")
private Integer version;

@CreatedDate
@Column(name = "CREATED_AT", updatable = false)
private LocalDateTime createdAt;

@CreatedBy
@Column(name = "created_by", updatable = false)
private String createdBy = "NAS SYSTEM";

@LastModifiedDate
@Column(name = "UPDATED_AT")
private LocalDateTime updatedAt;

@LastModifiedBy
@Column(name = "updated_by")
private String updatedBy;

@Column(name = "DELETED")
protected Boolean deleted = false;

@Column(name = "ACTIVE")
protected Boolean active = true;
}
17 changes: 17 additions & 0 deletions carrier-service/src/main/java/com/nas/carrier/model/Carrier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.nas.carrier.model;


import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class Carrier extends BaseEntity{



}
38 changes: 38 additions & 0 deletions carrier-service/src/main/java/com/nas/carrier/model/Job.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.nas.carrier.model;


import com.nas.carrier.command.ApplicationSubmitCommand;
import com.nas.carrier.command.JobCommand;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Set;
import java.util.stream.Collectors;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class Job extends BaseEntity{


@Column(name = "DESCRIPTION")
private String description;

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "job")
public Set<ApplicationSubmit> applicationSubmitSet;


public static Job create(final JobCommand jobCommand){
final Job job = new Job();

job.description = jobCommand.getDescription();
job.applicationSubmitSet = createPayloadForApplicationSubmitted(jobCommand.getApplicationSubmitCommands());

return job;
}
public static Set<ApplicationSubmit> createPayloadForApplicationSubmitted(final Set<ApplicationSubmitCommand> applicationSubmitCommands){
return applicationSubmitCommands.stream().map(ApplicationSubmit::create).collect(Collectors.toSet());
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven
#Fri Jan 06 18:50:16 WEST 2023
#Thu Jan 12 15:26:10 WEST 2023
groupId=com.nas
artifactId=circuit-breaker-example
version=1.0-SNAPSHOT
Binary file modified circuit-breaker/target/circuit-breaker-1.0-SNAPSHOT.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion circuit-breaker/target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven
#Fri Jan 06 18:50:13 WEST 2023
#Thu Jan 12 15:26:07 WEST 2023
groupId=com.nas
artifactId=circuit-breaker
version=1.0-SNAPSHOT
Binary file modified config-server/target/config-server-1.0-SNAPSHOT.jar
Binary file not shown.
Binary file modified config-server/target/config-server-1.0-SNAPSHOT.jar.original
Binary file not shown.
2 changes: 1 addition & 1 deletion config-server/target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven
#Fri Jan 06 18:50:05 WEST 2023
#Thu Jan 12 15:26:03 WEST 2023
groupId=com.nas
artifactId=config-server
version=1.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ private Map<String, Object> senderProps() {
return props;
}
@Bean
public ProducerFactory<String, String> producerFactory() {
public ProducerFactory<String, ?> producerFactory() {
return new DefaultKafkaProducerFactory<>(senderProps());
}
@Bean
public KafkaTemplate<String, String> kafkaTemplate(ProducerFactory<String, String> producerFactory) {
return new KafkaTemplate<String, String>(producerFactory);
public KafkaTemplate<String, ?> kafkaTemplate(ProducerFactory<String, ?> producerFactory) {
return new KafkaTemplate<>(producerFactory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import org.springframework.util.concurrent.ListenableFutureCallback;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Service
Expand All @@ -37,7 +35,7 @@ public class CustomerServiceImpl implements CustomerService{

private final CustomerRepository customerRepository;
private final RestTemplate restTemplate;
private final KafkaTemplate<String, String> kafkaTemplate;
private final KafkaTemplate<String, CustomerRequestDriver> kafkaTemplate;

@Override
public Customer create(CustomerCommand customerCommand) {
Expand Down Expand Up @@ -82,11 +80,11 @@ public void sendRequestDriver(CustomerRequestDriver requestDriver){
);
final Customer customer = findById(requestDriver.getCustomerId());

ListenableFuture<SendResult<String, String>> future =
kafkaTemplate.send("topic1", customer.getId());
future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
ListenableFuture<SendResult<String, CustomerRequestDriver>> future =
kafkaTemplate.send("topic1", requestDriver);
future.addCallback(new ListenableFutureCallback<SendResult<String, CustomerRequestDriver>>() {
@Override
public void onSuccess(SendResult<String, String> result) {
public void onSuccess(SendResult<String, CustomerRequestDriver> result) {
log.info("Message [{}] delivered with offset {}",
JSONUtil.toJSON(requestDriver),
result.getRecordMetadata().offset());
Expand Down
16 changes: 12 additions & 4 deletions driver-location-service/target/classes/application.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
spring:
data:
mongodb:
uri: mongodb+srv://mongodb:mongodb@driver-location.01ks23m.mongodb.net/driver-location
auto-index-creation: true
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: update
show-sql: true
datasource:
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/driverLocation
username: postgres
password: postgres

application:
name: driver-location
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
@Setter
public class CustomerRequestDriver {
private String customerId;
private String driverId;

public static CustomerRequestDriver create(final String customerId){
public static CustomerRequestDriver create(final String customerId, final String driverId){
final CustomerRequestDriver customerRequestDriver = new CustomerRequestDriver();

customerRequestDriver.customerId = customerId;
customerRequestDriver.driverId = driverId;

return customerRequestDriver;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nas.driver.config;


import com.nas.driver.command.CustomerRequestDriver;
import org.apache.kafka.clients.admin.NewTopic;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.common.serialization.StringDeserializer;
Expand All @@ -24,7 +25,7 @@ public NewTopic topic() {
.build();
}
@Bean
public ConsumerFactory<String, String> consumerFactory() {
public ConsumerFactory<String, ?> consumerFactory() {
return new DefaultKafkaConsumerFactory<>(consumerProps());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.nas.driver.dto.DriverDto;
import com.nas.driver.dto.mapper.DriverMapper;
import com.nas.driver.model.Driver;
import com.nas.driver.service.DriverService;
import com.nas.driver.service.driver.DriverService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down
10 changes: 4 additions & 6 deletions driver-service/src/main/java/com/nas/driver/model/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import com.nas.driver.enums.DriverStatus;
import lombok.*;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -28,8 +26,8 @@ public class Driver extends BaseEntity{
private String lastName;
private DriverStatus driverStatus;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "driver")
private Set<NotificationDriver> notificationDriversId;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Set<NotificationDriver> notificationDrivers;

public static Driver create(final DriverCommand driverCommand){
final Driver driver = new Driver();
Expand All @@ -46,7 +44,7 @@ public void updateInfo(final DriverCommand driverCommand){
this.updatedBy = this.firstName;
}
public void addToSet(NotificationDriver notificationDriver){
notificationDriver.linkToDriver(this);
this.notificationDrivers.add(notificationDriver);
}
public static Set<NotificationDriver> createNotificationPayload(Set<CustomerRequestDriver> customerRequestDrivers){
return customerRequestDrivers
Expand Down
Loading

0 comments on commit 453be64

Please sign in to comment.