galovics commented on code in PR #3693:
URL: https://github.com/apache/fineract/pull/3693#discussion_r1461512199
##########
fineract-client/src/main/java/org/apache/fineract/client/util/JSON.java:
##########
@@ -56,20 +57,64 @@ public class JSON {
private final SqlDateTypeAdapter sqlDateTypeAdapter = new
SqlDateTypeAdapter();
private final OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new
OffsetDateTimeTypeAdapter();
private final LocalDateTypeAdapter localDateTypeAdapter = new
LocalDateTypeAdapter();
+ private final LocalDateTimeTypeAdapter localDateTimeTypeAdapter = new
LocalDateTimeTypeAdapter();
private final ExternalIdAdapter externalIdAdapter = new
ExternalIdAdapter();
public JSON() {
gson = new
GsonFireBuilder().createGsonBuilder().registerTypeAdapter(Date.class,
dateTypeAdapter)
.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
.registerTypeAdapter(OffsetDateTime.class,
offsetDateTimeTypeAdapter)
- .registerTypeAdapter(LocalDate.class,
localDateTypeAdapter).registerTypeAdapter(ExternalId.class, externalIdAdapter)
+ .registerTypeAdapter(LocalDate.class, localDateTypeAdapter)
+ .registerTypeAdapter(LocalDateTime.class,
localDateTimeTypeAdapter).registerTypeAdapter(ExternalId.class,
externalIdAdapter)
.create();
}
public Gson getGson() {
return gson;
}
+ public static class LocalDateTimeTypeAdapter extends
TypeAdapter<LocalDateTime> {
+
+ private final DateTimeFormatter formatter =
DateTimeFormatter.ISO_LOCAL_DATE_TIME;
+
+ @Override
+ public void write(JsonWriter out, LocalDateTime date) throws
IOException {
+ if (date == null) {
+ out.nullValue();
+ } else {
+ out.value(formatter.format(date));
+ }
+ }
+
+ @Override
+ public LocalDateTime read(JsonReader in) throws IOException {
+ switch (in.peek()) {
+ case NULL:
+ in.nextNull();
+ return null;
+ case STRING:
+ String dateString = in.nextString();
+ if (dateString != null && dateString.length() != 0) {
+ return LocalDateTime.parse(dateString);
Review Comment:
Even though this is parsing in ISO_LOCAL_DATE_TIME format, since you already
have a formatter in this class, I'd pass it to the parse method, just to make
sure in case the format changes somehow, parsing doesn't break.
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/CustomSnapshotEventIntegrationTest.java:
##########
@@ -0,0 +1,342 @@
+/**
+ * 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.integrationtests;
+
+import static
org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE;
+
+import com.google.gson.Gson;
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.client.models.BusinessDateRequest;
+import org.apache.fineract.client.models.PostLoanProductsRequest;
+import org.apache.fineract.client.models.PostLoanProductsResponse;
+import
org.apache.fineract.infrastructure.event.external.service.validation.ExternalEventDTO;
+import org.apache.fineract.integrationtests.common.BusinessStepHelper;
+import org.apache.fineract.integrationtests.common.ClientHelper;
+import
org.apache.fineract.integrationtests.common.ExternalEventConfigurationHelper;
+import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
+import
org.apache.fineract.integrationtests.common.externalevents.ExternalEventHelper;
+import
org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@Slf4j
+@ExtendWith(LoanTestLifecycleExtension.class)
+public class CustomSnapshotEventIntegrationTest extends
BaseLoanIntegrationTest {
+
+ private SchedulerJobHelper schedulerJobHelper = new
SchedulerJobHelper(this.requestSpec);
+
+ @AfterEach
+ public void restoreEventConfigurationToDefault() {
+ log.info("Restoring event configurations to default");
+ disableAccountCustomSnapshotBusinessEvent();
Review Comment:
I think this is a good first step, but shouldn't we include this logic in an
extension you can use generally across all tests like we do with the
LoanTestLifecycleExtension?
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/event/external/service/InternalExternalEventService.java:
##########
@@ -0,0 +1,146 @@
+/**
+ * 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.infrastructure.event.external.service;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.avro.BulkMessageItemV1;
+import
org.apache.fineract.infrastructure.event.external.repository.ExternalEventRepository;
+import
org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEvent;
+import
org.apache.fineract.infrastructure.event.external.service.validation.ExternalEventDTO;
+import org.springframework.context.annotation.Profile;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+
+@Service
+@Profile("test")
Review Comment:
A while back I've created a class for having the profiles as constants:
FineractProfiles
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/event/external/api/InternalExternalEventsApiResource.java:
##########
@@ -0,0 +1,122 @@
+/**
+ * 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.infrastructure.event.external.api;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.DELETE;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
+import jakarta.ws.rs.core.MediaType;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Map;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import
org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
+import
org.apache.fineract.infrastructure.event.external.service.InternalExternalEventService;
+import
org.apache.fineract.infrastructure.event.external.service.validation.ExternalEventDTO;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.annotation.Profile;
+import org.springframework.stereotype.Component;
+
+@Profile("test")
+@Component
+@Path("/v1/internal/externalevents")
+@RequiredArgsConstructor
+@Slf4j
+public class InternalExternalEventsApiResource implements InitializingBean {
+
+ private final InternalExternalEventService internalExternalEventService;
+ private final DefaultToApiJsonSerializer<List<ExternalEventDTO>>
jsonSerializer;
+
+ @Override
+ @SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
+ public void afterPropertiesSet() throws Exception {
+
log.warn("------------------------------------------------------------");
+ log.warn("
");
+ log.warn("DO NOT USE THIS IN PRODUCTION!");
+ log.warn("Internal client services mode is enabled");
+ log.warn("DO NOT USE THIS IN PRODUCTION!");
+ log.warn("
");
+
log.warn("------------------------------------------------------------");
+ }
+
+ @GET
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ @Operation(summary = "Get all external events matching the provided query
parameters", description = "")
+ @ApiResponses({
Review Comment:
Do we want to keep the swagger annotations even though we're not using the
generated client?
##########
fineract-provider/src/main/java/org/apache/fineract/cob/loan/CustomSnapshotEventTriggerBusinessStep.java:
##########
@@ -0,0 +1,65 @@
+/**
+ * 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.cob.loan;
+
+import java.time.LocalDate;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.infrastructure.core.service.DateUtils;
+import
org.apache.fineract.infrastructure.event.business.domain.loan.LoanAccountCustomSnapshotBusinessEvent;
+import
org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
+import org.apache.fineract.portfolio.loanaccount.domain.Loan;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+@RequiredArgsConstructor
+public class CustomSnapshotEventTriggerBusinessStep implements
LoanCOBBusinessStep {
Review Comment:
I think we should capture the "business functionality" of this business
step, not the outcome of it.
I'd call this something like "CheckDueInstallmentsBusinessStep" or smthing
like that.
--
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]