-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(specification-storage): consume specification update request eve…
…nts (#78) Closes: MRSPECS-60
- Loading branch information
Showing
37 changed files
with
878 additions
and
87 deletions.
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
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
12 changes: 12 additions & 0 deletions
12
...ecifications-dto/src/main/java/org/folio/rspec/domain/dto/SubfieldUpdateRequestEvent.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,12 @@ | ||
package org.folio.rspec.domain.dto; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
public class SubfieldUpdateRequestEvent extends UpdateRequestEvent { | ||
|
||
private String targetFieldTag; | ||
private SubfieldDto subfield; | ||
} |
23 changes: 23 additions & 0 deletions
23
...ecord-specifications-dto/src/main/java/org/folio/rspec/domain/dto/UpdateRequestEvent.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,23 @@ | ||
package org.folio.rspec.domain.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes.Type; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; | ||
import lombok.Data; | ||
|
||
@Data | ||
@JsonTypeInfo( | ||
use = Id.NAME, | ||
property = "definitionType" | ||
) | ||
@JsonSubTypes({ | ||
@Type(value = SubfieldUpdateRequestEvent.class, name = "SUBFIELD") | ||
}) | ||
public abstract class UpdateRequestEvent { | ||
|
||
private Family family; | ||
private FamilyProfile profile; | ||
private DefinitionType definitionType; | ||
|
||
} |
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
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
17 changes: 17 additions & 0 deletions
17
...ions-server/src/main/java/org/folio/rspec/exception/UpdateRequestProcessingException.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,17 @@ | ||
package org.folio.rspec.exception; | ||
|
||
import org.folio.rspec.domain.dto.Family; | ||
import org.folio.rspec.domain.dto.FamilyProfile; | ||
|
||
public class UpdateRequestProcessingException extends RuntimeException { | ||
|
||
public UpdateRequestProcessingException(String message) { | ||
super(message); | ||
} | ||
|
||
public static UpdateRequestProcessingException specificationNotFound(Family family, FamilyProfile profile) { | ||
return new UpdateRequestProcessingException("Specification for family=%s, profile=%s not found" | ||
.formatted(family, profile)); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...-specifications-server/src/main/java/org/folio/rspec/integration/kafka/EventConsumer.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,29 @@ | ||
package org.folio.rspec.integration.kafka; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.folio.rspec.domain.dto.UpdateRequestEvent; | ||
import org.folio.rspec.service.processor.request.UpdateRequestEventProcessor; | ||
import org.springframework.kafka.annotation.KafkaListener; | ||
import org.springframework.messaging.MessageHeaders; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Log4j2 | ||
@Component | ||
@RequiredArgsConstructor | ||
public class EventConsumer { | ||
|
||
private final KafkaFolioContextExecutor executor; | ||
private final UpdateRequestEventProcessor updateRequestProcessor; | ||
|
||
@KafkaListener( | ||
containerFactory = "updateRequestEventListenerFactory", | ||
topicPattern = "#{folioKafkaProperties.listener['update-requests'].topicPattern}", | ||
groupId = "#{folioKafkaProperties.listener['update-requests'].groupId}", | ||
concurrency = "#{folioKafkaProperties.listener['update-requests'].concurrency}") | ||
public void handleSpecUpdateEvents(UpdateRequestEvent updateRequestEvent, MessageHeaders headers) { | ||
log.info("Received update request [event={}]", updateRequestEvent); | ||
executor.runInContext(headers, () -> updateRequestProcessor.process(updateRequestEvent)); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...ons-server/src/main/java/org/folio/rspec/integration/kafka/KafkaFolioContextExecutor.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,47 @@ | ||
package org.folio.rspec.integration.kafka; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import org.folio.spring.DefaultFolioExecutionContext; | ||
import org.folio.spring.FolioExecutionContext; | ||
import org.folio.spring.FolioModuleMetadata; | ||
import org.folio.spring.integration.XOkapiHeaders; | ||
import org.folio.spring.scope.FolioExecutionContextSetter; | ||
import org.springframework.messaging.MessageHeaders; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class KafkaFolioContextExecutor { | ||
|
||
private final FolioModuleMetadata moduleMetadata; | ||
|
||
public void runInContext(MessageHeaders headers, Runnable runnable) { | ||
try (var fec = new FolioExecutionContextSetter(getContextFromMessageHeaders(headers, moduleMetadata))) { | ||
runnable.run(); | ||
} | ||
} | ||
|
||
public static FolioExecutionContext getContextFromMessageHeaders(MessageHeaders headers, | ||
FolioModuleMetadata moduleMetadata) { | ||
Map<String, Collection<String>> map = new HashMap<>(); | ||
map.put(XOkapiHeaders.TENANT, getHeaderValue(headers, XOkapiHeaders.TENANT)); | ||
map.put(XOkapiHeaders.URL, getHeaderValue(headers, XOkapiHeaders.URL)); | ||
map.put(XOkapiHeaders.TOKEN, getHeaderValue(headers, XOkapiHeaders.TOKEN)); | ||
map.put(XOkapiHeaders.USER_ID, getHeaderValue(headers, XOkapiHeaders.USER_ID)); | ||
return new DefaultFolioExecutionContext(moduleMetadata, map); | ||
} | ||
|
||
private static List<String> getHeaderValue(MessageHeaders headers, String headerName) { | ||
var headerValue = headers.get(headerName); | ||
return headerValue == null | ||
? Collections.emptyList() | ||
: Collections.singletonList(new String((byte[]) headerValue, StandardCharsets.UTF_8)); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...specifications-server/src/main/java/org/folio/rspec/integration/kafka/KafkaTopicName.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,16 @@ | ||
package org.folio.rspec.integration.kafka; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum KafkaTopicName { | ||
|
||
SPECIFICATION_UPDATE("specification-storage.specification.update"), | ||
SPECIFICATION_UPDATED("specification-storage.specification.updated"); | ||
|
||
private final String topicName; | ||
|
||
KafkaTopicName(String topicName) { | ||
this.topicName = topicName; | ||
} | ||
} |
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
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
Oops, something went wrong.