Skip to content

Commit

Permalink
feat(locations): implement domain event production for location creat…
Browse files Browse the repository at this point in the history
…e/update/delete (#1006)
  • Loading branch information
psmagin authored Mar 26, 2024
1 parent 1925425 commit c3cb8b9
Show file tree
Hide file tree
Showing 17 changed files with 506 additions and 282 deletions.
22 changes: 22 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## v27.2.0 In progress
### Breaking changes
* Description ([ISSUE_NUMBER](https://issues.folio.org/browse/ISSUE_NUMBER))

### New APIs versions
* Provides `API_NAME vX.Y`
* Requires `API_NAME vX.Y`

### Features
* Implement domain event production for location create/update/delete ([MODINVSTOR-1181](https://issues.folio.org/browse/MODINVSTOR-1181))

### Bug fixes
* Description ([ISSUE_NUMBER](https://issues.folio.org/browse/ISSUE_NUMBER))

### Tech Dept
* Description ([ISSUE_NUMBER](https://issues.folio.org/browse/ISSUE_NUMBER))

### Dependencies
* Bump `LIB_NAME` from `OLD_VERSION` to `NEW_VERSION`
* Add `LIB_NAME` `2.7.4`
* Remove `LIB_NAME`

## v27.1.0 2024-03-19
### New APIs versions
* Provides `item-storage v10.1`
Expand Down
6 changes: 3 additions & 3 deletions ramls/dereferenceditem.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,17 @@
"permanentLocation": {
"type": "object",
"description": "Permanent item location is the default location, shelving location, or holding which is a physical place where items are stored, or an Online location.",
"$ref": "location.json"
"$ref": "locations/location.json"
},
"temporaryLocation": {
"type": "object",
"description": "Temporary item location is the temporarily location, shelving location, or holding which is a physical place where items are stored, or an Online location.",
"$ref": "location.json"
"$ref": "locations/location.json"
},
"effectiveLocation": {
"type": "object",
"description": "Read only current home location for the item.",
"$ref": "location.json",
"$ref": "locations/location.json",
"readonly": true
},
"electronicAccess": {
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions ramls/location.raml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ documentation:
(shelf) locations of the system

types:
location: !include location.json
locations: !include locations.json
location: !include locations/location.json
locations: !include locations/locations.json
errors: !include raml-util/schemas/errors.schema

traits:
Expand All @@ -27,8 +27,8 @@ resourceTypes:
/locations:
type:
collection:
exampleCollection: !include examples/locations.json
exampleItem: !include examples/location.json
exampleCollection: !include examples/locations/locations.json
exampleItem: !include examples/locations/location.json
schemaCollection: locations
schemaItem: location
get:
Expand All @@ -54,7 +54,7 @@ resourceTypes:
description: "Pass in the location id"
type:
collection-item:
exampleItem: !include examples/location.json
exampleItem: !include examples/locations/location.json
schema: location
get:
put:
Expand Down
10 changes: 5 additions & 5 deletions ramls/location.json → ramls/locations/location.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@
},
"primaryServicePoint": {
"description": "The UUID of the primary service point of this (shelf) location.",
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
"format": "uuid",
"type": "string"
},
"primaryServicePointObject": {
"type": "object",
"description": "Dereferenced object for primary service point. This should really just be called 'primaryServicePoint', but the field containing the ID of this object has that name -- it should really be called 'primaryServicePointId' -- so we need something different for this one.",
"$ref": "servicepoint.json",
"$ref": "../servicepoint.json",
"readonly": true,
"folio:isVirtual": true,
"folio:linkBase": "service-points",
Expand All @@ -99,7 +99,7 @@
"items": {
"description": "The UUID of a service point that belongs to this (shelf) location.",
"type": "string",
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
"format": "uuid",
"not": {
"type": "null"
}
Expand All @@ -110,7 +110,7 @@
"description": "List of dereferenced service points",
"items": {
"type": "object",
"$ref": "servicepoint.json"
"$ref": "../servicepoint.json"
},
"readonly": true,
"folio:isVirtual": true,
Expand All @@ -121,7 +121,7 @@
},
"metadata": {
"type": "object",
"$ref": "raml-util/schemas/metadata.schema",
"$ref": "../raml-util/schemas/metadata.schema",
"readonly": true
}
},
Expand Down
File renamed without changes.
28 changes: 19 additions & 9 deletions src/main/java/org/folio/InventoryKafkaTopic.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
package org.folio;

import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.folio.kafka.services.KafkaTopic;

public enum InventoryKafkaTopic implements KafkaTopic {

INSTANCE("instance"),
ITEM("item"),
HOLDINGS_RECORD("holdings-record"),
INSTANCE_CONTRIBUTION("instance-contribution"),
BOUND_WITH("bound-with"),
ASYNC_MIGRATION("async-migration"),
SERVICE_POINT("service-point"),
CLASSIFICATION_TYPE("classification-type");
CLASSIFICATION_TYPE("classification-type"),
LOCATION("location");

private static final String DEFAULT_NUM_PARTITIONS_PROPERTY = "KAFKA_DOMAIN_TOPIC_NUM_PARTITIONS";
private static final String DEFAULT_NUM_PARTITIONS_VALUE = "50";
private static final String CLASSIFICATION_TYPE_NUM_PARTITIONS_PROPERTY =
"KAFKA_CLASSIFICATION_TYPE_TOPIC_NUM_PARTITIONS";
private static final String CLASSIFICATION_TYPE_NUM_PARTITIONS_VALUE = "1";

/**
* Map where a key is {@link InventoryKafkaTopic} and value is a {@link Pair} of
* environment variable name that specifies number of partitions for the topic and default value is not specified.
*/
private static final Map<InventoryKafkaTopic, Pair<String, String>> TOPIC_PARTITION_MAP = Map.of(
CLASSIFICATION_TYPE, Pair.of("KAFKA_CLASSIFICATION_TYPE_TOPIC_NUM_PARTITIONS", "1"),
LOCATION, Pair.of("KAFKA_LOCATION_TOPIC_NUM_PARTITIONS", "1")
);

private final String topic;

InventoryKafkaTopic(String topic) {
Expand All @@ -36,11 +48,9 @@ public String topicName() {

@Override
public int numPartitions() {
if (this == CLASSIFICATION_TYPE) {
return getNumberOfPartitions(CLASSIFICATION_TYPE_NUM_PARTITIONS_PROPERTY,
CLASSIFICATION_TYPE_NUM_PARTITIONS_VALUE);
}
return getNumberOfPartitions(DEFAULT_NUM_PARTITIONS_PROPERTY, DEFAULT_NUM_PARTITIONS_VALUE);
return Optional.ofNullable(TOPIC_PARTITION_MAP.get(this))
.map(pair -> getNumberOfPartitions(pair.getKey(), pair.getValue()))
.orElse(getNumberOfPartitions(DEFAULT_NUM_PARTITIONS_PROPERTY, DEFAULT_NUM_PARTITIONS_VALUE));
}

private int getNumberOfPartitions(String propertyName, String defaultNumPartitions) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/folio/persist/LocationRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.folio.persist;

import static org.folio.rest.persist.PgUtil.postgresClient;
import static org.folio.services.location.LocationService.LOCATION_TABLE;

import io.vertx.core.Context;
import java.util.Map;
import org.folio.rest.jaxrs.model.Location;

public class LocationRepository extends AbstractRepository<Location> {

public LocationRepository(Context context, Map<String, String> okapiHeaders) {
super(postgresClient(context, okapiHeaders), LOCATION_TABLE, Location.class);
}

}
Loading

0 comments on commit c3cb8b9

Please sign in to comment.