FINERACT-2309: Emit external events on document upload and delete
This commit is contained in:
committed by
Adam Saghy
parent
496e37e3d4
commit
159eff0ad4
@@ -0,0 +1,80 @@
|
|||||||
|
{
|
||||||
|
"name": "DocumentDataV1",
|
||||||
|
"namespace": "org.apache.fineract.avro.document.v1",
|
||||||
|
"doc": "Metadata emitted by DocumentCreatedBusinessEvent when a file is stored in Fineract.",
|
||||||
|
"type": "record",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"default": null,
|
||||||
|
"name": "id",
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"long"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": null,
|
||||||
|
"name": "parentEntityType",
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"string"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": null,
|
||||||
|
"name": "parentEntityId",
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"long"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": null,
|
||||||
|
"name": "name",
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"string"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": null,
|
||||||
|
"name": "fileName",
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"string"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": null,
|
||||||
|
"name": "size",
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"long"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": null,
|
||||||
|
"name": "type",
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"string"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": null,
|
||||||
|
"name": "description",
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"string"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": null,
|
||||||
|
"name": "storageType",
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"int"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+8
-1
@@ -31,6 +31,9 @@ import org.apache.fineract.infrastructure.documentmanagement.domain.StorageType;
|
|||||||
import org.apache.fineract.infrastructure.documentmanagement.exception.ContentManagementException;
|
import org.apache.fineract.infrastructure.documentmanagement.exception.ContentManagementException;
|
||||||
import org.apache.fineract.infrastructure.documentmanagement.exception.DocumentNotFoundException;
|
import org.apache.fineract.infrastructure.documentmanagement.exception.DocumentNotFoundException;
|
||||||
import org.apache.fineract.infrastructure.documentmanagement.exception.InvalidEntityTypeForDocumentManagementException;
|
import org.apache.fineract.infrastructure.documentmanagement.exception.InvalidEntityTypeForDocumentManagementException;
|
||||||
|
import org.apache.fineract.infrastructure.event.business.domain.document.DocumentCreatedBusinessEvent;
|
||||||
|
import org.apache.fineract.infrastructure.event.business.domain.document.DocumentDeletedBusinessEvent;
|
||||||
|
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
||||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -48,13 +51,15 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr
|
|||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final DocumentRepository documentRepository;
|
private final DocumentRepository documentRepository;
|
||||||
private final ContentRepositoryFactory contentRepositoryFactory;
|
private final ContentRepositoryFactory contentRepositoryFactory;
|
||||||
|
private final BusinessEventNotifierService businessEventNotifierService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DocumentWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final DocumentRepository documentRepository,
|
public DocumentWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final DocumentRepository documentRepository,
|
||||||
final ContentRepositoryFactory documentStoreFactory) {
|
final ContentRepositoryFactory documentStoreFactory, BusinessEventNotifierService businessEventNotifierService) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.documentRepository = documentRepository;
|
this.documentRepository = documentRepository;
|
||||||
this.contentRepositoryFactory = documentStoreFactory;
|
this.contentRepositoryFactory = documentStoreFactory;
|
||||||
|
this.businessEventNotifierService = businessEventNotifierService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -78,6 +83,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr
|
|||||||
documentCommand.getDescription(), fileLocation, contentRepository.getStorageType());
|
documentCommand.getDescription(), fileLocation, contentRepository.getStorageType());
|
||||||
|
|
||||||
this.documentRepository.saveAndFlush(document);
|
this.documentRepository.saveAndFlush(document);
|
||||||
|
businessEventNotifierService.notifyPostBusinessEvent(new DocumentCreatedBusinessEvent(document));
|
||||||
|
|
||||||
return document.getId();
|
return document.getId();
|
||||||
} catch (final JpaSystemException | DataIntegrityViolationException dve) {
|
} catch (final JpaSystemException | DataIntegrityViolationException dve) {
|
||||||
@@ -158,6 +164,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr
|
|||||||
|
|
||||||
final ContentRepository contentRepository = this.contentRepositoryFactory.getRepository(document.storageType());
|
final ContentRepository contentRepository = this.contentRepositoryFactory.getRepository(document.storageType());
|
||||||
contentRepository.deleteFile(document.getLocation());
|
contentRepository.deleteFile(document.getLocation());
|
||||||
|
businessEventNotifierService.notifyPostBusinessEvent(new DocumentDeletedBusinessEvent(document));
|
||||||
return CommandProcessingResult.resourceResult(document.getId());
|
return CommandProcessingResult.resourceResult(document.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
* 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.business.domain.document;
|
||||||
|
|
||||||
|
import org.apache.fineract.infrastructure.documentmanagement.domain.Document;
|
||||||
|
import org.apache.fineract.infrastructure.event.business.domain.AbstractBusinessEvent;
|
||||||
|
|
||||||
|
public abstract class DocumentBusinessEvent extends AbstractBusinessEvent<Document> {
|
||||||
|
|
||||||
|
private static final String CATEGORY = "Document";
|
||||||
|
|
||||||
|
protected DocumentBusinessEvent(Document value) {
|
||||||
|
super(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCategory() {
|
||||||
|
return CATEGORY; // e.g. will appear as “Document”
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getAggregateRootId() {
|
||||||
|
return get().getId(); // primary-key of the uploaded doc
|
||||||
|
}
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* 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.business.domain.document;
|
||||||
|
|
||||||
|
import org.apache.fineract.infrastructure.documentmanagement.domain.Document;
|
||||||
|
|
||||||
|
public class DocumentCreatedBusinessEvent extends DocumentBusinessEvent {
|
||||||
|
|
||||||
|
private static final String TYPE = "DocumentCreatedBusinessEvent";
|
||||||
|
|
||||||
|
public DocumentCreatedBusinessEvent(Document value) {
|
||||||
|
super(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* 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.business.domain.document;
|
||||||
|
|
||||||
|
import org.apache.fineract.infrastructure.documentmanagement.domain.Document;
|
||||||
|
|
||||||
|
public class DocumentDeletedBusinessEvent extends DocumentBusinessEvent {
|
||||||
|
|
||||||
|
private static final String TYPE = "DocumentDeletedBusinessEvent";
|
||||||
|
|
||||||
|
public DocumentDeletedBusinessEvent(Document value) {
|
||||||
|
super(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.infrastructure.event.external.service.serialization.mapper.document;
|
||||||
|
|
||||||
|
import org.apache.fineract.avro.document.v1.DocumentDataV1;
|
||||||
|
import org.apache.fineract.infrastructure.documentmanagement.data.DocumentData;
|
||||||
|
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.support.AvroMapperConfig;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
@Mapper(config = AvroMapperConfig.class)
|
||||||
|
public interface DocumentDataMapper {
|
||||||
|
|
||||||
|
DocumentDataV1 map(DocumentData source);
|
||||||
|
}
|
||||||
+89
@@ -0,0 +1,89 @@
|
|||||||
|
/**
|
||||||
|
* 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.document;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.avro.generic.GenericContainer;
|
||||||
|
import org.apache.fineract.avro.document.v1.DocumentDataV1;
|
||||||
|
import org.apache.fineract.avro.generator.ByteBufferSerializable;
|
||||||
|
import org.apache.fineract.infrastructure.documentmanagement.data.DocumentData;
|
||||||
|
import org.apache.fineract.infrastructure.documentmanagement.domain.Document;
|
||||||
|
import org.apache.fineract.infrastructure.documentmanagement.service.DocumentReadPlatformService;
|
||||||
|
import org.apache.fineract.infrastructure.event.business.domain.BusinessEvent;
|
||||||
|
import org.apache.fineract.infrastructure.event.business.domain.document.DocumentBusinessEvent;
|
||||||
|
import org.apache.fineract.infrastructure.event.business.domain.document.DocumentCreatedBusinessEvent;
|
||||||
|
import org.apache.fineract.infrastructure.event.business.domain.document.DocumentDeletedBusinessEvent;
|
||||||
|
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.document.DocumentDataMapper;
|
||||||
|
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DocumentBusinessEventSerializer implements BusinessEventSerializer {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(DocumentBusinessEventSerializer.class);
|
||||||
|
private final DocumentReadPlatformService service;
|
||||||
|
private final DocumentDataMapper mapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> boolean canSerialize(BusinessEvent<T> event) {
|
||||||
|
return event instanceof DocumentCreatedBusinessEvent || event instanceof DocumentDeletedBusinessEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> ByteBufferSerializable toAvroDTO(BusinessEvent<T> rawEvent) {
|
||||||
|
|
||||||
|
DocumentBusinessEvent event = (DocumentBusinessEvent) rawEvent;
|
||||||
|
Document entity = event.get(); // domain entity
|
||||||
|
|
||||||
|
DocumentData dto = null;
|
||||||
|
if (rawEvent instanceof DocumentCreatedBusinessEvent) {
|
||||||
|
try {
|
||||||
|
dto = service.retrieveDocument(entity.getParentEntityType(), entity.getParentEntityId(), entity.getId());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// log at DEBUG and fall back to entity mapping
|
||||||
|
log.debug("DocumentData not found, falling back to entity", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have the DTO, let MapStruct do the work. Otherwise, build from the entity
|
||||||
|
|
||||||
|
DocumentDataV1 avro;
|
||||||
|
if (dto != null) {
|
||||||
|
avro = mapper.map(dto);
|
||||||
|
} else {
|
||||||
|
avro = DocumentDataV1.newBuilder().setId(entity.getId()).setParentEntityType(entity.getParentEntityType())
|
||||||
|
.setParentEntityId(entity.getParentEntityId()).setName(entity.getName()).setFileName(entity.getFileName())
|
||||||
|
.setSize(entity.getSize()).setType(entity.getType()).setDescription(entity.getDescription()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer storageTypeCode = (dto != null && dto.getStorageType() != null && dto.storageType() != null) ? dto.getStorageType()
|
||||||
|
: (entity.storageType() != null ? entity.storageType().getValue() : null);
|
||||||
|
avro.setStorageType(storageTypeCode);
|
||||||
|
|
||||||
|
return avro;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends GenericContainer> getSupportedSchema() {
|
||||||
|
return DocumentDataV1.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -202,4 +202,5 @@
|
|||||||
<include file="parts/0181_add_capitalized_income_amortization_adjustment_transaction.xml" relativeToChangelogFile="true" />
|
<include file="parts/0181_add_capitalized_income_amortization_adjustment_transaction.xml" relativeToChangelogFile="true" />
|
||||||
<include file="parts/0182_transaction_summary_with_asset_owner_report_fix_charge_reason_and_add_buyback_intermediate.xml" relativeToChangelogFile="true" />
|
<include file="parts/0182_transaction_summary_with_asset_owner_report_fix_charge_reason_and_add_buyback_intermediate.xml" relativeToChangelogFile="true" />
|
||||||
<include file="parts/0183_add_LoanCapitalizedIncomeTransactionCreatedBusinessEvent.xml" relativeToChangelogFile="true" />
|
<include file="parts/0183_add_LoanCapitalizedIncomeTransactionCreatedBusinessEvent.xml" relativeToChangelogFile="true" />
|
||||||
|
<include file="parts/0184_add_document_event_configuration.xml" relativeToChangelogFile="true" />
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
|||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
|
||||||
|
-->
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
|
||||||
|
<changeSet id="1" author="fineract">
|
||||||
|
<insert tableName="m_external_event_configuration">
|
||||||
|
<column name="type" value="DocumentCreatedBusinessEvent"/>
|
||||||
|
<column name="enabled" valueBoolean="false"/>
|
||||||
|
</insert>
|
||||||
|
<insert tableName="m_external_event_configuration">
|
||||||
|
<column name="type" value="DocumentDeletedBusinessEvent"/>
|
||||||
|
<column name="enabled" valueBoolean="false"/>
|
||||||
|
</insert>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
||||||
+20
-20
@@ -67,20 +67,20 @@ public class ExternalEventConfigurationValidationServiceTest {
|
|||||||
|
|
||||||
// given
|
// given
|
||||||
List<String> configurations = Arrays.asList("CentersCreateBusinessEvent", "ClientActivateBusinessEvent",
|
List<String> configurations = Arrays.asList("CentersCreateBusinessEvent", "ClientActivateBusinessEvent",
|
||||||
"ClientCreateBusinessEvent", "ClientRejectBusinessEvent", "FixedDepositAccountCreateBusinessEvent",
|
"ClientCreateBusinessEvent", "ClientRejectBusinessEvent", "DocumentCreatedBusinessEvent", "DocumentDeletedBusinessEvent",
|
||||||
"GroupsCreateBusinessEvent", "LoanAcceptTransferBusinessEvent", "LoanAddChargeBusinessEvent",
|
"FixedDepositAccountCreateBusinessEvent", "GroupsCreateBusinessEvent", "LoanAcceptTransferBusinessEvent",
|
||||||
"LoanAdjustTransactionBusinessEvent", "LoanApplyOverdueChargeBusinessEvent", "LoanApprovedBusinessEvent",
|
"LoanAddChargeBusinessEvent", "LoanAdjustTransactionBusinessEvent", "LoanApplyOverdueChargeBusinessEvent",
|
||||||
"LoanBalanceChangedBusinessEvent", "LoanChargebackTransactionBusinessEvent", "LoanChargePaymentPostBusinessEvent",
|
"LoanApprovedBusinessEvent", "LoanBalanceChangedBusinessEvent", "LoanChargebackTransactionBusinessEvent",
|
||||||
"LoanChargePaymentPreBusinessEvent", "LoanChargeRefundBusinessEvent", "LoanCloseAsRescheduleBusinessEvent",
|
"LoanChargePaymentPostBusinessEvent", "LoanChargePaymentPreBusinessEvent", "LoanChargeRefundBusinessEvent",
|
||||||
"LoanCloseBusinessEvent", "LoanCreatedBusinessEvent", "LoanCreditBalanceRefundPostBusinessEvent",
|
"LoanCloseAsRescheduleBusinessEvent", "LoanCloseBusinessEvent", "LoanCreatedBusinessEvent",
|
||||||
"LoanCreditBalanceRefundPreBusinessEvent", "LoanDeleteChargeBusinessEvent", "LoanDisbursalBusinessEvent",
|
"LoanCreditBalanceRefundPostBusinessEvent", "LoanCreditBalanceRefundPreBusinessEvent", "LoanDeleteChargeBusinessEvent",
|
||||||
"LoanDisbursalTransactionBusinessEvent", "LoanForeClosurePostBusinessEvent", "LoanForeClosurePreBusinessEvent",
|
"LoanDisbursalBusinessEvent", "LoanDisbursalTransactionBusinessEvent", "LoanForeClosurePostBusinessEvent",
|
||||||
"LoanInitiateTransferBusinessEvent", "LoanInterestRecalculationBusinessEvent", "LoanProductCreateBusinessEvent",
|
"LoanForeClosurePreBusinessEvent", "LoanInitiateTransferBusinessEvent", "LoanInterestRecalculationBusinessEvent",
|
||||||
"LoanReassignOfficerBusinessEvent", "LoanRefundPostBusinessEvent", "LoanRefundPreBusinessEvent",
|
"LoanProductCreateBusinessEvent", "LoanReassignOfficerBusinessEvent", "LoanRefundPostBusinessEvent",
|
||||||
"LoanRejectedBusinessEvent", "LoanRejectTransferBusinessEvent", "LoanRemoveOfficerBusinessEvent",
|
"LoanRefundPreBusinessEvent", "LoanRejectedBusinessEvent", "LoanRejectTransferBusinessEvent",
|
||||||
"LoanRepaymentDueBusinessEvent", "LoanRepaymentOverdueBusinessEvent", "LoanRescheduledDueCalendarChangeBusinessEvent",
|
"LoanRemoveOfficerBusinessEvent", "LoanRepaymentDueBusinessEvent", "LoanRepaymentOverdueBusinessEvent",
|
||||||
"LoanRescheduledDueHolidayBusinessEvent", "LoanScheduleVariationsAddedBusinessEvent",
|
"LoanRescheduledDueCalendarChangeBusinessEvent", "LoanRescheduledDueHolidayBusinessEvent",
|
||||||
"LoanScheduleVariationsDeletedBusinessEvent", "LoanStatusChangedBusinessEvent",
|
"LoanScheduleVariationsAddedBusinessEvent", "LoanScheduleVariationsDeletedBusinessEvent", "LoanStatusChangedBusinessEvent",
|
||||||
"LoanTransactionGoodwillCreditPostBusinessEvent", "LoanTransactionGoodwillCreditPreBusinessEvent",
|
"LoanTransactionGoodwillCreditPostBusinessEvent", "LoanTransactionGoodwillCreditPreBusinessEvent",
|
||||||
"LoanTransactionMakeRepaymentPostBusinessEvent", "LoanTransactionMakeRepaymentPreBusinessEvent",
|
"LoanTransactionMakeRepaymentPostBusinessEvent", "LoanTransactionMakeRepaymentPreBusinessEvent",
|
||||||
"LoanTransactionMerchantIssuedRefundPostBusinessEvent", "LoanTransactionMerchantIssuedRefundPreBusinessEvent",
|
"LoanTransactionMerchantIssuedRefundPostBusinessEvent", "LoanTransactionMerchantIssuedRefundPreBusinessEvent",
|
||||||
@@ -157,12 +157,12 @@ public class ExternalEventConfigurationValidationServiceTest {
|
|||||||
|
|
||||||
// given
|
// given
|
||||||
List<String> configurationWithMissingCentersCreateBusinessEvent = Arrays.asList("MockBusinessEvent", "MockBusinessEvent",
|
List<String> configurationWithMissingCentersCreateBusinessEvent = Arrays.asList("MockBusinessEvent", "MockBusinessEvent",
|
||||||
"ClientActivateBusinessEvent", "ClientCreateBusinessEvent", "ClientRejectBusinessEvent",
|
"ClientActivateBusinessEvent", "ClientCreateBusinessEvent", "ClientRejectBusinessEvent", "DocumentCreatedBusinessEvent",
|
||||||
"FixedDepositAccountCreateBusinessEvent", "GroupsCreateBusinessEvent", "LoanAcceptTransferBusinessEvent",
|
"DocumentDeletedBusinessEvent", "FixedDepositAccountCreateBusinessEvent", "GroupsCreateBusinessEvent",
|
||||||
"LoanAddChargeBusinessEvent", "LoanAdjustTransactionBusinessEvent", "LoanApplyOverdueChargeBusinessEvent",
|
"LoanAcceptTransferBusinessEvent", "LoanAddChargeBusinessEvent", "LoanAdjustTransactionBusinessEvent",
|
||||||
"LoanApprovedBusinessEvent", "LoanBalanceChangedBusinessEvent", "LoanChargebackTransactionBusinessEvent",
|
"LoanApplyOverdueChargeBusinessEvent", "LoanApprovedBusinessEvent", "LoanBalanceChangedBusinessEvent",
|
||||||
"LoanChargePaymentPostBusinessEvent", "LoanChargePaymentPreBusinessEvent", "LoanChargeRefundBusinessEvent",
|
"LoanChargebackTransactionBusinessEvent", "LoanChargePaymentPostBusinessEvent", "LoanChargePaymentPreBusinessEvent",
|
||||||
"LoanCloseAsRescheduleBusinessEvent", "LoanCloseBusinessEvent", "LoanCreatedBusinessEvent",
|
"LoanChargeRefundBusinessEvent", "LoanCloseAsRescheduleBusinessEvent", "LoanCloseBusinessEvent", "LoanCreatedBusinessEvent",
|
||||||
"LoanCreditBalanceRefundPostBusinessEvent", "LoanCreditBalanceRefundPreBusinessEvent", "LoanDeleteChargeBusinessEvent",
|
"LoanCreditBalanceRefundPostBusinessEvent", "LoanCreditBalanceRefundPreBusinessEvent", "LoanDeleteChargeBusinessEvent",
|
||||||
"LoanDisbursalBusinessEvent", "LoanDisbursalTransactionBusinessEvent", "LoanForeClosurePostBusinessEvent",
|
"LoanDisbursalBusinessEvent", "LoanDisbursalTransactionBusinessEvent", "LoanForeClosurePostBusinessEvent",
|
||||||
"LoanForeClosurePreBusinessEvent", "LoanInitiateTransferBusinessEvent", "LoanInterestRecalculationBusinessEvent",
|
"LoanForeClosurePreBusinessEvent", "LoanInitiateTransferBusinessEvent", "LoanInterestRecalculationBusinessEvent",
|
||||||
|
|||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
/**
|
||||||
|
* 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.document;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import org.apache.fineract.avro.document.v1.DocumentDataV1;
|
||||||
|
import org.apache.fineract.avro.generator.ByteBufferSerializable;
|
||||||
|
import org.apache.fineract.infrastructure.documentmanagement.data.DocumentData;
|
||||||
|
import org.apache.fineract.infrastructure.documentmanagement.domain.Document;
|
||||||
|
import org.apache.fineract.infrastructure.documentmanagement.domain.StorageType;
|
||||||
|
import org.apache.fineract.infrastructure.documentmanagement.service.DocumentReadPlatformService;
|
||||||
|
import org.apache.fineract.infrastructure.event.business.domain.document.DocumentCreatedBusinessEvent;
|
||||||
|
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.document.DocumentDataMapper;
|
||||||
|
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class DocumentBusinessEventSerializerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private DocumentReadPlatformService readService;
|
||||||
|
@Mock
|
||||||
|
private DocumentDataMapper mapper;
|
||||||
|
|
||||||
|
private BusinessEventSerializer serializer;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
serializer = new DocumentBusinessEventSerializer(readService, mapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void documentStorageTypeIsPatchedIntoAvro() {
|
||||||
|
|
||||||
|
long docId = 42L;
|
||||||
|
String parentEntity = "loans";
|
||||||
|
long parentEntityId = 979L;
|
||||||
|
String name = "test_document";
|
||||||
|
String fileName = "test_document.pdf";
|
||||||
|
String fileType = "application/pdf";
|
||||||
|
String description = "Test document description";
|
||||||
|
Integer storageTypeInt = StorageType.FILE_SYSTEM.getValue();
|
||||||
|
|
||||||
|
Document document = mock(Document.class);
|
||||||
|
when(document.getId()).thenReturn(docId);
|
||||||
|
when(document.getParentEntityType()).thenReturn(parentEntity);
|
||||||
|
when(document.getParentEntityId()).thenReturn(parentEntityId);
|
||||||
|
when(document.getName()).thenReturn(name);
|
||||||
|
when(document.getFileName()).thenReturn(fileName);
|
||||||
|
when(document.getType()).thenReturn(fileType);
|
||||||
|
when(document.getDescription()).thenReturn(description);
|
||||||
|
when(document.storageType()).thenReturn(StorageType.fromInt(storageTypeInt));
|
||||||
|
|
||||||
|
DocumentCreatedBusinessEvent event = new DocumentCreatedBusinessEvent(document);
|
||||||
|
|
||||||
|
DocumentData dtoFromReadService = mock(DocumentData.class);
|
||||||
|
when(readService.retrieveDocument(parentEntity, parentEntityId, docId)).thenReturn(dtoFromReadService);
|
||||||
|
|
||||||
|
DocumentDataV1 avroFromMapper = DocumentDataV1.newBuilder().setId(docId).setParentEntityType(parentEntity)
|
||||||
|
.setParentEntityId(parentEntityId).setName(name).setFileName(fileName).setType(fileType).setDescription(description)
|
||||||
|
.build();
|
||||||
|
when(mapper.map(any(DocumentData.class))).thenReturn(avroFromMapper);
|
||||||
|
|
||||||
|
ByteBufferSerializable serialised = serializer.toAvroDTO(event);
|
||||||
|
assertNotNull(serialised);
|
||||||
|
|
||||||
|
DocumentDataV1 avro = (DocumentDataV1) serialised;
|
||||||
|
|
||||||
|
assertEquals(storageTypeInt, avro.getStorageType(), "Serializer must patch storageType taken from the domain entity");
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -73,6 +73,16 @@ public class ExternalEventConfigurationHelper {
|
|||||||
clientRejectBusinessEvent.put("enabled", false);
|
clientRejectBusinessEvent.put("enabled", false);
|
||||||
defaults.add(clientRejectBusinessEvent);
|
defaults.add(clientRejectBusinessEvent);
|
||||||
|
|
||||||
|
Map<String, Object> documentCreatedBusinessEvent = new HashMap<>();
|
||||||
|
documentCreatedBusinessEvent.put("type", "DocumentCreatedBusinessEvent");
|
||||||
|
documentCreatedBusinessEvent.put("enabled", false);
|
||||||
|
defaults.add(documentCreatedBusinessEvent);
|
||||||
|
|
||||||
|
Map<String, Object> documentDeletedBusinessEvent = new HashMap<>();
|
||||||
|
documentDeletedBusinessEvent.put("type", "DocumentDeletedBusinessEvent");
|
||||||
|
documentDeletedBusinessEvent.put("enabled", false);
|
||||||
|
defaults.add(documentDeletedBusinessEvent);
|
||||||
|
|
||||||
Map<String, Object> fixedDepositAccountCreateBusinessEvent = new HashMap<>();
|
Map<String, Object> fixedDepositAccountCreateBusinessEvent = new HashMap<>();
|
||||||
fixedDepositAccountCreateBusinessEvent.put("type", "FixedDepositAccountCreateBusinessEvent");
|
fixedDepositAccountCreateBusinessEvent.put("type", "FixedDepositAccountCreateBusinessEvent");
|
||||||
fixedDepositAccountCreateBusinessEvent.put("enabled", false);
|
fixedDepositAccountCreateBusinessEvent.put("enabled", false);
|
||||||
|
|||||||
Reference in New Issue
Block a user