Skip to content

Commit

Permalink
format source code
Browse files Browse the repository at this point in the history
fix warnings
  • Loading branch information
deepcloudlabs committed Jun 29, 2020
1 parent 8fec39b commit a078b89
Show file tree
Hide file tree
Showing 53 changed files with 368 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class CustomerBaseEvent {
private long sequenceId;
private String sourceId;
private String identity;
@LastModifiedDate
private Date lastModified;
@CreatedDate
private Date createdAt;
@LastModifiedDate
private Date lastModified;
@CreatedDate
private Date createdAt;

public CustomerBaseEvent() {
}

Expand Down Expand Up @@ -70,24 +70,24 @@ public void setIdentity(String identity) {
this.identity = identity;
}

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
public Date getLastModified() {
return lastModified;
}
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
public Date getLastModified() {
return lastModified;
}

public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}

public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
public Date getCreatedAt() {
return createdAt;
}

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}

public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}

@Override
public String toString() {
return "CustomerBaseEvent [eventId=" + eventId + ", conversationId=" + conversationId + ", sequenceId="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public void setPhoto(String photo) {
public String toString() {
return "CustomerPhotoChangedEvent []";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
public interface BaseEventRepository extends MongoRepository<CustomerBaseEvent, String> {
List<CustomerBaseEvent> findAll(PageRequest page);

List<CustomerBaseEvent> findAllByIdentity(String identity);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
public interface CustomerRepository extends MongoRepository<Customer, String>{
public interface CustomerRepository extends MongoRepository<Customer, String> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
@EnableWebFlux
@EnableReactiveMongoRepositories
public class CrmReactiveMicroserviceApplication implements ApplicationRunner {
@Autowired private CustomerReactiveRepository customerReactiveRepository;

@Autowired
private CustomerReactiveRepository customerReactiveRepository;

public static void main(String[] args) {
SpringApplication.run(CrmReactiveMicroserviceApplication.class, args);
}

@Override
public void run(ApplicationArguments args) throws Exception {
customerReactiveRepository.findAllFlux(PageRequest.of(0, 10))
.subscribe(System.err::println);

customerReactiveRepository.findAllFlux(PageRequest.of(0, 10)).subscribe(System.err::println);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
public interface CustomerReactiveRepository extends ReactiveMongoRepository<Customer, String>{
public interface CustomerReactiveRepository extends ReactiveMongoRepository<Customer, String> {

@Query("{}")
Flux<Customer> findAllFlux(PageRequest page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@
*/
@Repository
@Persistence(PersistenceTarget.MONGO)
public class EmployeeRepositoryMongoAdapter implements EmployeeRepository{
public class EmployeeRepositoryMongoAdapter implements EmployeeRepository {
@Autowired
private EmployeeMongoRepository empRepo;
@Autowired
private ModelMapper mapper;

@Override
public Optional<Employee> findByIdentity(TcKimlikNo identity) {
Optional<EmployeeDocument> empDoc = empRepo.findById(identity.getValue());
if (!empDoc.isEmpty()) return Optional.empty();
if (!empDoc.isEmpty())
return Optional.empty();
Employee employee = mapper.map(empDoc.get(), Employee.class);
return Optional.of(employee);
}

@Override
public void save(Employee employee) {
//EmployeeDocument empDoc= mapper.map(employee, EmployeeDocument.class);
// EmployeeDocument empDoc= mapper.map(employee, EmployeeDocument.class);
EmployeeDocument employeeDocument = new EmployeeDocument();
employeeDocument.setIdentity(employee.getIdentityNo().getValue());
FullName fullname = employee.getFullname();
Expand All @@ -54,7 +55,7 @@ public void save(Employee employee) {

@Override
public void remove(Employee employee) {
empRepo.deleteById(employee.getIdentityNo().getValue());
empRepo.deleteById(employee.getIdentityNo().getValue());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.PARAMETER, ElementType.FIELD})
@Target({ ElementType.TYPE, ElementType.PARAMETER, ElementType.FIELD })
@Qualifier
public @interface Persistence {
PersistenceTarget value() ;
PersistenceTarget value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
*
*/
public interface EmployeeJpaRepository extends JpaRepository<EmployeeEntity, String> {
List<EmployeeDocument> findByBirthYearBetween(int fromYear,int toYear);
List<EmployeeDocument> findByBirthYearBetween(int fromYear, int toYear);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
public interface EmployeeMongoRepository extends MongoRepository<EmployeeDocument, String>{
List<EmployeeDocument> findAllByBirthYearBetweenAndDepartment(int fromYear,int toYear,Department department);
public interface EmployeeMongoRepository extends MongoRepository<EmployeeDocument, String> {
List<EmployeeDocument> findAllByBirthYearBetweenAndDepartment(int fromYear, int toYear, Department department);

@Query(value = "{'birthYear': {'$gt': ?0, '$lt': ?1}}")
List<EmployeeDocument> araBul(int fromYear,int toYear);
List<EmployeeDocument> araBul(int fromYear, int toYear);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
@SpringBootApplication
public class IdentityCardMicroserviceApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import com.example.hr.events.BusinessEvent;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
@Service
public class CardService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

import com.example.hr.events.BusinessEvent;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
@Service
public class SimpleKafkaConsumer {
private KafkaConsumer<String, BusinessEvent> kafkaConsumer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
import java.net.http.HttpResponse;
import java.util.concurrent.TimeUnit;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
public class MarketApiHttpClient {

private static final String URL = "https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT";

public static void main(String[] args) throws IOException, InterruptedException {
var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder().uri(URI.create(URL)).header("Accept", "application/json").build();
while(true) {
while (true) {
var response = client.send(request, HttpResponse.BodyHandlers.ofString()).body();
System.out.println(response);
TimeUnit.SECONDS.sleep(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
import java.net.http.WebSocket.Listener;
import java.util.concurrent.CompletionStage;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
public class MarketApiWebsocketClient {
private static final String URL = "wss://stream.binance.com:9443/ws/btcusdt@trade";

public static void main(String[] args) throws InterruptedException {
Listener listener = new MarketWebsocketListener();
HttpClient.newHttpClient().newWebSocketBuilder().buildAsync(URI.create(URL),listener);
HttpClient.newHttpClient().newWebSocketBuilder().buildAsync(URI.create(URL), listener);
Thread.sleep(60_000);
}
}
Expand All @@ -26,9 +31,9 @@ public void onOpen(WebSocket webSocket) {

@Override
public CompletionStage<?> onText(WebSocket webSocket, CharSequence data, boolean last) {
System.err.println(data);
webSocket.request(1);
return null;
System.err.println(data);
webSocket.request(1);
return null;
}

@Override
Expand All @@ -39,7 +44,7 @@ public CompletionStage<?> onClose(WebSocket webSocket, int statusCode, String re

@Override
public void onError(WebSocket webSocket, Throwable error) {
System.err.println("An error has occured: "+error.getMessage()+" at session "+webSocket);
System.err.println("An error has occured: " + error.getMessage() + " at session " + webSocket);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class FallbackLotteryService implements LotteryService {

@Override
public LotteryResponse getLotteryNumbers(int column) {
return new LotteryResponse(IntStream.range(0, column).mapToObj(i -> List.of(1,2,3,4,5,6)).collect(Collectors.toList()));
return new LotteryResponse(
IntStream.range(0, column).mapToObj(i -> List.of(1, 2, 3, 4, 5, 6)).collect(Collectors.toList()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import com.example.lottery.dto.LotteryResponse;

@FeignClient(name="lottery",fallback = FallbackLotteryService.class)
@FeignClient(name = "lottery", fallback = FallbackLotteryService.class)
public interface LotteryService {
@GetMapping("/lottery/api/v1/numbers")
LotteryResponse getLotteryNumbers(@RequestParam int column);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@
*/
@Service
public class LotteryConsumerServiceWithCircuitBreaker {
// integration client -> http -> Rest API (server)
// tomcat -> http/websocket (synchronous) -> (thread pool)
// capacity
// reactive system jetty -> http/websokcet (event queue, asynchronous) -> (thread pool)
// Fixed Thread Pool -> fixed (30)
// Cached Thread Pool -> variable
@CircuitBreaker(name="lotterySrvCircuitBreaker",
fallbackMethod = "getLotteryNumbersFallback")
// integration client -> http -> Rest API (server)
// tomcat -> http/websocket (synchronous) -> (thread pool)
// capacity
// reactive system jetty -> http/websokcet (event queue, asynchronous) ->
// (thread pool)
// Fixed Thread Pool -> fixed (30)
// Cached Thread Pool -> variable
@CircuitBreaker(name = "lotterySrvCircuitBreaker", fallbackMethod = "getLotteryNumbersFallback")
public LotteryResponse getNumbers() {
System.err.println("Calling lottery service from LotteryClientWithCircuitBreaker...");
RestTemplate rt = new RestTemplate();
return rt.getForObject("http://localhost:8001/lottery/api/v1/numbers?column=10", LotteryResponse.class);
}

public LotteryResponse getLotteryNumbersFallback(Exception e) {
System.err.println("getLotteryNumbersFallback()");
return new LotteryResponse(IntStream.range(0, 5).mapToObj(i -> List.of(1,2,3,4,5,6)).collect(Collectors.toList()));
return new LotteryResponse(
IntStream.range(0, 5).mapToObj(i -> List.of(1, 2, 3, 4, 5, 6)).collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@Service
public class StudyRetryStrategy {

@Retryable(value = { SocketTimeoutException.class, // exponential backoff: 2^{n} * 3 seconds
@Retryable(value = { SocketTimeoutException.class, // exponential backoff: 2^{n} * 3 seconds
SocketException.class }, maxAttempts = 3, backoff = @Backoff(multiplier = 2, delay = 3_000))
public LotteryResponse getNumbers() {
System.err.println("Calling lottery service from StudyRetryStrategy...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
@SpringBootApplication
public class LotteryMicroserviceV1Application {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@

import com.example.lottery.filter.JwtTokenFilter;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private UserDetailsService userDetailsService;
@Value("${security.jwt.token.secret-key}")
private String secret;

@Override
protected void configure(HttpSecurity http) throws Exception {
System.out.println("configurating security...");
http.csrf().disable().authorizeRequests().antMatchers("/signin").permitAll().anyRequest().authenticated().and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

http.addFilterBefore(new JwtTokenFilter(userDetailsService, secret), UsernamePasswordAuthenticationFilter.class);

http.addFilterBefore(new JwtTokenFilter(userDetailsService, secret),
UsernamePasswordAuthenticationFilter.class);

}

Expand Down
Loading

0 comments on commit a078b89

Please sign in to comment.