Skip to content
Merged
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
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
19 changes: 19 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
38 changes: 34 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
version: "3.7"
services:
postgres:
server_postgres:
image: postgres:14
ports:
- "5432:5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
volumes:
- postgres_data:/var/lib/postgresql/data
- ./init-scripts:/docker-entrypoint-initdb.d
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d postgres"]
interval: 10s
timeout: 5s
retries: 5
networks:
- microservices-net
zookeeper:
image: confluentinc/cp-zookeeper:5.5.3
environment:
ZOOKEEPER_CLIENT_PORT: 2181
networks:
- microservices-net
kafka:
image: confluentinc/cp-enterprise-kafka:5.5.3
depends_on: [zookeeper]
Expand All @@ -23,6 +35,24 @@ services:
KAFKA_JMX_PORT: 9991
ports:
- 9092:9092
networks:
- microservices-net
kafka-topics-init:
image: confluentinc/cp-kafka:5.5.3
depends_on:
- kafka
entrypoint: >
bash -c "
kafka-topics --create --topic topic-crea-transaction --bootstrap-server kafka:29092 --partitions 3 --replication-factor 1 &&
kafka-topics --create --topic topic-valida-transaction --bootstrap-server kafka:29092 --partitions 3 --replication-factor 1
"
networks:
- microservices-net

volumes:
oracle-data:
oracle-backup:
postgres_data:

networks:
microservices-net:
driver: bridge

4 changes: 4 additions & 0 deletions init-scripts/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Habilitar la autenticación remota
ALTER SYSTEM SET listen_addresses = '*';
-- Configurar las reglas para conexiones remotas
\! echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf
21 changes: 21 additions & 0 deletions ms-antifraude/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.prueba</groupId>
<artifactId>java-code-challenge</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<groupId>com.prueba.antifraude</groupId>
<artifactId>ms-antifraude</artifactId>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.prueba.antifraude.msantifraude.Kafka;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.prueba.antifraude.msantifraude.model.TransactionNew;
import com.prueba.antifraude.msantifraude.service.AntiFraudeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.KafkaListener;

import java.io.IOException;

@Configuration
public class KafkaConsumer {

@Autowired
AntiFraudeService antiFraudeService;

private Logger logger = LoggerFactory.getLogger(KafkaConsumer.class);

@KafkaListener(topics = "topic-crea-transaction", groupId = "my-group-id")
public void consumerTransaction(String message) throws IOException {
logger.info("Transaction CREADA: " + message);
ObjectMapper objectMapper = new ObjectMapper();

try {

TransactionNew transaction = objectMapper.readValue(message, TransactionNew.class);
antiFraudeService.validaAntifraude(transaction);

} catch (Exception e) {
logger.error("Error al convertir JSON a Entity: " + e.getMessage());
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.prueba.antifraude.msantifraude;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MsAntifraudeApplication {

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.prueba.antifraude.msantifraude.config;

import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.config.KafkaListenerContainerFactory;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class KafkaConfig {

@Value("${spring.kafka.bootstrap.servers}")
private String bootstrapServers;

public Map<String, Object> consumerConfig() {
Map<String, Object> properties = new HashMap<>();
properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringSerializer.class);
properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringSerializer.class);
return properties;
}

@Bean
public ConsumerFactory<String, String> consumerFactory() {
return new DefaultKafkaConsumerFactory<>(consumerConfig());
}

@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> consumer(
ConsumerFactory consumerFactory) {
ConcurrentKafkaListenerContainerFactory<String, String> factory =
new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory);
return factory;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.prueba.antifraude.msantifraude.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;


@Entity
@Table(name = "transaction")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TransactionNew {
@Id
@JsonProperty("accountExternalId")
private String accountExternalId;
@JsonProperty("tranferTypeId")
private int tranferTypeId;
@JsonProperty("value")
private Double value;

private Date createdAt;
@JsonIgnore
private Date updateAt;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.prueba.antifraude.msantifraude.model;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class TransactionStatus {
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.prueba.antifraude.msantifraude.model;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class TransactionType {
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.prueba.antifraude.msantifraude.model;

import lombok.Builder;
import lombok.Data;

import java.util.Date;
import java.util.UUID;

@Data
@Builder
public class TransactionValidate {
private String transactionExternalId;
private TransactionType transactionType;
private TransactionStatus transactionStatus;
private Double value;
private String createdAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.prueba.antifraude.msantifraude.repository;

import com.prueba.antifraude.msantifraude.model.TransactionNew;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface TransactionRepository extends JpaRepository<TransactionNew, String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.prueba.antifraude.msantifraude.service;

import com.prueba.antifraude.msantifraude.model.TransactionNew;
import reactor.core.publisher.Mono;

import java.io.IOException;
import java.text.ParseException;

public interface AntiFraudeService {

Mono<Void> validaAntifraude(TransactionNew transaction) throws IOException, ParseException;
}
Loading