galovics commented on code in PR #2682:
URL: https://github.com/apache/fineract/pull/2682#discussion_r997881096
##########
fineract-provider/src/main/java/org/apache/fineract/commands/domain/CommandSource.java:
##########
@@ -104,17 +105,21 @@ public class CommandSource extends
AbstractPersistableCustom {
@Column(name = "organisation_creditbureau_id")
private Long organisationCreditBureauId;
+ @Column(name = "idempotency_key", length = 50)
+ private String idempotencyKey;
+
public static CommandSource fullEntryFrom(final CommandWrapper wrapper,
final JsonCommand command, final AppUser maker) {
return new CommandSource(wrapper.actionName(), wrapper.entityName(),
wrapper.getHref(), command.entityId(), command.subentityId(),
- command.json(), maker);
+ command.json(), maker,
+ wrapper.getIdempotencyKey() == null ?
IdempotencyKeyGenerator.create() : wrapper.getIdempotencyKey());
Review Comment:
We shall move this one level higher and ensure that the wrapper always have
an idempotency key set. That should be an invariant property.
##########
fineract-provider/src/main/java/org/apache/fineract/commands/service/IdempotencyKeyGenerator.java:
##########
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.commands.service;
+
+import java.util.UUID;
+
+public final class IdempotencyKeyGenerator {
+
+ private IdempotencyKeyGenerator() {}
+
+ public static String create() {
+ return UUID.randomUUID().toString();
Review Comment:
Big no-no. This definitely shouldn't be a static factory for the idempotency
keys but a Spring bean. Makes future testing easier + if you make an interface
behind the bean class, it can be replaced with the existing modularization
approach so one could alter the idempotency key generation.
##########
fineract-provider/src/main/resources/db/changelog/tenant/parts/0058_add_idempotency_key_to_comman_source.xml:
##########
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
+ <changeSet author="fineract" id="1" context="postgresql">
+ <sql>
+ CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
+ </sql>
+ </changeSet>
+
+ <changeSet author="fineract" id="2">
+ <addColumn tableName="m_portfolio_command_source">
+ <column defaultValueComputed="NULL" name="idempotency_key"
type="VARCHAR(50)"/>
+ </addColumn>
+ <update tableName="m_portfolio_command_source">
+ <column name="idempotency_key" valueComputed="${uuid}" />
Review Comment:
I think at this time, since all rows have been updated with a UUID value; we
should mark the idempotency_key column non-nullable. Thoughts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]