diff --git a/fineract-provider/dependencies.gradle b/fineract-provider/dependencies.gradle index a4f1cccc2..be2c1f962 100644 --- a/fineract-provider/dependencies.gradle +++ b/fineract-provider/dependencies.gradle @@ -26,6 +26,9 @@ dependencies { // implementation dependencies are directly used (compiled against) in src/main (and src/test) // + implementation( + project(path: ':fineract-avro-schemas') + ) implementation( 'org.springframework.boot:spring-boot-starter-web', 'org.springframework.boot:spring-boot-starter-security', @@ -38,7 +41,7 @@ dependencies { 'org.springframework.integration:spring-integration-event', 'org.springframework.integration:spring-integration-jms', - + 'org.apache.avro:avro', 'jakarta.ws.rs:jakarta.ws.rs-api', 'org.glassfish.jersey.media:jersey-media-multipart', diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorServiceImpl.java index 0c1e6d1a9..a636bbdb4 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorServiceImpl.java @@ -93,7 +93,7 @@ import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadPlatform import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData; import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeReadPlatformService; import org.apache.fineract.portfolio.products.data.ProductData; -import org.apache.fineract.portfolio.products.service.ProductReadPlatformService; +import org.apache.fineract.portfolio.products.service.ShareProductReadPlatformService; import org.apache.fineract.portfolio.savings.DepositAccountType; import org.apache.fineract.portfolio.savings.data.DepositProductData; import org.apache.fineract.portfolio.savings.data.FixedDepositProductData; @@ -132,7 +132,7 @@ public class BulkImportWorkbookPopulatorServiceImpl implements BulkImportWorkboo private final SavingsAccountReadPlatformService savingsAccountReadPlatformService; private final CodeValueReadPlatformService codeValueReadPlatformService; private final SavingsProductReadPlatformService savingsProductReadPlatformService; - private final ProductReadPlatformService productReadPlatformService; + private final ShareProductReadPlatformService shareProductReadPlatformService; private final ChargeReadPlatformService chargeReadPlatformService; private final DepositProductReadPlatformService depositProductReadPlatformService; private final RoleReadPlatformService roleReadPlatformService; @@ -149,7 +149,8 @@ public class BulkImportWorkbookPopulatorServiceImpl implements BulkImportWorkboo final SavingsAccountReadPlatformService savingsAccountReadPlatformService, final CodeValueReadPlatformService codeValueReadPlatformService, final SavingsProductReadPlatformService savingsProductReadPlatformService, - final ProductReadPlatformService productReadPlatformService, final ChargeReadPlatformService chargeReadPlatformService, + final ShareProductReadPlatformService shareProductReadPlatformService, + final ChargeReadPlatformService chargeReadPlatformService, final DepositProductReadPlatformService depositProductReadPlatformService, final RoleReadPlatformService roleReadPlatformService) { this.officeReadPlatformService = officeReadPlatformService; @@ -167,7 +168,7 @@ public class BulkImportWorkbookPopulatorServiceImpl implements BulkImportWorkboo this.savingsAccountReadPlatformService = savingsAccountReadPlatformService; this.codeValueReadPlatformService = codeValueReadPlatformService; this.savingsProductReadPlatformService = savingsProductReadPlatformService; - this.productReadPlatformService = productReadPlatformService; + this.shareProductReadPlatformService = shareProductReadPlatformService; this.chargeReadPlatformService = chargeReadPlatformService; this.depositProductReadPlatformService = depositProductReadPlatformService; this.roleReadPlatformService = roleReadPlatformService; @@ -536,7 +537,7 @@ public class BulkImportWorkbookPopulatorServiceImpl implements BulkImportWorkboo } private List fetchSharedProducts() { - List productDataList = productReadPlatformService.retrieveAllProducts(0, 50).getPageItems(); + List productDataList = shareProductReadPlatformService.retrieveAllProducts(0, 50).getPageItems(); List sharedProductDataList = new ArrayList<>(); if (productDataList != null) { for (ProductData data : productDataList) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java index 70568a799..d2aab3cf5 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java @@ -41,6 +41,8 @@ public class FineractProperties { private FineractRemoteJobMessageHandlerProperties remoteJobMessageHandler; + private FineractEventsProperties events; + @Getter @Setter public static class FineractTenantProperties { @@ -119,4 +121,18 @@ public class FineractProperties { private String requestQueueName; private String brokerUrl; } + + @Getter + @Setter + public static class FineractEventsProperties { + + private FineractExternalEventsProperties external; + } + + @Getter + @Setter + public static class FineractExternalEventsProperties { + + private boolean enabled; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/JPAConfig.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/JPAConfig.java index 47938cb7f..2061fdb6e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/JPAConfig.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/JPAConfig.java @@ -51,7 +51,7 @@ import org.springframework.transaction.support.TransactionTemplate; @Configuration @EnableJpaAuditing -@EnableJpaRepositories(basePackages = "org.apache.fineract.**.domain") +@EnableJpaRepositories(basePackages = { "org.apache.fineract.**.domain", "org.apache.fineract.**.repository" }) @EnableConfigurationProperties(JpaProperties.class) @Import(JpaAuditingHandlerRegistrar.class) public class JPAConfig extends JpaBaseConfiguration { diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/repository/ExternalEventRepository.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/repository/ExternalEventRepository.java new file mode 100644 index 000000000..0745503a1 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/repository/ExternalEventRepository.java @@ -0,0 +1,24 @@ +/** + * 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.repository; + +import org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEvent; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ExternalEventRepository extends JpaRepository {} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/repository/domain/ExternalEvent.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/repository/domain/ExternalEvent.java new file mode 100644 index 000000000..cfe1a4edf --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/repository/domain/ExternalEvent.java @@ -0,0 +1,77 @@ +/** + * 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.repository.domain; + +import java.time.LocalDate; +import java.time.OffsetDateTime; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.Lob; +import javax.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; +import org.apache.fineract.infrastructure.core.service.DateUtils; + +@Entity +@Table(name = "m_external_event") +@Getter +@NoArgsConstructor +public class ExternalEvent extends AbstractPersistableCustom { + + @Column(name = "type", nullable = false) + private String type; + + @Basic(fetch = FetchType.LAZY) + @Lob + @Column(name = "data", nullable = false, columnDefinition = "BLOB NOT NULL") + private byte[] data; + + @Column(name = "created_at", nullable = false) + private OffsetDateTime createdAt; + + @Enumerated(EnumType.STRING) + @Column(name = "status", nullable = false) + @Setter + private ExternalEventStatus status; + + @Column(name = "sent_at", nullable = false) + @Setter + private OffsetDateTime sentAt; + + @Column(name = "idempotency_key", nullable = false) + private String idempotencyKey; + + @Column(name = "business_date", nullable = false) + private LocalDate businessDate; + + public ExternalEvent(String type, byte[] data, String idempotencyKey) { + this.type = type; + this.data = data; + this.idempotencyKey = idempotencyKey; + this.createdAt = DateUtils.getOffsetDateTimeOfTenant(); + this.status = ExternalEventStatus.TO_BE_SENT; + this.businessDate = DateUtils.getBusinessLocalDate(); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/repository/domain/ExternalEventStatus.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/repository/domain/ExternalEventStatus.java new file mode 100644 index 000000000..0a04399e5 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/repository/domain/ExternalEventStatus.java @@ -0,0 +1,23 @@ +/** + * 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.repository.domain; + +public enum ExternalEventStatus { + TO_BE_SENT, SENT +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/DelayedExternalEventService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/DelayedExternalEventService.java new file mode 100644 index 000000000..b01f7ca29 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/DelayedExternalEventService.java @@ -0,0 +1,38 @@ +package org.apache.fineract.infrastructure.event.external.service; + +import java.util.ArrayList; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.portfolio.businessevent.domain.BulkBusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class DelayedExternalEventService { + + private final ThreadLocal>> localEventStorage = ThreadLocal.withInitial(ArrayList::new); + + private final ExternalEventService delegate; + + public void enqueueEvent(BusinessEvent event) { + if (event == null) { + throw new IllegalArgumentException("event cannot be null"); + } + + localEventStorage.get().add(event); + } + + public boolean hasEnqueuedEvents() { + return !localEventStorage.get().isEmpty(); + } + + public void postEnqueuedEvents() { + List> enqueuedEvents = localEventStorage.get(); + if (enqueuedEvents.isEmpty()) { + throw new IllegalStateException("No events have been enqueued"); + } + + delegate.postEvent(new BulkBusinessEvent(enqueuedEvents)); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventService.java new file mode 100644 index 000000000..a2bbb6835 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventService.java @@ -0,0 +1,57 @@ +/** + * 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 java.io.IOException; +import lombok.RequiredArgsConstructor; +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.idempotency.ExternalEventIdempotencyKeyGenerator; +import org.apache.fineract.infrastructure.event.external.service.serialization.BusinessEventSerializerFactory; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class ExternalEventService { + + private final ExternalEventRepository repository; + private final ExternalEventIdempotencyKeyGenerator idempotencyKeyGenerator; + private final BusinessEventSerializerFactory serializerFactory; + + public void postEvent(BusinessEvent event) { + if (event == null) { + throw new IllegalArgumentException("event cannot be null"); + } + + String eventType = event.getType(); + String idempotencyKey = idempotencyKeyGenerator.generate(event); + try { + byte[] data = serializerFactory.create(event).serialize(event); + ExternalEvent externalEvent = new ExternalEvent(eventType, data, idempotencyKey); + + repository.save(externalEvent); + } catch (IOException e) { + throw new RuntimeException("Error while serializing event " + event.getClass().getSimpleName(), e); + } + + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/idempotency/DefaultExternalEventIdempotencyKeyGenerator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/idempotency/DefaultExternalEventIdempotencyKeyGenerator.java new file mode 100644 index 000000000..875b6c273 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/idempotency/DefaultExternalEventIdempotencyKeyGenerator.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.infrastructure.event.external.service.idempotency; + +import java.util.UUID; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.springframework.stereotype.Component; + +@Component +public class DefaultExternalEventIdempotencyKeyGenerator implements ExternalEventIdempotencyKeyGenerator { + + @Override + public String generate(BusinessEvent event) { + return UUID.randomUUID().toString(); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/idempotency/ExternalEventIdempotencyKeyGenerator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/idempotency/ExternalEventIdempotencyKeyGenerator.java new file mode 100644 index 000000000..63646530e --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/idempotency/ExternalEventIdempotencyKeyGenerator.java @@ -0,0 +1,26 @@ +/** + * 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.idempotency; + +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; + +public interface ExternalEventIdempotencyKeyGenerator { + + String generate(BusinessEvent event); +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/BusinessEventSerializerComparator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/BusinessEventSerializerComparator.java new file mode 100644 index 000000000..6cff1b1d5 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/BusinessEventSerializerComparator.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.infrastructure.event.external.service.serialization; + +import java.util.Comparator; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; + +public class BusinessEventSerializerComparator implements Comparator { + + @Override + public int compare(BusinessEventSerializer o1, BusinessEventSerializer o2) { + int o1Order = getOrderOrDefault(o1); + int o2Order = getOrderOrDefault(o2); + return Integer.compare(o1Order, o2Order); + } + + private int getOrderOrDefault(BusinessEventSerializer serializer) { + Order orderAnnotation = serializer.getClass().getAnnotation(Order.class); + if (orderAnnotation != null) { + return orderAnnotation.value(); + } else { + return Ordered.LOWEST_PRECEDENCE; + } + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/BusinessEventSerializerFactory.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/BusinessEventSerializerFactory.java new file mode 100644 index 000000000..86421db0d --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/BusinessEventSerializerFactory.java @@ -0,0 +1,44 @@ +/** + * 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.serialization; + +import java.util.List; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.springframework.stereotype.Component; + +@Component +public class BusinessEventSerializerFactory { + + private final List serializers; + + public BusinessEventSerializerFactory(List serializers) { + this.serializers = serializers.stream().sorted(new BusinessEventSerializerComparator()).toList(); + } + + public BusinessEventSerializer create(BusinessEvent event) { + for (BusinessEventSerializer serializer : serializers) { + if (serializer.canSerialize(event)) { + return serializer; + } + } + throw new IllegalStateException("There's no serializer that's capable of serializing a " + event.getClass().getSimpleName()); + } + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/client/ClientDataMapper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/client/ClientDataMapper.java new file mode 100644 index 000000000..d6a87cd05 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/client/ClientDataMapper.java @@ -0,0 +1,29 @@ +/** + * 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.serialization.mapper.client; + +import org.apache.fineract.avro.client.v1.ClientDataV1; +import org.apache.fineract.portfolio.client.data.ClientData; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface ClientDataMapper { + + ClientDataV1 map(ClientData source); +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/fixeddeposit/FixedDepositAccountDataMapper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/fixeddeposit/FixedDepositAccountDataMapper.java new file mode 100644 index 000000000..c3dabfe12 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/fixeddeposit/FixedDepositAccountDataMapper.java @@ -0,0 +1,29 @@ +/** + * 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.serialization.mapper.fixeddeposit; + +import org.apache.fineract.avro.fixeddeposit.v1.FixedDepositAccountDataV1; +import org.apache.fineract.portfolio.savings.data.FixedDepositAccountData; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface FixedDepositAccountDataMapper { + + FixedDepositAccountDataV1 map(FixedDepositAccountData source); +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/generic/CommandProcessingResultMapper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/generic/CommandProcessingResultMapper.java new file mode 100644 index 000000000..e805709b0 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/generic/CommandProcessingResultMapper.java @@ -0,0 +1,29 @@ +/** + * 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.serialization.mapper.generic; + +import org.apache.fineract.avro.generic.v1.CommandProcessingResultV1; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface CommandProcessingResultMapper { + + CommandProcessingResultV1 map(CommandProcessingResult source); +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/LoanAccountDataMapper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/LoanAccountDataMapper.java new file mode 100644 index 000000000..c3caeaf25 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/LoanAccountDataMapper.java @@ -0,0 +1,29 @@ +/** + * 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.serialization.mapper.loan; + +import org.apache.fineract.avro.loan.v1.LoanAccountDataV1; +import org.apache.fineract.portfolio.loanaccount.data.LoanAccountData; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface LoanAccountDataMapper { + + LoanAccountDataV1 map(LoanAccountData source); +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/LoanChargeDataMapper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/LoanChargeDataMapper.java new file mode 100644 index 000000000..4aa3ebcb4 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/LoanChargeDataMapper.java @@ -0,0 +1,29 @@ +/** + * 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.serialization.mapper.loan; + +import org.apache.fineract.avro.loan.v1.LoanChargeDataV1; +import org.apache.fineract.portfolio.loanaccount.data.LoanChargeData; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface LoanChargeDataMapper { + + LoanChargeDataV1 map(LoanChargeData source); +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/LoanProductDataMapper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/LoanProductDataMapper.java new file mode 100644 index 000000000..0e37b1ed9 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/LoanProductDataMapper.java @@ -0,0 +1,29 @@ +/** + * 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.serialization.mapper.loan; + +import org.apache.fineract.avro.loan.v1.LoanProductDataV1; +import org.apache.fineract.portfolio.loanproduct.data.LoanProductData; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface LoanProductDataMapper { + + LoanProductDataV1 map(LoanProductData source); +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/LoanTransactionDataMapper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/LoanTransactionDataMapper.java new file mode 100644 index 000000000..1d6dc9065 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/LoanTransactionDataMapper.java @@ -0,0 +1,29 @@ +/** + * 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.serialization.mapper.loan; + +import org.apache.fineract.avro.loan.v1.LoanTransactionDataV1; +import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface LoanTransactionDataMapper { + + LoanTransactionDataV1 map(LoanTransactionData source); +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/recurringdeposit/RecurringDepositAccountDataMapper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/recurringdeposit/RecurringDepositAccountDataMapper.java new file mode 100644 index 000000000..c8943c250 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/recurringdeposit/RecurringDepositAccountDataMapper.java @@ -0,0 +1,29 @@ +/** + * 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.serialization.mapper.recurringdeposit; + +import org.apache.fineract.avro.recurringdeposit.v1.RecurringDepositAccountDataV1; +import org.apache.fineract.portfolio.savings.data.RecurringDepositAccountData; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface RecurringDepositAccountDataMapper { + + RecurringDepositAccountDataV1 map(RecurringDepositAccountData source); +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/savings/SavingsAccountDataMapper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/savings/SavingsAccountDataMapper.java new file mode 100644 index 000000000..05a9402fc --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/savings/SavingsAccountDataMapper.java @@ -0,0 +1,29 @@ +/** + * 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.serialization.mapper.savings; + +import org.apache.fineract.avro.savings.v1.SavingsAccountDataV1; +import org.apache.fineract.portfolio.savings.data.SavingsAccountData; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface SavingsAccountDataMapper { + + SavingsAccountDataV1 map(SavingsAccountData source); +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/share/ShareAccountDataMapper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/share/ShareAccountDataMapper.java new file mode 100644 index 000000000..a808e5a79 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/share/ShareAccountDataMapper.java @@ -0,0 +1,29 @@ +/** + * 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.serialization.mapper.share; + +import org.apache.fineract.avro.share.v1.ShareAccountDataV1; +import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountData; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface ShareAccountDataMapper { + + ShareAccountDataV1 map(ShareAccountData source); +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/share/ShareProductDataMapper.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/share/ShareProductDataMapper.java new file mode 100644 index 000000000..3e96e423d --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/share/ShareProductDataMapper.java @@ -0,0 +1,29 @@ +/** + * 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.serialization.mapper.share; + +import org.apache.fineract.avro.share.v1.ShareProductDataV1; +import org.apache.fineract.portfolio.shareproducts.data.ShareProductData; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface ShareProductDataMapper { + + ShareProductDataV1 map(ShareProductData source); +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/BusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/BusinessEventSerializer.java new file mode 100644 index 000000000..fa50fa0bf --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/BusinessEventSerializer.java @@ -0,0 +1,29 @@ +/** + * 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.serialization.serializer; + +import java.io.IOException; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; + +public interface BusinessEventSerializer { + + boolean canSerialize(BusinessEvent event); + + byte[] serialize(BusinessEvent rawEvent) throws IOException; +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/client/ClientBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/client/ClientBusinessEventSerializer.java new file mode 100644 index 000000000..3446818ba --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/client/ClientBusinessEventSerializer.java @@ -0,0 +1,55 @@ +/** + * 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.serialization.serializer.client; + +import java.io.IOException; +import java.nio.ByteBuffer; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.avro.client.v1.ClientDataV1; +import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.client.ClientDataMapper; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.client.ClientBusinessEvent; +import org.apache.fineract.portfolio.client.data.ClientData; +import org.apache.fineract.portfolio.client.service.ClientReadPlatformService; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class ClientBusinessEventSerializer implements BusinessEventSerializer { + + private final ClientReadPlatformService service; + private final ClientDataMapper mapper; + private final ByteBufferConverter byteBufferConverter; + + @Override + public boolean canSerialize(BusinessEvent event) { + return event instanceof ClientBusinessEvent; + } + + @Override + public byte[] serialize(BusinessEvent rawEvent) throws IOException { + ClientBusinessEvent event = (ClientBusinessEvent) rawEvent; + ClientData data = service.retrieveOne(event.get().getId()); + ClientDataV1 avroDto = mapper.map(data); + ByteBuffer buffer = avroDto.toByteBuffer(); + return byteBufferConverter.convert(buffer); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/fixeddeposit/FixedDepositAccountBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/fixeddeposit/FixedDepositAccountBusinessEventSerializer.java new file mode 100644 index 000000000..ca07e7009 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/fixeddeposit/FixedDepositAccountBusinessEventSerializer.java @@ -0,0 +1,56 @@ +/** + * 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.serialization.serializer.fixeddeposit; + +import java.io.IOException; +import java.nio.ByteBuffer; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.avro.fixeddeposit.v1.FixedDepositAccountDataV1; +import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.fixeddeposit.FixedDepositAccountDataMapper; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.deposit.FixedDepositAccountBusinessEvent; +import org.apache.fineract.portfolio.savings.DepositAccountType; +import org.apache.fineract.portfolio.savings.data.FixedDepositAccountData; +import org.apache.fineract.portfolio.savings.service.DepositAccountReadPlatformService; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class FixedDepositAccountBusinessEventSerializer implements BusinessEventSerializer { + + private final DepositAccountReadPlatformService service; + private final FixedDepositAccountDataMapper mapper; + private final ByteBufferConverter byteBufferConverter; + + @Override + public boolean canSerialize(BusinessEvent event) { + return event instanceof FixedDepositAccountBusinessEvent; + } + + @Override + public byte[] serialize(BusinessEvent rawEvent) throws IOException { + FixedDepositAccountBusinessEvent event = (FixedDepositAccountBusinessEvent) rawEvent; + FixedDepositAccountData data = (FixedDepositAccountData) service.retrieveOne(DepositAccountType.FIXED_DEPOSIT, event.get().getId()); + FixedDepositAccountDataV1 avroDto = mapper.map(data); + ByteBuffer buffer = avroDto.toByteBuffer(); + return byteBufferConverter.convert(buffer); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/group/GroupsBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/group/GroupsBusinessEventSerializer.java new file mode 100644 index 000000000..485fff5c5 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/group/GroupsBusinessEventSerializer.java @@ -0,0 +1,51 @@ +/** + * 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.serialization.serializer.group; + +import java.io.IOException; +import java.nio.ByteBuffer; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.avro.generic.v1.CommandProcessingResultV1; +import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.generic.CommandProcessingResultMapper; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.group.GroupsBusinessEvent; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class GroupsBusinessEventSerializer implements BusinessEventSerializer { + + private final CommandProcessingResultMapper mapper; + private final ByteBufferConverter byteBufferConverter; + + @Override + public boolean canSerialize(BusinessEvent event) { + return event instanceof GroupsBusinessEvent; + } + + @Override + public byte[] serialize(BusinessEvent rawEvent) throws IOException { + GroupsBusinessEvent event = (GroupsBusinessEvent) rawEvent; + CommandProcessingResultV1 avroDto = mapper.map(event.get()); + ByteBuffer buffer = avroDto.toByteBuffer(); + return byteBufferConverter.convert(buffer); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanAdjustTransactionBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanAdjustTransactionBusinessEventSerializer.java new file mode 100644 index 000000000..62d163d7a --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanAdjustTransactionBusinessEventSerializer.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.infrastructure.event.external.service.serialization.serializer.loan; + +import java.io.IOException; +import java.nio.ByteBuffer; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.avro.loan.v1.LoanTransactionAdjustmentDataV1; +import org.apache.fineract.avro.loan.v1.LoanTransactionDataV1; +import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanTransactionDataMapper; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.loan.LoanAdjustTransactionBusinessEvent; +import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData; +import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction; +import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class LoanAdjustTransactionBusinessEventSerializer implements BusinessEventSerializer { + + private final LoanReadPlatformService service; + private final LoanTransactionDataMapper mapper; + private final ByteBufferConverter byteBufferConverter; + + @Override + public boolean canSerialize(BusinessEvent event) { + return event instanceof LoanAdjustTransactionBusinessEvent; + } + + @Override + public byte[] serialize(BusinessEvent rawEvent) throws IOException { + LoanAdjustTransactionBusinessEvent event = (LoanAdjustTransactionBusinessEvent) rawEvent; + LoanTransaction transactionToAdjust = event.get().getTransactionToAdjust(); + LoanTransaction newTransactionDetail = event.get().getNewTransactionDetail(); + LoanTransactionData transactionToAdjustData = service.retrieveLoanTransaction(transactionToAdjust.getLoan().getId(), + transactionToAdjust.getId()); + LoanTransactionData newTransactionDetailData = service.retrieveLoanTransaction(newTransactionDetail.getLoan().getId(), + newTransactionDetail.getId()); + LoanTransactionDataV1 transactionToAdjustAvroDto = mapper.map(transactionToAdjustData); + LoanTransactionDataV1 newTransactionDetailAvroDto = mapper.map(newTransactionDetailData); + LoanTransactionAdjustmentDataV1 avroDto = new LoanTransactionAdjustmentDataV1(transactionToAdjustAvroDto, + newTransactionDetailAvroDto); + ByteBuffer buffer = avroDto.toByteBuffer(); + return byteBufferConverter.convert(buffer); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanBusinessEventSerializer.java new file mode 100644 index 000000000..383be874d --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanBusinessEventSerializer.java @@ -0,0 +1,55 @@ +/** + * 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.serialization.serializer.loan; + +import java.io.IOException; +import java.nio.ByteBuffer; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.avro.loan.v1.LoanAccountDataV1; +import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanAccountDataMapper; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.loan.LoanBusinessEvent; +import org.apache.fineract.portfolio.loanaccount.data.LoanAccountData; +import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class LoanBusinessEventSerializer implements BusinessEventSerializer { + + private final LoanReadPlatformService service; + private final LoanAccountDataMapper mapper; + private final ByteBufferConverter byteBufferConverter; + + @Override + public boolean canSerialize(BusinessEvent event) { + return event instanceof LoanBusinessEvent; + } + + @Override + public byte[] serialize(BusinessEvent rawEvent) throws IOException { + LoanBusinessEvent event = (LoanBusinessEvent) rawEvent; + LoanAccountData data = service.retrieveOne(event.get().getId()); + LoanAccountDataV1 avroDto = mapper.map(data); + ByteBuffer buffer = avroDto.toByteBuffer(); + return byteBufferConverter.convert(buffer); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanChargeBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanChargeBusinessEventSerializer.java new file mode 100644 index 000000000..4b1d6d116 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanChargeBusinessEventSerializer.java @@ -0,0 +1,55 @@ +/** + * 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.serialization.serializer.loan; + +import java.io.IOException; +import java.nio.ByteBuffer; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.avro.loan.v1.LoanChargeDataV1; +import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanChargeDataMapper; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.loan.charge.LoanChargeBusinessEvent; +import org.apache.fineract.portfolio.loanaccount.data.LoanChargeData; +import org.apache.fineract.portfolio.loanaccount.service.LoanChargeReadPlatformService; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class LoanChargeBusinessEventSerializer implements BusinessEventSerializer { + + private final LoanChargeReadPlatformService service; + private final LoanChargeDataMapper mapper; + private final ByteBufferConverter byteBufferConverter; + + @Override + public boolean canSerialize(BusinessEvent event) { + return event instanceof LoanChargeBusinessEvent; + } + + @Override + public byte[] serialize(BusinessEvent rawEvent) throws IOException { + LoanChargeBusinessEvent event = (LoanChargeBusinessEvent) rawEvent; + LoanChargeData data = service.retrieveLoanChargeDetails(event.get().getId(), event.get().getLoan().getId()); + LoanChargeDataV1 avroDto = mapper.map(data); + ByteBuffer buffer = avroDto.toByteBuffer(); + return byteBufferConverter.convert(buffer); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanProductBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanProductBusinessEventSerializer.java new file mode 100644 index 000000000..ff5e70284 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanProductBusinessEventSerializer.java @@ -0,0 +1,55 @@ +/** + * 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.serialization.serializer.loan; + +import java.io.IOException; +import java.nio.ByteBuffer; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.avro.loan.v1.LoanProductDataV1; +import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanProductDataMapper; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.loan.product.LoanProductBusinessEvent; +import org.apache.fineract.portfolio.loanproduct.data.LoanProductData; +import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadPlatformService; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class LoanProductBusinessEventSerializer implements BusinessEventSerializer { + + private final LoanProductReadPlatformService service; + private final LoanProductDataMapper mapper; + private final ByteBufferConverter byteBufferConverter; + + @Override + public boolean canSerialize(BusinessEvent event) { + return event instanceof LoanProductBusinessEvent; + } + + @Override + public byte[] serialize(BusinessEvent rawEvent) throws IOException { + LoanProductBusinessEvent event = (LoanProductBusinessEvent) rawEvent; + LoanProductData data = service.retrieveLoanProduct(event.get().getId()); + LoanProductDataV1 avroDto = mapper.map(data); + ByteBuffer buffer = avroDto.toByteBuffer(); + return byteBufferConverter.convert(buffer); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanTransactionBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanTransactionBusinessEventSerializer.java new file mode 100644 index 000000000..c41d591e5 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanTransactionBusinessEventSerializer.java @@ -0,0 +1,55 @@ +/** + * 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.serialization.serializer.loan; + +import java.io.IOException; +import java.nio.ByteBuffer; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.avro.loan.v1.LoanTransactionDataV1; +import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanTransactionDataMapper; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.loan.transaction.LoanTransactionBusinessEvent; +import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData; +import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class LoanTransactionBusinessEventSerializer implements BusinessEventSerializer { + + private final LoanReadPlatformService service; + private final LoanTransactionDataMapper mapper; + private final ByteBufferConverter byteBufferConverter; + + @Override + public boolean canSerialize(BusinessEvent event) { + return event instanceof LoanTransactionBusinessEvent; + } + + @Override + public byte[] serialize(BusinessEvent rawEvent) throws IOException { + LoanTransactionBusinessEvent event = (LoanTransactionBusinessEvent) rawEvent; + LoanTransactionData data = service.retrieveLoanTransaction(event.get().getLoan().getId(), event.get().getId()); + LoanTransactionDataV1 avroDto = mapper.map(data); + ByteBuffer buffer = avroDto.toByteBuffer(); + return byteBufferConverter.convert(buffer); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/recurringdeposit/RecurringDepositAccountBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/recurringdeposit/RecurringDepositAccountBusinessEventSerializer.java new file mode 100644 index 000000000..0517c9ed7 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/recurringdeposit/RecurringDepositAccountBusinessEventSerializer.java @@ -0,0 +1,57 @@ +/** + * 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.serialization.serializer.recurringdeposit; + +import java.io.IOException; +import java.nio.ByteBuffer; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.avro.recurringdeposit.v1.RecurringDepositAccountDataV1; +import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.recurringdeposit.RecurringDepositAccountDataMapper; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.deposit.RecurringDepositAccountBusinessEvent; +import org.apache.fineract.portfolio.savings.DepositAccountType; +import org.apache.fineract.portfolio.savings.data.RecurringDepositAccountData; +import org.apache.fineract.portfolio.savings.service.DepositAccountReadPlatformService; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class RecurringDepositAccountBusinessEventSerializer implements BusinessEventSerializer { + + private final DepositAccountReadPlatformService service; + private final RecurringDepositAccountDataMapper mapper; + private final ByteBufferConverter byteBufferConverter; + + @Override + public boolean canSerialize(BusinessEvent event) { + return event instanceof RecurringDepositAccountBusinessEvent; + } + + @Override + public byte[] serialize(BusinessEvent rawEvent) throws IOException { + RecurringDepositAccountBusinessEvent event = (RecurringDepositAccountBusinessEvent) rawEvent; + RecurringDepositAccountData data = (RecurringDepositAccountData) service.retrieveOne(DepositAccountType.RECURRING_DEPOSIT, + event.get().getId()); + RecurringDepositAccountDataV1 avroDto = mapper.map(data); + ByteBuffer buffer = avroDto.toByteBuffer(); + return byteBufferConverter.convert(buffer); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/savings/SavingsAccountBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/savings/SavingsAccountBusinessEventSerializer.java new file mode 100644 index 000000000..c211a9c29 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/savings/SavingsAccountBusinessEventSerializer.java @@ -0,0 +1,55 @@ +/** + * 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.serialization.serializer.savings; + +import java.io.IOException; +import java.nio.ByteBuffer; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.avro.savings.v1.SavingsAccountDataV1; +import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.savings.SavingsAccountDataMapper; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.savings.SavingsAccountBusinessEvent; +import org.apache.fineract.portfolio.savings.data.SavingsAccountData; +import org.apache.fineract.portfolio.savings.service.SavingsAccountReadPlatformService; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class SavingsAccountBusinessEventSerializer implements BusinessEventSerializer { + + private final SavingsAccountReadPlatformService service; + private final SavingsAccountDataMapper mapper; + private final ByteBufferConverter byteBufferConverter; + + @Override + public boolean canSerialize(BusinessEvent event) { + return event instanceof SavingsAccountBusinessEvent; + } + + @Override + public byte[] serialize(BusinessEvent rawEvent) throws IOException { + SavingsAccountBusinessEvent event = (SavingsAccountBusinessEvent) rawEvent; + SavingsAccountData data = service.retrieveOne(event.get().getId()); + SavingsAccountDataV1 avroDto = mapper.map(data); + ByteBuffer buffer = avroDto.toByteBuffer(); + return byteBufferConverter.convert(buffer); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/share/ShareAccountBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/share/ShareAccountBusinessEventSerializer.java new file mode 100644 index 000000000..f69ed9f59 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/share/ShareAccountBusinessEventSerializer.java @@ -0,0 +1,55 @@ +/** + * 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.serialization.serializer.share; + +import java.io.IOException; +import java.nio.ByteBuffer; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.avro.share.v1.ShareAccountDataV1; +import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.share.ShareAccountDataMapper; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.share.ShareAccountBusinessEvent; +import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountData; +import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountReadPlatformService; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class ShareAccountBusinessEventSerializer implements BusinessEventSerializer { + + private final ShareAccountReadPlatformService service; + private final ShareAccountDataMapper mapper; + private final ByteBufferConverter byteBufferConverter; + + @Override + public boolean canSerialize(BusinessEvent event) { + return event instanceof ShareAccountBusinessEvent; + } + + @Override + public byte[] serialize(BusinessEvent rawEvent) throws IOException { + ShareAccountBusinessEvent event = (ShareAccountBusinessEvent) rawEvent; + ShareAccountData data = service.retrieveOne(event.get().getId(), false); + ShareAccountDataV1 avroDto = mapper.map(data); + ByteBuffer buffer = avroDto.toByteBuffer(); + return byteBufferConverter.convert(buffer); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/share/ShareProductDividentsCreateBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/share/ShareProductDividentsCreateBusinessEventSerializer.java new file mode 100644 index 000000000..50b5abf2e --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/share/ShareProductDividentsCreateBusinessEventSerializer.java @@ -0,0 +1,55 @@ +/** + * 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.serialization.serializer.share; + +import java.io.IOException; +import java.nio.ByteBuffer; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.avro.share.v1.ShareProductDataV1; +import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.share.ShareProductDataMapper; +import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer; +import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter; +import org.apache.fineract.portfolio.businessevent.domain.BusinessEvent; +import org.apache.fineract.portfolio.businessevent.domain.share.ShareProductDividentsCreateBusinessEvent; +import org.apache.fineract.portfolio.products.service.ShareProductReadPlatformService; +import org.apache.fineract.portfolio.shareproducts.data.ShareProductData; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class ShareProductDividentsCreateBusinessEventSerializer implements BusinessEventSerializer { + + private final ShareProductReadPlatformService service; + private final ShareProductDataMapper mapper; + private final ByteBufferConverter byteBufferConverter; + + @Override + public boolean canSerialize(BusinessEvent event) { + return event instanceof ShareProductDividentsCreateBusinessEvent; + } + + @Override + public byte[] serialize(BusinessEvent rawEvent) throws IOException { + ShareProductDividentsCreateBusinessEvent event = (ShareProductDividentsCreateBusinessEvent) rawEvent; + ShareProductData data = (ShareProductData) service.retrieveOne(event.get(), false); + ShareProductDataV1 avroDto = mapper.map(data); + ByteBuffer buffer = avroDto.toByteBuffer(); + return byteBufferConverter.convert(buffer); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/support/ByteBufferConverter.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/support/ByteBufferConverter.java new file mode 100644 index 000000000..5ef4daf51 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/support/ByteBufferConverter.java @@ -0,0 +1,15 @@ +package org.apache.fineract.infrastructure.event.external.service.support; + +import java.nio.ByteBuffer; +import org.springframework.stereotype.Component; + +@Component +public class ByteBufferConverter { + + public byte[] convert(ByteBuffer buffer) { + byte[] bytes = new byte[buffer.remaining()]; + buffer.get(bytes); + buffer.position(buffer.position() - bytes.length); + return bytes; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/BulkBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/BulkBusinessEvent.java new file mode 100644 index 000000000..11862dce6 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/BulkBusinessEvent.java @@ -0,0 +1,33 @@ +/** + * 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.portfolio.businessevent.domain; + +import java.util.List; + +public class BulkBusinessEvent extends AbstractBusinessEvent>> { + + public BulkBusinessEvent(List> value) { + super(value); + } + + @Override + public String getType() { + return "BulkBusinessEvent"; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/BusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/BusinessEvent.java index da12bb295..3f6b2403a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/BusinessEvent.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/BusinessEvent.java @@ -21,4 +21,6 @@ package org.apache.fineract.portfolio.businessevent.domain; public interface BusinessEvent { T get(); + + String getType(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/client/ClientActivateBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/client/ClientActivateBusinessEvent.java index d7efcd423..f42ce00a9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/client/ClientActivateBusinessEvent.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/client/ClientActivateBusinessEvent.java @@ -25,4 +25,9 @@ public class ClientActivateBusinessEvent extends ClientBusinessEvent { public ClientActivateBusinessEvent(Client value) { super(value); } + + @Override + public String getType() { + return "ClientActivateBusinessEvent"; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/client/ClientCreateBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/client/ClientCreateBusinessEvent.java index 16370acf7..8c7be9754 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/client/ClientCreateBusinessEvent.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/client/ClientCreateBusinessEvent.java @@ -25,4 +25,9 @@ public class ClientCreateBusinessEvent extends ClientBusinessEvent { public ClientCreateBusinessEvent(Client value) { super(value); } + + @Override + public String getType() { + return "ClientCreateBusinessEvent"; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/client/ClientRejectBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/client/ClientRejectBusinessEvent.java index 8a4d190ec..8a7ef74cf 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/client/ClientRejectBusinessEvent.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/client/ClientRejectBusinessEvent.java @@ -25,4 +25,9 @@ public class ClientRejectBusinessEvent extends ClientBusinessEvent { public ClientRejectBusinessEvent(Client value) { super(value); } + + @Override + public String getType() { + return "ClientRejectBusinessEvent"; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/deposit/FixedDepositAccountCreateBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/deposit/FixedDepositAccountCreateBusinessEvent.java index 1099ebd80..c61c53aa8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/deposit/FixedDepositAccountCreateBusinessEvent.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/deposit/FixedDepositAccountCreateBusinessEvent.java @@ -25,4 +25,9 @@ public class FixedDepositAccountCreateBusinessEvent extends FixedDepositAccountB public FixedDepositAccountCreateBusinessEvent(FixedDepositAccount value) { super(value); } + + @Override + public String getType() { + return "FixedDepositAccountCreateBusinessEvent"; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/deposit/RecurringDepositAccountCreateBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/deposit/RecurringDepositAccountCreateBusinessEvent.java index ca7096991..498de1c2c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/deposit/RecurringDepositAccountCreateBusinessEvent.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/deposit/RecurringDepositAccountCreateBusinessEvent.java @@ -25,4 +25,9 @@ public class RecurringDepositAccountCreateBusinessEvent extends RecurringDeposit public RecurringDepositAccountCreateBusinessEvent(RecurringDepositAccount value) { super(value); } + + @Override + public String getType() { + return "RecurringDepositAccountCreateBusinessEvent"; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/group/CentersCreateBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/group/CentersCreateBusinessEvent.java index ccfa2f105..d027a2a07 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/group/CentersCreateBusinessEvent.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/group/CentersCreateBusinessEvent.java @@ -25,4 +25,9 @@ public class CentersCreateBusinessEvent extends GroupsBusinessEvent { public CentersCreateBusinessEvent(CommandProcessingResult value) { super(value); } + + @Override + public String getType() { + return "CentersCreateBusinessEvent"; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/group/GroupsCreateBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/group/GroupsCreateBusinessEvent.java index ee53b704a..5597f9394 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/group/GroupsCreateBusinessEvent.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/group/GroupsCreateBusinessEvent.java @@ -25,4 +25,9 @@ public class GroupsCreateBusinessEvent extends GroupsBusinessEvent { public GroupsCreateBusinessEvent(CommandProcessingResult value) { super(value); } + + @Override + public String getType() { + return "GroupsCreateBusinessEvent"; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/loan/LoanAcceptTransferBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/loan/LoanAcceptTransferBusinessEvent.java index 8abb87df7..418b26aab 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/loan/LoanAcceptTransferBusinessEvent.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/loan/LoanAcceptTransferBusinessEvent.java @@ -25,4 +25,9 @@ public class LoanAcceptTransferBusinessEvent extends LoanBusinessEvent { public LoanAcceptTransferBusinessEvent(Loan value) { super(value); } + + @Override + public String getType() { + return "LoanAcceptTransferBusinessEvent"; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/loan/LoanAdjustTransactionBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/loan/LoanAdjustTransactionBusinessEvent.java index ed6ebe588..485232734 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/loan/LoanAdjustTransactionBusinessEvent.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/businessevent/domain/loan/LoanAdjustTransactionBusinessEvent.java @@ -30,6 +30,11 @@ public class LoanAdjustTransactionBusinessEvent extends AbstractBusinessEvent> preListeners = new HashMap<>(); private final Map> postListeners = new HashMap<>(); + private final ExternalEventService externalEventService; + private final FineractProperties fineractProperties; + + @Override + public void afterPropertiesSet() throws Exception { + if (isExternalEventPostingEnabled()) { + log.info("External event posting is enabled"); + } else { + log.info("External event posting is disabled"); + } + } + @Override public void notifyPreBusinessEvent(BusinessEvent businessEvent) { List businessEventListeners = preListeners.get(businessEvent.getClass()); @@ -61,6 +80,14 @@ public class BusinessEventNotifierServiceImpl implements BusinessEventNotifierSe eventListener.onBusinessEvent(businessEvent); } } + if (isExternalEventPostingEnabled()) { + // we only want to create external events for operations that were successful, hence the post listener + externalEventService.postEvent(businessEvent); + } + } + + private boolean isExternalEventPostingEnabled() { + return fineractProperties.getEvents().getExternal().isEnabled(); } @Override @@ -72,5 +99,4 @@ public class BusinessEventNotifierServiceImpl implements BusinessEventNotifierSe } businessEventListeners.add(listener); } - } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/rescheduleloan/domain/LoanTermVariationsRepository.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/rescheduleloan/domain/LoanTermVariationsRepository.java new file mode 100644 index 000000000..70af211d1 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/rescheduleloan/domain/LoanTermVariationsRepository.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.portfolio.loanaccount.rescheduleloan.domain; + +import java.util.List; +import org.apache.fineract.portfolio.loanaccount.domain.LoanTermVariations; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface LoanTermVariationsRepository + extends JpaRepository, JpaSpecificationExecutor { + + @Query("select lrr from LoanTermVariations lrr where lrr.loan.id = :loanId") + List findAllLoanTermVariationsByLoanId(@Param("loanId") Long loanId); + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/products/api/ProductsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/products/api/ProductsApiResource.java index 528164fa2..bc41974b6 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/products/api/ProductsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/products/api/ProductsApiResource.java @@ -49,7 +49,7 @@ import org.apache.fineract.infrastructure.security.service.PlatformSecurityConte import org.apache.fineract.portfolio.products.constants.ProductsApiConstants; import org.apache.fineract.portfolio.products.data.ProductData; import org.apache.fineract.portfolio.products.exception.ResourceNotFoundException; -import org.apache.fineract.portfolio.products.service.ProductReadPlatformService; +import org.apache.fineract.portfolio.products.service.ShareProductReadPlatformService; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -87,7 +87,7 @@ public class ProductsApiResource { @Context final UriInfo uriInfo) { String serviceName = productType + ProductsApiConstants.READPLATFORM_NAME; try { - ProductReadPlatformService service = (ProductReadPlatformService) this.applicationContext.getBean(serviceName); + ShareProductReadPlatformService service = (ShareProductReadPlatformService) this.applicationContext.getBean(serviceName); ProductData data = service.retrieveTemplate(); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams()); @@ -108,7 +108,7 @@ public class ProductsApiResource { @PathParam("type") @Parameter(description = "type") final String productType, @Context final UriInfo uriInfo) { try { String serviceName = productType + ProductsApiConstants.READPLATFORM_NAME; - ProductReadPlatformService service = (ProductReadPlatformService) this.applicationContext.getBean(serviceName); + ShareProductReadPlatformService service = (ShareProductReadPlatformService) this.applicationContext.getBean(serviceName); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); ProductData data = service.retrieveOne(productId, settings.isTemplate()); return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams()); @@ -129,7 +129,7 @@ public class ProductsApiResource { @QueryParam("limit") @Parameter(description = "limit") final Integer limit, @Context final UriInfo uriInfo) { try { String serviceName = productType + ProductsApiConstants.READPLATFORM_NAME; - ProductReadPlatformService service = (ProductReadPlatformService) this.applicationContext.getBean(serviceName); + ShareProductReadPlatformService service = (ShareProductReadPlatformService) this.applicationContext.getBean(serviceName); Page data = service.retrieveAllProducts(offset, limit); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/products/service/ProductReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/products/service/ShareProductReadPlatformService.java similarity index 96% rename from fineract-provider/src/main/java/org/apache/fineract/portfolio/products/service/ProductReadPlatformService.java rename to fineract-provider/src/main/java/org/apache/fineract/portfolio/products/service/ShareProductReadPlatformService.java index 72cfd4dfc..9c9d15ee2 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/products/service/ProductReadPlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/products/service/ShareProductReadPlatformService.java @@ -23,7 +23,7 @@ import java.util.Set; import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.portfolio.products.data.ProductData; -public interface ProductReadPlatformService { +public interface ShareProductReadPlatformService { Page retrieveAllProducts(Integer offSet, Integer limit); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/shareaccounts/api/SelfShareAccountsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/shareaccounts/api/SelfShareAccountsApiResource.java index 612e74df5..99ada8b57 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/shareaccounts/api/SelfShareAccountsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/shareaccounts/api/SelfShareAccountsApiResource.java @@ -52,7 +52,7 @@ import org.apache.fineract.portfolio.charge.data.ChargeData; import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformService; import org.apache.fineract.portfolio.client.exception.ClientNotFoundException; import org.apache.fineract.portfolio.products.data.ProductData; -import org.apache.fineract.portfolio.products.service.ProductReadPlatformService; +import org.apache.fineract.portfolio.products.service.ShareProductReadPlatformService; import org.apache.fineract.portfolio.self.client.service.AppuserClientMapperReadService; import org.apache.fineract.portfolio.self.shareaccounts.data.SelfShareAccountsDataValidator; import org.apache.fineract.portfolio.self.shareaccounts.service.AppUserShareAccountsMapperReadPlatformService; @@ -78,7 +78,7 @@ public class SelfShareAccountsApiResource { private final DefaultToApiJsonSerializer toApiJsonSerializer; private final AppuserClientMapperReadService appuserClientMapperReadService; private final SelfShareAccountsDataValidator selfShareAccountsDataValidator; - private final ProductReadPlatformService productReadPlatformService; + private final ShareProductReadPlatformService shareProductReadPlatformService; private final ChargeReadPlatformService chargeReadPlatformService; private final AppUserShareAccountsMapperReadPlatformService appUserShareAccountsMapperReadPlatformService; @@ -87,7 +87,8 @@ public class SelfShareAccountsApiResource { final ShareAccountReadPlatformService readPlatformService, final DefaultToApiJsonSerializer toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper, final AppuserClientMapperReadService appuserClientMapperReadService, final SelfShareAccountsDataValidator selfShareAccountsDataValidator, - final ProductReadPlatformService productReadPlatformService, final ChargeReadPlatformService chargeReadPlatformService, + final ShareProductReadPlatformService shareProductReadPlatformService, + final ChargeReadPlatformService chargeReadPlatformService, final AppUserShareAccountsMapperReadPlatformService appUserShareAccountsMapperReadPlatformService) { this.context = context; this.accountsApiResource = accountsApiResource; @@ -96,7 +97,7 @@ public class SelfShareAccountsApiResource { this.apiRequestParameterHelper = apiRequestParameterHelper; this.selfShareAccountsDataValidator = selfShareAccountsDataValidator; this.appuserClientMapperReadService = appuserClientMapperReadService; - this.productReadPlatformService = productReadPlatformService; + this.shareProductReadPlatformService = shareProductReadPlatformService; this.chargeReadPlatformService = chargeReadPlatformService; this.appUserShareAccountsMapperReadPlatformService = appUserShareAccountsMapperReadPlatformService; } @@ -120,9 +121,9 @@ public class SelfShareAccountsApiResource { Collection productOptions = new ArrayList(); if (productId != null) { final boolean includeTemplate = true; - productOptions.add(productReadPlatformService.retrieveOne(productId, includeTemplate)); + productOptions.add(shareProductReadPlatformService.retrieveOne(productId, includeTemplate)); } else { - productOptions = productReadPlatformService.retrieveAllForLookup(); + productOptions = shareProductReadPlatformService.retrieveAllForLookup(); } String clientName = null; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountReadPlatformServiceImpl.java index 2bb840d54..f2ccb0989 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountReadPlatformServiceImpl.java @@ -46,7 +46,7 @@ import org.apache.fineract.portfolio.client.data.ClientData; import org.apache.fineract.portfolio.client.service.ClientReadPlatformService; import org.apache.fineract.portfolio.products.constants.ProductsApiConstants; import org.apache.fineract.portfolio.products.data.ProductData; -import org.apache.fineract.portfolio.products.service.ProductReadPlatformService; +import org.apache.fineract.portfolio.products.service.ShareProductReadPlatformService; import org.apache.fineract.portfolio.savings.DepositAccountType; import org.apache.fineract.portfolio.savings.data.SavingsAccountData; import org.apache.fineract.portfolio.savings.service.SavingsAccountReadPlatformService; @@ -108,7 +108,7 @@ public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlat public ShareAccountData retrieveTemplate(Long clientId, Long productId) { ShareAccountData toReturn = null; String serviceName = "share" + ProductsApiConstants.READPLATFORM_NAME; - ProductReadPlatformService service = (ProductReadPlatformService) this.applicationContext.getBean(serviceName); + ShareProductReadPlatformService service = (ShareProductReadPlatformService) this.applicationContext.getBean(serviceName); ClientData client = this.clientReadPlatformService.retrieveOne(clientId); if (productId != null) { @@ -157,7 +157,7 @@ public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlat String query = "select " + mapper.schema() + "where sa.id=?"; ShareAccountData data = (ShareAccountData) this.jdbcTemplate.queryForObject(query, mapper, new Object[] { id }); // NOSONAR String serviceName = "share" + ProductsApiConstants.READPLATFORM_NAME; - ProductReadPlatformService service = (ProductReadPlatformService) this.applicationContext.getBean(serviceName); + ShareProductReadPlatformService service = (ShareProductReadPlatformService) this.applicationContext.getBean(serviceName); final ShareProductData productData = (ShareProductData) service.retrieveOne(data.getProductId(), false); final BigDecimal currentMarketPrice = deriveMarketPrice(productData); data.setCurrentMarketPrice(currentMarketPrice); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java index 3dc5b1f22..91942d2ef 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java @@ -26,7 +26,7 @@ import java.util.HashMap; import java.util.Map; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; import org.apache.fineract.organisation.monetary.domain.Money; -import org.apache.fineract.portfolio.products.service.ProductReadPlatformService; +import org.apache.fineract.portfolio.products.service.ShareProductReadPlatformService; import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountData; import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountTransactionData; import org.apache.fineract.portfolio.shareaccounts.domain.PurchasedSharesStatusType; @@ -41,7 +41,7 @@ import org.springframework.stereotype.Component; @Component public class ShareProductDividendAssembler { - private final ProductReadPlatformService shareProductReadPlatformService; + private final ShareProductReadPlatformService shareProductReadPlatformService; private final ShareAccountReadPlatformService shareAccountReadPlatformService; @Autowired diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java index 4261a384f..2e2d5b9f8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java @@ -45,7 +45,7 @@ import org.apache.fineract.portfolio.charge.data.ChargeData; import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformService; import org.apache.fineract.portfolio.products.data.ProductData; import org.apache.fineract.portfolio.products.exception.ProductNotFoundException; -import org.apache.fineract.portfolio.products.service.ProductReadPlatformService; +import org.apache.fineract.portfolio.products.service.ShareProductReadPlatformService; import org.apache.fineract.portfolio.shareaccounts.service.SharesEnumerations; import org.apache.fineract.portfolio.shareproducts.data.ShareProductData; import org.apache.fineract.portfolio.shareproducts.data.ShareProductMarketPriceData; @@ -56,7 +56,7 @@ import org.springframework.stereotype.Service; @Service(value = "shareReadPlatformService") @RequiredArgsConstructor -public class ShareProductReadPlatformServiceImpl implements ProductReadPlatformService { +public class ShareProductReadPlatformServiceImpl implements ShareProductReadPlatformService { private final JdbcTemplate jdbcTemplate; private final CurrencyReadPlatformService currencyReadPlatformService; diff --git a/fineract-provider/src/main/resources/application.properties b/fineract-provider/src/main/resources/application.properties index 2cce16a7f..9e2f46bef 100644 --- a/fineract-provider/src/main/resources/application.properties +++ b/fineract-provider/src/main/resources/application.properties @@ -53,6 +53,8 @@ fineract.remote-job-message-handler.jms.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HA fineract.remote-job-message-handler.jms.request-queue-name=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_QUEUE_NAME:JMS-request-queue} fineract.remote-job-message-handler.jms.broker-url=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_BROKER_URL:tcp://127.0.0.1:61616} +fineract.events.external.enabled=${FINERACT_EXTERNAL_EVENTS_ENABLED:false} + # Logging pattern for the console logging.pattern.console=${CONSOLE_LOG_PATTERN:%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(%replace([%X{correlationId}]){'\\[\\]', ''}) %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}}