You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fineract.apache.org by "edk12564 (via GitHub)" <gi...@apache.org> on 2026/06/08 15:10:40 UTC
[PR] FINERACT-2634: Implement Registration Feature [fineract-consumer-facing]
edk12564 opened a new pull request, #13:
URL: https://github.com/apache/fineract-consumer-facing/pull/13
More summary and details to be added soon.
- created registration feature
- created user feature service
- created fineract client
- added custom exceptions and handling
- removed gitkeep placeholders
- removed ping feature
- expanded liquibase user columns
- implemented cqrs separation
- added command/query aspects for cross cutting concerns
- added cucumber tests for some happy paths
- added otp feature service
- added cucumber infrastructure for mailpit client
--
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: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2634: Implement Registration Feature [fineract-consumer-facing]
Posted by "edk12564 (via GitHub)" <gi...@apache.org>.
edk12564 commented on code in PR #13:
URL: https://github.com/apache/fineract-consumer-facing/pull/13#discussion_r3375922589
##########
consumer/src/main/java/org/apache/fineract/consumer/infrastructure/exception/MethodArgumentNotValidExceptionHandler.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.consumer.infrastructure.exception;
+
+import java.util.Map;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+@Slf4j
+@Order(Ordered.HIGHEST_PRECEDENCE)
+@RestControllerAdvice
+public class MethodArgumentNotValidExceptionHandler {
+
+ @ExceptionHandler(MethodArgumentNotValidException.class)
+ public ResponseEntity<Map<String, String>> handle(MethodArgumentNotValidException ex) {
+ log.info("invalid request body: {}", ex.getClass().getSimpleName());
+ return ResponseEntity.status(HttpStatus.BAD_REQUEST)
+ .body(Map.of("error", "invalid request"));
Review Comment:
fixed in newest commit
##########
consumer/src/main/java/org/apache/fineract/consumer/otp/command/exception/OtpDeliveryFailedException.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.consumer.otp.command.exception;
+
+import org.apache.fineract.consumer.infrastructure.exception.AbstractConsumerException;
+import org.springframework.http.HttpStatus;
+
+public class OtpDeliveryFailedException extends AbstractConsumerException {
+
+ public OtpDeliveryFailedException(Throwable cause) {
+ super(HttpStatus.BAD_GATEWAY, "verification code could not be sent", cause);
Review Comment:
fixed in newest commit
--
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: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2634: Implement Registration Feature [fineract-consumer-facing]
Posted by "edk12564 (via GitHub)" <gi...@apache.org>.
edk12564 commented on code in PR #13:
URL: https://github.com/apache/fineract-consumer-facing/pull/13#discussion_r3375925035
##########
consumer/src/test/java/org/apache/fineract/consumer/cucumber/helpers/FineractSeeder.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.consumer.cucumber.helpers;
+
+import feign.Feign;
+import feign.RequestInterceptor;
+import feign.auth.BasicAuthRequestInterceptor;
+import feign.jackson.JacksonDecoder;
+import feign.jackson.JacksonEncoder;
+import feign.okhttp.OkHttpClient;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.fineract.consumer.cucumber.clients.FineractClientSeedClient;
+import org.apache.fineract.consumer.cucumber.clients.FineractCodeLookupClient;
+import org.apache.fineract.consumer.cucumber.clients.FineractIdentifierSeedClient;
+
+public class FineractSeeder {
+
+ private static final String BASE_URL = System.getenv().getOrDefault(
+ "FINERACT_BASE_URL", "http://localhost:8888/fineract-provider/api/v1");
+ private static final String USERNAME = System.getenv().getOrDefault("FINERACT_USERNAME", "mifos");
+ private static final String PASSWORD = System.getenv().getOrDefault("FINERACT_PASSWORD", "password");
+ private static final String TENANT = System.getenv().getOrDefault("FINERACT_TENANT", "default");
+ private static final long HEAD_OFFICE_ID = 1L;
+ private static final String CUSTOMER_IDENTIFIER_CODE = "Customer Identifier";
+ private static final String PASSPORT_DOCUMENT_TYPE = "Passport";
+
+ private static final FineractClientSeedClient CLIENTS = buildFeignClient(FineractClientSeedClient.class);
+ private static final FineractIdentifierSeedClient IDENTIFIERS = buildFeignClient(FineractIdentifierSeedClient.class);
+ private static final FineractCodeLookupClient CODES = buildFeignClient(FineractCodeLookupClient.class);
+
+ private static volatile Long cachedPassportCodeValueId;
+
+ public record SeededClient(long fineractClientId, String documentTypeName, String documentKey) {}
+
+ public SeededClient seedClientWithPassport() {
+ long clientId = createClient();
+ String documentKey = "PASS-" + UUID.randomUUID().toString().substring(0, 8).toUpperCase();
+ attachPassportIdentifier(clientId, documentKey);
+ return new SeededClient(clientId, PASSPORT_DOCUMENT_TYPE, documentKey);
+ }
+
+ private long createClient() {
+ String suffix = UUID.randomUUID().toString().substring(0, 8);
+ Map<String, Object> body = Map.of(
+ "officeId", HEAD_OFFICE_ID,
+ "firstname", "Test",
+ "lastname", "User-" + suffix,
+ "active", false,
+ "legalFormId", 1,
+ "locale", "en",
+ "dateFormat", "dd MMMM yyyy");
+ Map<String, Object> response = CLIENTS.createClient(body);
+ return ((Number) response.get("clientId")).longValue();
+ }
+
+ private void attachPassportIdentifier(long clientId, String documentKey) {
+ long passportId = resolvePassportCodeValueId();
+ Map<String, Object> body = Map.of(
+ "documentTypeId", passportId,
+ "documentKey", documentKey,
+ "status", "ACTIVE");
+ IDENTIFIERS.createIdentifier(clientId, body);
+ }
+
+ private long resolvePassportCodeValueId() {
+ Long cached = cachedPassportCodeValueId;
+ if (cached != null) {
+ return cached;
+ }
+ synchronized (FineractSeeder.class) {
+ if (cachedPassportCodeValueId != null) {
+ return cachedPassportCodeValueId;
+ }
+ long codeId = findIdByName(CODES.listCodes(), CUSTOMER_IDENTIFIER_CODE);
+ long passportId = findIdByName(CODES.listCodeValues(codeId), PASSPORT_DOCUMENT_TYPE);
+ cachedPassportCodeValueId = passportId;
+ return passportId;
+ }
+ }
+
+ private long findIdByName(List<Map<String, Object>> entries, String name) {
+ return entries.stream()
+ .filter(entry -> name.equals(entry.get("name")))
+ .map(entry -> ((Number) entry.get("id")).longValue())
+ .findFirst()
+ .orElseThrow(() -> new IllegalStateException("Fineract entry not found: " + name));
+ }
+
+ private static <T> T buildFeignClient(Class<T> apiType) {
+ return Feign.builder()
+ .client(new OkHttpClient())
+ .encoder(new JacksonEncoder())
+ .decoder(new JacksonDecoder())
+ .requestInterceptor(new BasicAuthRequestInterceptor(USERNAME, PASSWORD))
+ .requestInterceptor(tenantInterceptor())
+ .target(apiType, BASE_URL);
+ }
+
+ private static RequestInterceptor tenantInterceptor() {
+ return template -> template.header("Fineract-Platform-TenantId", TENANT);
Review Comment:
fixed in newest commit
--
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: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2634: Implement Registration Feature [fineract-consumer-facing]
Posted by "edk12564 (via GitHub)" <gi...@apache.org>.
edk12564 commented on code in PR #13:
URL: https://github.com/apache/fineract-consumer-facing/pull/13#discussion_r3375923610
##########
consumer/src/main/java/org/apache/fineract/consumer/otp/command/repository/OtpCommandRepository.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.consumer.otp.command.repository;
+
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.fineract.consumer.otp.command.data.PendingOtp;
+import org.springframework.stereotype.Repository;
+import org.springframework.util.Assert;
+
+@Repository
+public class OtpCommandRepository {
+
+ private final ConcurrentHashMap<UUID, PendingOtp> store = new ConcurrentHashMap<>();
+
+ public PendingOtp getPendingOtpForUser(UUID externalId) {
+ Assert.notNull(externalId, "externalId must not be null");
Review Comment:
fixed in newest commit
##########
consumer/src/main/java/org/apache/fineract/consumer/user/query/repository/UserQueryRepository.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.consumer.user.query.repository;
+
+import java.util.Optional;
+import java.util.UUID;
+import org.apache.fineract.consumer.user.command.domain.User;
+import org.apache.fineract.consumer.user.query.data.UserQueryData;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.Repository;
+
+public interface UserQueryRepository extends Repository<User, Long> {
+
+ @Query("SELECT new org.apache.fineract.consumer.user.query.data.UserQueryData(u.id, u.externalId, u.email, u.status) "
Review Comment:
fixed in newest commit
--
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: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2634: Implement Registration Feature [fineract-consumer-facing]
Posted by "Aman-Mittal (via GitHub)" <gi...@apache.org>.
Aman-Mittal commented on code in PR #13:
URL: https://github.com/apache/fineract-consumer-facing/pull/13#discussion_r3385869744
##########
consumer/src/test/java/org/apache/fineract/consumer/cucumber/clients/FineractIdentifierSeedClient.java:
##########
@@ -0,0 +1,32 @@
+/*
+ * 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.consumer.cucumber.clients;
+
+import feign.Headers;
+import feign.Param;
+import feign.RequestLine;
+import java.util.Map;
+
+public interface FineractIdentifierSeedClient {
+
+ @RequestLine("POST /clients/{clientId}/identifiers")
+ @Headers("Content-Type: application/json")
Review Comment:
Resolving this for now can be handled in separate PR
--
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: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2634: Implement Registration Feature [fineract-consumer-facing]
Posted by "Aman-Mittal (via GitHub)" <gi...@apache.org>.
Aman-Mittal commented on code in PR #13:
URL: https://github.com/apache/fineract-consumer-facing/pull/13#discussion_r3374700369
##########
consumer/src/main/java/org/apache/fineract/consumer/otp/command/exception/OtpDeliveryFailedException.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.consumer.otp.command.exception;
+
+import org.apache.fineract.consumer.infrastructure.exception.AbstractConsumerException;
+import org.springframework.http.HttpStatus;
+
+public class OtpDeliveryFailedException extends AbstractConsumerException {
+
+ public OtpDeliveryFailedException(Throwable cause) {
+ super(HttpStatus.BAD_GATEWAY, "verification code could not be sent", cause);
Review Comment:
Maybe you can maintain centralized error codes for these?
##########
consumer/src/main/java/org/apache/fineract/consumer/otp/command/repository/OtpCommandRepository.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.consumer.otp.command.repository;
+
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.fineract.consumer.otp.command.data.PendingOtp;
+import org.springframework.stereotype.Repository;
+import org.springframework.util.Assert;
+
+@Repository
+public class OtpCommandRepository {
+
+ private final ConcurrentHashMap<UUID, PendingOtp> store = new ConcurrentHashMap<>();
+
+ public PendingOtp getPendingOtpForUser(UUID externalId) {
+ Assert.notNull(externalId, "externalId must not be null");
Review Comment:
Maintain constants here
##########
consumer/src/test/java/org/apache/fineract/consumer/cucumber/clients/FineractIdentifierSeedClient.java:
##########
@@ -0,0 +1,32 @@
+/*
+ * 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.consumer.cucumber.clients;
+
+import feign.Headers;
+import feign.Param;
+import feign.RequestLine;
+import java.util.Map;
+
+public interface FineractIdentifierSeedClient {
+
+ @RequestLine("POST /clients/{clientId}/identifiers")
+ @Headers("Content-Type: application/json")
Review Comment:
I remember there are enums maintained in one of the dependencies. See fineract code for more
Content-Type : application/json
##########
consumer/src/main/java/org/apache/fineract/consumer/infrastructure/exception/MethodArgumentNotValidExceptionHandler.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.consumer.infrastructure.exception;
+
+import java.util.Map;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+@Slf4j
+@Order(Ordered.HIGHEST_PRECEDENCE)
+@RestControllerAdvice
+public class MethodArgumentNotValidExceptionHandler {
+
+ @ExceptionHandler(MethodArgumentNotValidException.class)
+ public ResponseEntity<Map<String, String>> handle(MethodArgumentNotValidException ex) {
+ log.info("invalid request body: {}", ex.getClass().getSimpleName());
+ return ResponseEntity.status(HttpStatus.BAD_REQUEST)
+ .body(Map.of("error", "invalid request"));
Review Comment:
Maybe you can maintain constants for error , invalid request
##########
consumer/src/main/java/org/apache/fineract/consumer/user/query/repository/UserQueryRepository.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.consumer.user.query.repository;
+
+import java.util.Optional;
+import java.util.UUID;
+import org.apache.fineract.consumer.user.command.domain.User;
+import org.apache.fineract.consumer.user.query.data.UserQueryData;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.Repository;
+
+public interface UserQueryRepository extends Repository<User, Long> {
+
+ @Query("SELECT new org.apache.fineract.consumer.user.query.data.UserQueryData(u.id, u.externalId, u.email, u.status) "
Review Comment:
You can use textBox her like """ <QUERY> """
##########
consumer/src/test/java/org/apache/fineract/consumer/cucumber/helpers/FineractSeeder.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.consumer.cucumber.helpers;
+
+import feign.Feign;
+import feign.RequestInterceptor;
+import feign.auth.BasicAuthRequestInterceptor;
+import feign.jackson.JacksonDecoder;
+import feign.jackson.JacksonEncoder;
+import feign.okhttp.OkHttpClient;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.fineract.consumer.cucumber.clients.FineractClientSeedClient;
+import org.apache.fineract.consumer.cucumber.clients.FineractCodeLookupClient;
+import org.apache.fineract.consumer.cucumber.clients.FineractIdentifierSeedClient;
+
+public class FineractSeeder {
+
+ private static final String BASE_URL = System.getenv().getOrDefault(
+ "FINERACT_BASE_URL", "http://localhost:8888/fineract-provider/api/v1");
+ private static final String USERNAME = System.getenv().getOrDefault("FINERACT_USERNAME", "mifos");
+ private static final String PASSWORD = System.getenv().getOrDefault("FINERACT_PASSWORD", "password");
+ private static final String TENANT = System.getenv().getOrDefault("FINERACT_TENANT", "default");
+ private static final long HEAD_OFFICE_ID = 1L;
+ private static final String CUSTOMER_IDENTIFIER_CODE = "Customer Identifier";
+ private static final String PASSPORT_DOCUMENT_TYPE = "Passport";
+
+ private static final FineractClientSeedClient CLIENTS = buildFeignClient(FineractClientSeedClient.class);
+ private static final FineractIdentifierSeedClient IDENTIFIERS = buildFeignClient(FineractIdentifierSeedClient.class);
+ private static final FineractCodeLookupClient CODES = buildFeignClient(FineractCodeLookupClient.class);
+
+ private static volatile Long cachedPassportCodeValueId;
+
+ public record SeededClient(long fineractClientId, String documentTypeName, String documentKey) {}
+
+ public SeededClient seedClientWithPassport() {
+ long clientId = createClient();
+ String documentKey = "PASS-" + UUID.randomUUID().toString().substring(0, 8).toUpperCase();
+ attachPassportIdentifier(clientId, documentKey);
+ return new SeededClient(clientId, PASSPORT_DOCUMENT_TYPE, documentKey);
+ }
+
+ private long createClient() {
+ String suffix = UUID.randomUUID().toString().substring(0, 8);
+ Map<String, Object> body = Map.of(
+ "officeId", HEAD_OFFICE_ID,
+ "firstname", "Test",
+ "lastname", "User-" + suffix,
+ "active", false,
+ "legalFormId", 1,
+ "locale", "en",
+ "dateFormat", "dd MMMM yyyy");
+ Map<String, Object> response = CLIENTS.createClient(body);
+ return ((Number) response.get("clientId")).longValue();
+ }
+
+ private void attachPassportIdentifier(long clientId, String documentKey) {
+ long passportId = resolvePassportCodeValueId();
+ Map<String, Object> body = Map.of(
+ "documentTypeId", passportId,
+ "documentKey", documentKey,
+ "status", "ACTIVE");
+ IDENTIFIERS.createIdentifier(clientId, body);
+ }
+
+ private long resolvePassportCodeValueId() {
+ Long cached = cachedPassportCodeValueId;
+ if (cached != null) {
+ return cached;
+ }
+ synchronized (FineractSeeder.class) {
+ if (cachedPassportCodeValueId != null) {
+ return cachedPassportCodeValueId;
+ }
+ long codeId = findIdByName(CODES.listCodes(), CUSTOMER_IDENTIFIER_CODE);
+ long passportId = findIdByName(CODES.listCodeValues(codeId), PASSPORT_DOCUMENT_TYPE);
+ cachedPassportCodeValueId = passportId;
+ return passportId;
+ }
+ }
+
+ private long findIdByName(List<Map<String, Object>> entries, String name) {
+ return entries.stream()
+ .filter(entry -> name.equals(entry.get("name")))
+ .map(entry -> ((Number) entry.get("id")).longValue())
+ .findFirst()
+ .orElseThrow(() -> new IllegalStateException("Fineract entry not found: " + name));
+ }
+
+ private static <T> T buildFeignClient(Class<T> apiType) {
+ return Feign.builder()
+ .client(new OkHttpClient())
+ .encoder(new JacksonEncoder())
+ .decoder(new JacksonDecoder())
+ .requestInterceptor(new BasicAuthRequestInterceptor(USERNAME, PASSWORD))
+ .requestInterceptor(tenantInterceptor())
+ .target(apiType, BASE_URL);
+ }
+
+ private static RequestInterceptor tenantInterceptor() {
+ return template -> template.header("Fineract-Platform-TenantId", TENANT);
Review Comment:
Maintain Fineract-Platform-TenantId as common constant
--
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: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2634: Implement Registration Feature [fineract-consumer-facing]
Posted by "Aman-Mittal (via GitHub)" <gi...@apache.org>.
Aman-Mittal merged PR #13:
URL: https://github.com/apache/fineract-consumer-facing/pull/13
--
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: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org