-
Notifications
You must be signed in to change notification settings - Fork 7
MODGOBI-232. Introduce DB and use it to store custom mappings #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| import org.mockito.junit.jupiter.MockitoExtension; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| @CopilotGenerated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add what model was used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was 3 models, some parts of each what have influence
| .map(configs -> buildOrderMappingsViewResponse(configs, orderType)); | ||
| return pgClient.withConn(conn -> orderMappingsDao.getByOrderType(orderType, conn) | ||
| .map(orderMapping -> { | ||
| if (orderMapping == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here you can just pass orderMapping directly without the if-else
Code Review for DAO Refactoring - Custom Order MappingsOverviewThis pull request refactors the custom order mappings functionality to use a database-backed DAO pattern instead of calling the mod-configuration module. The changes introduce:
Files Modified: 20 files Suggestions🔧 Missing @OverRide annotation in DAO implementation
@Override
public Future<Void> update(String id, OrderMappings orderMappings, Conn conn) {
return conn.update(TABLE_NAME, orderMappings, id)
.onFailure(t -> log.error("update:: Failed to update order mapping with id: {}", id, t))
.mapEmpty();
}⛏️ Inconsistent error logging message in getByOrderType
.onFailure(t -> log.error("getByOrderType:: Failed to find order mapping by orderType: {}", orderType, t));🔧 Potential issue with CompletableFuture nesting in DataSourceResolver
if (translateDefValue) {
return ((DataSourceResolver) defValue).resolve(doc)
.thenCompose(v -> applyTranslation(v != null ? v.toString() : null));
} else {
return ((DataSourceResolver) defValue).resolve(doc);
}♻️ Unused imports in MappingHelper
🔧 Missing null-safety check in MappingHelper.extractOrderMappings
public Map<Mapping.Field, DataSourceResolver> extractOrderMappings(OrderMappings orderMapping) {
Map<Mapping.Field, DataSourceResolver> map = new EnumMap<>(Mapping.Field.class);
if (orderMapping == null || orderMapping.getMappings() == null) {
return map;
}
for (Mapping mapping : orderMapping.getMappings()) {
map.put(mapping.getField(), getDS(mapping, map));
}
return map;
}🌱 Consider caching strategy for default mappings
🔧 Database connection management in GobiOrdersCustomMappingsImpl
public class GobiOrdersCustomMappingsImpl extends BaseApi implements GobiOrdersCustomMappings {
private final OrderMappingsDao orderMappingsDao = new OrderMappingsDaoImpl();
private GobiCustomMappingsService getCustomMappingsService(Map<String, String> okapiHeaders, Context vertxContext) {
String tenantId = TenantTool.tenantId(okapiHeaders);
PostgresClient pgClient = PostgresClient.getInstance(vertxContext.owner(), tenantId);
return new GobiCustomMappingsService(pgClient, orderMappingsDao);
}
}📝 RestClient cleanup removed useful query building methods
🔧 Error handling in updateByOrderType could be more specific
@Override
public Future<Void> updateByOrderType(String orderType, OrderMappings orderMappings, Conn conn) {
return conn.update(TABLE_NAME, orderMappings, getOrderTypeCriterion(orderType), true)
.compose(updateResult -> {
if (updateResult.size() == 0) {
log.warn("updateByOrderType:: No mapping found for orderType {} to update", orderType);
return Future.failedFuture(
new HttpException(404, "No matching order mapping found to update for orderType: " + orderType)
);
}
return Future.succeededFuture();
})
.onFailure(t -> log.error("updateByOrderType:: Failed to update order mapping for orderType: {}", orderType, t))
.mapEmpty();
}⛏️ Test class should be package-private
👍 Excellent test coverage for OrderMappingsDao
🔧 BaseIntegrationTest has hardcoded module version
.body(new JsonObject()
.put("module_to", "mod-gobi-" + System.getProperty("project.version", "1.0.0"))
.encode())🔧 Integration test cleanup might not execute on test failure
@AfterEach
void cleanup() {
try {
OrderMappingsViewCollection collection = RestAssured.with()
.spec(spec)
.get(MAPPINGS_PATH)
.then()
.statusCode(200)
.contentType(ContentType.JSON)
.extract().as(OrderMappingsViewCollection.class);
collection.getOrderMappingsViews().stream()
.filter(view -> MappingType.CUSTOM == view.getMappingType())
.forEach(view -> {
try {
OrderType orderType = view.getOrderMappings().getOrderType();
log.info("Cleaning up mapping for order type: {}", orderType);
RestAssured.with()
.spec(spec)
.delete(MAPPINGS_PATH + "/" + orderType.value())
.then()
.statusCode(200);
} catch (Exception e) {
log.warn("Failed to delete mapping during cleanup", e);
}
});
} catch (Exception e) {
log.error("Cleanup failed", e);
}
}⛏️ Mock server test no longer validates configuration endpoint
🔧 Test uses @ExtendWith(MockitoExtension.class) but also calls MockitoAnnotations.openMocks
@ExtendWith(MockitoExtension.class)
@CopilotGenerated
class OrderMappingsDaoTest {
// ...
@BeforeEach
void setUp() {
dao = new OrderMappingsDaoImpl();
}
// Remove the closeable field and @AfterEach tearDown method
}💭 Consider adding database migration scripts
{
"tables": [
{
"tableName": "order_mappings",
"withMetadata": true,
"uniqueIndex": [
{
"fieldName": "orderType",
"tOps": "ADD"
}
]
}
]
}♻️ PostGobiOrdersHelper has reduced separation of concerns
public class PostGobiOrdersHelper {
private final OrderMappingsDao orderMappingsDao;
private final PostgresClient pgClient;
public PostGobiOrdersHelper(
Handler<AsyncResult<Response>> asyncResultHandler,
Map<String, String> okapiHeaders,
Context ctx,
OrderMappingsDao orderMappingsDao,
PostgresClient pgClient
) {
// ...
this.orderMappingsDao = orderMappingsDao != null
? orderMappingsDao
: new OrderMappingsDaoImpl();
this.pgClient = pgClient != null
? pgClient
: PostgresClient.getInstance(ctx.owner(), tenantId);
}
}🔧 Removed method
|
|



Purpose
https://folio-org.atlassian.net/browse/MODGOBI-217
Approach
Pre-Review Checklist