Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Store-Producer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mahesh Rohra
Store-Producer
Commits
04ee40c4
Commit
04ee40c4
authored
May 06, 2020
by
Simhadri Guntreddi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'MapStructBranch-1' into 'master'
Added Mapstruct changes See merge request
!1
parents
2356d4c0
c626d93b
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
252 additions
and
23 deletions
+252
-23
build.gradle
build.gradle
+31
-0
ConfigProps.java
src/main/java/com/safeway/epe/Config/ConfigProps.java
+13
-0
TransactionController.java
...ava/com/safeway/epe/controller/TransactionController.java
+3
-8
ConsumerPayload.java
src/main/java/com/safeway/epe/domain/ConsumerPayload.java
+20
-0
Offsets.java
src/main/java/com/safeway/epe/domain/Offsets.java
+19
-0
Record.java
src/main/java/com/safeway/epe/domain/Record.java
+18
-0
TransactionPayload.java
src/main/java/com/safeway/epe/domain/TransactionPayload.java
+16
-0
TransactionRecorder.java
...main/java/com/safeway/epe/domain/TransactionRecorder.java
+4
-4
TransactionPayloadMapper.java
...java/com/safeway/epe/mapper/TransactionPayloadMapper.java
+29
-0
TransactionRecordMapper.java
.../java/com/safeway/epe/mapper/TransactionRecordMapper.java
+25
-0
ProducerService.java
src/main/java/com/safeway/epe/service/ProducerService.java
+18
-0
TransactionService.java
...main/java/com/safeway/epe/service/TransactionService.java
+3
-2
TransactionServiceImpl.java
.../java/com/safeway/epe/service/TransactionServiceImpl.java
+25
-8
application.yml
src/main/resources/application.yml
+9
-1
transactionRecord.avsc
src/main/resources/avro/transactionRecord.avsc
+19
-0
No files found.
build.gradle
View file @
04ee40c4
import
com.commercehub.gradle.plugin.avro.GenerateAvroJavaTask
plugins
{
id
'org.springframework.boot'
version
'2.2.6.RELEASE'
id
'io.spring.dependency-management'
version
'1.0.9.RELEASE'
id
'java'
id
'com.commercehub.gradle.plugin.avro'
version
'0.9.1'
}
group
=
'com.safeway.epe'
...
...
@@ -19,15 +21,26 @@ configurations {
}
repositories
{
gradlePluginPortal
()
mavenCentral
()
maven
{
url
"http://packages.confluent.io/maven/"
}
maven
{
url
"https://plugins.gradle.org/m2/"
}
}
dependencies
{
implementation
'org.springframework.boot:spring-boot-starter-data-jpa'
implementation
'org.springframework.boot:spring-boot-starter-web'
implementation
'org.mapstruct:mapstruct:1.3.1.Final'
implementation
'io.confluent:kafka-avro-serializer:5.4.0'
compile
(
group:
'io.confluent'
,
name:
'kafka-schema-registry'
,
version:
'5.4.0'
){
exclude
group:
'org.slf4j'
,
module:
'slf4j-log4j12'
}
compile
"org.apache.avro:avro:1.9.1"
compile
group:
'org.apache.kafka'
,
name:
'kafka-clients'
,
version:
'5.4.1-ccs'
compileOnly
'org.projectlombok:lombok'
developmentOnly
'org.springframework.boot:spring-boot-devtools'
runtimeOnly
'org.postgresql:postgresql'
annotationProcessor
'org.mapstruct:mapstruct-processor:1.3.1.Final'
annotationProcessor
'org.projectlombok:lombok'
compile
'com.vladmihalcea:hibernate-types-52:2.0.0'
testImplementation
(
'org.springframework.boot:spring-boot-starter-test'
)
{
...
...
@@ -38,3 +51,21 @@ dependencies {
test
{
useJUnitPlatform
()
}
avro
{
createSetters
=
false
fieldVisibility
=
"PRIVATE"
stringType
=
"String"
outputCharacterEncoding
=
"UTF-8"
}
task
generateAvro
(
type:
GenerateAvroJavaTask
)
{
source
(
"src/main/resources/avro/"
)
outputDir
=
file
(
"build/generated/java/main"
)
}
sourceSets
{
main
{
java
.
srcDirs
+=
generateAvro
.
outputs
}
}
src/main/java/com/safeway/epe/Config/ConfigProps.java
0 → 100644
View file @
04ee40c4
package
com
.
safeway
.
epe
.
Config
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
@Data
@Configuration
@ConfigurationProperties
(
prefix
=
"kafka.producer"
)
public
class
ConfigProps
{
private
String
offerTransactionRecordTopic
;
}
src/main/java/com/safeway/epe/controller/TransactionController.java
View file @
04ee40c4
package
com
.
safeway
.
epe
.
controller
;
import
com.safeway.epe.domain.Offsets
;
import
com.safeway.epe.domain.TransactionRecorder
;
import
com.safeway.epe.service.TransactionService
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -16,15 +17,9 @@ public class TransactionController
@Autowired
private
TransactionService
service
;
/*@GetMapping("transactions")
public ResponseEntity<List<TransactionController>> getAllTransactions()
{
return service.getAllTransactions();
}*/
@GetMapping
(
"transaction/{uuid}"
)
public
ResponseEntity
<
TransactionRecorder
>
getTransaction
(
@PathVariable
(
"uuid"
)
String
uuid
)
public
ResponseEntity
<
List
<
Offsets
>
>
getTransaction
(
@PathVariable
(
"uuid"
)
String
uuid
)
{
return
service
.
getTransactionById
(
uuid
);
return
service
.
produceMessage
(
uuid
);
}
}
src/main/java/com/safeway/epe/domain/ConsumerPayload.java
0 → 100644
View file @
04ee40c4
package
com
.
safeway
.
epe
.
domain
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
ConsumerPayload
{
@JsonProperty
(
"key_schema_id"
)
private
String
keySchemaId
;
@JsonProperty
(
"value_schema_id"
)
private
String
valueSchemaId
;
@JsonProperty
(
"offsets"
)
private
List
<
Offsets
>
offsetsList
;
}
\ No newline at end of file
src/main/java/com/safeway/epe/domain/Offsets.java
0 → 100644
View file @
04ee40c4
package
com
.
safeway
.
epe
.
domain
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
Offsets
{
@JsonProperty
(
"partition"
)
private
String
partition
;
@JsonProperty
(
"offset"
)
private
String
offset
;
}
src/main/java/com/safeway/epe/domain/Record.java
0 → 100644
View file @
04ee40c4
package
com
.
safeway
.
epe
.
domain
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
Record
{
@JsonProperty
(
"key"
)
private
String
key
;
@JsonProperty
(
"value"
)
private
TransactionRecorder
transactionRecorder
;
}
\ No newline at end of file
src/main/java/com/safeway/epe/domain/TransactionPayload.java
0 → 100644
View file @
04ee40c4
package
com
.
safeway
.
epe
.
domain
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
TransactionPayload
{
@JsonProperty
(
"records"
)
private
List
<
Record
>
records
;
}
\ No newline at end of file
src/main/java/com/safeway/epe/domain/TransactionRecorder.java
View file @
04ee40c4
...
...
@@ -33,13 +33,13 @@ public class TransactionRecorder
@Column
(
name
=
"uuid"
)
@JsonProperty
(
"uuid"
)
UUID
uuid
;
@Type
(
type
=
"jsonb"
)
@JsonProperty
(
"offertransactionresponse"
)
//
@Type(type = "jsonb")
//
@JsonProperty("offertransactionresponse")
@Column
(
name
=
"offertransactionresponse"
)
String
offerTransactionResponse
;
@Type
(
type
=
"jsonb"
)
@JsonProperty
(
"offers"
)
//
@Type(type="jsonb")
//
@JsonProperty("offers")
@Column
(
name
=
"offers"
)
String
offers
;
...
...
src/main/java/com/safeway/epe/mapper/TransactionPayloadMapper.java
0 → 100644
View file @
04ee40c4
package
com
.
safeway
.
epe
.
mapper
;
import
com.safeway.epe.domain.Record
;
import
com.safeway.epe.domain.TransactionPayload
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mapping
;
import
org.mapstruct.Mappings
;
import
org.mapstruct.Named
;
import
org.mapstruct.factory.Mappers
;
import
java.util.ArrayList
;
import
java.util.List
;
@Mapper
public
interface
TransactionPayloadMapper
{
TransactionPayloadMapper
INSTANCE
=
Mappers
.
getMapper
(
TransactionPayloadMapper
.
class
);
@Mappings
({
@Mapping
(
source
=
"record"
,
target
=
"records"
,
qualifiedByName
=
"transactionCreation"
)
})
public
TransactionPayload
transactionPayloadMapper
(
Record
record
);
@Named
(
"transactionCreation"
)
default
List
<
Record
>
transactionConversion
(
Record
record
){
List
<
Record
>
recordList
=
new
ArrayList
<>();
recordList
.
add
(
record
);
return
recordList
;
}
}
src/main/java/com/safeway/epe/mapper/TransactionRecordMapper.java
0 → 100644
View file @
04ee40c4
package
com
.
safeway
.
epe
.
mapper
;
import
com.safeway.epe.domain.Record
;
import
com.safeway.epe.domain.TransactionRecorder
;
import
org.mapstruct.*
;
import
org.mapstruct.factory.Mappers
;
@Mapper
(
nullValueCheckStrategy
=
NullValueCheckStrategy
.
ALWAYS
)
public
interface
TransactionRecordMapper
{
TransactionRecordMapper
INSTANCE
=
Mappers
.
getMapper
(
TransactionRecordMapper
.
class
);
@Mappings
({
@Mapping
(
source
=
"transactionRecorder"
,
target
=
"transactionRecorder"
,
qualifiedByName
=
"recordCreation"
),
@Mapping
(
target
=
"key"
,
qualifiedByName
=
"recordCreation"
)
})
public
Record
transactionRecordMapper
(
String
key
,
TransactionRecorder
transactionRecorder
);
@Named
(
"recordCreation"
)
default
Record
recordConvertion
(
String
key
,
TransactionRecorder
transactionRecorder
)
{
return
new
Record
(
key
,
transactionRecorder
);
}
}
src/main/java/com/safeway/epe/service/ProducerService.java
0 → 100644
View file @
04ee40c4
package
com
.
safeway
.
epe
.
service
;
import
com.safeway.epe.domain.Offsets
;
import
com.safeway.epe.domain.TransactionPayload
;
import
com.safeway.epe.domain.TransactionRecorder
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.List
;
@Component
public
class
ProducerService
{
public
List
<
Offsets
>
produce
(
TransactionPayload
request
,
String
topic
,
TransactionRecorder
transactionRecorder
,
boolean
isReprocesed
){
return
new
ArrayList
<>();
}
}
src/main/java/com/safeway/epe/service/TransactionService.java
View file @
04ee40c4
package
com
.
safeway
.
epe
.
service
;
import
com.safeway.epe.controller.TransactionController
;
import
com.safeway.epe.domain.Offsets
;
import
com.safeway.epe.domain.TransactionRecorder
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -8,6 +9,6 @@ import java.util.List;
public
interface
TransactionService
{
//ResponseEntity<List<TransactionController>> getAllTransactions();
ResponseEntity
<
TransactionRecorder
>
getTransactionById
(
String
uuid
);
ResponseEntity
<
List
<
Offsets
>>
produceMessage
(
String
uuid
);
}
src/main/java/com/safeway/epe/service/TransactionServiceImpl.java
View file @
04ee40c4
package
com
.
safeway
.
epe
.
service
;
import
com.safeway.epe.Config.ConfigProps
;
import
com.safeway.epe.controller.TransactionController
;
import
com.safeway.epe.domain.Offsets
;
import
com.safeway.epe.domain.Record
;
import
com.safeway.epe.domain.TransactionPayload
;
import
com.safeway.epe.domain.TransactionRecorder
;
import
com.safeway.epe.mapper.TransactionPayloadMapper
;
import
com.safeway.epe.mapper.TransactionRecordMapper
;
import
com.safeway.epe.repository.TransactionRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -16,16 +22,27 @@ public class TransactionServiceImpl implements TransactionService
@Autowired
TransactionRepository
repository
;
/*@Override
public ResponseEntity<List<TransactionController>> getAllTransactions() {
List<TransactionRecorder> transactions = new ArrayList<TransactionRecorder>();
repository.findAll().forEach(transactions::add);
return new ResponseEntity<List<TransactionController>>(HttpStatus.OK);
}*/
@Autowired
ConfigProps
configProps
;
@Autowired
ProducerService
producerService
;
@Override
public
ResponseEntity
<
TransactionRecorder
>
getTransactionById
(
String
uuid
)
{
public
ResponseEntity
<
List
<
Offsets
>>
produceMessage
(
String
uuid
)
{
Optional
<
TransactionRecorder
>
optionalTransaction
=
repository
.
findById
(
UUID
.
fromString
(
uuid
));
return
ResponseEntity
.
status
(
HttpStatus
.
FOUND
).
body
(
optionalTransaction
.
get
());
if
(
optionalTransaction
.
isPresent
())
{
return
sendData
(
optionalTransaction
.
get
(),
false
);
}
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
body
(
Arrays
.
asList
(
new
Offsets
()));
}
private
ResponseEntity
<
List
<
Offsets
>>
sendData
(
TransactionRecorder
transactionRecorder
,
boolean
isReprocesed
)
{
Record
record
=
TransactionRecordMapper
.
INSTANCE
.
recordConvertion
(
transactionRecorder
.
getUuid
().
toString
(),
transactionRecorder
);
TransactionPayload
transactionPayload
=
TransactionPayloadMapper
.
INSTANCE
.
transactionPayloadMapper
(
record
);
System
.
out
.
println
(
configProps
.
getOfferTransactionRecordTopic
());
// return ResponseEntity.status(HttpStatus.NOT_FOUND).body(Arrays.asList(new Offsets()));
return
ResponseEntity
.
ok
(
producerService
.
produce
(
transactionPayload
,
configProps
.
getOfferTransactionRecordTopic
(),
transactionRecorder
,
isReprocesed
));
}
}
src/main/resources/application.yml
View file @
04ee40c4
...
...
@@ -12,4 +12,12 @@ spring:
hibernate
:
dialect
:
org.hibernate.dialect.PostgreSQLDialect
server
:
port
:
8200
\ No newline at end of file
port
:
8200
kafka
:
producer
:
offer-transaction-record-topic
:
transactionRecord
schema
:
api
:
baseurl
:
http://localhost:8082
src/main/resources/avro/transactionRecord.avsc
0 → 100644
View file @
04ee40c4
{
"name": "TransactionRecorder1",
"type": "record",
"namespace": "com.safeway.epe.domain",
"fields": [
{
"name": "uuid",
"type": "string"
},
{
"name": "offertransactionresponse",
"type": "string"
},
{
"name": "offers",
"type": "string"
}
]
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment