generated from FINTLabs/fint-spring-boot-template-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from FINTLabs/FFS-1140-lage-producer-i-authori…
…zation-service-som-publiserer-source-application-ids-per-user-pa-entity-topic Ffs 1140 lage producer i authorization service som publiserer source application ids per user pa entity topic
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/no/fintlabs/flyt/authorization/user/kafka/UserPermission.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package no.fintlabs.flyt.authorization.user.kafka; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
@Builder | ||
public class UserPermission { | ||
private UUID objectIdentifier; | ||
private List<Long> sourceApplicationIds; | ||
} |
42 changes: 42 additions & 0 deletions
42
...n/java/no/fintlabs/flyt/authorization/user/kafka/UserPermissionEntityProducerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package no.fintlabs.flyt.authorization.user.kafka; | ||
|
||
import no.fintlabs.kafka.entity.EntityProducer; | ||
import no.fintlabs.kafka.entity.EntityProducerFactory; | ||
import no.fintlabs.kafka.entity.EntityProducerRecord; | ||
import no.fintlabs.kafka.entity.topic.EntityTopicNameParameters; | ||
import no.fintlabs.kafka.entity.topic.EntityTopicService; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@Service | ||
public class UserPermissionEntityProducerService { | ||
|
||
private final EntityProducer<UserPermission> entityProducer; | ||
private final EntityTopicNameParameters entityTopicNameParameters; | ||
|
||
public UserPermissionEntityProducerService( | ||
EntityProducerFactory entityProducerFactory, | ||
EntityTopicService entityTopicService | ||
) { | ||
this.entityProducer = entityProducerFactory.createProducer(UserPermission.class); | ||
entityTopicNameParameters = EntityTopicNameParameters | ||
.builder() | ||
.resource("userpermission") | ||
.build(); | ||
int retentionTimeInHours = 1; | ||
long retentionTimeInMilliseconds = TimeUnit.HOURS.toMillis(retentionTimeInHours); | ||
entityTopicService.ensureTopic(entityTopicNameParameters, retentionTimeInMilliseconds); | ||
} | ||
|
||
public void send(UserPermission userPermission) { | ||
entityProducer.send( | ||
EntityProducerRecord.<UserPermission>builder() | ||
.topicNameParameters(entityTopicNameParameters) | ||
.key(String.valueOf(userPermission.getObjectIdentifier())) | ||
.value(userPermission) | ||
.build() | ||
); | ||
} | ||
|
||
} |