FINERACT-2309: Emit external events on document upload and delete
This commit is contained in:
committed by
Adam Saghy
parent
496e37e3d4
commit
159eff0ad4
+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.DocumentNotFoundException;
|
||||
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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -48,13 +51,15 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr
|
||||
private final PlatformSecurityContext context;
|
||||
private final DocumentRepository documentRepository;
|
||||
private final ContentRepositoryFactory contentRepositoryFactory;
|
||||
private final BusinessEventNotifierService businessEventNotifierService;
|
||||
|
||||
@Autowired
|
||||
public DocumentWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final DocumentRepository documentRepository,
|
||||
final ContentRepositoryFactory documentStoreFactory) {
|
||||
final ContentRepositoryFactory documentStoreFactory, BusinessEventNotifierService businessEventNotifierService) {
|
||||
this.context = context;
|
||||
this.documentRepository = documentRepository;
|
||||
this.contentRepositoryFactory = documentStoreFactory;
|
||||
this.businessEventNotifierService = businessEventNotifierService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -78,6 +83,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr
|
||||
documentCommand.getDescription(), fileLocation, contentRepository.getStorageType());
|
||||
|
||||
this.documentRepository.saveAndFlush(document);
|
||||
businessEventNotifierService.notifyPostBusinessEvent(new DocumentCreatedBusinessEvent(document));
|
||||
|
||||
return document.getId();
|
||||
} catch (final JpaSystemException | DataIntegrityViolationException dve) {
|
||||
@@ -158,6 +164,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr
|
||||
|
||||
final ContentRepository contentRepository = this.contentRepositoryFactory.getRepository(document.storageType());
|
||||
contentRepository.deleteFile(document.getLocation());
|
||||
businessEventNotifierService.notifyPostBusinessEvent(new DocumentDeletedBusinessEvent(document));
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user