Skip to content

Commit

Permalink
MRSPECS-73 Include specification family, profile into specificati…
Browse files Browse the repository at this point in the history
…on updated event
  • Loading branch information
psmagin committed Nov 14, 2024
1 parent 169586a commit d58749f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Requires `API_NAME vX.Y`

### Features
* Description ([ISSUE](https://folio-org.atlassian.net/browse/ISSUE))
* Include specification `family`, `profile` into specification updated event ([MRSPECS-73](https://folio-org.atlassian.net/browse/MRSPECS-73))

### Bug fixes
* Fix tenant upgrade not being ran on schema existence ([MRSPECS-71](https://folio-org.atlassian.net/browse/MRSPECS-71))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import java.util.UUID;

public record SpecificationUpdatedEvent(UUID specificationId, String tenantId, UpdateExtent updateExtent) {
public record SpecificationUpdatedEvent(UUID specificationId,
String tenantId,
Family family,
FamilyProfile profile,
UpdateExtent updateExtent) {

public enum UpdateExtent {
FULL, PARTIAL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package org.folio.rspec.integration.kafka;

import java.util.UUID;
import org.folio.rspec.domain.dto.SpecificationUpdatedEvent;
import org.folio.rspec.domain.repository.SpecificationRepository;
import org.folio.spring.FolioExecutionContext;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component("fullChangeProducer")
public class SpecificationFullChangedEventProducer extends SpecificationPartialChangedEventProducer {
public SpecificationFullChangedEventProducer(
KafkaTemplate<String, SpecificationUpdatedEvent> template,
FolioExecutionContext context) {
super(template, context);

public SpecificationFullChangedEventProducer(KafkaTemplate<String, SpecificationUpdatedEvent> template,
SpecificationRepository specificationRepository,
FolioExecutionContext context) {
super(template, specificationRepository, context);
}

@Override
protected SpecificationUpdatedEvent buildEvent(UUID specificationId) {
return new SpecificationUpdatedEvent(specificationId, tenantId(), SpecificationUpdatedEvent.UpdateExtent.FULL);
protected SpecificationUpdatedEvent.UpdateExtent updateExtent() {
return SpecificationUpdatedEvent.UpdateExtent.FULL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.UUID;
import org.folio.rspec.domain.dto.SpecificationUpdatedEvent;
import org.folio.rspec.domain.repository.SpecificationRepository;
import org.folio.rspec.exception.ResourceNotFoundException;
import org.folio.spring.FolioExecutionContext;
import org.springframework.context.annotation.Primary;
import org.springframework.kafka.core.KafkaTemplate;
Expand All @@ -11,10 +13,13 @@
@Component
public class SpecificationPartialChangedEventProducer extends EventProducer<UUID, SpecificationUpdatedEvent> {

public SpecificationPartialChangedEventProducer(
KafkaTemplate<String, SpecificationUpdatedEvent> template,
FolioExecutionContext context) {
private final SpecificationRepository specificationRepository;

public SpecificationPartialChangedEventProducer(KafkaTemplate<String, SpecificationUpdatedEvent> template,
SpecificationRepository specificationRepository,
FolioExecutionContext context) {
super(template, context);
this.specificationRepository = specificationRepository;
}

@Override
Expand All @@ -24,6 +29,18 @@ protected String topicName() {

@Override
protected SpecificationUpdatedEvent buildEvent(UUID specificationId) {
return new SpecificationUpdatedEvent(specificationId, tenantId(), SpecificationUpdatedEvent.UpdateExtent.PARTIAL);
var specification = specificationRepository.findById(specificationId)
.orElseThrow(() -> ResourceNotFoundException.forSpecification(specificationId));
return new SpecificationUpdatedEvent(
specification.getId(),
tenantId(),
specification.getFamily(),
specification.getProfile(),
updateExtent()
);
}

protected SpecificationUpdatedEvent.UpdateExtent updateExtent() {
return SpecificationUpdatedEvent.UpdateExtent.PARTIAL;
}
}

0 comments on commit d58749f

Please sign in to comment.